serverless-webpack
Advanced tools
Comparing version 5.3.1 to 5.3.2
163
index.js
@@ -20,3 +20,2 @@ 'use strict'; | ||
class ServerlessWebpack { | ||
static get lib() { | ||
@@ -32,6 +31,6 @@ return lib; | ||
(_.has(this.serverless, 'service.custom.webpack') && | ||
_.isString(this.serverless.service.custom.webpack) && | ||
_.endsWith(this.serverless.service.custom.webpack, '.ts')) || | ||
_.isString(this.serverless.service.custom.webpack) && | ||
_.endsWith(this.serverless.service.custom.webpack, '.ts')) || | ||
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') && | ||
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts')) | ||
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts')) | ||
) { | ||
@@ -59,10 +58,8 @@ require('ts-node/register'); | ||
usage: 'Bundle with Webpack', | ||
lifecycleEvents: [ | ||
'webpack' | ||
], | ||
lifecycleEvents: ['webpack'], | ||
options: { | ||
out: { | ||
usage: 'Path to output directory', | ||
shortcut: 'o', | ||
}, | ||
shortcut: 'o' | ||
} | ||
}, | ||
@@ -72,17 +69,11 @@ commands: { | ||
type: 'entrypoint', | ||
lifecycleEvents: [ | ||
'validate', | ||
], | ||
lifecycleEvents: ['validate'] | ||
}, | ||
compile: { | ||
type: 'entrypoint', | ||
lifecycleEvents: [ | ||
'compile', | ||
], | ||
lifecycleEvents: ['compile'], | ||
commands: { | ||
watch: { | ||
type: 'entrypoint', | ||
lifecycleEvents: [ | ||
'compile' | ||
] | ||
lifecycleEvents: ['compile'] | ||
} | ||
@@ -93,40 +84,39 @@ } | ||
type: 'entrypoint', | ||
lifecycleEvents: [ | ||
'packExternalModules', | ||
'packageModules' | ||
], | ||
}, | ||
}, | ||
}, | ||
lifecycleEvents: [ 'packExternalModules', 'packageModules' ] | ||
} | ||
} | ||
} | ||
}; | ||
this.hooks = { | ||
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
'before:package:createDeploymentArtifacts': () => | ||
BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
'after:package:createDeploymentArtifacts': () => BbPromise.bind(this) | ||
.then(this.cleanup), | ||
'after:package:createDeploymentArtifacts': () => BbPromise.bind(this).then(this.cleanup), | ||
'before:deploy:function:packageFunction': () => BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
'before:deploy:function:packageFunction': () => | ||
BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
'before:invoke:local:invoke': () => BbPromise.bind(this) | ||
.then(() => { | ||
lib.webpack.isLocal = true; | ||
// --no-build override | ||
if (this.options.build === false) { | ||
this.skipCompile = true; | ||
} | ||
'before:invoke:local:invoke': () => | ||
BbPromise.bind(this) | ||
.then(() => { | ||
lib.webpack.isLocal = true; | ||
// --no-build override | ||
if (this.options.build === false) { | ||
this.skipCompile = true; | ||
} | ||
return this.serverless.pluginManager.spawn('webpack:validate'); | ||
}) | ||
.then(() => this.skipCompile ? BbPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(this.prepareLocalInvoke), | ||
return this.serverless.pluginManager.spawn('webpack:validate'); | ||
}) | ||
.then(() => (this.skipCompile ? BbPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile'))) | ||
.then(this.prepareLocalInvoke), | ||
'after:invoke:local:invoke': () => BbPromise.bind(this) | ||
.then(() => { | ||
'after:invoke:local:invoke': () => | ||
BbPromise.bind(this).then(() => { | ||
if (this.options.watch && !this.isWatching) { | ||
@@ -138,11 +128,12 @@ return this.watch('invoke:local'); | ||
'before:run:run': () => BbPromise.bind(this) | ||
.then(() => _.set(this.serverless, 'service.package.individually', false)) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(this.packExternalModules) | ||
.then(this.prepareRun), | ||
'before:run:run': () => | ||
BbPromise.bind(this) | ||
.then(() => _.set(this.serverless, 'service.package.individually', false)) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(this.packExternalModules) | ||
.then(this.prepareRun), | ||
'after:run:run': () => BbPromise.bind(this) | ||
.then(() => { | ||
'after:run:run': () => | ||
BbPromise.bind(this).then(() => { | ||
if (this.options.watch && !this.isWatching) { | ||
@@ -154,6 +145,7 @@ return this.watch(this.watchRun.bind(this)); | ||
'webpack:webpack': () => BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
'webpack:webpack': () => | ||
BbPromise.bind(this) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:validate')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:package')), | ||
@@ -163,36 +155,35 @@ /* | ||
*/ | ||
'webpack:validate:validate': () => BbPromise.bind(this) | ||
.then(this.validate), | ||
'webpack:validate:validate': () => BbPromise.bind(this).then(this.validate), | ||
'webpack:compile:compile': () => BbPromise.bind(this) | ||
.then(this.compile), | ||
'webpack:compile:compile': () => BbPromise.bind(this).then(this.compile), | ||
'webpack:compile:watch:compile': () => BbPromise.resolve(), | ||
'webpack:package:packExternalModules': () => BbPromise.bind(this) | ||
.then(this.packExternalModules), | ||
'webpack:package:packExternalModules': () => BbPromise.bind(this).then(this.packExternalModules), | ||
'webpack:package:packageModules': () => BbPromise.bind(this) | ||
.then(this.packageModules), | ||
'webpack:package:packageModules': () => BbPromise.bind(this).then(this.packageModules), | ||
'before:offline:start': () => BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareOfflineInvoke) | ||
.then(this.wpwatch), | ||
'before:offline:start': () => | ||
BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareOfflineInvoke) | ||
.then(this.wpwatch), | ||
'before:offline:start:init': () => BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareOfflineInvoke) | ||
.then(this.wpwatch), | ||
'before:offline:start:init': () => | ||
BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareOfflineInvoke) | ||
.then(this.wpwatch), | ||
'before:step-functions-offline:start': () => BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareStepOfflineInvoke) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')), | ||
'before:step-functions-offline:start': () => | ||
BbPromise.bind(this) | ||
.tap(() => { | ||
lib.webpack.isLocal = true; | ||
}) | ||
.then(this.prepareStepOfflineInvoke) | ||
.then(() => this.serverless.pluginManager.spawn('webpack:compile')) | ||
}; | ||
@@ -199,0 +190,0 @@ } |
@@ -21,3 +21,3 @@ 'use strict'; | ||
return BbPromise.resolve(); | ||
}, | ||
} | ||
}; |
@@ -14,38 +14,36 @@ 'use strict'; | ||
return BbPromise | ||
.fromCallback(cb => compiler.run(cb)) | ||
.then(stats => { | ||
return BbPromise.fromCallback(cb => compiler.run(cb)).then(stats => { | ||
if (!this.multiCompile) { | ||
stats = { stats: [stats] }; | ||
} | ||
if (!this.multiCompile) { | ||
stats = { stats: [stats] }; | ||
const compileOutputPaths = []; | ||
const consoleStats = this.webpackConfig.stats || | ||
_.get(this, 'webpackConfig[0].stats') || { | ||
colors: tty.isatty(process.stdout.fd), | ||
hash: false, | ||
version: false, | ||
chunks: false, | ||
children: false | ||
}; | ||
_.forEach(stats.stats, compileStats => { | ||
const statsOutput = compileStats.toString(consoleStats); | ||
if (statsOutput) { | ||
this.serverless.cli.consoleLog(statsOutput); | ||
} | ||
const compileOutputPaths = []; | ||
const consoleStats = this.webpackConfig.stats || _.get(this, 'webpackConfig[0].stats') || { | ||
colors: tty.isatty(process.stdout.fd), | ||
hash: false, | ||
version: false, | ||
chunks: false, | ||
children: false | ||
}; | ||
if (compileStats.compilation.errors.length) { | ||
throw new Error('Webpack compilation error, see above'); | ||
} | ||
_.forEach(stats.stats, compileStats => { | ||
const statsOutput = compileStats.toString(consoleStats); | ||
if (statsOutput) { | ||
this.serverless.cli.consoleLog(statsOutput); | ||
} | ||
compileOutputPaths.push(compileStats.compilation.compiler.outputPath); | ||
}); | ||
if (compileStats.compilation.errors.length) { | ||
throw new Error('Webpack compilation error, see above'); | ||
} | ||
this.compileOutputPaths = compileOutputPaths; | ||
this.compileStats = stats; | ||
compileOutputPaths.push(compileStats.compilation.compiler.outputPath); | ||
}); | ||
this.compileOutputPaths = compileOutputPaths; | ||
this.compileStats = stats; | ||
return BbPromise.resolve(); | ||
}); | ||
}, | ||
return BbPromise.resolve(); | ||
}); | ||
} | ||
}; |
@@ -21,5 +21,3 @@ 'use strict'; | ||
class Configuration { | ||
constructor(custom) { | ||
this._config = {}; | ||
@@ -84,2 +82,2 @@ this._hasLegacyConfig = false; | ||
module.exports = Configuration; | ||
module.exports = Configuration; |
@@ -21,3 +21,3 @@ 'use strict'; | ||
func.package = { | ||
artifact: artifactPath, | ||
artifact: artifactPath | ||
}; | ||
@@ -30,6 +30,3 @@ } | ||
// Create artifact in temp path and move it to the package path (if any) later | ||
const artifactFilePath = path.join(this.serverless.config.servicePath, | ||
'.serverless', | ||
name | ||
); | ||
const artifactFilePath = path.join(this.serverless.config.servicePath, '.serverless', name); | ||
this.serverless.utils.writeFileDir(artifactFilePath); | ||
@@ -43,8 +40,7 @@ | ||
silent: true, | ||
follow: true, | ||
follow: true | ||
}); | ||
if (_.isEmpty(files)) { | ||
const error = new this.serverless | ||
.classes.Error('Packaging: No files found'); | ||
const error = new this.serverless.classes.Error('Packaging: No files found'); | ||
return BbPromise.reject(error); | ||
@@ -57,6 +53,3 @@ } | ||
_.forEach(files, filePath => { | ||
const fullPath = path.resolve( | ||
directory, | ||
filePath | ||
); | ||
const fullPath = path.resolve(directory, filePath); | ||
@@ -69,3 +62,3 @@ const stats = fs.statSync(fullPath); | ||
mode: stats.mode, | ||
date: new Date(0), // necessary to get the same hash when zipping the same content | ||
date: new Date(0) // necessary to get the same hash when zipping the same content | ||
}); | ||
@@ -80,3 +73,3 @@ } | ||
output.on('close', () => resolve(artifactFilePath)); | ||
zip.on('error', (err) => reject(err)); | ||
zip.on('error', err => reject(err)); | ||
}); | ||
@@ -95,13 +88,23 @@ } | ||
const startZip = _.now(); | ||
return zip.call(this, modulePath, filename) | ||
.tap(() => this.options.verbose && | ||
this.serverless.cli.log(`Zip ${_.isEmpty(entryFunction) ? 'service' : 'function'}: ${modulePath} [${_.now() - startZip} ms]`)) | ||
.then(artifactPath => { | ||
if (_.get(this.serverless, 'service.package.individually')) { | ||
setArtifactPath.call(this, entryFunction.funcName, entryFunction.func, path.relative(this.serverless.config.servicePath, artifactPath)); | ||
} | ||
return artifactPath; | ||
}); | ||
}) | ||
.then(artifacts => { | ||
return zip | ||
.call(this, modulePath, filename) | ||
.tap( | ||
() => | ||
this.options.verbose && | ||
this.serverless.cli.log( | ||
`Zip ${_.isEmpty(entryFunction) ? 'service' : 'function'}: ${modulePath} [${_.now() - startZip} ms]` | ||
) | ||
) | ||
.then(artifactPath => { | ||
if (_.get(this.serverless, 'service.package.individually')) { | ||
setArtifactPath.call( | ||
this, | ||
entryFunction.funcName, | ||
entryFunction.func, | ||
path.relative(this.serverless.config.servicePath, artifactPath) | ||
); | ||
} | ||
return artifactPath; | ||
}); | ||
}).then(artifacts => { | ||
if (!_.get(this.serverless, 'service.package.individually') && !_.isEmpty(artifacts)) { | ||
@@ -116,3 +119,7 @@ // Set the service artifact to all functions | ||
if (_.get(this.serverless, 'service.provider.name') === 'google') { | ||
_.set(this.serverless, 'service.package.artifact', path.relative(this.serverless.config.servicePath, artifacts[0])); | ||
_.set( | ||
this.serverless, | ||
'service.package.artifact', | ||
path.relative(this.serverless.config.servicePath, artifacts[0]) | ||
); | ||
} | ||
@@ -119,0 +126,0 @@ } |
'use strict'; | ||
/** | ||
* Factory for supported packagers. | ||
* | ||
* | ||
* All packagers must implement the following interface: | ||
* | ||
* | ||
* interface Packager { | ||
* | ||
* | ||
* static get lockfileName(): string; | ||
@@ -17,3 +17,3 @@ * static get copyPackageSectionNames(): Array<string>; | ||
* static runScripts(cwd: string, scriptNames): BbPromise<void>; | ||
* | ||
* | ||
* } | ||
@@ -20,0 +20,0 @@ */ |
@@ -11,3 +11,4 @@ 'use strict'; | ||
class NPM { | ||
static get lockfileName() { // eslint-disable-line lodash/prefer-constant | ||
// eslint-disable-next-line lodash/prefer-constant | ||
static get lockfileName() { | ||
return 'package-lock.json'; | ||
@@ -20,3 +21,4 @@ } | ||
static get mustCopyModules() { // eslint-disable-line lodash/prefer-constant | ||
// eslint-disable-next-line lodash/prefer-constant | ||
static get mustCopyModules() { | ||
return true; | ||
@@ -30,3 +32,3 @@ } | ||
'ls', | ||
'-prod', // Only prod dependencies | ||
'-prod', // Only prod dependencies | ||
'-json', | ||
@@ -39,3 +41,3 @@ `-depth=${depth || 1}` | ||
{ npmError: 'missing', log: false }, | ||
{ npmError: 'peer dep missing', log: true }, | ||
{ npmError: 'peer dep missing', log: true } | ||
]; | ||
@@ -46,22 +48,29 @@ | ||
}) | ||
.catch(err => { | ||
if (err instanceof Utils.SpawnError) { | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = _.split(err.stderr, '\n'); | ||
const failed = _.reduce(errors, (failed, error) => { | ||
if (failed) { | ||
return true; | ||
.catch(err => { | ||
if (err instanceof Utils.SpawnError) { | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = _.split(err.stderr, '\n'); | ||
const failed = _.reduce( | ||
errors, | ||
(failed, error) => { | ||
if (failed) { | ||
return true; | ||
} | ||
return ( | ||
!_.isEmpty(error) && | ||
!_.some(ignoredNpmErrors, ignoredError => _.startsWith(error, `npm ERR! ${ignoredError.npmError}`)) | ||
); | ||
}, | ||
false | ||
); | ||
if (!failed && !_.isEmpty(err.stdout)) { | ||
return BbPromise.resolve({ stdout: err.stdout }); | ||
} | ||
return !_.isEmpty(error) && !_.some(ignoredNpmErrors, ignoredError => _.startsWith(error, `npm ERR! ${ignoredError.npmError}`)); | ||
}, false); | ||
if (!failed && !_.isEmpty(err.stdout)) { | ||
return BbPromise.resolve({ stdout: err.stdout }); | ||
} | ||
} | ||
return BbPromise.reject(err); | ||
}) | ||
.then(processOutput => processOutput.stdout) | ||
.then(depJson => BbPromise.try(() => JSON.parse(depJson))); | ||
return BbPromise.reject(err); | ||
}) | ||
.then(processOutput => processOutput.stdout) | ||
.then(depJson => BbPromise.try(() => JSON.parse(depJson))); | ||
} | ||
@@ -74,10 +83,10 @@ | ||
} | ||
return moduleVersion; | ||
} | ||
/** | ||
* We should not be modifying 'package-lock.json' | ||
* because this file should be treated as internal to npm. | ||
* | ||
* | ||
* Rebase package-lock is a temporary workaround and must be | ||
@@ -90,3 +99,3 @@ * removed as soon as https://github.com/npm/npm/issues/19183 gets fixed. | ||
} | ||
if (lockfile.dependencies) { | ||
@@ -100,3 +109,3 @@ _.forIn(lockfile.dependencies, lockedDependency => { | ||
} | ||
static install(cwd) { | ||
@@ -106,4 +115,3 @@ const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; | ||
return Utils.spawnProcess(command, args, { cwd }) | ||
.return(); | ||
return Utils.spawnProcess(command, args, { cwd }).return(); | ||
} | ||
@@ -115,4 +123,3 @@ | ||
return Utils.spawnProcess(command, args, { cwd }) | ||
.return(); | ||
return Utils.spawnProcess(command, args, { cwd }).return(); | ||
} | ||
@@ -123,10 +130,6 @@ | ||
return BbPromise.mapSeries(scriptNames, scriptName => { | ||
const args = [ | ||
'run', | ||
scriptName | ||
]; | ||
const args = [ 'run', scriptName ]; | ||
return Utils.spawnProcess(command, args, { cwd }); | ||
}) | ||
.return(); | ||
}).return(); | ||
} | ||
@@ -133,0 +136,0 @@ } |
'use strict'; | ||
/** | ||
* Yarn packager. | ||
* | ||
* | ||
* Yarn specific packagerOptions (default): | ||
@@ -15,3 +15,4 @@ * flat (false) - Use --flat with install | ||
class Yarn { | ||
static get lockfileName() { // eslint-disable-line lodash/prefer-constant | ||
// eslint-disable-next-line lodash/prefer-constant | ||
static get lockfileName() { | ||
return 'yarn.lock'; | ||
@@ -24,3 +25,4 @@ } | ||
static get mustCopyModules() { // eslint-disable-line lodash/prefer-constant | ||
// eslint-disable-next-line lodash/prefer-constant | ||
static get mustCopyModules() { | ||
return false; | ||
@@ -31,8 +33,3 @@ } | ||
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; | ||
const args = [ | ||
'list', | ||
`--depth=${depth || 1}`, | ||
'--json', | ||
'--production' | ||
]; | ||
const args = [ 'list', `--depth=${depth || 1}`, '--json', '--production' ]; | ||
@@ -45,44 +42,56 @@ // If we need to ignore some errors add them here | ||
}) | ||
.catch(err => { | ||
if (err instanceof Utils.SpawnError) { | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = _.split(err.stderr, '\n'); | ||
const failed = _.reduce(errors, (failed, error) => { | ||
if (failed) { | ||
return true; | ||
.catch(err => { | ||
if (err instanceof Utils.SpawnError) { | ||
// Only exit with an error if we have critical npm errors for 2nd level inside | ||
const errors = _.split(err.stderr, '\n'); | ||
const failed = _.reduce( | ||
errors, | ||
(failed, error) => { | ||
if (failed) { | ||
return true; | ||
} | ||
return ( | ||
!_.isEmpty(error) && | ||
!_.some(ignoredYarnErrors, ignoredError => _.startsWith(error, `npm ERR! ${ignoredError.npmError}`)) | ||
); | ||
}, | ||
false | ||
); | ||
if (!failed && !_.isEmpty(err.stdout)) { | ||
return BbPromise.resolve({ stdout: err.stdout }); | ||
} | ||
return !_.isEmpty(error) && !_.some(ignoredYarnErrors, ignoredError => _.startsWith(error, `npm ERR! ${ignoredError.npmError}`)); | ||
}, false); | ||
if (!failed && !_.isEmpty(err.stdout)) { | ||
return BbPromise.resolve({ stdout: err.stdout }); | ||
} | ||
} | ||
return BbPromise.reject(err); | ||
}) | ||
.then(processOutput => processOutput.stdout) | ||
.then(depJson => BbPromise.try(() => JSON.parse(depJson))) | ||
.then(parsedTree => { | ||
const convertTrees = trees => _.reduce(trees, (__, tree) => { | ||
const splitModule = _.split(tree.name, '@'); | ||
// If we have a scoped module we have to re-add the @ | ||
if (_.startsWith(tree.name, '@')) { | ||
splitModule.splice(0, 1); | ||
splitModule[0] = '@' + splitModule[0]; | ||
} | ||
__[_.first(splitModule)] = { | ||
version: _.join(_.tail(splitModule), '@'), | ||
dependencies: convertTrees(tree.children) | ||
return BbPromise.reject(err); | ||
}) | ||
.then(processOutput => processOutput.stdout) | ||
.then(depJson => BbPromise.try(() => JSON.parse(depJson))) | ||
.then(parsedTree => { | ||
const convertTrees = trees => | ||
_.reduce( | ||
trees, | ||
(__, tree) => { | ||
const splitModule = _.split(tree.name, '@'); | ||
// If we have a scoped module we have to re-add the @ | ||
if (_.startsWith(tree.name, '@')) { | ||
splitModule.splice(0, 1); | ||
splitModule[0] = '@' + splitModule[0]; | ||
} | ||
__[_.first(splitModule)] = { | ||
version: _.join(_.tail(splitModule), '@'), | ||
dependencies: convertTrees(tree.children) | ||
}; | ||
return __; | ||
}, | ||
{} | ||
); | ||
const trees = _.get(parsedTree, 'data.trees', []); | ||
const result = { | ||
problems: [], | ||
dependencies: convertTrees(trees) | ||
}; | ||
return __; | ||
}, {}); | ||
const trees = _.get(parsedTree, 'data.trees', []); | ||
const result = { | ||
problems: [], | ||
dependencies: convertTrees(trees) | ||
}; | ||
return result; | ||
}); | ||
return result; | ||
}); | ||
} | ||
@@ -94,3 +103,3 @@ | ||
let match; | ||
// Detect all references and create replacement line strings | ||
@@ -105,5 +114,3 @@ while ((match = fileVersionMatcher.exec(lockfile)) !== null) { | ||
// Replace all lines in lockfile | ||
return _.reduce(replacements, (__, replacement) => { | ||
return _.replace(__, replacement.oldRef, replacement.newRef); | ||
}, lockfile); | ||
return _.reduce(replacements, (__, replacement) => _.replace(__, replacement.oldRef, replacement.newRef), lockfile); | ||
} | ||
@@ -113,7 +120,3 @@ | ||
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; | ||
const args = [ | ||
'install', | ||
'--frozen-lockfile', | ||
'--non-interactive' | ||
]; | ||
const args = [ 'install', '--frozen-lockfile', '--non-interactive' ]; | ||
@@ -125,4 +128,3 @@ // Convert supported packagerOptions | ||
return Utils.spawnProcess(command, args, { cwd }) | ||
.return(); | ||
return Utils.spawnProcess(command, args, { cwd }).return(); | ||
} | ||
@@ -138,10 +140,6 @@ | ||
return BbPromise.mapSeries(scriptNames, scriptName => { | ||
const args = [ | ||
'run', | ||
scriptName | ||
]; | ||
const args = [ 'run', scriptName ]; | ||
return Utils.spawnProcess(command, args, { cwd }); | ||
}) | ||
.return(); | ||
}).return(); | ||
} | ||
@@ -148,0 +146,0 @@ } |
@@ -14,3 +14,7 @@ 'use strict'; | ||
const filePath = _.replace(moduleVersion, /^file:/, ''); | ||
return _.replace(`${_.startsWith(moduleVersion, 'file:') ? 'file:' : ''}${pathToPackageRoot}/${filePath}`, /\\/g, '/'); | ||
return _.replace( | ||
`${_.startsWith(moduleVersion, 'file:') ? 'file:' : ''}${pathToPackageRoot}/${filePath}`, | ||
/\\/g, | ||
'/' | ||
); | ||
} | ||
@@ -45,3 +49,4 @@ | ||
function removeExcludedModules(modules, packageForceExcludes, log) { | ||
const excludedModules = _.remove(modules, externalModule => { // eslint-disable-line lodash/prefer-immutable-method | ||
// eslint-disable-next-line lodash/prefer-immutable-method | ||
const excludedModules = _.remove(modules, externalModule => { | ||
const splitModule = _.split(externalModule, '@'); | ||
@@ -94,3 +99,9 @@ // If we have a scoped module we have to re-add the @ | ||
this.options.verbose && this.serverless.cli.log(`Adding explicit peers for dependency ${module.external}`); | ||
const peerModules = getProdModules.call(this, _.map(peerDependencies, (value, key) => ({ external: key })), packagePath, dependencyGraph, forceExcludes); | ||
const peerModules = getProdModules.call( | ||
this, | ||
_.map(peerDependencies, (value, key) => ({ external: key })), | ||
packagePath, | ||
dependencyGraph, | ||
forceExcludes | ||
); | ||
Array.prototype.push.apply(prodModules, peerModules); | ||
@@ -110,3 +121,7 @@ } | ||
prodModules.push(moduleVersion ? `${module.external}@${moduleVersion}` : module.external); | ||
} else if (packageJson.devDependencies && packageJson.devDependencies[module.external] && !_.includes(forceExcludes, module.external)) { | ||
} else if ( | ||
packageJson.devDependencies && | ||
packageJson.devDependencies[module.external] && | ||
!_.includes(forceExcludes, module.external) | ||
) { | ||
// To minimize the chance of breaking setups we whitelist packages available on AWS here. These are due to the previously missing check | ||
@@ -118,7 +133,12 @@ // most likely set in devDependencies and should not lead to an error now. | ||
// Runtime dependency found in devDependencies but not forcefully excluded | ||
this.serverless.cli.log(`ERROR: Runtime dependency '${module.external}' found in devDependencies. Move it to dependencies or use forceExclude to explicitly exclude it.`); | ||
this.serverless.cli.log( | ||
`ERROR: Runtime dependency '${module.external}' found in devDependencies. Move it to dependencies or use forceExclude to explicitly exclude it.` | ||
); | ||
throw new this.serverless.classes.Error(`Serverless-webpack dependency error: ${module.external}.`); | ||
} | ||
this.options.verbose && this.serverless.cli.log(`INFO: Runtime dependency '${module.external}' found in devDependencies. It has been excluded automatically.`); | ||
this.options.verbose && | ||
this.serverless.cli.log( | ||
`INFO: Runtime dependency '${module.external}' found in devDependencies. It has been excluded automatically.` | ||
); | ||
} | ||
@@ -198,3 +218,2 @@ } | ||
packExternalModules() { | ||
const stats = this.compileStats; | ||
@@ -213,151 +232,202 @@ | ||
const packageJsonPath = path.join(process.cwd(), packagePath); | ||
const packageScripts = _.reduce(this.configuration.packagerOptions.scripts || [], (__, script, index) => { | ||
__[`script${index}`] = script; | ||
return __; | ||
}, {}); | ||
const packageScripts = _.reduce( | ||
this.configuration.packagerOptions.scripts || [], | ||
(__, script, index) => { | ||
__[`script${index}`] = script; | ||
return __; | ||
}, | ||
{} | ||
); | ||
// Determine and create packager | ||
return BbPromise.try(() => Packagers.get.call(this, this.configuration.packager)) | ||
.then(packager => { | ||
// Fetch needed original package.json sections | ||
const sectionNames = packager.copyPackageSectionNames; | ||
const packageJson = this.serverless.utils.readFileSync(packageJsonPath); | ||
const packageSections = _.pick(packageJson, sectionNames); | ||
if (!_.isEmpty(packageSections)) { | ||
this.options.verbose && this.serverless.cli.log(`Using package.json sections ${_.join(_.keys(packageSections), ', ')}`); | ||
} | ||
return BbPromise.try(() => Packagers.get.call(this, this.configuration.packager)).then(packager => { | ||
// Fetch needed original package.json sections | ||
const sectionNames = packager.copyPackageSectionNames; | ||
const packageJson = this.serverless.utils.readFileSync(packageJsonPath); | ||
const packageSections = _.pick(packageJson, sectionNames); | ||
if (!_.isEmpty(packageSections)) { | ||
this.options.verbose && | ||
this.serverless.cli.log(`Using package.json sections ${_.join(_.keys(packageSections), ', ')}`); | ||
} | ||
// Get first level dependency graph | ||
this.options.verbose && this.serverless.cli.log(`Fetch dependency graph from ${packageJsonPath}`); | ||
// Get first level dependency graph | ||
this.options.verbose && this.serverless.cli.log(`Fetch dependency graph from ${packageJsonPath}`); | ||
return packager.getProdDependencies(path.dirname(packageJsonPath), 1) | ||
.then(dependencyGraph => { | ||
const problems = _.get(dependencyGraph, 'problems', []); | ||
if (this.options.verbose && !_.isEmpty(problems)) { | ||
this.serverless.cli.log(`Ignoring ${_.size(problems)} NPM errors:`); | ||
_.forEach(problems, problem => { | ||
this.serverless.cli.log(`=> ${problem}`); | ||
}); | ||
} | ||
return packager.getProdDependencies(path.dirname(packageJsonPath), 1).then(dependencyGraph => { | ||
const problems = _.get(dependencyGraph, 'problems', []); | ||
if (this.options.verbose && !_.isEmpty(problems)) { | ||
this.serverless.cli.log(`Ignoring ${_.size(problems)} NPM errors:`); | ||
_.forEach(problems, problem => { | ||
this.serverless.cli.log(`=> ${problem}`); | ||
}); | ||
} | ||
// (1) Generate dependency composition | ||
const compositeModules = _.uniq(_.flatMap(stats.stats, compileStats => { | ||
const externalModules = _.concat( | ||
getExternalModules.call(this, compileStats), | ||
_.map(packageForceIncludes, whitelistedPackage => ({ external: whitelistedPackage })) | ||
); | ||
return getProdModules.call(this, externalModules, packagePath, dependencyGraph, packageForceExcludes); | ||
})); | ||
removeExcludedModules.call(this, compositeModules, packageForceExcludes, true); | ||
// (1) Generate dependency composition | ||
const compositeModules = _.uniq( | ||
_.flatMap(stats.stats, compileStats => { | ||
const externalModules = _.concat( | ||
getExternalModules.call(this, compileStats), | ||
_.map(packageForceIncludes, whitelistedPackage => ({ | ||
external: whitelistedPackage | ||
})) | ||
); | ||
return getProdModules.call(this, externalModules, packagePath, dependencyGraph, packageForceExcludes); | ||
}) | ||
); | ||
removeExcludedModules.call(this, compositeModules, packageForceExcludes, true); | ||
if (_.isEmpty(compositeModules)) { | ||
// The compiled code does not reference any external modules at all | ||
this.serverless.cli.log('No external modules needed'); | ||
return BbPromise.resolve(); | ||
} | ||
if (_.isEmpty(compositeModules)) { | ||
// The compiled code does not reference any external modules at all | ||
this.serverless.cli.log('No external modules needed'); | ||
return BbPromise.resolve(); | ||
} | ||
// (1.a) Install all needed modules | ||
const compositeModulePath = path.join(this.webpackOutputPath, 'dependencies'); | ||
const compositePackageJson = path.join(compositeModulePath, 'package.json'); | ||
// (1.a) Install all needed modules | ||
const compositeModulePath = path.join(this.webpackOutputPath, 'dependencies'); | ||
const compositePackageJson = path.join(compositeModulePath, 'package.json'); | ||
// (1.a.1) Create a package.json | ||
const compositePackage = _.defaults({ | ||
name: this.serverless.service.service, | ||
version: '1.0.0', | ||
description: `Packaged externals for ${this.serverless.service.service}`, | ||
private: true, | ||
scripts: packageScripts | ||
}, packageSections); | ||
const relPath = path.relative(compositeModulePath, path.dirname(packageJsonPath)); | ||
addModulesToPackageJson(compositeModules, compositePackage, relPath); | ||
this.serverless.utils.writeFileSync(compositePackageJson, JSON.stringify(compositePackage, null, 2)); | ||
// (1.a.1) Create a package.json | ||
const compositePackage = _.defaults( | ||
{ | ||
name: this.serverless.service.service, | ||
version: '1.0.0', | ||
description: `Packaged externals for ${this.serverless.service.service}`, | ||
private: true, | ||
scripts: packageScripts | ||
}, | ||
packageSections | ||
); | ||
const relPath = path.relative(compositeModulePath, path.dirname(packageJsonPath)); | ||
addModulesToPackageJson(compositeModules, compositePackage, relPath); | ||
this.serverless.utils.writeFileSync(compositePackageJson, JSON.stringify(compositePackage, null, 2)); | ||
// (1.a.2) Copy package-lock.json if it exists, to prevent unwanted upgrades | ||
const packageLockPath = path.join(path.dirname(packageJsonPath), packager.lockfileName); | ||
let hasPackageLock = false; | ||
return BbPromise.fromCallback(cb => fse.pathExists(packageLockPath, cb)) | ||
.then(exists => { | ||
if (exists) { | ||
this.serverless.cli.log('Package lock found - Using locked versions'); | ||
try { | ||
let packageLockFile = this.serverless.utils.readFileSync(packageLockPath); | ||
packageLockFile = packager.rebaseLockfile(relPath, packageLockFile); | ||
if (_.isObject(packageLockFile)) { | ||
packageLockFile = JSON.stringify(packageLockFile, null, 2); | ||
} | ||
this.serverless.utils.writeFileSync(path.join(compositeModulePath, packager.lockfileName), packageLockFile); | ||
hasPackageLock = true; | ||
} catch (err) { | ||
this.serverless.cli.log(`Warning: Could not read lock file: ${err.message}`); | ||
} | ||
// (1.a.2) Copy package-lock.json if it exists, to prevent unwanted upgrades | ||
const packageLockPath = path.join(path.dirname(packageJsonPath), packager.lockfileName); | ||
let hasPackageLock = false; | ||
return BbPromise.fromCallback(cb => fse.pathExists(packageLockPath, cb)) | ||
.then(exists => { | ||
if (exists) { | ||
this.serverless.cli.log('Package lock found - Using locked versions'); | ||
try { | ||
let packageLockFile = this.serverless.utils.readFileSync(packageLockPath); | ||
packageLockFile = packager.rebaseLockfile(relPath, packageLockFile); | ||
if (_.isObject(packageLockFile)) { | ||
packageLockFile = JSON.stringify(packageLockFile, null, 2); | ||
} | ||
return BbPromise.resolve(); | ||
}) | ||
.then(() => { | ||
const start = _.now(); | ||
this.serverless.cli.log('Packing external modules: ' + compositeModules.join(', ')); | ||
return packager.install(compositeModulePath, this.configuration.packagerOptions) | ||
.then(() => this.options.verbose && this.serverless.cli.log(`Package took [${_.now() - start} ms]`)) | ||
.return(stats.stats); | ||
}) | ||
.mapSeries(compileStats => { | ||
const modulePath = compileStats.compilation.compiler.outputPath; | ||
// Create package.json | ||
const modulePackageJson = path.join(modulePath, 'package.json'); | ||
const modulePackage = _.defaults({ | ||
name: this.serverless.service.service, | ||
version: '1.0.0', | ||
description: `Packaged externals for ${this.serverless.service.service}`, | ||
private: true, | ||
scripts: packageScripts, | ||
dependencies: {} | ||
}, packageSections); | ||
const prodModules = getProdModules.call(this, | ||
_.concat( | ||
getExternalModules.call(this, compileStats), | ||
_.map(packageForceIncludes, whitelistedPackage => ({ external: whitelistedPackage })) | ||
), packagePath, dependencyGraph, packageForceExcludes); | ||
removeExcludedModules.call(this, prodModules, packageForceExcludes); | ||
const relPath = path.relative(modulePath, path.dirname(packageJsonPath)); | ||
addModulesToPackageJson(prodModules, modulePackage, relPath); | ||
this.serverless.utils.writeFileSync(modulePackageJson, JSON.stringify(modulePackage, null, 2)); | ||
this.serverless.utils.writeFileSync( | ||
path.join(compositeModulePath, packager.lockfileName), | ||
packageLockFile | ||
); | ||
hasPackageLock = true; | ||
} catch (err) { | ||
this.serverless.cli.log(`Warning: Could not read lock file: ${err.message}`); | ||
} | ||
} | ||
return BbPromise.resolve(); | ||
}) | ||
.then(() => { | ||
const start = _.now(); | ||
this.serverless.cli.log('Packing external modules: ' + compositeModules.join(', ')); | ||
return packager | ||
.install(compositeModulePath, this.configuration.packagerOptions) | ||
.then(() => this.options.verbose && this.serverless.cli.log(`Package took [${_.now() - start} ms]`)) | ||
.return(stats.stats); | ||
}) | ||
.mapSeries(compileStats => { | ||
const modulePath = compileStats.compilation.compiler.outputPath; | ||
// GOOGLE: Copy modules only if not google-cloud-functions | ||
// GCF Auto installs the package json | ||
if (_.get(this.serverless, 'service.provider.name') === 'google') { | ||
return BbPromise.resolve(); | ||
} | ||
// Create package.json | ||
const modulePackageJson = path.join(modulePath, 'package.json'); | ||
const modulePackage = _.defaults( | ||
{ | ||
name: this.serverless.service.service, | ||
version: '1.0.0', | ||
description: `Packaged externals for ${this.serverless.service.service}`, | ||
private: true, | ||
scripts: packageScripts, | ||
dependencies: {} | ||
}, | ||
packageSections | ||
); | ||
const prodModules = getProdModules.call( | ||
this, | ||
_.concat( | ||
getExternalModules.call(this, compileStats), | ||
_.map(packageForceIncludes, whitelistedPackage => ({ | ||
external: whitelistedPackage | ||
})) | ||
), | ||
packagePath, | ||
dependencyGraph, | ||
packageForceExcludes | ||
); | ||
removeExcludedModules.call(this, prodModules, packageForceExcludes); | ||
const relPath = path.relative(modulePath, path.dirname(packageJsonPath)); | ||
addModulesToPackageJson(prodModules, modulePackage, relPath); | ||
this.serverless.utils.writeFileSync(modulePackageJson, JSON.stringify(modulePackage, null, 2)); | ||
const startCopy = _.now(); | ||
return BbPromise.try(() => { | ||
// Only copy dependency modules if demanded by packager | ||
if (packager.mustCopyModules) { | ||
return BbPromise.fromCallback(callback => fse.copy(path.join(compositeModulePath, 'node_modules'), path.join(modulePath, 'node_modules'), callback)); | ||
} | ||
return BbPromise.resolve(); | ||
}) | ||
.then(() => hasPackageLock ? | ||
BbPromise.fromCallback(callback => fse.copy(path.join(compositeModulePath, packager.lockfileName), path.join(modulePath, packager.lockfileName), callback)) : | ||
BbPromise.resolve() | ||
// GOOGLE: Copy modules only if not google-cloud-functions | ||
// GCF Auto installs the package json | ||
if (_.get(this.serverless, 'service.provider.name') === 'google') { | ||
return BbPromise.resolve(); | ||
} | ||
const startCopy = _.now(); | ||
return BbPromise.try(() => { | ||
// Only copy dependency modules if demanded by packager | ||
if (packager.mustCopyModules) { | ||
return BbPromise.fromCallback(callback => | ||
fse.copy( | ||
path.join(compositeModulePath, 'node_modules'), | ||
path.join(modulePath, 'node_modules'), | ||
callback | ||
) | ||
.tap(() => this.options.verbose && this.serverless.cli.log(`Copy modules: ${modulePath} [${_.now() - startCopy} ms]`)) | ||
.then(() => { | ||
// Prune extraneous packages - removes not needed ones | ||
const startPrune = _.now(); | ||
return packager.prune(modulePath, this.configuration.packagerOptions) | ||
.tap(() => this.options.verbose && this.serverless.cli.log(`Prune: ${modulePath} [${_.now() - startPrune} ms]`)); | ||
}) | ||
.then(() => { | ||
// Prune extraneous packages - removes not needed ones | ||
const startRunScripts = _.now(); | ||
return packager.runScripts(modulePath, _.keys(packageScripts)) | ||
.tap(() => this.options.verbose && this.serverless.cli.log(`Run scripts: ${modulePath} [${_.now() - startRunScripts} ms]`)); | ||
}); | ||
); | ||
} | ||
return BbPromise.resolve(); | ||
}) | ||
.then(() => | ||
hasPackageLock | ||
? BbPromise.fromCallback(callback => | ||
fse.copy( | ||
path.join(compositeModulePath, packager.lockfileName), | ||
path.join(modulePath, packager.lockfileName), | ||
callback | ||
) | ||
) | ||
: BbPromise.resolve() | ||
) | ||
.tap( | ||
() => | ||
this.options.verbose && | ||
this.serverless.cli.log(`Copy modules: ${modulePath} [${_.now() - startCopy} ms]`) | ||
) | ||
.then(() => { | ||
// Prune extraneous packages - removes not needed ones | ||
const startPrune = _.now(); | ||
return packager | ||
.prune(modulePath, this.configuration.packagerOptions) | ||
.tap( | ||
() => | ||
this.options.verbose && | ||
this.serverless.cli.log(`Prune: ${modulePath} [${_.now() - startPrune} ms]`) | ||
); | ||
}) | ||
.return(); | ||
}); | ||
.then(() => { | ||
// Prune extraneous packages - removes not needed ones | ||
const startRunScripts = _.now(); | ||
return packager | ||
.runScripts(modulePath, _.keys(packageScripts)) | ||
.tap( | ||
() => | ||
this.options.verbose && | ||
this.serverless.cli.log(`Run scripts: ${modulePath} [${_.now() - startRunScripts} ms]`) | ||
); | ||
}); | ||
}) | ||
.return(); | ||
}); | ||
}); | ||
} | ||
}; |
@@ -12,11 +12,11 @@ 'use strict'; | ||
prepareOfflineInvoke() { | ||
// Use service packaging for compile | ||
_.set(this.serverless, 'service.package.individually', false); | ||
return this.serverless.pluginManager.spawn('webpack:validate') | ||
.then(() => { | ||
return this.serverless.pluginManager.spawn('webpack:validate').then(() => { | ||
// Set offline location automatically if not set manually | ||
if (!this.options.location && !_.get(this.serverless, 'service.custom.serverless-offline.location')) { | ||
_.set(this.serverless, 'service.custom.serverless-offline.location', | ||
_.set( | ||
this.serverless, | ||
'service.custom.serverless-offline.location', | ||
path.relative(this.serverless.config.servicePath, path.join(this.webpackOutputPath, 'service')) | ||
@@ -23,0 +23,0 @@ ); |
@@ -14,12 +14,13 @@ 'use strict'; | ||
return this.serverless.pluginManager.spawn('webpack:validate') | ||
.then(() => { | ||
if (!this.options.location && !_.get(this.serverless, 'service.custom.stepFunctionsOffline.location')) { | ||
_.set(this.serverless, 'service.custom.stepFunctionsOffline.location', | ||
path.relative(this.serverless.config.servicePath, path.join(this.webpackOutputPath, 'service')) | ||
); | ||
} | ||
return null; | ||
}); | ||
return this.serverless.pluginManager.spawn('webpack:validate').then(() => { | ||
if (!this.options.location && !_.get(this.serverless, 'service.custom.stepFunctionsOffline.location')) { | ||
_.set( | ||
this.serverless, | ||
'service.custom.stepFunctionsOffline.location', | ||
path.relative(this.serverless.config.servicePath, path.join(this.webpackOutputPath, 'service')) | ||
); | ||
} | ||
return null; | ||
}); | ||
} | ||
}; |
@@ -28,4 +28,4 @@ 'use strict'; | ||
} | ||
BbPromise.try(() => { // eslint-disable-line promise/catch-or-return, promise/no-promise-in-callback | ||
// eslint-disable-next-line promise/catch-or-return, promise/no-promise-in-callback | ||
BbPromise.try(() => { | ||
if (this.originalServicePath) { | ||
@@ -47,6 +47,5 @@ process.chdir(this.originalServicePath); | ||
return this.serverless.pluginManager.spawn(command); | ||
}) | ||
.then(() => this.serverless.cli.log('Waiting for changes ...')); | ||
}).then(() => this.serverless.cli.log('Waiting for changes ...')); | ||
}); | ||
}, | ||
} | ||
}; |
@@ -28,20 +28,16 @@ 'use strict'; | ||
// because the functions are already registered in the event gateway | ||
const deployFunctionsToLocalEmulator = require( | ||
path.join( | ||
this.serverless.config.serverlessPath, | ||
'plugins', | ||
'run', | ||
'utils', | ||
'deployFunctionsToLocalEmulator' | ||
) | ||
); | ||
const getLocalRootUrl = require( | ||
path.join( | ||
this.serverless.config.serverlessPath, | ||
'plugins', | ||
'run', | ||
'utils', | ||
'getLocalRootUrl' | ||
) | ||
); | ||
const deployFunctionsToLocalEmulator = require(path.join( | ||
this.serverless.config.serverlessPath, | ||
'plugins', | ||
'run', | ||
'utils', | ||
'deployFunctionsToLocalEmulator' | ||
)); | ||
const getLocalRootUrl = require(path.join( | ||
this.serverless.config.serverlessPath, | ||
'plugins', | ||
'run', | ||
'utils', | ||
'getLocalRootUrl' | ||
)); | ||
@@ -54,9 +50,10 @@ // Reset configuration | ||
return this.hooks['before:run:run']() | ||
.then(() => deployFunctionsToLocalEmulator( | ||
this.serverless.service, | ||
this.serverless.config.servicePath, | ||
getLocalRootUrl(this.options.lport) | ||
)); | ||
return this.hooks['before:run:run']().then(() => | ||
deployFunctionsToLocalEmulator( | ||
this.serverless.service, | ||
this.serverless.config.servicePath, | ||
getLocalRootUrl(this.options.lport) | ||
) | ||
); | ||
} | ||
}; |
@@ -18,11 +18,10 @@ 'use strict'; | ||
* Remove the specified module from the require cache. | ||
* @param {string} moduleName | ||
* @param {string} moduleName | ||
*/ | ||
function purgeCache(moduleName) { | ||
return searchAndProcessCache(moduleName, function (mod) { | ||
return searchAndProcessCache(moduleName, function(mod) { | ||
delete require.cache[mod.id]; | ||
}) | ||
.then(() => { | ||
}).then(() => { | ||
_.forEach(_.keys(module.constructor._pathCache), function(cacheKey) { | ||
if (cacheKey.indexOf(moduleName)>0) { | ||
if (cacheKey.indexOf(moduleName) > 0) { | ||
delete module.constructor._pathCache[cacheKey]; | ||
@@ -38,3 +37,3 @@ } | ||
const visitedModules = []; | ||
if (mod_src && ((mod_src = require.cache[mod_src]) !== undefined)) { | ||
if (mod_src && (mod_src = require.cache[mod_src]) !== undefined) { | ||
const modStack = [mod_src]; | ||
@@ -107,3 +106,3 @@ | ||
SpawnError, | ||
spawnProcess, | ||
spawnProcess | ||
}; |
@@ -16,8 +16,3 @@ 'use strict'; | ||
*/ | ||
const preferredExtensions = [ | ||
'.js', | ||
'.ts', | ||
'.jsx', | ||
'.tsx' | ||
]; | ||
const preferredExtensions = [ '.js', '.ts', '.jsx', '.tsx' ]; | ||
@@ -43,3 +38,5 @@ module.exports = { | ||
// If we cannot find any handler we should terminate with an error | ||
throw new this.serverless.classes.Error(`No matching handler found for '${fileName}' in '${this.serverless.config.servicePath}'. Check your service definition.`); | ||
throw new this.serverless.classes.Error( | ||
`No matching handler found for '${fileName}' in '${this.serverless.config.servicePath}'. Check your service definition.` | ||
); | ||
} | ||
@@ -50,6 +47,3 @@ | ||
_.concat( | ||
_.sortBy( | ||
_.filter(files, file => _.includes(preferredExtensions, path.extname(file))), | ||
a => _.size(a) | ||
), | ||
_.sortBy(_.filter(files, file => _.includes(preferredExtensions, path.extname(file))), a => _.size(a)), | ||
files | ||
@@ -60,3 +54,5 @@ ) | ||
if (_.size(sortedFiles) > 1) { | ||
this.serverless.cli.log(`WARNING: More than one matching handlers found for '${fileName}'. Using '${_.first(sortedFiles)}'.`); | ||
this.serverless.cli.log( | ||
`WARNING: More than one matching handlers found for '${fileName}'. Using '${_.first(sortedFiles)}'.` | ||
); | ||
} | ||
@@ -72,3 +68,5 @@ return path.extname(_.first(sortedFiles)); | ||
_.get(this.serverless, 'service.provider.name') !== 'google' && | ||
this.serverless.cli.log(`\nWARNING: Entry for ${name}@${handler} could not be retrieved.\nPlease check your service config if you want to use lib.entries.`); | ||
this.serverless.cli.log( | ||
`\nWARNING: Entry for ${name}@${handler} could not be retrieved.\nPlease check your service config if you want to use lib.entries.` | ||
); | ||
return {}; | ||
@@ -86,5 +84,8 @@ } | ||
this.configuration = new Configuration(this.serverless.service.custom); | ||
this.options.verbose && this.serverless.cli.log(`Using configuration:\n${JSON.stringify(this.configuration, null, 2)}`); | ||
this.options.verbose && | ||
this.serverless.cli.log(`Using configuration:\n${JSON.stringify(this.configuration, null, 2)}`); | ||
if (this.configuration.hasLegacyConfig) { | ||
this.serverless.cli.log('Legacy configuration detected. Consider to use "custom.webpack" as object (see README).'); | ||
this.serverless.cli.log( | ||
'Legacy configuration detected. Consider to use "custom.webpack" as object (see README).' | ||
); | ||
} | ||
@@ -117,4 +118,7 @@ | ||
if (!this.serverless.utils.fileExistsSync(webpackConfigFilePath)) { | ||
return BbPromise.reject(new this.serverless.classes | ||
.Error('The webpack plugin could not find the configuration file at: ' + webpackConfigFilePath)); | ||
return BbPromise.reject( | ||
new this.serverless.classes.Error( | ||
'The webpack plugin could not find the configuration file at: ' + webpackConfigFilePath | ||
) | ||
); | ||
} | ||
@@ -148,3 +152,3 @@ try { | ||
path: outputPath, | ||
filename: '[name].js', | ||
filename: '[name].js' | ||
}; | ||
@@ -161,4 +165,3 @@ } | ||
if (!fse.pathExistsSync(this.webpackConfig.output.path)) { | ||
return BbPromise.reject(new this.serverless.classes | ||
.Error('No compiled output found')); | ||
return BbPromise.reject(new this.serverless.classes.Error('No compiled output found')); | ||
} | ||
@@ -180,21 +183,21 @@ this.keepOutputDirectory = true; | ||
if (this.webpackConfig.entry && !_.isEqual(this.webpackConfig.entry, entries)) { | ||
return BbPromise.reject(new this.serverless.classes | ||
.Error('Webpack entry must be automatically resolved when package.individually is set to true. ' + | ||
'In webpack.config.js, remove the entry declaration or set entry to slsw.lib.entries.')); | ||
return BbPromise.reject( | ||
new this.serverless.classes.Error( | ||
'Webpack entry must be automatically resolved when package.individually is set to true. ' + | ||
'In webpack.config.js, remove the entry declaration or set entry to slsw.lib.entries.' | ||
) | ||
); | ||
} | ||
// Lookup associated Serverless functions | ||
const allEntryFunctions = _.map( | ||
this.serverless.service.getAllFunctions(), | ||
funcName => { | ||
const func = this.serverless.service.getFunction(funcName); | ||
const handler = func.handler; | ||
const handlerFile = path.relative('.', getHandlerFile(handler)); | ||
return { | ||
handlerFile, | ||
funcName, | ||
func | ||
}; | ||
} | ||
); | ||
const allEntryFunctions = _.map(this.serverless.service.getAllFunctions(), funcName => { | ||
const func = this.serverless.service.getFunction(funcName); | ||
const handler = func.handler; | ||
const handlerFile = path.relative('.', getHandlerFile(handler)); | ||
return { | ||
handlerFile, | ||
funcName, | ||
func | ||
}; | ||
}); | ||
@@ -241,3 +244,3 @@ this.entryFunctions = _.flatMap(entries, (value, key) => { | ||
} | ||
}, | ||
} | ||
}; |
@@ -28,4 +28,4 @@ 'use strict'; | ||
// This allows us to hold the compile until "webpack:compile:watch" has resolved | ||
const beforeCompile = () => ( | ||
new BbPromise((resolve) => { | ||
const beforeCompile = () => | ||
new BbPromise(resolve => { | ||
// eslint-disable-next-line promise/catch-or-return | ||
@@ -36,3 +36,3 @@ BbPromise.resolve(currentCompileWatch) | ||
.catch(error => error) | ||
.then((error) => { | ||
.then(error => { | ||
if (error) { | ||
@@ -46,4 +46,3 @@ return null; | ||
}); | ||
}) | ||
); | ||
}); | ||
@@ -61,4 +60,5 @@ const compiler = webpack(this.webpackConfig); | ||
compiler.plugin('before-compile', (compilationParams, callback) => { | ||
// eslint-disable-next-line promise/no-callback-in-promise | ||
beforeCompile().then(callback).catch(_.noop); | ||
beforeCompile() | ||
.then(callback) // eslint-disable-line promise/no-callback-in-promise | ||
.catch(_.noop); | ||
}); | ||
@@ -78,3 +78,3 @@ } | ||
const startWatch = (callback) => { | ||
const startWatch = callback => { | ||
let firstRun = true; | ||
@@ -90,3 +90,4 @@ compiler.watch(watchOptions, (err, stats) => { | ||
process.env.SLS_DEBUG && this.serverless.cli.log(`Webpack watch invoke: HASH NEW=${stats.hash} CUR=${lastHash}`); | ||
process.env.SLS_DEBUG && | ||
this.serverless.cli.log(`Webpack watch invoke: HASH NEW=${stats.hash} CUR=${lastHash}`); | ||
@@ -117,5 +118,6 @@ // If the file hash did not change there were no effective code changes detected | ||
} else if (canEmit && currentCompileWatch === null) { | ||
currentCompileWatch = BbPromise.resolve( // eslint-disable-line promise/no-promise-in-callback | ||
this.serverless.pluginManager.spawn('webpack:compile:watch') | ||
).then(() => this.serverless.cli.log('Watching for changes...')); | ||
// eslint-disable-next-line promise/no-promise-in-callback | ||
currentCompileWatch = BbPromise.resolve(this.serverless.pluginManager.spawn('webpack:compile:watch')).then( | ||
() => this.serverless.cli.log('Watching for changes...') | ||
); | ||
} | ||
@@ -128,3 +130,3 @@ }); | ||
}); | ||
}, | ||
} | ||
}; |
{ | ||
"name": "serverless-webpack", | ||
"version": "5.3.1", | ||
"version": "5.3.2", | ||
"description": "Serverless plugin to bundle your javascript with Webpack", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"author": "Frank Schmid <fschmid740@googlemail.com>", | ||
@@ -31,3 +32,4 @@ "repository": { | ||
"test": "nyc ./node_modules/mocha/bin/_mocha tests/all index.test.js \"lib/**/*.test.js\" -R spec --recursive", | ||
"eslint": "node node_modules/eslint/bin/eslint.js --ext .js lib" | ||
"eslint": "eslint --ext .js *.js lib tests", | ||
"format": "prettier-eslint \"*.js\" \"lib/**/*.js\" \"tests/**/*.js\" --write" | ||
}, | ||
@@ -50,28 +52,28 @@ "nyc": { | ||
"dependencies": { | ||
"archiver": "^2.1.1", | ||
"bluebird": "^3.5.4", | ||
"fs-extra": "^4.0.3", | ||
"glob": "^7.1.2", | ||
"is-builtin-module": "^1.0.0", | ||
"lodash": "^4.17.11", | ||
"semver": "^5.5.0", | ||
"ts-node": "^3.2.0" | ||
"archiver": "^3.0.3", | ||
"bluebird": "^3.5.5", | ||
"fs-extra": "^8.1.0", | ||
"glob": "^7.1.4", | ||
"is-builtin-module": "^3.0.0", | ||
"lodash": "^4.17.15", | ||
"semver": "^6.2.0", | ||
"ts-node": "^8.3.0" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^8.2.5", | ||
"babel-eslint": "^10.0.2", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.0.3", | ||
"coveralls": "^3.0.5", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.2.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-lodash": "^5.1.0", | ||
"eslint-plugin-promise": "^4.1.1", | ||
"husky": "^2.1.0", | ||
"lint-staged": "^8.1.5", | ||
"mocha": "^5.2.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-lodash": "^7.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"husky": "^3.0.1", | ||
"lint-staged": "^9.2.0", | ||
"mocha": "^6.2.0", | ||
"mockery": "^2.1.0", | ||
"nyc": "^14.1.0", | ||
"prettier": "^1.17.0", | ||
"serverless": "^1.41.1", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.18.2", | ||
"prettier-eslint-cli": "^5.0.0", | ||
"serverless": "^1.48.2", | ||
"sinon": "^7.3.2", | ||
@@ -78,0 +80,0 @@ "sinon-chai": "^3.3.0" |
module.exports = { | ||
arrowParens: 'always', | ||
bracketSpacing: false, | ||
printWidth: 120, | ||
arrowParens: 'avoid', | ||
bracketSpacing: true, | ||
semi: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
trailingComma: 'none' | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
107946
27
1641
+ Addedarchiver@3.1.1(transitive)
+ Addedarchiver-utils@2.1.0(transitive)
+ Addedarg@4.1.3(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuiltin-modules@3.3.0(transitive)
+ Addedcompress-commons@2.1.1(transitive)
+ Addedcrc32-stream@3.0.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedfs-extra@8.1.0(transitive)
+ Addedis-builtin-module@3.2.1(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.difference@4.5.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.union@4.6.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedts-node@8.10.2(transitive)
+ Addedtypescript@5.8.2(transitive)
+ Addedyn@3.1.1(transitive)
+ Addedzip-stream@2.1.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedarchiver@2.1.1(transitive)
- Removedarchiver-utils@1.3.0(transitive)
- Removedarrify@1.0.1(transitive)
- Removedbl@1.2.3(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedbuiltin-modules@1.1.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcompress-commons@1.2.2(transitive)
- Removedcrc32-stream@2.0.0(transitive)
- Removeddiff@3.5.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfs-extra@4.0.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhomedir-polyfill@1.0.3(transitive)
- Removedis-builtin-module@1.0.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedparse-passwd@1.0.0(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-support@0.4.18(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedts-node@3.3.0(transitive)
- Removedtsconfig@6.0.0(transitive)
- Removedv8flags@3.2.0(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyn@2.0.0(transitive)
- Removedzip-stream@1.2.0(transitive)
Updatedarchiver@^3.0.3
Updatedbluebird@^3.5.5
Updatedfs-extra@^8.1.0
Updatedglob@^7.1.4
Updatedis-builtin-module@^3.0.0
Updatedlodash@^4.17.15
Updatedsemver@^6.2.0
Updatedts-node@^8.3.0