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

Automatically update dependent packages when publishing #104

Closed
wants to merge 3 commits 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
223 changes: 217 additions & 6 deletions src/__tests__/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ describe('PUBLISH command', () => {
}
});

it('stops when no sub-package is dirty', async () => {
git._setSubpackageDiff('');
await publish(NOMINAL_OPTIONS);
expect(git.gitPushWithTags).not.toHaveBeenCalled();
});

it('proceeds if there are dirty sub-packages', async () => {
await publish(NOMINAL_OPTIONS);
expect(git.gitPushWithTags).toHaveBeenCalled();
Expand All @@ -116,6 +110,203 @@ describe('PUBLISH command', () => {
expect(git.gitPushWithTags).toHaveBeenCalledTimes(1);
});

it('updates the version on dirty sub-packages, including exact dependencies', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const options = Object.assign({}, NOMINAL_OPTIONS, {
bumpDependentReqs: "exact",
});
await publish(options);

expect(writeSpecs).toHaveBeenCalledTimes(1 + NUM_FIXTURE_SUBPACKAGES);
writeSpecs.mock.calls.forEach(([, specs]) => {
expect(specs.version).toEqual('99.99.99');
});
expect(writeSpecs).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({
name: "oao",
version: "99.99.99",
}));
expect(writeSpecs).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
name: "oao-b",
version: "99.99.99",
dependencies: {
oao: "99.99.99",
timm: "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(3, expect.any(String), expect.objectContaining({
name: "oao-c",
version: "99.99.99",
dependencies: {
oao: "99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "99.99.99",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(4, expect.any(String), expect.objectContaining({
name: "oao-d",
version: "99.99.99",
dependencies: {
oao: "99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "99.99.99",
"oao-c": "99.99.99",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(5, expect.any(String), expect.objectContaining({
name: "oao-priv",
version: "99.99.99",
dependencies: {
oao: "99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "99.99.99",
"oao-c": "99.99.99",
"xxl": "1.x",
},
}));
expect(git.gitCommitChanges).toHaveBeenCalledTimes(1);
expect(git.gitAddTag).toHaveBeenCalledTimes(1);
expect(git.gitPushWithTags).toHaveBeenCalledTimes(1);
});

it('updates the version on dirty sub-packages, including dependencies in range', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
await publish(NOMINAL_OPTIONS);

expect(writeSpecs).toHaveBeenCalledTimes(1 + NUM_FIXTURE_SUBPACKAGES);

writeSpecs.mock.calls.forEach(([, specs]) => {
expect(specs.version).toEqual('99.99.99');
});
expect(writeSpecs).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({
name: "oao",
version: "99.99.99",
}));
expect(writeSpecs).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
name: "oao-b",
version: "99.99.99",
dependencies: {
oao: "^99.99.99",
timm: "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(3, expect.any(String), expect.objectContaining({
name: "oao-c",
version: "99.99.99",
dependencies: {
oao: "^99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "^99.99.99",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(4, expect.any(String), expect.objectContaining({
name: "oao-d",
version: "99.99.99",
dependencies: {
oao: "^99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "^99.99.99",
"oao-c": "^99.99.99",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(5, expect.any(String), expect.objectContaining({
name: "oao-priv",
version: "99.99.99",
dependencies: {
oao: "^99.99.99",
timm: "1.x",
},
devDependencies: {
"oao-b": "^99.99.99",
"oao-c": "^99.99.99",
"xxl": "1.x",
},
}));
expect(git.gitCommitChanges).toHaveBeenCalledTimes(1);
expect(git.gitAddTag).toHaveBeenCalledTimes(1);
expect(git.gitPushWithTags).toHaveBeenCalledTimes(1);
});

it('updates the version on dirty sub-packages, without dependencies', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const options = Object.assign({}, NOMINAL_OPTIONS, {
bumpDependentReqs: "no",
});
await publish(options);

expect(writeSpecs).toHaveBeenCalledTimes(1 + NUM_FIXTURE_SUBPACKAGES);

writeSpecs.mock.calls.forEach(([, specs]) => {
expect(specs.version).toEqual('99.99.99');
});
expect(writeSpecs).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({
name: "oao",
version: "99.99.99",
}));
expect(writeSpecs).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
name: "oao-b",
version: "99.99.99",
dependencies: {
oao: "*",
timm: "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(3, expect.any(String), expect.objectContaining({
name: "oao-c",
version: "99.99.99",
dependencies: {
oao: "*",
timm: "1.x",
},
devDependencies: {
"oao-b": "*",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(4, expect.any(String), expect.objectContaining({
name: "oao-d",
version: "99.99.99",
dependencies: {
oao: "*",
timm: "1.x",
},
devDependencies: {
"oao-b": "*",
"oao-c": "*",
"xxl": "1.x",
},
}));
expect(writeSpecs).toHaveBeenNthCalledWith(5, expect.any(String), expect.objectContaining({
name: "oao-priv",
version: "99.99.99",
dependencies: {
oao: "*",
timm: "1.x",
},
devDependencies: {
"oao-b": "*",
"oao-c": "*",
"xxl": "1.x",
},
}));
expect(git.gitCommitChanges).toHaveBeenCalledTimes(1);
expect(git.gitAddTag).toHaveBeenCalledTimes(1);
expect(git.gitPushWithTags).toHaveBeenCalledTimes(1);
});

it('increments version by major when incrementVersionBy is "major" and newVersion is not set', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const options = Object.assign({}, NOMINAL_OPTIONS, {
Expand Down Expand Up @@ -196,6 +387,10 @@ describe('PUBLISH command', () => {

it('runs `npm publish` on dirty sub-packages (which are not private)', async () => {
const { exec } = require('../utils/shell');
git.gitDiffSinceIn.mockImplementation((version, path) => {
// Only oao-d was modified, but everything is still published
return path === "test/fixtures/packages/oao-d" ? "SOMETHING_HAS_CHANGED" : "";
})
await publish(NOMINAL_OPTIONS);
expect(exec).toHaveBeenCalledTimes(
NUM_FIXTURE_SUBPACKAGES - NUM_FIXTURE_PRIVATE_SUBPACKAGES
Expand Down Expand Up @@ -224,6 +419,22 @@ describe('PUBLISH command', () => {
]);
});

it('runs `npm publish` on dirty sub-packages, with dependencies (which are not private)', async () => {
const { exec } = require('../utils/shell');

git.gitDiffSinceIn.mockImplementation((version, path) => {
// Only oao-b was modified, but everything is still published
return path === "test/fixtures/packages/oao-b" ? "SOMETHING_HAS_CHANGED" : "";
})
await publish(NOMINAL_OPTIONS);
expect(exec).toHaveBeenCalledTimes(
NUM_FIXTURE_SUBPACKAGES - NUM_FIXTURE_PRIVATE_SUBPACKAGES
);
exec.mock.calls.forEach(([cmd]) => {
expect(cmd).toEqual('npm publish');
});
});

it('runs `npm publish --tag X` on dirty sub-packages', async () => {
const { exec } = require('../utils/shell');
await publish(merge(NOMINAL_OPTIONS, { publishTag: 'next' }));
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ createCommand('publish', 'Publish updated sub-packages')
.option('--no-changelog', 'skip changelog updates')
.option('--otp <code>', 'use 2FA to publish your package')
.option('--access <type>', 'publish public or restricted packages')
.option('--bump-dependent-reqs <range|exact|no>', 'bump dependencies ')
.action(cmd => {
const options = processOptions(cmd.opts());
initConsole(options);
Expand Down
Loading