-
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
feat(init): reify on init new workspace #4892
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
const Arborist = require('@npmcli/arborist') | ||
const reifyFinish = require('../utils/reify-finish.js') | ||
|
||
async function updateWorkspaces ({ | ||
config, | ||
wraithgar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flatOptions, | ||
localPrefix, | ||
npm, | ||
workspaces, | ||
}) { | ||
if (!flatOptions.workspacesUpdate || !workspaces.length) { | ||
return | ||
} | ||
|
||
// default behavior is to not save by default in order to avoid | ||
// race condition problems when publishing multiple workspaces | ||
// that have dependencies on one another, it might still be useful | ||
// in some cases, which then need to set --save | ||
const save = config.isDefault('save') | ||
? false | ||
: config.get('save') | ||
|
||
// runs a minimalistic reify update, targetting only the workspaces | ||
// that had version updates and skipping fund/audit/save | ||
const opts = { | ||
...flatOptions, | ||
audit: false, | ||
fund: false, | ||
path: localPrefix, | ||
save, | ||
} | ||
const arb = new Arborist(opts) | ||
|
||
await arb.reify({ ...opts, update: workspaces }) | ||
await reifyFinish(npm, arb) | ||
} | ||
|
||
module.exports = updateWorkspaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,7 @@ t.test('workspaces', t => { | |
t.teardown(() => { | ||
npm._mockOutputs.length = 0 | ||
}) | ||
npm._mockOutputs.length = 0 | ||
npm.localPrefix = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
name: 'top-level', | ||
|
@@ -306,6 +307,39 @@ t.test('workspaces', t => { | |
t.matchSnapshot(npm._mockOutputs, 'should print helper info') | ||
}) | ||
|
||
t.test('post workspace-init reify', async t => { | ||
const _consolelog = console.log | ||
console.log = () => null | ||
t.teardown(() => { | ||
console.log = _consolelog | ||
npm._mockOutputs.length = 0 | ||
delete npm.flatOptions.workspacesUpdate | ||
}) | ||
npm.started = Date.now() | ||
npm._mockOutputs.length = 0 | ||
npm.flatOptions.workspacesUpdate = true | ||
npm.localPrefix = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
name: 'top-level', | ||
}), | ||
}) | ||
|
||
const Init = t.mock('../../../lib/commands/init.js', { | ||
...mocks, | ||
'init-package-json': (dir, initFile, config, cb) => { | ||
t.equal(dir, resolve(npm.localPrefix, 'a'), 'should use the ws path') | ||
return require('init-package-json')(dir, initFile, config, cb) | ||
}, | ||
}) | ||
const init = new Init(npm) | ||
await init.execWorkspaces([], ['a']) | ||
const output = npm._mockOutputs.map(arr => arr.map(i => i.replace(/[0-9]*ms$/, '100ms'))) | ||
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. nit: this could be a t.cleanSnapshot |
||
t.matchSnapshot(output, 'should print helper info') | ||
const lockFilePath = resolve(npm.localPrefix, 'package-lock.json') | ||
const lockFile = fs.readFileSync(lockFilePath, { encoding: 'utf8' }) | ||
t.matchSnapshot(lockFile, 'should reify tree on init ws complete') | ||
}) | ||
|
||
t.test('no args, existing folder', async t => { | ||
t.teardown(() => { | ||
npm._mockOutputs.length = 0 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what does "run an update" mean?
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.
it means the npm cli will run a
npm update <workspace-name>
cmd behind the scenes, to be clear this text is already there, ref: https://docs.npmjs.com/cli/v8/using-npm/config#workspaces-update - in case you want to propose improvements here, I'm due to a follow up PR improving docs and would appreciate the feedback 😊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.
sure, but it doesn't seem clear that "run an update" means this. Perhaps:
?
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.
I think that's very close to what I want, I'll follow up with a docs PR once this lands 😊 thanks!