feat: add esbuild-package hook (#12783)

* feat: add esbuild-package hook

* feat: add esbuild-package hook
This commit is contained in:
Max Marze 2024-09-03 15:38:15 -04:00 committed by GitHub
parent 0b15744829
commit 8664adb59e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,6 +53,18 @@ class Esbuild {
await this._package()
}
},
'before:esbuild-package': async () => {},
}
this.commands = {
'esbuild-package': {
groupName: 'main',
options: {},
usage:
'Internal hook for esbuild to call for packaging logic prior to internal packaging',
lifecycleEvents: ['package'],
type: 'entrypoint',
},
}
}
@ -654,8 +666,11 @@ class Esbuild {
const limit = pLimit(concurrency)
await this.serverless.pluginManager.spawn('esbuild-package')
const packageIncludes = await globby(
this.serverless.service.package?.patterns ?? [],
{ cwd: this.serverless.serviceDir },
)
const zipPromises = Object.entries(functions).map(
@ -679,6 +694,7 @@ class Esbuild {
output.on('open', async () => {
const functionIncludes = await globby(
functionObject.package?.patterns ?? [],
{ cwd: this.serverless.serviceDir },
)
const includesToPackage = _.union(
@ -721,11 +737,15 @@ class Esbuild {
await Promise.all(
includesToPackage.map(async (filePath) => {
const stats = await stat(filePath)
const absolutePath = path.join(
this.serverless.config.serviceDir,
filePath,
)
const stats = await stat(absolutePath)
if (stats.isDirectory()) {
zip.directory(filePath, filePath)
zip.directory(absolutePath, filePath)
} else {
zip.file(filePath, { name: filePath })
zip.file(absolutePath, { name: filePath })
}
}),
)
@ -757,8 +777,11 @@ class Esbuild {
zipName,
)
await this.serverless.pluginManager.spawn('esbuild-package')
const packageIncludes = await globby(
this.serverless.service.package.patterns ?? [],
{ cwd: this.serverless.serviceDir },
)
const zip = archiver.create('zip')
@ -807,11 +830,12 @@ class Esbuild {
await Promise.all(
packageIncludes.map(async (filePath) => {
const stats = await stat(filePath)
const absolutePath = path.join(this.serverless.serviceDir, filePath)
const stats = await stat(absolutePath)
if (stats.isDirectory()) {
zip.directory(filePath, filePath)
zip.directory(absolutePath, filePath)
} else {
zip.file(filePath, { name: filePath })
zip.file(absolutePath, { name: filePath })
}
}),
)