Skip to content

Commit

Permalink
feat(core): generate new workspaces without tasks runner options (#19483
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AgentEnder authored Oct 11, 2023
1 parent b8e1500 commit 05e7602
Show file tree
Hide file tree
Showing 48 changed files with 347 additions and 352 deletions.
9 changes: 9 additions & 0 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Nx.json configuration
- [namedInputs](../../devkit/documents/NxJsonConfiguration#namedinputs): Object
- [npmScope](../../devkit/documents/NxJsonConfiguration#npmscope): string
- [nxCloudAccessToken](../../devkit/documents/NxJsonConfiguration#nxcloudaccesstoken): string
- [nxCloudEncryptionKey](../../devkit/documents/NxJsonConfiguration#nxcloudencryptionkey): string
- [nxCloudUrl](../../devkit/documents/NxJsonConfiguration#nxcloudurl): string
- [parallel](../../devkit/documents/NxJsonConfiguration#parallel): number
- [plugins](../../devkit/documents/NxJsonConfiguration#plugins): string[]
Expand Down Expand Up @@ -170,6 +171,14 @@ To use a different runner that accepts an access token, define it in [tasksRunne

---

### nxCloudEncryptionKey

`Optional` **nxCloudEncryptionKey**: `string`

Specifies the encryption key used to encrypt artifacts data before sending it to nx cloud.

---

### nxCloudUrl

`Optional` **nxCloudUrl**: `string`
Expand Down
13 changes: 13 additions & 0 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [namedInputs](../../devkit/documents/Workspace#namedinputs): Object
- [npmScope](../../devkit/documents/Workspace#npmscope): string
- [nxCloudAccessToken](../../devkit/documents/Workspace#nxcloudaccesstoken): string
- [nxCloudEncryptionKey](../../devkit/documents/Workspace#nxcloudencryptionkey): string
- [nxCloudUrl](../../devkit/documents/Workspace#nxcloudurl): string
- [parallel](../../devkit/documents/Workspace#parallel): number
- [plugins](../../devkit/documents/Workspace#plugins): string[]
Expand Down Expand Up @@ -214,6 +215,18 @@ To use a different runner that accepts an access token, define it in [tasksRunne

---

### nxCloudEncryptionKey

`Optional` **nxCloudEncryptionKey**: `string`

Specifies the encryption key used to encrypt artifacts data before sending it to nx cloud.

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[nxCloudEncryptionKey](../../devkit/documents/NxJsonConfiguration#nxcloudencryptionkey)

---

### nxCloudUrl

`Optional` **nxCloudUrl**: `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/migration/from-turborepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ For each `turbo.json` configuration property, the equivalent Nx property is list
| | |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `turbo run test lint build` | [`nx run-many -t test lint build`](/nx-api/nx/documents/run-many) |
| `--cache-dir` | Set in [`nx.json` under `tasksRunnerOptions.default.options.cacheDirectory`](/reference/nx-json#tasks-runner-options) |
| `--cache-dir` | Set in [`nx.json` under `cacheDirectory`](/reference/nx-json#cache-directory) |
| `--concurrency` | [`--parallel`](/nx-api/nx/documents/run-many#parallel) |
| `--continue` | [Use `--nx-bail`](/nx-api/nx/documents/run-many#nx-bail) with the inverse value |
| `--cwd` | Available when using the [`run-commands` executor](/nx-api/nx/executors/run-commands#cwd) |
Expand Down
11 changes: 3 additions & 8 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
affected: {
defaultBase: 'main',
},
tasksRunnerOptions: {
default: {
options: {
cacheableOperations: ['build', 'test', 'e2e'],
},
runner: 'nx/tasks-runners/default',
},
},
namedInputs: {
default: ['{projectRoot}/**/*', 'sharedGlobals'],
production: [
Expand All @@ -164,12 +156,15 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
build: {
dependsOn: ['^build'],
inputs: ['production', '^production'],
cache: true,
},
e2e: {
inputs: ['default', '^production'],
cache: true,
},
test: {
inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'],
cache: true,
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-misc/src/nxw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('nx wrapper / .nx installation', () => {
);

updateJson<NxJsonConfiguration>('nx.json', (json) => {
json.tasksRunnerOptions.default.options.cacheableOperations = ['echo'];
json.targetDefaults.echo = { cache: true };
json.installation.plugins = {
'@nx/js': getPublishedVersion(),
};
Expand Down
13 changes: 5 additions & 8 deletions e2e/nx-run/src/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ describe('cache', () => {
const originalNxJson = readFile('nx.json');
updateFile('nx.json', (c) => {
const nxJson = JSON.parse(c);
nxJson.tasksRunnerOptions = {
default: {
options: {
cacheableOperations: [],
},
},
};
for (const key in nxJson.targetDefaults ?? {}) {
delete nxJson.targetDefaults[key].cache;
}
return JSON.stringify(nxJson, null, 2);
});

Expand Down Expand Up @@ -262,6 +258,7 @@ describe('cache', () => {
c.targetDefaults = {
test: {
inputs: ['default', '^prod'],
cache: true,
},
};
return c;
Expand Down Expand Up @@ -319,9 +316,9 @@ describe('cache', () => {
const lib = uniq('lib');
runCLI(`generate @nx/js:lib ${lib}`);
updateJson(`nx.json`, (c) => {
c.tasksRunnerOptions.default.options.cacheableOperations.push('echo');
c.targetDefaults = {
echo: {
cache: true,
inputs: [
{
env: 'NAME',
Expand Down
15 changes: 11 additions & 4 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe('Nx Running Tests', () => {
beforeAll(() => (proj = newProject()));
afterAll(() => cleanupProject());

// Ensures that nx.json is restored to its original state after each test
let existingNxJson;
beforeEach(() => {
existingNxJson = readJson('nx.json');
});
afterEach(() => {
updateFile('nx.json', JSON.stringify(existingNxJson, null, 2));
});

describe('running targets', () => {
describe('(forwarding params)', () => {
let proj = uniq('proj');
Expand Down Expand Up @@ -465,16 +474,14 @@ describe('Nx Running Tests', () => {
return config;
});

nxJson.tasksRunnerOptions.default.options.cacheableOperations = [
'prep',
'outside',
];
nxJson.targetDefaults = {
prep: {
outputs: ['{workspaceRoot}/one.txt'],
cache: true,
},
outside: {
dependsOn: ['prep'],
cache: true,
},
};
updateFile('nx.json', JSON.stringify(nxJson));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
},
"targetDefaults": {
"build": {
"cache": true,
"dependsOn": [
"^build",
],
Expand All @@ -110,39 +111,29 @@ exports[`workspace move to nx layout should create nx.json 1`] = `
],
},
"e2e": {
"cache": true,
"inputs": [
"default",
"^production",
],
},
"lint": {
"cache": true,
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/eslint.config.js",
],
},
"test": {
"cache": true,
"inputs": [
"default",
"^production",
"{workspaceRoot}/karma.conf.js",
],
},
},
"tasksRunnerOptions": {
"default": {
"options": {
"cacheableOperations": [
"build",
"test",
"lint",
"e2e",
],
},
"runner": "nx/tasks-runners/default",
},
},
}
`;

Expand Down
14 changes: 5 additions & 9 deletions packages/angular/src/generators/ng-add/migrators/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@ export abstract class Migrator {

const nxJson = readNxJson(this.tree);

Object.keys(nxJson.tasksRunnerOptions ?? {}).forEach((taskRunnerName) => {
const taskRunner = nxJson.tasksRunnerOptions[taskRunnerName];
taskRunner.options.cacheableOperations = Array.from(
new Set([
...(taskRunner.options.cacheableOperations ?? []),
...targetNames,
])
);
});
nxJson.targetDefaults ??= {};
for (const target of targetNames) {
nxJson.targetDefaults[target] ??= {};
nxJson.targetDefaults[target].cache ??= true;
}

updateNxJson(this.tree, nxJson);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1618,9 +1618,9 @@ describe('app migrator', () => {

await migrator.migrate();

const { tasksRunnerOptions } = readNxJson(tree);
const { targetDefaults } = readNxJson(tree);
expect(
tasksRunnerOptions.default.options.cacheableOperations
Object.keys(targetDefaults).filter((f) => targetDefaults[f].cache)
).toStrictEqual([
'build',
'lint',
Expand Down Expand Up @@ -1654,9 +1654,9 @@ describe('app migrator', () => {

await migrator.migrate();

const { tasksRunnerOptions } = readNxJson(tree);
const { targetDefaults } = readNxJson(tree);
expect(
tasksRunnerOptions.default.options.cacheableOperations
Object.keys(targetDefaults).filter((f) => targetDefaults[f].cache)
).toStrictEqual(['build', 'lint', 'test', 'e2e', 'myCustomTest']);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,9 @@ describe('lib migrator', () => {

await migrator.migrate();

const { tasksRunnerOptions } = readNxJson(tree);
const { targetDefaults } = readNxJson(tree);
expect(
tasksRunnerOptions.default.options.cacheableOperations
Object.keys(targetDefaults).filter((f) => targetDefaults[f].cache)
).toStrictEqual([
'build',
'lint',
Expand Down Expand Up @@ -1304,9 +1304,9 @@ describe('lib migrator', () => {

await migrator.migrate();

const { tasksRunnerOptions } = readNxJson(tree);
const { targetDefaults } = readNxJson(tree);
expect(
tasksRunnerOptions.default.options.cacheableOperations
Object.keys(targetDefaults).filter((f) => targetDefaults[f].cache)
).toStrictEqual(['build', 'lint', 'test', 'e2e', 'myCustomTest']);
});
});
Expand Down
17 changes: 4 additions & 13 deletions packages/angular/src/generators/ng-add/utilities/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ export function createNxJson(
affected: {
defaultBase: options.defaultBase ?? deduceDefaultBase(),
},
tasksRunnerOptions: {
default: {
runner: 'nx/tasks-runners/default',
options: {
cacheableOperations: [
'build',
targets.test ? 'test' : undefined,
targets.lint ? 'lint' : undefined,
targets.e2e ? 'e2e' : undefined,
].filter(Boolean),
},
},
},
namedInputs: {
sharedGlobals: [],
default: ['{projectRoot}/**/*', 'sharedGlobals'],
Expand All @@ -86,10 +73,12 @@ export function createNxJson(
build: {
dependsOn: ['^build'],
inputs: ['production', '^production'],
cache: true,
},
test: targets.test
? {
inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'],
cache: true,
}
: undefined,
lint: targets.lint
Expand All @@ -99,11 +88,13 @@ export function createNxJson(
'{workspaceRoot}/.eslintrc.json',
'{workspaceRoot}/eslint.config.js',
],
cache: true,
}
: undefined,
e2e: targets.e2e
? {
inputs: ['default', '^production'],
cache: true,
}
: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export function updateProjectConfig(tree: Tree, schema: Schema) {
];
updateNxJson(tree, nxJson);
}
nxJson.targetDefaults ??= {};
nxJson.targetDefaults.server ??= {};
nxJson.targetDefaults.server.cache ??= true;
updateNxJson(tree, nxJson);
}

function getServerOptions(
Expand Down
34 changes: 2 additions & 32 deletions packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,7 @@ describe('setupSSR', () => {
expect(packageJson.devDependencies[dep]).toEqual(version);
}
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
expect(nxJson.tasksRunnerOptions).toMatchInlineSnapshot(`
{
"default": {
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e",
"server",
],
},
"runner": "nx/tasks-runners/default",
},
}
`);
expect(nxJson.targetDefaults.server.cache).toBe(true);
});

it('should use fileReplacements if they already exist', async () => {
Expand Down Expand Up @@ -219,22 +204,7 @@ describe('setupSSR', () => {
expect(packageJson.devDependencies[dep]).toEqual(version);
}
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
expect(nxJson.tasksRunnerOptions).toMatchInlineSnapshot(`
{
"default": {
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e",
"server",
],
},
"runner": "nx/tasks-runners/default",
},
}
`);
expect(nxJson.targetDefaults.server.cache).toEqual(true);
});

it('should add hydration correctly for NgModule apps', async () => {
Expand Down
Loading

1 comment on commit 05e7602

@vercel
Copy link

@vercel vercel bot commented on 05e7602 Oct 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.