mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
feat: add esbuild-package hook (#12783)
* feat: add esbuild-package hook * feat: add esbuild-package hook
This commit is contained in:
parent
0b15744829
commit
8664adb59e
@ -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 })
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user