Skip to content

Commit

Permalink
feat(js): replace publish script with nx release config (#21474)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Mar 5, 2024
1 parent 391f3ab commit 38179ad
Show file tree
Hide file tree
Showing 32 changed files with 1,676 additions and 194 deletions.
24 changes: 24 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Update Your Local Registry Setup to use Nx Release",
"path": "/recipes/nx-release/update-local-registry-setup",
"id": "update-local-registry-setup",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
Expand Down Expand Up @@ -4147,6 +4155,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Update Your Local Registry Setup to use Nx Release",
"path": "/recipes/nx-release/update-local-registry-setup",
"id": "update-local-registry-setup",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
Expand Down Expand Up @@ -4199,6 +4215,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Update Your Local Registry Setup to use Nx Release",
"path": "/recipes/nx-release/update-local-registry-setup",
"id": "update-local-registry-setup",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Other",
"path": "/recipes/other",
Expand Down
33 changes: 33 additions & 0 deletions docs/generated/manifests/nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3177,6 +3177,17 @@
"isExternal": false,
"path": "/recipes/nx-release/publish-rust-crates",
"tags": ["nx-release"]
},
{
"id": "update-local-registry-setup",
"name": "Update Your Local Registry Setup to use Nx Release",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/update-local-registry-setup",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
}
],
"isExternal": false,
Expand Down Expand Up @@ -5678,6 +5689,17 @@
"isExternal": false,
"path": "/recipes/nx-release/publish-rust-crates",
"tags": ["nx-release"]
},
{
"id": "update-local-registry-setup",
"name": "Update Your Local Registry Setup to use Nx Release",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/update-local-registry-setup",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
}
],
"isExternal": false,
Expand Down Expand Up @@ -5750,6 +5772,17 @@
"path": "/recipes/nx-release/publish-rust-crates",
"tags": ["nx-release"]
},
"/recipes/nx-release/update-local-registry-setup": {
"id": "update-local-registry-setup",
"name": "Update Your Local Registry Setup to use Nx Release",
"description": "",
"mediaImage": "",
"file": "shared/recipes/nx-release/update-local-registry-setup",
"itemList": [],
"isExternal": false,
"path": "/recipes/nx-release/update-local-registry-setup",
"tags": ["nx-release"]
},
"/recipes/other": {
"id": "other",
"name": "Other",
Expand Down
7 changes: 7 additions & 0 deletions docs/generated/manifests/tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,13 @@
"id": "publish-rust-crates",
"name": "Publish Rust Crates",
"path": "/recipes/nx-release/publish-rust-crates"
},
{
"description": "",
"file": "shared/recipes/nx-release/update-local-registry-setup",
"id": "update-local-registry-setup",
"name": "Update Your Local Registry Setup to use Nx Release",
"path": "/recipes/nx-release/update-local-registry-setup"
}
],
"database": [
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/js/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"publishable": {
"type": "boolean",
"default": false,
"description": "Generate a publishable library.",
"description": "Configure the library ready for use with `nx release` (https://nx.dev/core-features/manage-releases).",
"x-priority": "important"
},
"importPath": {
Expand Down
12 changes: 12 additions & 0 deletions docs/generated/packages/js/generators/release-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
"type": "object",
"description": "Additional metadata to pass to the current version resolver.",
"default": {}
},
"skipLockFileUpdate": {
"type": "boolean",
"description": "Whether to skip updating the lock file after updating the version."
},
"installArgs": {
"type": "string",
"description": "Additional arguments to pass to the package manager when updating the lock file with an install command."
},
"installIgnoreScripts": {
"type": "boolean",
"description": "Whether to ignore install lifecycle scripts when updating the lock file with an install command."
}
},
"required": ["projects", "projectGraph", "releaseGroup"],
Expand Down
6 changes: 6 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,12 @@
"id": "publish-rust-crates",
"tags": ["nx-release"],
"file": "shared/recipes/nx-release/publish-rust-crates"
},
{
"name": "Update Your Local Registry Setup to use Nx Release",
"id": "update-local-registry-setup",
"tags": ["nx-release"],
"file": "shared/recipes/nx-release/update-local-registry-setup"
}
]
},
Expand Down
79 changes: 79 additions & 0 deletions docs/shared/recipes/nx-release/update-local-registry-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Update Your Local Registry Setup to use Nx Release

Nx will create a `tools/start-local-registry.ts` script for starting a local registry and publishing packages to it in preparation for running end to end tests. If you have an existing `tools/start-local-registry.ts` script from a previous version of Nx, you should update it to use Nx Release to publish packages to the local registry. This will ensure that newly generated libraries are published appropriately when running end to end tests.

## The Previous Version

The previous version of the `tools/start-local-registry.ts` script used publish targets on each project to publish the packages to the local registry. This is no longer necessary with Nx Release. You can identify the previous version by the `nx run-many` command that publishes the packages:

```typescript
/**
* This script starts a local registry for e2e testing purposes.
* It is meant to be called in jest's globalSetup.
*/
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { execFileSync } from 'child_process';

export default async () => {
// local registry target to run
const localRegistryTarget = '@demo-plugin-1800/source:local-registry';
// storage folder for the local registry
const storage = './tmp/local-registry/storage';

global.stopLocalRegistry = await startLocalRegistry({
localRegistryTarget,
storage,
verbose: false,
});
const nx = require.resolve('nx');
execFileSync(
nx,
['run-many', '--targets', 'publish', '--ver', '0.0.0-e2e', '--tag', 'e2e'],
{ env: process.env, stdio: 'inherit' }
);
};
```

If your script looks like this, you should update it.

## The Updated Version

The updated version of the `tools/start-local-registry.ts` script uses Nx Release to publish the packages to the local registry. This is done by running `releaseVersion` and `releasePublish` functions from `nx/release`. Your updated script should look like this:

```typescript
/**
* This script starts a local registry for e2e testing purposes.
* It is meant to be called in jest's globalSetup.
*/
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { execFileSync } from 'child_process';
import { releasePublish, releaseVersion } from 'nx/release';

export default async () => {
// local registry target to run
const localRegistryTarget = '@demo-plugin-1800/source:local-registry';
// storage folder for the local registry
const storage = './tmp/local-registry/storage';

global.stopLocalRegistry = await startLocalRegistry({
localRegistryTarget,
storage,
verbose: false,
});

await releaseVersion({
specifier: '0.0.0-e2e',
stageChanges: false,
gitCommit: false,
gitTag: false,
firstRelease: true,
generatorOptionsOverrides: {
skipLockFileUpdate: true,
},
});
await releasePublish({
tag: 'e2e',
firstRelease: true,
});
};
```
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
- [Publish in CI/CD](/recipes/nx-release/publish-in-ci-cd)
- [Automate GitHub Releases](/recipes/nx-release/automate-github-releases)
- [Publish Rust Crates](/recipes/nx-release/publish-rust-crates)
- [Update Your Local Registry Setup to use Nx Release](/recipes/nx-release/update-local-registry-setup)
- [Other](/recipes/other)
- [Rescope Packages from @nrwl to @nx](/recipes/other/rescope)
- [Showcase](/showcase)
Expand Down
3 changes: 1 addition & 2 deletions e2e/esbuild/src/esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {
readJson,
runCLI,
runCommand,
runCommandUntil,
tmpProjPath,
uniq,
updateFile,
updateJson,
waitUntil,
} from '@nx/e2e/utils';
import { join } from 'path';

Expand Down Expand Up @@ -44,6 +42,7 @@ describe('EsBuild Plugin', () => {
expect(packageJson).toEqual({
name: `@proj/${myPkg}`,
version: '0.0.1',
private: true,
type: 'commonjs',
main: './index.cjs',
dependencies: {},
Expand Down
1 change: 1 addition & 0 deletions e2e/eslint/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ describe('Linter', () => {
},
"main": "./src/index.js",
"name": "@proj/${mylib}",
"private": true,
"type": "commonjs",
"typings": "./src/index.d.ts",
"version": "0.0.1",
Expand Down
3 changes: 2 additions & 1 deletion e2e/plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
} from '@nx/e2e/utils';
import type { PackageJson } from 'nx/src/utils/package-json';

import { join } from 'path';
import {
ASYNC_GENERATOR_EXECUTOR_CONTENTS,
NX_PLUGIN_V2_CONTENTS,
} from './nx-plugin.fixtures';
import { join } from 'path';

describe('Nx Plugin', () => {
let workspaceName: string;
Expand Down Expand Up @@ -50,6 +50,7 @@ describe('Nx Plugin', () => {
expect(project).toMatchObject({
tags: [],
});

runCLI(`e2e ${plugin}-e2e`);
}, 90000);

Expand Down
Loading

0 comments on commit 38179ad

Please sign in to comment.