Skip to content

Commit

Permalink
Merge pull request #782 from boundstate/npm-7
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r authored Apr 12, 2021
2 parents 0f24afb + 3c9898e commit 2371550
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/packagers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NPM {
];

const ignoredNpmErrors = [
{ npmError: 'code ELSPROBLEMS', log: false }, // npm >= 7
{ npmError: 'extraneous', log: false },
{ npmError: 'missing', log: false },
{ npmError: 'peer dep missing', log: true }
Expand All @@ -44,7 +45,9 @@ class NPM {
.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');
// ignoring any extra output from npm >= 7
const lines = _.split(err.stderr, '\n');
const errors = _.takeWhile(lines, line => line !== '{');
const failed = _.reduce(
errors,
(failed, error) => {
Expand Down
51 changes: 50 additions & 1 deletion lib/packagers/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('npm', () => {
);
});

it('should ignore minor local NPM errors and log them', () => {
it('should ignore minor local NPM errors and log them (NPM < 7)', () => {
const stderr = _.join(
[
'npm ERR! extraneous: sinon@2.3.8 ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon',
Expand Down Expand Up @@ -202,6 +202,55 @@ describe('npm', () => {
);
});

it('should ignore minor local NPM errors and log them (NPM >= 7)', () => {
const stderr = _.join(
[
'npm ERR! code ELSPROBLEMS',
'npm ERR! extraneous: sinon@2.3.8 ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon',
'npm ERR! missing: internalpackage-1@1.0.0, required by internalpackage-2@1.0.0',
'npm ERR! peer dep missing: sinon@2.3.8',
'{',
' "error": {',
' "code": "ELSPROBLEMS",',
' "summary": "extraneous: sinon@2.3.8 ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon\nmissing: internalpackage-1@1.0.0, required by internalpackage-2@1.0.0\npeer dep missing: sinon@2.3.8',
' "detail": ""',
' }',
'}'
],
'\n'
);
const lsResult = {
version: '1.0.0',
problems: [
'npm ERR! extraneous: sinon@2.3.8 ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon',
'npm ERR! missing: internalpackage-1@1.0.0, required by internalpackage-2@1.0.0',
'npm ERR! peer dep missing: sinon@2.3.8'
],
dependencies: {
'@scoped/vendor': '1.0.0',
uuid: '^5.4.1',
bluebird: '^3.4.0'
}
};

Utils.spawnProcess.returns(
BbPromise.reject(new Utils.SpawnError('Command execution failed', JSON.stringify(lsResult), stderr))
);
return expect(npmModule.getProdDependencies('myPath', 1)).to.be.fulfilled.then(dependencies =>
BbPromise.all([
// npm ls and npm prune should have been called
expect(Utils.spawnProcess).to.have.been.calledOnce,
expect(Utils.spawnProcess.firstCall).to.have.been.calledWith(sinon.match(/^npm/), [
'ls',
'-prod',
'-json',
'-depth=1'
]),
expect(dependencies).to.deep.equal(lsResult)
])
);
});

it('should rebase lock file references', () => {
const expectedLocalModule = 'file:../../locals/../../mymodule';
const fakePackageLockJSON = {
Expand Down

0 comments on commit 2371550

Please sign in to comment.