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

fix: ignore packageLockOnly in npx/exec #4649

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const exec = async (opts) => {
yes = undefined,
...flatOptions
} = opts
delete flatOptions.packageLock
delete flatOptions.packageLockOnly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't delete things from flatOptions since we pass it everywhere and it could have unintended side effects. I think creating a new object and omitting these specifically is a better option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen in the command itself too.


// dereferences values because we manipulate it later
const packages = [..._packages]
Expand Down
48 changes: 48 additions & 0 deletions workspaces/libnpmexec/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,51 @@ t.test('workspaces', async t => {
const wRes = fs.readFileSync(resolve(path, 'a/resfile')).toString()
t.equal(wRes, 'LOCAL PKG', 'should run existing bin from workspace level')
})

t.test('run from registry with package lock', async t => {
const testdir = t.testdir({
cache: {},
npxCache: {},
work: {
'package.json': JSON.stringify({
name: 'some-package',
version: '1.0.0',
}),
'package-lock.json': JSON.stringify({
name: 'some-package',
version: '1.0.0',
lockfileVersion: 2,
requires: true,
packages: {
'': {
name: 'some-package',
version: '1.0.0',
},
},
}),
},
})
const path = resolve(testdir, 'work')
const runPath = path
const cache = resolve(testdir, 'cache')
const npxCache = resolve(testdir, 'npxCache')

t.throws(
() => fs.statSync(resolve(path, 'index.js')),
{ code: 'ENOENT' },
'should not have template file'
)

await libexec({
...baseOpts,
packageLock: true,
packageLockOnly: true,
args: ['@ruyadorno/create-index'],
cache,
npxCache,
path,
runPath,
})

t.ok(fs.statSync(resolve(path, 'index.js')).isFile(), 'ran create pkg')
})