serverless-esbuild
Advanced tools
Comparing version
@@ -68,3 +68,3 @@ "use strict"; | ||
const detailsDeps = ((_a = originalObject[depName]) === null || _a === void 0 ? void 0 : _a.dependencies) || details.dependencies; | ||
return ramda_1.uniq([...acc, depName, ...exports.flatDep(detailsDeps, undefined, originalObject)]); | ||
return (0, ramda_1.uniq)([...acc, depName, ...(0, exports.flatDep)(detailsDeps, undefined, originalObject)]); | ||
}, []); | ||
@@ -80,3 +80,3 @@ }; | ||
const requireMatch = matchAll(bundleContent, /require\("(.*?)"\)/gim); | ||
return ramda_1.uniq(Array.from(requireMatch).map(match => match[1])); | ||
return (0, ramda_1.uniq)(Array.from(requireMatch).map(match => match[1])); | ||
}; | ||
@@ -83,0 +83,0 @@ exports.getDepsFromBundle = getDepsFromBundle; |
@@ -43,3 +43,3 @@ "use strict"; | ||
constructor(serverless, options) { | ||
this.getCachedOptions = ramda_1.memoizeWith(ramda_1.always('cache'), () => { | ||
this.getCachedOptions = (0, ramda_1.memoizeWith)((0, ramda_1.always)('cache'), () => { | ||
var _a, _b; | ||
@@ -49,4 +49,4 @@ const runtimeMatcher = helper_1.providerRuntimeMatcher[this.serverless.service.provider.name]; | ||
const resolvedOptions = Object.assign({}, (target ? { target } : {})); | ||
const withDefaultOptions = ramda_1.mergeRight(DEFAULT_BUILD_OPTIONS); | ||
const withResolvedOptions = ramda_1.mergeRight(withDefaultOptions(resolvedOptions)); | ||
const withDefaultOptions = (0, ramda_1.mergeRight)(DEFAULT_BUILD_OPTIONS); | ||
const withResolvedOptions = (0, ramda_1.mergeRight)(withDefaultOptions(resolvedOptions)); | ||
return withResolvedOptions((_b = (_a = this.serverless.service.custom) === null || _a === void 0 ? void 0 : _a.esbuild) !== null && _b !== void 0 ? _b : {}); | ||
@@ -123,3 +123,3 @@ }); | ||
get rootFileNames() { | ||
return helper_1.extractFileNames(this.serviceDirPath, this.serverless.service.provider.name, this.functions); | ||
return (0, helper_1.extractFileNames)(this.serviceDirPath, this.serverless.service.provider.name, this.functions); | ||
} | ||
@@ -146,3 +146,3 @@ watch() { | ||
...(((_a = this.serverless.service.package) === null || _a === void 0 ? void 0 : _a.include) || []), | ||
...(((_b = this.serverless.service.package) === null || _b === void 0 ? void 0 : _b.exclude) || []).map(ramda_1.concat('!')), | ||
...(((_b = this.serverless.service.package) === null || _b === void 0 ? void 0 : _b.exclude) || []).map((0, ramda_1.concat)('!')), | ||
...(((_c = this.serverless.service.package) === null || _c === void 0 ? void 0 : _c.patterns) || []), | ||
@@ -157,3 +157,3 @@ '!node_modules/serverless-esbuild', | ||
...(((_d = fn.package) === null || _d === void 0 ? void 0 : _d.include) || []), | ||
...(((_e = fn.package) === null || _e === void 0 ? void 0 : _e.exclude) || []).map(ramda_1.concat('!')), | ||
...(((_e = fn.package) === null || _e === void 0 ? void 0 : _e.exclude) || []).map((0, ramda_1.concat)('!')), | ||
...(((_f = fn.package) === null || _f === void 0 ? void 0 : _f.patterns) || []), | ||
@@ -184,5 +184,5 @@ ]), | ||
} | ||
const result = yield esbuild_1.build(config); | ||
const result = yield (0, esbuild_1.build)(config); | ||
if (config.metafile) { | ||
fs.writeFileSync(path.join(this.buildDirPath, `${utils_1.trimExtension(entry)}-meta.json`), JSON.stringify(result.metafile, null, 2)); | ||
fs.writeFileSync(path.join(this.buildDirPath, `${(0, utils_1.trimExtension)(entry)}-meta.json`), JSON.stringify(result.metafile, null, 2)); | ||
} | ||
@@ -189,0 +189,0 @@ return { result, bundlePath, func, functionAlias }; |
@@ -20,4 +20,4 @@ "use strict"; | ||
if (/^(?:file:[^/]{2}|\.\/|\.\.\/)/.test(moduleVersion)) { | ||
const filePath = ramda_1.replace(/^file:/, '', moduleVersion); | ||
return ramda_1.replace(/\\/g, '/', `${ramda_1.startsWith('file:', moduleVersion) ? 'file:' : ''}${pathToPackageRoot}/${filePath}`); | ||
const filePath = (0, ramda_1.replace)(/^file:/, '', moduleVersion); | ||
return (0, ramda_1.replace)(/\\/g, '/', `${(0, ramda_1.startsWith)('file:', moduleVersion) ? 'file:' : ''}${pathToPackageRoot}/${filePath}`); | ||
} | ||
@@ -30,14 +30,14 @@ return moduleVersion; | ||
function addModulesToPackageJson(externalModules, packageJson, pathToPackageRoot) { | ||
ramda_1.forEach(externalModule => { | ||
const splitModule = ramda_1.split('@', externalModule); | ||
(0, ramda_1.forEach)(externalModule => { | ||
const splitModule = (0, ramda_1.split)('@', externalModule); | ||
// If we have a scoped module we have to re-add the @ | ||
if (ramda_1.startsWith('@', externalModule)) { | ||
if ((0, ramda_1.startsWith)('@', externalModule)) { | ||
splitModule.splice(0, 1); | ||
splitModule[0] = '@' + splitModule[0]; | ||
} | ||
let moduleVersion = ramda_1.join('@', ramda_1.tail(splitModule)); | ||
let moduleVersion = (0, ramda_1.join)('@', (0, ramda_1.tail)(splitModule)); | ||
// We have to rebase file references to the target package.json | ||
moduleVersion = rebaseFileReferences(pathToPackageRoot, moduleVersion); | ||
packageJson.dependencies = packageJson.dependencies || {}; | ||
packageJson.dependencies[ramda_1.head(splitModule)] = moduleVersion; | ||
packageJson.dependencies[(0, ramda_1.head)(splitModule)] = moduleVersion; | ||
}, externalModules); | ||
@@ -57,25 +57,45 @@ } | ||
// Get versions of all transient modules | ||
ramda_1.forEach(externalModule => { | ||
const moduleVersion = packageJson.dependencies[externalModule.external]; | ||
if (moduleVersion) { | ||
prodModules.push(`${externalModule.external}@${moduleVersion}`); | ||
(0, ramda_1.forEach)(externalModule => { | ||
// (1) If present in Dev Dependencies | ||
if (!packageJson.dependencies[externalModule.external] && | ||
packageJson.devDependencies[externalModule.external]) { | ||
// To minimize the chance of breaking setups we whitelist packages available on AWS here. These are due to the previously missing check | ||
// most likely set in devDependencies and should not lead to an error now. | ||
const ignoredDevDependencies = ['aws-sdk']; | ||
if (!(0, ramda_1.includes)(externalModule.external, ignoredDevDependencies)) { | ||
// Runtime dependency found in devDependencies but not forcefully excluded | ||
this.serverless.cli.log(`ERROR: Runtime dependency '${externalModule.external}' found in devDependencies.`); | ||
throw new this.serverless.classes.Error(`Serverless-webpack dependency error: ${externalModule.external}.`); | ||
} | ||
this.options.verbose && | ||
this.serverless.cli.log(`INFO: Runtime dependency '${externalModule.external}' found in devDependencies. It has been excluded automatically.`); | ||
} | ||
else { | ||
// (2) otherwise let's get the version | ||
// get module package - either from root or local node_modules - will be used for version and peer deps | ||
const rootModulePackagePath = path.join(path.dirname(rootPackageJsonPath), 'node_modules', externalModule.external, 'package.json'); | ||
const localModulePackagePath = path.join(path.dirname(packageJsonPath), 'node_modules', externalModule.external, 'package.json'); | ||
const modulePackagePath = fse.pathExistsSync(localModulePackagePath) | ||
? localModulePackagePath | ||
: fse.pathExistsSync(rootModulePackagePath) | ||
? rootModulePackagePath | ||
: null; | ||
const modulePackage = modulePackagePath ? require(modulePackagePath) : {}; | ||
// Get version | ||
const moduleVersion = packageJson.dependencies[externalModule.external] || modulePackage.version; | ||
// add dep with version if we have it - versionless otherwise | ||
if (moduleVersion) | ||
prodModules.push(`${externalModule.external}@${moduleVersion}`); | ||
else | ||
prodModules.push(externalModule.external); | ||
// Check if the module has any peer dependencies and include them too | ||
try { | ||
const rootModulePackagePath = path.join(path.dirname(rootPackageJsonPath), 'node_modules', externalModule.external, 'package.json'); | ||
const localModulePackagePath = path.join(path.dirname(packageJsonPath), 'node_modules', externalModule.external, 'package.json'); | ||
// check if module exists in local node_modules or root node_modules | ||
const modulePackagePath = fse.pathExistsSync(localModulePackagePath) | ||
? localModulePackagePath | ||
: fse.pathExistsSync(rootModulePackagePath) | ||
? rootModulePackagePath | ||
: null; | ||
const modulePackage = require(modulePackagePath); | ||
// find peer dependencies but remove optional ones and excluded ones | ||
const peerDependencies = modulePackage.peerDependencies; | ||
const optionalPeerDependencies = Object.keys(ramda_1.pickBy(val => val.optional, modulePackage.peerDependenciesMeta || {})); | ||
const peerDependenciesWithoutOptionals = ramda_1.omit([...optionalPeerDependencies, ...this.buildOptions.exclude], peerDependencies); | ||
if (!ramda_1.isEmpty(peerDependenciesWithoutOptionals)) { | ||
const optionalPeerDependencies = Object.keys((0, ramda_1.pickBy)(val => val.optional, modulePackage.peerDependenciesMeta || {})); | ||
const peerDependenciesWithoutOptionals = (0, ramda_1.omit)([...optionalPeerDependencies, ...this.buildOptions.exclude], peerDependencies); | ||
if (!(0, ramda_1.isEmpty)(peerDependenciesWithoutOptionals)) { | ||
this.options.verbose && | ||
this.serverless.cli.log(`Adding explicit non-optionals peers for dependency ${externalModule.external}`); | ||
const peerModules = getProdModules.call(this, ramda_1.compose(ramda_1.map(([external]) => ({ external })), ramda_1.toPairs)(peerDependenciesWithoutOptionals), packageJsonPath, rootPackageJsonPath); | ||
const peerModules = getProdModules.call(this, (0, ramda_1.compose)((0, ramda_1.map)(([external]) => ({ external })), ramda_1.toPairs)(peerDependenciesWithoutOptionals), packageJsonPath, rootPackageJsonPath); | ||
Array.prototype.push.apply(prodModules, peerModules); | ||
@@ -88,19 +108,2 @@ } | ||
} | ||
else { | ||
if (!packageJson.devDependencies || !packageJson.devDependencies[externalModule.external]) { | ||
prodModules.push(externalModule.external); | ||
} | ||
else { | ||
// To minimize the chance of breaking setups we whitelist packages available on AWS here. These are due to the previously missing check | ||
// most likely set in devDependencies and should not lead to an error now. | ||
const ignoredDevDependencies = ['aws-sdk']; | ||
if (!ramda_1.includes(externalModule.external, ignoredDevDependencies)) { | ||
// Runtime dependency found in devDependencies but not forcefully excluded | ||
this.serverless.cli.log(`ERROR: Runtime dependency '${externalModule.external}' found in devDependencies.`); | ||
throw new this.serverless.classes.Error(`Serverless-webpack dependency error: ${externalModule.external}.`); | ||
} | ||
this.options.verbose && | ||
this.serverless.cli.log(`INFO: Runtime dependency '${externalModule.external}' found in devDependencies. It has been excluded automatically.`); | ||
} | ||
} | ||
}, externalModules); | ||
@@ -126,5 +129,5 @@ return prodModules; | ||
const plugins = require(path.join(this.serviceDirPath, this.buildOptions.plugins)); | ||
if (plugins | ||
&& plugins.map(plugin => plugin.name).includes('node-externals') | ||
&& fse.existsSync(path.resolve(__dirname, '../../esbuild-node-externals/dist/utils.js'))) { | ||
if (plugins && | ||
plugins.map(plugin => plugin.name).includes('node-externals') && | ||
fse.existsSync(path.resolve(__dirname, '../../esbuild-node-externals/dist/utils.js'))) { | ||
const { findDependencies, findPackagePaths } = require('esbuild-node-externals/dist/utils'); | ||
@@ -134,7 +137,7 @@ this.buildOptions.external = findDependencies({ | ||
packagePaths: findPackagePaths(), | ||
allowList: [] | ||
allowList: [], | ||
}); | ||
} | ||
} | ||
const externals = ramda_1.without(this.buildOptions.exclude, this.buildOptions.external); | ||
const externals = (0, ramda_1.without)(this.buildOptions.exclude, this.buildOptions.external); | ||
if (!externals || !externals.length) { | ||
@@ -146,6 +149,6 @@ return; | ||
// if this is a yarn workspace, it will be the monorepo package.json | ||
const rootPackageJsonPath = path.join(utils_1.findProjectRoot(), './package.json'); | ||
const rootPackageJsonPath = path.join((0, utils_1.findProjectRoot)() || '', './package.json'); | ||
// get the local package.json by looking up until we hit a package.json file | ||
// if this is *not* a yarn workspace, it will be the same as rootPackageJsonPath | ||
const packageJsonPath = this.buildOptions.packagePath || path.join(utils_1.findUp('package.json'), './package.json'); | ||
const packageJsonPath = this.buildOptions.packagePath || path.join((0, utils_1.findUp)('package.json'), './package.json'); | ||
// Determine and create packager | ||
@@ -157,3 +160,4 @@ const packager = yield Packagers.get(this.buildOptions.packager); | ||
const packagerScripts = this.buildOptions.packagerOptions | ||
? ([].concat(this.buildOptions.packagerOptions.scripts || [])) | ||
? [] | ||
.concat(this.buildOptions.packagerOptions.scripts || []) | ||
.reduce((scripts, script, index) => { | ||
@@ -169,6 +173,6 @@ scripts[`script${index}`] = script; | ||
: rootPackageJson; | ||
const packageSections = ramda_1.pick(sectionNames, packageJson); | ||
if (!ramda_1.isEmpty(packageSections)) { | ||
const packageSections = (0, ramda_1.pick)(sectionNames, packageJson); | ||
if (!(0, ramda_1.isEmpty)(packageSections)) { | ||
this.options.verbose && | ||
this.serverless.cli.log(`Using package.json sections ${ramda_1.join(', ', ramda_1.keys(packageSections))}`); | ||
this.serverless.cli.log(`Using package.json sections ${(0, ramda_1.join)(', ', (0, ramda_1.keys)(packageSections))}`); | ||
} | ||
@@ -178,5 +182,5 @@ // Get first level dependency graph | ||
// (1) Generate dependency composition | ||
const externalModules = ramda_1.map(external => ({ external }), externals); | ||
const compositeModules = ramda_1.uniq(getProdModules.call(this, externalModules, packageJsonPath, rootPackageJsonPath)); | ||
if (ramda_1.isEmpty(compositeModules)) { | ||
const externalModules = (0, ramda_1.map)(external => ({ external }), externals); | ||
const compositeModules = (0, ramda_1.uniq)(getProdModules.call(this, externalModules, packageJsonPath, rootPackageJsonPath)); | ||
if ((0, ramda_1.isEmpty)(compositeModules)) { | ||
// The compiled code does not reference any external modules at all | ||
@@ -190,3 +194,3 @@ this.serverless.cli.log('No external modules needed'); | ||
// (1.a.1) Create a package.json | ||
const compositePackage = ramda_1.mergeRight({ | ||
const compositePackage = (0, ramda_1.mergeRight)({ | ||
name: this.serverless.service.service, | ||
@@ -209,3 +213,3 @@ version: '1.0.0', | ||
packageLockFile = packager.rebaseLockfile(relativePath, packageLockFile); | ||
if (ramda_1.is(Object)(packageLockFile)) { | ||
if ((0, ramda_1.is)(Object)(packageLockFile)) { | ||
packageLockFile = JSON.stringify(packageLockFile, null, 2); | ||
@@ -221,3 +225,3 @@ } | ||
// GCF Auto installs the package json | ||
if (ramda_1.path(['service', 'provider', 'name'], this.serverless) === 'google') { | ||
if ((0, ramda_1.path)(['service', 'provider', 'name'], this.serverless) === 'google') { | ||
return; | ||
@@ -224,0 +228,0 @@ } |
@@ -66,3 +66,3 @@ "use strict"; | ||
.map(localPath => ({ localPath, rootPath: path.join(this.buildDirPath, localPath) })); | ||
if (ramda_1.isEmpty(files)) { | ||
if ((0, ramda_1.isEmpty)(files)) { | ||
throw new Error('Packaging: No files found'); | ||
@@ -75,7 +75,7 @@ } | ||
// remove prefixes from individual extra files | ||
const filesPathList = ramda_1.pipe(ramda_1.reject(ramda_1.test(/^__only_[^/]+$/)), ramda_1.map(ramda_1.over(ramda_1.lensProp('localPath'), ramda_1.replace(/^__only_[^/]+\//, ''))))(files); | ||
const filesPathList = (0, ramda_1.pipe)((0, ramda_1.reject)((0, ramda_1.test)(/^__only_[^/]+$/)), (0, ramda_1.map)((0, ramda_1.over)((0, ramda_1.lensProp)('localPath'), (0, ramda_1.replace)(/^__only_[^/]+\//, ''))))(files); | ||
const startZip = Date.now(); | ||
yield utils_1.zip(artifactPath, filesPathList, this.buildDirPath); | ||
yield (0, utils_1.zip)(artifactPath, filesPathList, this.buildDirPath); | ||
const { size } = fs.statSync(artifactPath); | ||
this.serverless.cli.log(`Zip service ${this.serverless.service.service} - ${utils_1.humanSize(size)} [${Date.now() - startZip} ms]`); | ||
this.serverless.cli.log(`Zip service ${this.serverless.service.service} - ${(0, utils_1.humanSize)(size)} [${Date.now() - startZip} ms]`); | ||
// defined present zip as output artifact | ||
@@ -91,3 +91,3 @@ this.serverless.service.package.artifact = artifactPath; | ||
// get a list of externals | ||
const externals = ramda_1.without(this.buildOptions.exclude, this.buildOptions.external); | ||
const externals = (0, ramda_1.without)(this.buildOptions.exclude, this.buildOptions.external); | ||
const hasExternals = !!(externals === null || externals === void 0 ? void 0 : externals.length); | ||
@@ -105,5 +105,5 @@ // get a tree of all production dependencies | ||
if (hasExternals) { | ||
const bundleDeps = helper_1.getDepsFromBundle(path.join(this.buildDirPath, bundlePath)); | ||
const bundleExternals = ramda_1.intersection(bundleDeps, externals); | ||
depWhiteList = helper_1.flatDep(packagerDependenciesList.dependencies, bundleExternals); | ||
const bundleDeps = (0, helper_1.getDepsFromBundle)(path.join(this.buildDirPath, bundlePath)); | ||
const bundleExternals = (0, ramda_1.intersection)(bundleDeps, externals); | ||
depWhiteList = (0, helper_1.flatDep)(packagerDependenciesList.dependencies, bundleExternals); | ||
} | ||
@@ -128,3 +128,3 @@ const zipName = `${name}.zip`; | ||
// this is needed for dependencies that maps to a path (like scoped ones) | ||
!depWhiteList.find(dep => helper_1.doSharePath(localPath, 'node_modules/' + dep))) | ||
!depWhiteList.find(dep => (0, helper_1.doSharePath)(localPath, 'node_modules/' + dep))) | ||
return false; | ||
@@ -140,5 +140,5 @@ } | ||
const startZip = Date.now(); | ||
yield utils_1.zip(artifactPath, filesPathList, this.buildDirPath); | ||
yield (0, utils_1.zip)(artifactPath, filesPathList, this.buildDirPath); | ||
const { size } = fs.statSync(artifactPath); | ||
this.serverless.cli.log(`Zip function: ${func.name} - ${utils_1.humanSize(size)} [${Date.now() - startZip} ms]`); | ||
this.serverless.cli.log(`Zip function: ${func.name} - ${(0, utils_1.humanSize)(size)} [${Date.now() - startZip} ms]`); | ||
// defined present zip as output artifact | ||
@@ -145,0 +145,0 @@ setFunctionArtifactPath.call(this, func, path.relative(this.serviceDirPath, artifactPath)); |
@@ -44,3 +44,3 @@ "use strict"; | ||
try { | ||
const processOutput = yield utils_1.spawnProcess(command, args, { cwd }); | ||
const processOutput = yield (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
const depJson = processOutput.stdout; | ||
@@ -52,11 +52,11 @@ return JSON.parse(depJson); | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = ramda_1.split('\n', err.stderr); | ||
const failed = ramda_1.reduce((f, error) => { | ||
const errors = (0, ramda_1.split)('\n', err.stderr); | ||
const failed = (0, ramda_1.reduce)((f, error) => { | ||
if (f) { | ||
return true; | ||
} | ||
return (!ramda_1.isEmpty(error) && | ||
!ramda_1.any(ignoredError => ramda_1.startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredNpmErrors)); | ||
return (!(0, ramda_1.isEmpty)(error) && | ||
!(0, ramda_1.any)(ignoredError => (0, ramda_1.startsWith)(`npm ERR! ${ignoredError.npmError}`, error), ignoredNpmErrors)); | ||
}, false, errors); | ||
if (!failed && !ramda_1.isEmpty(err.stdout)) { | ||
if (!failed && !(0, ramda_1.isEmpty)(err.stdout)) { | ||
return { stdout: err.stdout }; | ||
@@ -71,4 +71,4 @@ } | ||
if (/^file:[^/]{2}/.test(moduleVersion)) { | ||
const filePath = ramda_1.replace(/^file:/, '', moduleVersion); | ||
return ramda_1.replace(/\\/g, '/', `file:${pathToPackageRoot}/${filePath}`); | ||
const filePath = (0, ramda_1.replace)(/^file:/, '', moduleVersion); | ||
return (0, ramda_1.replace)(/\\/g, '/', `file:${pathToPackageRoot}/${filePath}`); | ||
} | ||
@@ -99,3 +99,3 @@ return moduleVersion; | ||
const args = ['install']; | ||
yield utils_1.spawnProcess(command, args, { cwd }); | ||
yield (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
}); | ||
@@ -107,3 +107,3 @@ } | ||
const args = ['prune']; | ||
yield utils_1.spawnProcess(command, args, { cwd }); | ||
yield (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
}); | ||
@@ -116,3 +116,3 @@ } | ||
const args = ['run', scriptName]; | ||
return utils_1.spawnProcess(command, args, { cwd }); | ||
return (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
})); | ||
@@ -119,0 +119,0 @@ }); |
@@ -40,3 +40,3 @@ "use strict"; | ||
try { | ||
processOutput = yield utils_1.spawnProcess(command, args, { cwd }); | ||
processOutput = yield (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
} | ||
@@ -46,11 +46,11 @@ catch (err) { | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = ramda_1.split('\n', err.stderr); | ||
const failed = ramda_1.reduce((f, error) => { | ||
const errors = (0, ramda_1.split)('\n', err.stderr); | ||
const failed = (0, ramda_1.reduce)((f, error) => { | ||
if (f) { | ||
return true; | ||
} | ||
return (!ramda_1.isEmpty(error) && | ||
!ramda_1.any(ignoredError => ramda_1.startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredYarnErrors)); | ||
return (!(0, ramda_1.isEmpty)(error) && | ||
!(0, ramda_1.any)(ignoredError => (0, ramda_1.startsWith)(`npm ERR! ${ignoredError.npmError}`, error), ignoredYarnErrors)); | ||
}, false, errors); | ||
if (!failed && !ramda_1.isEmpty(err.stdout)) { | ||
if (!failed && !(0, ramda_1.isEmpty)(err.stdout)) { | ||
return { stdout: err.stdout }; | ||
@@ -63,11 +63,11 @@ } | ||
const parsedTree = JSON.parse(depJson); | ||
const convertTrees = convertingTrees => ramda_1.reduce((__, tree) => { | ||
const splitModule = ramda_1.split('@', tree.name); | ||
const convertTrees = convertingTrees => (0, ramda_1.reduce)((__, tree) => { | ||
const splitModule = (0, ramda_1.split)('@', tree.name); | ||
// If we have a scoped module we have to re-add the @ | ||
if (ramda_1.startsWith('@', tree.name)) { | ||
if ((0, ramda_1.startsWith)('@', tree.name)) { | ||
splitModule.splice(0, 1); | ||
splitModule[0] = '@' + splitModule[0]; | ||
} | ||
__[ramda_1.head(splitModule)] = { | ||
version: ramda_1.join('@', ramda_1.tail(splitModule)), | ||
__[(0, ramda_1.head)(splitModule)] = { | ||
version: (0, ramda_1.join)('@', (0, ramda_1.tail)(splitModule)), | ||
dependencies: convertTrees(tree.children), | ||
@@ -77,3 +77,3 @@ }; | ||
}, {}, convertingTrees || []); | ||
const trees = ramda_1.pathOr([], ['data', 'trees'], parsedTree); | ||
const trees = (0, ramda_1.pathOr)([], ['data', 'trees'], parsedTree); | ||
const result = { | ||
@@ -94,7 +94,7 @@ problems: [], | ||
oldRef: match[1], | ||
newRef: ramda_1.replace(/\\/g, '/', `${pathToPackageRoot}/${match[1]}`), | ||
newRef: (0, ramda_1.replace)(/\\/g, '/', `${pathToPackageRoot}/${match[1]}`), | ||
}); | ||
} | ||
// Replace all lines in lockfile | ||
return ramda_1.reduce((__, replacement) => ramda_1.replace(__, replacement.oldRef, replacement.newRef), lockfile, replacements); | ||
return (0, ramda_1.reduce)((__, replacement) => (0, ramda_1.replace)(__, replacement.oldRef, replacement.newRef), lockfile, replacements); | ||
} | ||
@@ -107,3 +107,3 @@ install(cwd, useLockfile = true) { | ||
: ['install', '--non-interactive']; | ||
yield utils_1.spawnProcess(command, args, { cwd }); | ||
yield (0, utils_1.spawnProcess)(command, args, { cwd }); | ||
}); | ||
@@ -118,3 +118,3 @@ } | ||
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; | ||
yield Promise.all(scriptNames.map(scriptName => utils_1.spawnProcess(command, ['run', scriptName], { cwd }))); | ||
yield Promise.all(scriptNames.map(scriptName => (0, utils_1.spawnProcess)(command, ['run', scriptName], { cwd }))); | ||
}); | ||
@@ -121,0 +121,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
if (!((_d = (_c = (_b = (_a = this.serverless) === null || _a === void 0 ? void 0 : _a.service) === null || _b === void 0 ? void 0 : _b.custom) === null || _c === void 0 ? void 0 : _c['serverless-offline']) === null || _d === void 0 ? void 0 : _d.location)) { | ||
const newServerless = ramda_1.assocPath(['service', 'custom', 'serverless-offline', 'location'], path_1.relative(this.serviceDirPath, this.buildDirPath), this.serverless); | ||
const newServerless = (0, ramda_1.assocPath)(['service', 'custom', 'serverless-offline', 'location'], (0, path_1.relative)(this.serviceDirPath, this.buildDirPath), this.serverless); | ||
this.serverless.service.custom = newServerless.service.custom; | ||
@@ -13,0 +13,0 @@ } |
@@ -8,3 +8,3 @@ "use strict"; | ||
/* Broken implementation in pack-externals we're trying to fix. */ | ||
const rootPackageJsonPath = path.join(utils_1.findProjectRoot(), './package.json'); | ||
const rootPackageJsonPath = path.join((0, utils_1.findProjectRoot)() || '', './package.json'); | ||
/* Looking up at project root relative to ./src/tests/ */ | ||
@@ -11,0 +11,0 @@ expect(rootPackageJsonPath).toEqual(path.join(__dirname, '../../package.json')); |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (exitCode !== 0) { | ||
reject(new SpawnError(`${command} ${ramda_1.join(' ', args)} failed with code ${exitCode}`, stdout, stderr)); | ||
reject(new SpawnError(`${command} ${(0, ramda_1.join)(' ', args)} failed with code ${exitCode}`, stdout, stderr)); | ||
} | ||
@@ -61,5 +61,9 @@ else { | ||
*/ | ||
function findUp(name, directory = process.cwd()) { | ||
function findUp(names, directory = process.cwd()) { | ||
const absoluteDirectory = path.resolve(directory); | ||
if (typeof name === 'string') { | ||
if (typeof names === 'string') { | ||
names = [names]; | ||
} | ||
/* For vs. .forEach so it can exit when we get a hit. */ | ||
for (const name of names) { | ||
if (fs.existsSync(path.join(directory, name))) { | ||
@@ -69,10 +73,2 @@ return directory; | ||
} | ||
else { | ||
/* For vs. .forEach so it can exit when we get a hit. */ | ||
for (let x = 0; x < name.length; x++) { | ||
if (fs.existsSync(path.join(directory, name[x]))) { | ||
return directory; | ||
} | ||
} | ||
} | ||
const { root } = path.parse(absoluteDirectory); | ||
@@ -82,3 +78,3 @@ if (absoluteDirectory === root) { | ||
} | ||
return findUp(name, path.dirname(absoluteDirectory)); | ||
return findUp(names, path.dirname(absoluteDirectory)); | ||
} | ||
@@ -90,3 +86,3 @@ exports.findUp = findUp; | ||
function findProjectRoot(rootDir) { | ||
return rootDir !== null && rootDir !== void 0 ? rootDir : findUp(['yarn.lock', 'package-lock.json', 'package.json']); | ||
return rootDir !== null && rootDir !== void 0 ? rootDir : findUp(['yarn.lock', 'package-lock.json']); | ||
} | ||
@@ -102,6 +98,6 @@ exports.findProjectRoot = findProjectRoot; | ||
fs.mkdirpSync(path.dirname(zipPath)); | ||
return bestzip_1.bestzip({ | ||
return (0, bestzip_1.bestzip)({ | ||
source: filesPathList.map((file) => file.localPath), | ||
destination: zipPath, | ||
cwd: workingDir || process.cwd() | ||
cwd: workingDir || process.cwd(), | ||
}); | ||
@@ -108,0 +104,0 @@ }; |
{ | ||
"name": "serverless-esbuild", | ||
"description": "Serverless plugin for zero-config JavaScript and TypeScript code bundling using extremely fast esbuild", | ||
"version": "1.16.1", | ||
"version": "1.16.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": "Victor Korzunin", |
@@ -166,2 +166,12 @@ # 💨 serverless-esbuild | ||
## Plugin-Specific Options in Serverless Config | ||
These options belong under `custom.esbuild` in your `serverless.yml` or `serverless.ts` file, and are specific to this plugin (these are not esbuild API options): | ||
- `packager`: Package to use (npm or yarn - npm is default) | ||
- `packagePath`: Path to the `package.json` file (`./package.json` is default) | ||
- `packagerOptions`: | ||
- `scripts`: A string or array of scripts to be executed, currently only supports 'scripts' for npm and yarn | ||
- `exclude`: An array of dependencies to exclude (declares it as an external as well as excludes it from Lambda ZIP file) | ||
## Author | ||
@@ -168,0 +178,0 @@ |
68171
1.76%185
5.71%