Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local errors with NPM 7 workspaces #782

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [email protected] ./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: [email protected] ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon',
'npm ERR! missing: [email protected], required by [email protected]',
'npm ERR! peer dep missing: [email protected]',
'{',
' "error": {',
' "code": "ELSPROBLEMS",',
' "summary": "extraneous: [email protected] ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon\nmissing: [email protected], required by [email protected]\npeer dep missing: [email protected]',
' "detail": ""',
' }',
'}'
],
'\n'
);
const lsResult = {
version: '1.0.0',
problems: [
'npm ERR! extraneous: [email protected] ./babel-dynamically-entries/node_modules/serverless-webpack/node_modules/sinon',
'npm ERR! missing: [email protected], required by [email protected]',
'npm ERR! peer dep missing: [email protected]'
],
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