-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: don't emit package-lock.json when package.json does not exist #7097
base: latest
Are you sure you want to change the base?
Changes from all commits
909cfab
1d965ae
0acd2a2
ef640d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const { resolve, join } = require('path') | |
const runScript = require('@npmcli/run-script') | ||
const pacote = require('pacote') | ||
const checks = require('npm-install-checks') | ||
const PackageJson = require('@npmcli/package-json') | ||
|
||
const ArboristWorkspaceCmd = require('../arborist-cmd.js') | ||
class Install extends ArboristWorkspaceCmd { | ||
|
@@ -140,6 +141,21 @@ class Install extends ArboristWorkspaceCmd { | |
throw this.usageError() | ||
} | ||
|
||
if (!isGlobalInstall) { | ||
const pkgJson = new PackageJson() | ||
await pkgJson.load(this.npm.prefix) | ||
const jsonContent = pkgJson.content | ||
const isJsonEmptyObject = Object.keys(jsonContent).length === 0 | ||
&& jsonContent.constructor === Object | ||
|
||
const emptyJson = new Error('EEMPTYPKGJSON: package.json is empty object') | ||
emptyJson.code = 'EEMPTYPKGJSON' | ||
emptyJson.path = pkgJson.filename | ||
if (isJsonEmptyObject) { | ||
throw emptyJson | ||
} | ||
Comment on lines
+147
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @wraithgar, that code do you mean this snippet? But it's written by me, not left over before I wrote the commit? I still don't understand, Can you point to one place of the code for example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to infer why the test for an empty object was there and assumed it was due to |
||
} | ||
|
||
const Arborist = require('@npmcli/arborist') | ||
const opts = { | ||
...this.npm.flatOptions, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,22 @@ const setup = require('./fixtures/setup.js') | |
|
||
t.test('proxy', async t => { | ||
const { npm, readFile } = await setup(t, { | ||
testdir: { | ||
project: { | ||
'.npmrc': '', | ||
'package.json': { | ||
name: 'placeholder', | ||
}, | ||
}, | ||
}, | ||
mockRegistry: false, | ||
useProxy: true, | ||
}) | ||
|
||
await npm('install', '[email protected]') | ||
|
||
t.strictSame(await readFile('package.json'), { | ||
name: 'placeholder', | ||
dependencies: { abbrev: '^1.0.4' }, | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not remove this check, let it generate empty lock file if package.json is empty. Only make sure not to generate lock file if package.json file doesn't exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'll read my (admittedly long) comment you'll see that this check in this place is not the right solution to begin with.