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(release): only add nx-release-publish to public packages #21338

Merged
merged 8 commits into from
Jan 26, 2024
53 changes: 41 additions & 12 deletions e2e/release/src/independent-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ describe('nx release - independent projects', () => {

pkg3 = uniq('my-pkg-3');
runCLI(`generate @nx/workspace:npm-package ${pkg3}`);
updateJson(`${pkg3}/package.json`, (json) => {
json.private = true;
return json;
});

/**
* Update pkg2 to depend on pkg3.
Expand Down Expand Up @@ -205,9 +201,6 @@ describe('nx release - independent projects', () => {
+ "version": "999.9.9-package.3",
"scripts": {

}
+


"dependencies": {
- "@proj/{project-name}": "0.0.0"
Expand Down Expand Up @@ -424,7 +417,7 @@ describe('nx release - independent projects', () => {
release: {
projectsRelationship: 'independent',
changelog: {
projectChangelogs: {}, // enable project changelogs with default options
projectChangelogs: true, // enable project changelogs with default options
workspaceChangelog: false, // disable workspace changelog
},
},
Expand Down Expand Up @@ -746,7 +739,25 @@ describe('nx release - independent projects', () => {

> nx run {project-name}:nx-release-publish

Skipped package "@proj/{project-name}" from project "{project-name}", because it has \`"private": true\` in {project-name}/package.json

📦 @proj/{project-name}@999.9.9-version-git-operations-test.3
=== Tarball Contents ===

XXXB CHANGELOG.md
XXB index.js
XXXB package.json
XXB project.json
=== Tarball Details ===
name: @proj/{project-name}
version: 999.9.9-version-git-operations-test.3
filename: proj-{project-name}-999.9.9-version-git-operations-test.3.tgz
package size: XXXB
unpacked size: XXXB
shasum: {SHASUM}
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 4

Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set



Expand Down Expand Up @@ -837,7 +848,25 @@ describe('nx release - independent projects', () => {

> nx run {project-name}:nx-release-publish

Skipped package "@proj/{project-name}" from project "{project-name}", because it has \`"private": true\` in {project-name}/package.json

📦 @proj/{project-name}@999.9.9-version-git-operations-test.3
=== Tarball Contents ===

XXXB CHANGELOG.md
XXB index.js
XXXB package.json
XXB project.json
=== Tarball Details ===
name: @proj/{project-name}
version: 999.9.9-version-git-operations-test.3
filename: proj-{project-name}-999.9.9-version-git-operations-test.3.tgz
package size: XXXB
unpacked size: XXXB
shasum: {SHASUM}
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 4

Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set



Expand All @@ -862,7 +891,7 @@ describe('nx release - independent projects', () => {
},
},
changelog: {
projectChangelogs: {},
projectChangelogs: true,
},
},
};
Expand Down Expand Up @@ -920,7 +949,7 @@ describe('nx release - independent projects', () => {
},
},
changelog: {
projectChangelogs: {},
projectChangelogs: true,
},
},
};
Expand Down
17 changes: 6 additions & 11 deletions e2e/release/src/private-js-packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,23 @@ describe('nx release - private JS packages', () => {

`);

const privatePkgPublishOutput = runCLI(`release publish -p ${privatePkg}`);
const privatePkgPublishOutput = runCLI(`release publish -p ${privatePkg}`, {
silenceError: true,
});
expect(privatePkgPublishOutput).toMatchInlineSnapshot(`

> NX Your filter "{private-project-name}" matched the following projects:

- {private-project-name}


> NX Running target nx-release-publish for project {private-project-name}:
> NX Based on your config, the following projects were matched for publishing but do not have the "nx-release-publish" target specified:

- {private-project-name}

There are a few possible reasons for this: (1) The projects may be private (2) You may not have an appropriate plugin (such as \`@nx/js\`) installed which adds the target automatically to public projects (3) You intended to configure the target manually, or exclude those projects via config in nx.json


> nx run {private-project-name}:nx-release-publish

Skipped package "@proj/{private-project-name}" from project "{private-project-name}", because it has \`"private": true\` in {private-project-name}/package.json



> NX Successfully ran target nx-release-publish for project {private-project-name}

Pass --verbose to see the stacktrace.


`);
Expand Down
10 changes: 6 additions & 4 deletions packages/nx/src/command-line/release/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ const publishCommand: CommandModule<NxReleaseArgs, PublishOptions> = {
description:
'A one-time password for publishing to a registry that requires 2FA',
}),
handler: (args) =>
import('./publish').then((m) =>
m.releasePublishCLIHandler(coerceParallelOption(withOverrides(args, 2)))
),
handler: async (args) => {
const status = await (
await import('./publish')
).releasePublishCLIHandler(coerceParallelOption(withOverrides(args, 2)));
process.exit(status);
},
};

function coerceParallelOption(args: any) {
Expand Down
148 changes: 0 additions & 148 deletions packages/nx/src/command-line/release/config/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1967,80 +1967,6 @@ describe('createNxReleaseConfig()', () => {
}
`);
});

it('should return an error if any matched projects do not have the required target specified', async () => {
const res = await createNxReleaseConfig(
{
...projectGraph,
nodes: {
...projectGraph.nodes,
'project-without-target': {
name: 'project-without-target',
type: 'lib',
data: {
root: 'libs/project-without-target',
targets: {},
} as any,
},
},
},
{
groups: {
'group-1': {
projects: '*', // using string form to ensure that is supported in addition to array form
},
},
},
'nx-release-publish'
);
expect(res).toMatchInlineSnapshot(`
{
"error": {
"code": "PROJECTS_MISSING_TARGET",
"data": {
"projects": [
"project-without-target",
],
"targetName": "nx-release-publish",
},
},
"nxReleaseConfig": null,
}
`);

const res2 = await createNxReleaseConfig(
{
...projectGraph,
nodes: {
...projectGraph.nodes,
'another-project-without-target': {
name: 'another-project-without-target',
type: 'lib',
data: {
root: 'libs/another-project-without-target',
targets: {},
} as any,
},
},
},
{},
'nx-release-publish'
);
expect(res2).toMatchInlineSnapshot(`
{
"error": {
"code": "PROJECTS_MISSING_TARGET",
"data": {
"projects": [
"another-project-without-target",
],
"targetName": "nx-release-publish",
},
},
"nxReleaseConfig": null,
}
`);
});
});

describe('user config -> mixed top level and granular git', () => {
Expand Down Expand Up @@ -2172,80 +2098,6 @@ describe('createNxReleaseConfig()', () => {
`);
});

it('should return an error if any matched projects do not have the required target specified', async () => {
const res = await createNxReleaseConfig(
{
...projectGraph,
nodes: {
...projectGraph.nodes,
'project-without-target': {
name: 'project-without-target',
type: 'lib',
data: {
root: 'libs/project-without-target',
targets: {},
} as any,
},
},
},
{
groups: {
'group-1': {
projects: '*', // using string form to ensure that is supported in addition to array form
},
},
},
'nx-release-publish'
);
expect(res).toMatchInlineSnapshot(`
{
"error": {
"code": "PROJECTS_MISSING_TARGET",
"data": {
"projects": [
"project-without-target",
],
"targetName": "nx-release-publish",
},
},
"nxReleaseConfig": null,
}
`);

const res2 = await createNxReleaseConfig(
{
...projectGraph,
nodes: {
...projectGraph.nodes,
'another-project-without-target': {
name: 'another-project-without-target',
type: 'lib',
data: {
root: 'libs/another-project-without-target',
targets: {},
} as any,
},
},
},
{},
'nx-release-publish'
);
expect(res2).toMatchInlineSnapshot(`
{
"error": {
"code": "PROJECTS_MISSING_TARGET",
"data": {
"projects": [
"another-project-without-target",
],
"targetName": "nx-release-publish",
},
},
"nxReleaseConfig": null,
}
`);
});

it("should return an error if a group's releaseTagPattern has no {version} placeholder", async () => {
const res = await createNxReleaseConfig(projectGraph, {
groups: {
Expand Down
Loading