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

Updating the update cmd to add workspace:* for internal upgrade #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const upgrade /*: Upgrade */ = async ({root, args}) => {
const {projects} = await getManifest({root});
const roots = projects.map(dir => `${root}/${dir}`);

if (!args.length) {
throw new Error(
'Command must have at least one dependency name. \nUsage: jazelle upgrade [dependency]\n'
Copy link

Choose a reason for hiding this comment

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

Thanks!

);
}

// group by whether the dep is local (listed in manifest.json) or external (from registry)
const locals = [];
const externals = [];
Expand All @@ -38,10 +44,12 @@ const upgrade /*: Upgrade */ = async ({root, args}) => {
throw new Error(error);
}

const localVersion = 'workspace:*';

// don't update peerDependencies, we don't want to inadvertedly cause downstreams to have multiple versions of things
update(meta, 'dependencies', name, local.meta.version);
update(meta, 'devDependencies', name, local.meta.version);
update(meta, 'optionalDependencies', name, local.meta.version);
update(meta, 'dependencies', name, localVersion);
update(meta, 'devDependencies', name, localVersion);
update(meta, 'optionalDependencies', name, localVersion);
}
await write(
`${cwd}/package.json`,
Expand Down
16 changes: 14 additions & 2 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,32 @@ async function testFocus() {
}

async function testUpgrade() {
const errorMessage =
'Command must have at least one dependency name. \nUsage: jazelle upgrade [dependency]\n';
const meta = `${tmp}/tmp/upgrade/a/package.json`;
const lockfile = `${tmp}/tmp/upgrade/yarn.lock`;
const cmd = `cp -r ${__dirname}/fixtures/upgrade/ ${tmp}/tmp/upgrade`;
await exec(cmd);

// external upgrade
await upgrade({
root: `${tmp}/tmp/upgrade`,
args: ['[email protected]'],
});
assert((await read(meta, 'utf8')).includes('"has": "1.0.3"'));
assert((await read(lockfile, 'utf8')).includes('function-bind'));

// internal upgrade
await upgrade({root: `${tmp}/tmp/upgrade`, args: ['b']});
assert((await read(meta, 'utf8')).includes('"b": "1.0.0"'));
assert((await read(meta, 'utf8')).includes('"b": "workspace:*"'));

// missing dependency
try {
await upgrade({root: `${tmp}/tmp/upgrade`, args: []});
} catch (e) {
// $FlowFixMe
assert(e.message.includes(errorMessage));
}
}

async function testPurge() {
Expand Down Expand Up @@ -535,7 +547,7 @@ async function testBump() {

// downstream is greenkept
const meta = JSON.parse(await read(downstreamMeta));
assert.equal(meta.dependencies['@uber/not-a-real-project'], '0.1.0-0');
assert.equal(meta.dependencies['@uber/not-a-real-project'], 'workspace:*');
assert.equal(meta.version, '0.1.0-0');
}

Expand Down
2 changes: 1 addition & 1 deletion utils/report-mismatched-top-level-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type GetErrorMessage = (Report, boolean) => string;
const getErrorMessage /*: GetErrorMessage */ = (result, json = false) => {
if (!result.valid) {
const message = red(
`Version policy violation. Use \`jazelle upgrade\` to ensure all projects use the same dependency version`
`Version policy violation. Use \`jazelle upgrade [dependency]\` to ensure all projects use the same dependency version`
);
const report = JSON.stringify(result.reported, null, 2);
let violations = `\nViolations:\n${report}`;
Expand Down