chore(core): remove readProjectsConfigurations from workspaces (#18329)
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
parent
37fd20b706
commit
40d66ec715
@ -138,12 +138,12 @@ It only uses language primitives and immutable objects
|
|||||||
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
|
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
|
||||||
- [parseJson](../../devkit/documents/parseJson)
|
- [parseJson](../../devkit/documents/parseJson)
|
||||||
- [parseTargetString](../../devkit/documents/parseTargetString)
|
- [parseTargetString](../../devkit/documents/parseTargetString)
|
||||||
- [readAllWorkspaceConfiguration](../../devkit/documents/readAllWorkspaceConfiguration)
|
|
||||||
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
|
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
|
||||||
- [readJson](../../devkit/documents/readJson)
|
- [readJson](../../devkit/documents/readJson)
|
||||||
- [readJsonFile](../../devkit/documents/readJsonFile)
|
- [readJsonFile](../../devkit/documents/readJsonFile)
|
||||||
- [readNxJson](../../devkit/documents/readNxJson)
|
- [readNxJson](../../devkit/documents/readNxJson)
|
||||||
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
||||||
|
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
|
||||||
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
||||||
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
||||||
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Class: Workspaces
|
# Class: Workspaces
|
||||||
|
|
||||||
|
**`Deprecated`**
|
||||||
|
|
||||||
|
This will be removed in v18. Use [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) instead.
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
### Constructors
|
### Constructors
|
||||||
@ -8,13 +12,10 @@
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- [cachedProjectsConfig](../../devkit/documents/Workspaces#cachedprojectsconfig)
|
|
||||||
- [root](../../devkit/documents/Workspaces#root)
|
- [root](../../devkit/documents/Workspaces#root)
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
|
|
||||||
- [mergeTargetDefaultsIntoProjectDescriptions](../../devkit/documents/Workspaces#mergetargetdefaultsintoprojectdescriptions)
|
|
||||||
- [readProjectsConfigurations](../../devkit/documents/Workspaces#readprojectsconfigurations)
|
|
||||||
- [readWorkspaceConfiguration](../../devkit/documents/Workspaces#readworkspaceconfiguration)
|
- [readWorkspaceConfiguration](../../devkit/documents/Workspaces#readworkspaceconfiguration)
|
||||||
|
|
||||||
## Constructors
|
## Constructors
|
||||||
@ -31,67 +32,19 @@
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
### cachedProjectsConfig
|
|
||||||
|
|
||||||
• `Private` **cachedProjectsConfig**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### root
|
### root
|
||||||
|
|
||||||
• `Private` **root**: `string`
|
• `Private` **root**: `string`
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### mergeTargetDefaultsIntoProjectDescriptions
|
### readWorkspaceConfiguration
|
||||||
|
|
||||||
▸ `Private` **mergeTargetDefaultsIntoProjectDescriptions**(`projects`, `nxJson`): `Record`<`string`, [`ProjectConfiguration`](../../devkit/documents/ProjectConfiguration)\>
|
▸ **readWorkspaceConfiguration**(): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\>
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :--------- | :----------------------------------------------------------------------------------------- |
|
|
||||||
| `projects` | `Record`<`string`, [`ProjectConfiguration`](../../devkit/documents/ProjectConfiguration)\> |
|
|
||||||
| `nxJson` | [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\> |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
`Record`<`string`, [`ProjectConfiguration`](../../devkit/documents/ProjectConfiguration)\>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### readProjectsConfigurations
|
|
||||||
|
|
||||||
▸ **readProjectsConfigurations**(`opts?`): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
|
||||||
|
|
||||||
**`Deprecated`**
|
**`Deprecated`**
|
||||||
|
|
||||||
#### Parameters
|
Use [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) instead.
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :-------------------------------------- | :-------- |
|
|
||||||
| `opts?` | `Object` |
|
|
||||||
| `opts._includeProjectsFromAngularJson?` | `boolean` |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
[`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### readWorkspaceConfiguration
|
|
||||||
|
|
||||||
▸ **readWorkspaceConfiguration**(`opts?`): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\>
|
|
||||||
|
|
||||||
Deprecated. Use readProjectsConfigurations
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :-------------------------------------- | :-------- |
|
|
||||||
| `opts?` | `Object` |
|
|
||||||
| `opts._ignorePluginInference?` | `boolean` |
|
|
||||||
| `opts._includeProjectsFromAngularJson?` | `boolean` |
|
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
# Function: readAllWorkspaceConfiguration
|
|
||||||
|
|
||||||
▸ **readAllWorkspaceConfiguration**(): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)
|
|
||||||
|
|
||||||
**`Deprecated`**
|
|
||||||
|
|
||||||
Use readProjectsConfigurationFromProjectGraph(await createProjectGraphAsync())
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
[`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)
|
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
# Function: readProjectsConfigurationFromProjectGraph
|
||||||
|
|
||||||
|
▸ **readProjectsConfigurationFromProjectGraph**(`projectGraph`): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
||||||
|
|
||||||
|
Get the [ProjectsConfigurations](../../devkit/documents/ProjectsConfigurations) from the [ProjectGraph](../../devkit/documents/ProjectGraph)
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :------------- | :---------------------------------------------------- |
|
||||||
|
| `projectGraph` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
||||||
@ -138,12 +138,12 @@ It only uses language primitives and immutable objects
|
|||||||
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
|
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
|
||||||
- [parseJson](../../devkit/documents/parseJson)
|
- [parseJson](../../devkit/documents/parseJson)
|
||||||
- [parseTargetString](../../devkit/documents/parseTargetString)
|
- [parseTargetString](../../devkit/documents/parseTargetString)
|
||||||
- [readAllWorkspaceConfiguration](../../devkit/documents/readAllWorkspaceConfiguration)
|
|
||||||
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
|
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
|
||||||
- [readJson](../../devkit/documents/readJson)
|
- [readJson](../../devkit/documents/readJson)
|
||||||
- [readJsonFile](../../devkit/documents/readJsonFile)
|
- [readJsonFile](../../devkit/documents/readJsonFile)
|
||||||
- [readNxJson](../../devkit/documents/readNxJson)
|
- [readNxJson](../../devkit/documents/readNxJson)
|
||||||
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
||||||
|
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
|
||||||
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
||||||
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
||||||
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
||||||
|
|||||||
@ -173,8 +173,10 @@ describe('Angular Module Federation', () => {
|
|||||||
|
|
||||||
// ports
|
// ports
|
||||||
const hostPort = 4500;
|
const hostPort = 4500;
|
||||||
const remote1Port = readProjectConfig(remote1).targets.serve.options.port;
|
const remote1Port = (await readProjectConfig(remote1)).targets.serve.options
|
||||||
const remote2Port = readProjectConfig(remote2).targets.serve.options.port;
|
.port;
|
||||||
|
const remote2Port = (await readProjectConfig(remote2)).targets.serve.options
|
||||||
|
.port;
|
||||||
|
|
||||||
const process = await runCommandUntil(
|
const process = await runCommandUntil(
|
||||||
`serve-ssr ${host} --port=${hostPort}`,
|
`serve-ssr ${host} --port=${hostPort}`,
|
||||||
|
|||||||
@ -268,7 +268,7 @@ describe('Angular Projects', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// update the angular.json
|
// update the angular.json
|
||||||
updateProjectConfig(app1, (config) => {
|
await updateProjectConfig(app1, (config) => {
|
||||||
config.targets.build.executor = '@nx/angular:webpack-browser';
|
config.targets.build.executor = '@nx/angular:webpack-browser';
|
||||||
config.targets.build.options = {
|
config.targets.build.options = {
|
||||||
...config.targets.build.options,
|
...config.targets.build.options,
|
||||||
@ -276,7 +276,7 @@ describe('Angular Projects', () => {
|
|||||||
};
|
};
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
updateProjectConfig(esbuildApp, (config) => {
|
await updateProjectConfig(esbuildApp, (config) => {
|
||||||
config.targets.build.executor = '@nx/angular:browser-esbuild';
|
config.targets.build.executor = '@nx/angular:browser-esbuild';
|
||||||
config.targets.build.options = {
|
config.targets.build.options = {
|
||||||
...config.targets.build.options,
|
...config.targets.build.options,
|
||||||
|
|||||||
@ -30,7 +30,7 @@ describe('Angular Cypress Component Tests', () => {
|
|||||||
|
|
||||||
createBuildableLib(projectName, buildableLibName);
|
createBuildableLib(projectName, buildableLibName);
|
||||||
|
|
||||||
useWorkspaceAssetsInApp(appName);
|
await useWorkspaceAssetsInApp(appName);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => cleanupProject());
|
afterAll(() => cleanupProject());
|
||||||
@ -265,7 +265,7 @@ export class AppModule {}
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useWorkspaceAssetsInApp(appName: string) {
|
async function useWorkspaceAssetsInApp(appName: string) {
|
||||||
// make sure assets from the workspace root work.
|
// make sure assets from the workspace root work.
|
||||||
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
|
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
|
||||||
createFile(
|
createFile(
|
||||||
@ -279,7 +279,7 @@ function useWorkspaceAssetsInApp(appName: string) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets['build'].options.stylePreprocessorOptions = {
|
config.targets['build'].options.stylePreprocessorOptions = {
|
||||||
includePaths: ['assets/styles'],
|
includePaths: ['assets/styles'],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -360,7 +360,7 @@ describe('Tailwind support', () => {
|
|||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/angular:app ${appWithTailwind} --add-tailwind --no-interactive`
|
`generate @nx/angular:app ${appWithTailwind} --add-tailwind --no-interactive`
|
||||||
);
|
);
|
||||||
updateProjectConfig(appWithTailwind, (config) => {
|
await updateProjectConfig(appWithTailwind, (config) => {
|
||||||
config.targets.build.executor = '@nx/angular:webpack-browser';
|
config.targets.build.executor = '@nx/angular:webpack-browser';
|
||||||
config.targets.build.options = {
|
config.targets.build.options = {
|
||||||
...config.targets.build.options,
|
...config.targets.build.options,
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import {
|
|||||||
packageInstall,
|
packageInstall,
|
||||||
readFile,
|
readFile,
|
||||||
readJson,
|
readJson,
|
||||||
rmDist,
|
|
||||||
runCLI,
|
runCLI,
|
||||||
runCommand,
|
runCommand,
|
||||||
runCommandUntil,
|
runCommandUntil,
|
||||||
@ -27,7 +26,7 @@ describe('EsBuild Plugin', () => {
|
|||||||
const myPkg = uniq('my-pkg');
|
const myPkg = uniq('my-pkg');
|
||||||
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
|
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
|
||||||
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('Hello');\n`);
|
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('Hello');\n`);
|
||||||
updateProjectConfig(myPkg, (json) => {
|
await updateProjectConfig(myPkg, (json) => {
|
||||||
json.targets.build.options.assets = [`libs/${myPkg}/assets/*`];
|
json.targets.build.options.assets = [`libs/${myPkg}/assets/*`];
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
@ -179,12 +178,12 @@ describe('EsBuild Plugin', () => {
|
|||||||
expect(runCommand(`node dist/libs/${myPkg}`)).toMatch(/Hello/);
|
expect(runCommand(`node dist/libs/${myPkg}`)).toMatch(/Hello/);
|
||||||
}, 300_000);
|
}, 300_000);
|
||||||
|
|
||||||
it('should support additional entry points', () => {
|
it('should support additional entry points', async () => {
|
||||||
const myPkg = uniq('my-pkg');
|
const myPkg = uniq('my-pkg');
|
||||||
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
|
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
|
||||||
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\n`);
|
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\n`);
|
||||||
updateFile(`libs/${myPkg}/src/extra.ts`, `console.log('extra');\n`);
|
updateFile(`libs/${myPkg}/src/extra.ts`, `console.log('extra');\n`);
|
||||||
updateProjectConfig(myPkg, (json) => {
|
await updateProjectConfig(myPkg, (json) => {
|
||||||
json.targets.build.options.additionalEntryPoints = [
|
json.targets.build.options.additionalEntryPoints = [
|
||||||
`libs/${myPkg}/src/extra.ts`,
|
`libs/${myPkg}/src/extra.ts`,
|
||||||
];
|
];
|
||||||
@ -212,7 +211,7 @@ describe('EsBuild Plugin', () => {
|
|||||||
`libs/${myPkg}/esbuild.config.js`,
|
`libs/${myPkg}/esbuild.config.js`,
|
||||||
`console.log('custom config loaded');\nmodule.exports = {};\n`
|
`console.log('custom config loaded');\nmodule.exports = {};\n`
|
||||||
);
|
);
|
||||||
updateProjectConfig(myPkg, (json) => {
|
await updateProjectConfig(myPkg, (json) => {
|
||||||
delete json.targets.build.options.esbuildOptions;
|
delete json.targets.build.options.esbuildOptions;
|
||||||
json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`;
|
json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`;
|
||||||
return json;
|
return json;
|
||||||
|
|||||||
@ -85,8 +85,8 @@ describe('expo', () => {
|
|||||||
it('should prebuild', async () => {
|
it('should prebuild', async () => {
|
||||||
// run prebuild command with git check disable
|
// run prebuild command with git check disable
|
||||||
// set a mock package name for ios and android in expo's app.json
|
// set a mock package name for ios and android in expo's app.json
|
||||||
const workspace = readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
const root = workspace.projects[appName].root;
|
const root = projects[appName].root;
|
||||||
const appJsonPath = join(root, `app.json`);
|
const appJsonPath = join(root, `app.json`);
|
||||||
const appJson = await readJson(appJsonPath);
|
const appJson = await readJson(appJsonPath);
|
||||||
if (appJson.expo.ios) {
|
if (appJson.expo.ios) {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ describe('js:node error handling', () => {
|
|||||||
|
|
||||||
afterEach(() => cleanupProject());
|
afterEach(() => cleanupProject());
|
||||||
|
|
||||||
it('should log out the error', () => {
|
it('should log out the error', async () => {
|
||||||
const esbuildLib = uniq('esbuildlib');
|
const esbuildLib = uniq('esbuildlib');
|
||||||
|
|
||||||
runCLI(
|
runCLI(
|
||||||
@ -30,7 +30,7 @@ describe('js:node error handling', () => {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProjectConfig(esbuildLib, (config) => {
|
await updateProjectConfig(esbuildLib, (config) => {
|
||||||
config.targets['run-node'] = {
|
config.targets['run-node'] = {
|
||||||
executor: '@nx/js:node',
|
executor: '@nx/js:node',
|
||||||
options: {
|
options: {
|
||||||
@ -48,7 +48,7 @@ describe('js:node error handling', () => {
|
|||||||
expect(output).toContain('This is an error');
|
expect(output).toContain('This is an error');
|
||||||
}, 240_000);
|
}, 240_000);
|
||||||
|
|
||||||
it('should execute library compiled with rollup', () => {
|
it('should execute library compiled with rollup', async () => {
|
||||||
const rollupLib = uniq('rolluplib');
|
const rollupLib = uniq('rolluplib');
|
||||||
|
|
||||||
runCLI(
|
runCLI(
|
||||||
@ -61,7 +61,7 @@ describe('js:node error handling', () => {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProjectConfig(rollupLib, (config) => {
|
await updateProjectConfig(rollupLib, (config) => {
|
||||||
config.targets['run-node'] = {
|
config.targets['run-node'] = {
|
||||||
executor: '@nx/js:node',
|
executor: '@nx/js:node',
|
||||||
options: {
|
options: {
|
||||||
@ -76,7 +76,7 @@ describe('js:node error handling', () => {
|
|||||||
expect(output).toContain('Hello from my library!');
|
expect(output).toContain('Hello from my library!');
|
||||||
}, 240_000);
|
}, 240_000);
|
||||||
|
|
||||||
it('should execute library compiled with tsc', () => {
|
it('should execute library compiled with tsc', async () => {
|
||||||
const tscLib = uniq('tsclib');
|
const tscLib = uniq('tsclib');
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${tscLib} --bundler=tsc --no-interactive`);
|
runCLI(`generate @nx/js:lib ${tscLib} --bundler=tsc --no-interactive`);
|
||||||
@ -87,7 +87,7 @@ describe('js:node error handling', () => {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProjectConfig(tscLib, (config) => {
|
await updateProjectConfig(tscLib, (config) => {
|
||||||
config.targets['run-node'] = {
|
config.targets['run-node'] = {
|
||||||
executor: '@nx/js:node',
|
executor: '@nx/js:node',
|
||||||
options: {
|
options: {
|
||||||
@ -102,7 +102,7 @@ describe('js:node error handling', () => {
|
|||||||
expect(output).toContain('Hello from my tsc library!');
|
expect(output).toContain('Hello from my tsc library!');
|
||||||
}, 240_000);
|
}, 240_000);
|
||||||
|
|
||||||
it('should execute library compiled with swc', () => {
|
it('should execute library compiled with swc', async () => {
|
||||||
const swcLib = uniq('swclib');
|
const swcLib = uniq('swclib');
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${swcLib} --bundler=swc --no-interactive`);
|
runCLI(`generate @nx/js:lib ${swcLib} --bundler=swc --no-interactive`);
|
||||||
@ -113,7 +113,7 @@ describe('js:node error handling', () => {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProjectConfig(swcLib, (config) => {
|
await updateProjectConfig(swcLib, (config) => {
|
||||||
config.targets['run-node'] = {
|
config.targets['run-node'] = {
|
||||||
executor: '@nx/js:node',
|
executor: '@nx/js:node',
|
||||||
options: {
|
options: {
|
||||||
@ -128,7 +128,7 @@ describe('js:node error handling', () => {
|
|||||||
expect(output).toContain('Hello from my swc library!');
|
expect(output).toContain('Hello from my swc library!');
|
||||||
}, 240_000);
|
}, 240_000);
|
||||||
|
|
||||||
it('should execute webpack app', () => {
|
it('should execute webpack app', async () => {
|
||||||
const webpackProject = uniq('webpackproject');
|
const webpackProject = uniq('webpackproject');
|
||||||
|
|
||||||
runCLI(
|
runCLI(
|
||||||
@ -141,7 +141,7 @@ describe('js:node error handling', () => {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateProjectConfig(webpackProject, (config) => {
|
await updateProjectConfig(webpackProject, (config) => {
|
||||||
config.targets['run-node'] = {
|
config.targets['run-node'] = {
|
||||||
executor: '@nx/js:node',
|
executor: '@nx/js:node',
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
@ -123,7 +123,7 @@ describe('bundling libs', () => {
|
|||||||
expect(output).toContain(rollupLib);
|
expect(output).toContain(rollupLib);
|
||||||
}, 500_000);
|
}, 500_000);
|
||||||
|
|
||||||
it('should support tsc and swc for building libs', () => {
|
it('should support tsc and swc for building libs', async () => {
|
||||||
const tscLib = uniq('tsclib');
|
const tscLib = uniq('tsclib');
|
||||||
const swcLib = uniq('swclib');
|
const swcLib = uniq('swclib');
|
||||||
const tscEsmLib = uniq('tscesmlib');
|
const tscEsmLib = uniq('tscesmlib');
|
||||||
@ -154,7 +154,7 @@ describe('bundling libs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add additional entry points for `exports` field
|
// Add additional entry points for `exports` field
|
||||||
updateProjectConfig(tscLib, (json) => {
|
await updateProjectConfig(tscLib, (json) => {
|
||||||
json.targets.build.options.additionalEntryPoints = [
|
json.targets.build.options.additionalEntryPoints = [
|
||||||
`libs/${tscLib}/src/foo/*.ts`,
|
`libs/${tscLib}/src/foo/*.ts`,
|
||||||
];
|
];
|
||||||
@ -162,7 +162,7 @@ describe('bundling libs', () => {
|
|||||||
});
|
});
|
||||||
updateFile(`libs/${tscLib}/src/foo/bar.ts`, `export const bar = 'bar';`);
|
updateFile(`libs/${tscLib}/src/foo/bar.ts`, `export const bar = 'bar';`);
|
||||||
updateFile(`libs/${tscLib}/src/foo/faz.ts`, `export const faz = 'faz';`);
|
updateFile(`libs/${tscLib}/src/foo/faz.ts`, `export const faz = 'faz';`);
|
||||||
updateProjectConfig(swcLib, (json) => {
|
await updateProjectConfig(swcLib, (json) => {
|
||||||
json.targets.build.options.additionalEntryPoints = [
|
json.targets.build.options.additionalEntryPoints = [
|
||||||
`libs/${swcLib}/src/foo/*.ts`,
|
`libs/${swcLib}/src/foo/*.ts`,
|
||||||
];
|
];
|
||||||
|
|||||||
@ -67,7 +67,7 @@ describe('Next.js Applications', () => {
|
|||||||
|
|
||||||
// Additional assets that should be copied to dist
|
// Additional assets that should be copied to dist
|
||||||
const sharedLib = uniq('sharedLib');
|
const sharedLib = uniq('sharedLib');
|
||||||
updateProjectConfig(appName, (json) => {
|
await updateProjectConfig(appName, (json) => {
|
||||||
json.targets.build.options.assets = [
|
json.targets.build.options.assets = [
|
||||||
{
|
{
|
||||||
glob: '**/*',
|
glob: '**/*',
|
||||||
@ -367,7 +367,7 @@ describe('Next.js Applications', () => {
|
|||||||
checkFilesExist(`dist/apps/${appName}/next.config.js`);
|
checkFilesExist(`dist/apps/${appName}/next.config.js`);
|
||||||
|
|
||||||
// Make sure withNx works with run-commands.
|
// Make sure withNx works with run-commands.
|
||||||
updateProjectConfig(appName, (json) => {
|
await updateProjectConfig(appName, (json) => {
|
||||||
json.targets.build = {
|
json.targets.build = {
|
||||||
command: 'npx next build',
|
command: 'npx next build',
|
||||||
outputs: [`apps/${appName}/.next`],
|
outputs: [`apps/${appName}/.next`],
|
||||||
|
|||||||
@ -151,7 +151,7 @@ describe('Node Applications + webpack', () => {
|
|||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/node:app ${nodeApp2} --framework=none --no-interactive`
|
`generate @nx/node:app ${nodeApp2} --framework=none --no-interactive`
|
||||||
);
|
);
|
||||||
updateProjectConfig(nodeApp1, (config) => {
|
await updateProjectConfig(nodeApp1, (config) => {
|
||||||
config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`];
|
config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -55,7 +55,7 @@ describe('Node Applications + webpack', () => {
|
|||||||
const lib = uniq('nodelib');
|
const lib = uniq('nodelib');
|
||||||
runCLI(`generate @nx/js:lib ${lib} --bundler=esbuild --no-interactive`);
|
runCLI(`generate @nx/js:lib ${lib} --bundler=esbuild --no-interactive`);
|
||||||
|
|
||||||
updateProjectConfig(app, (config) => {
|
await updateProjectConfig(app, (config) => {
|
||||||
// Since we read from lib from dist, we should re-build it when lib changes.
|
// Since we read from lib from dist, we should re-build it when lib changes.
|
||||||
config.targets.build.options.buildLibsFromSource = false;
|
config.targets.build.options.buildLibsFromSource = false;
|
||||||
config.targets.serve.options.runBuildTargetDependencies = true;
|
config.targets.serve.options.runBuildTargetDependencies = true;
|
||||||
|
|||||||
@ -75,7 +75,7 @@ describe('Node Applications', () => {
|
|||||||
const nodeapp = uniq('nodeapp');
|
const nodeapp = uniq('nodeapp');
|
||||||
runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`);
|
runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`);
|
||||||
|
|
||||||
updateProjectConfig(nodeapp, (config) => {
|
await updateProjectConfig(nodeapp, (config) => {
|
||||||
config.targets.build.options.outputFileName = 'index.js';
|
config.targets.build.options.outputFileName = 'index.js';
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -94,7 +94,7 @@ describe('Node Applications', () => {
|
|||||||
const lintResults = runCLI(`lint ${nodeapp}`);
|
const lintResults = runCLI(`lint ${nodeapp}`);
|
||||||
expect(lintResults).toContain('All files pass linting.');
|
expect(lintResults).toContain('All files pass linting.');
|
||||||
|
|
||||||
updateProjectConfig(nodeapp, (config) => {
|
await updateProjectConfig(nodeapp, (config) => {
|
||||||
config.targets.build.options.additionalEntryPoints = [
|
config.targets.build.options.additionalEntryPoints = [
|
||||||
{
|
{
|
||||||
entryName: 'additional-main',
|
entryName: 'additional-main',
|
||||||
@ -254,7 +254,7 @@ describe('Node Applications', () => {
|
|||||||
config.target = 'es2020';
|
config.target = 'es2020';
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
updateProjectConfig(esmapp, (config) => {
|
await updateProjectConfig(esmapp, (config) => {
|
||||||
config.targets.build.options.outputFileName = 'main.mjs';
|
config.targets.build.options.outputFileName = 'main.mjs';
|
||||||
config.targets.build.options.assets = [];
|
config.targets.build.options.assets = [];
|
||||||
return config;
|
return config;
|
||||||
@ -436,7 +436,7 @@ ${jslib}();
|
|||||||
|
|
||||||
packageInstall('@nestjs/swagger', undefined, '^6.0.0');
|
packageInstall('@nestjs/swagger', undefined, '^6.0.0');
|
||||||
|
|
||||||
updateProjectConfig(nestapp, (config) => {
|
await updateProjectConfig(nestapp, (config) => {
|
||||||
config.targets.build.options.tsPlugins = ['@nestjs/swagger/plugin'];
|
config.targets.build.options.tsPlugins = ['@nestjs/swagger/plugin'];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -549,7 +549,7 @@ describe('nest libraries', function () {
|
|||||||
|
|
||||||
packageInstall('@nestjs/swagger', undefined, '~6.3.0');
|
packageInstall('@nestjs/swagger', undefined, '~6.3.0');
|
||||||
|
|
||||||
updateProjectConfig(nestlib, (config) => {
|
await updateProjectConfig(nestlib, (config) => {
|
||||||
config.targets.build.options.transformers = [
|
config.targets.build.options.transformers = [
|
||||||
{
|
{
|
||||||
name: '@nestjs/swagger/plugin',
|
name: '@nestjs/swagger/plugin',
|
||||||
|
|||||||
@ -18,7 +18,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
it('should stream output', async () => {
|
it('should stream output', async () => {
|
||||||
const myapp = 'abcdefghijklmon';
|
const myapp = 'abcdefghijklmon';
|
||||||
runCLI(`generate @nx/web:app ${myapp}`);
|
runCLI(`generate @nx/web:app ${myapp}`);
|
||||||
updateProjectConfig(myapp, (c) => {
|
await updateProjectConfig(myapp, (c) => {
|
||||||
c.targets['inner'] = {
|
c.targets['inner'] = {
|
||||||
command: 'echo inner',
|
command: 'echo inner',
|
||||||
};
|
};
|
||||||
@ -122,7 +122,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
process.platform === 'win32'
|
process.platform === 'win32'
|
||||||
? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows
|
? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows
|
||||||
: `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`;
|
: `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`;
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
config.targets.echoEnvVariables.options.command += ` ${command}`;
|
config.targets.echoEnvVariables.options.command += ` ${command}`;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -135,7 +135,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
it('should pass options', async () => {
|
it('should pass options', async () => {
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
config.targets.echo = {
|
config.targets.echo = {
|
||||||
command: 'echo --var1={args.var1}',
|
command: 'echo --var1={args.var1}',
|
||||||
options: {
|
options: {
|
||||||
@ -151,7 +151,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
|
|
||||||
it('should interpolate provided arguments', async () => {
|
it('should interpolate provided arguments', async () => {
|
||||||
const echoTarget = uniq('echo');
|
const echoTarget = uniq('echo');
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
config.targets[echoTarget] = {
|
config.targets[echoTarget] = {
|
||||||
executor: 'nx:run-commands',
|
executor: 'nx:run-commands',
|
||||||
options: {
|
options: {
|
||||||
@ -186,7 +186,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
it('should fail when a process exits non-zero', async () => {
|
it('should fail when a process exits non-zero', async () => {
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
config.targets.error = {
|
config.targets.error = {
|
||||||
executor: 'nx:run-commands',
|
executor: 'nx:run-commands',
|
||||||
options: {
|
options: {
|
||||||
@ -207,7 +207,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('run command should not break if output property is missing in options and arguments', async () => {
|
it('run command should not break if output property is missing in options and arguments', async () => {
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
config.targets.lint.outputs = ['{options.outputFile}'];
|
config.targets.lint.outputs = ['{options.outputFile}'];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -241,7 +241,7 @@ describe('Extra Nx Misc Tests', () => {
|
|||||||
: `mkdir -p ${folder}`,
|
: `mkdir -p ${folder}`,
|
||||||
`echo dummy > ${folder}/dummy.txt`,
|
`echo dummy > ${folder}/dummy.txt`,
|
||||||
];
|
];
|
||||||
updateProjectConfig(mylib, (config) => {
|
await updateProjectConfig(mylib, (config) => {
|
||||||
delete config.targets.build.options.command;
|
delete config.targets.build.options.command;
|
||||||
config.targets.build.options = {
|
config.targets.build.options = {
|
||||||
...config.targets.build.options,
|
...config.targets.build.options,
|
||||||
|
|||||||
@ -113,7 +113,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib3, (config) => {
|
await updateProjectConfig(lib3, (config) => {
|
||||||
config.implicitDependencies = [`${lib1}-data-access`];
|
config.implicitDependencies = [`${lib1}-data-access`];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -172,13 +172,13 @@ describe('Workspace Tests', () => {
|
|||||||
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
||||||
checkFilesExist(rootClassPath);
|
checkFilesExist(rootClassPath);
|
||||||
|
|
||||||
let workspace = await readResolvedConfiguration();
|
let projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
|
expect(projects[`${lib1}-data-access`]).toBeUndefined();
|
||||||
const newConfig = readProjectConfig(newName);
|
const newConfig = await readProjectConfig(newName);
|
||||||
expect(newConfig).toMatchObject({
|
expect(newConfig).toMatchObject({
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
const lib3Config = readProjectConfig(lib3);
|
const lib3Config = await readProjectConfig(lib3);
|
||||||
expect(lib3Config.implicitDependencies).toEqual([
|
expect(lib3Config.implicitDependencies).toEqual([
|
||||||
`shared-${lib1}-data-access`,
|
`shared-${lib1}-data-access`,
|
||||||
]);
|
]);
|
||||||
@ -194,9 +194,9 @@ describe('Workspace Tests', () => {
|
|||||||
]
|
]
|
||||||
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
||||||
|
|
||||||
workspace = readResolvedConfiguration();
|
projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
|
expect(projects[`${lib1}-data-access`]).toBeUndefined();
|
||||||
const project = readProjectConfig(newName);
|
const project = await readProjectConfig(newName);
|
||||||
expect(project).toBeTruthy();
|
expect(project).toBeTruthy();
|
||||||
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
||||||
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
||||||
@ -251,7 +251,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib3, (config) => {
|
await updateProjectConfig(lib3, (config) => {
|
||||||
config.implicitDependencies = [`${lib1}-data-access`];
|
config.implicitDependencies = [`${lib1}-data-access`];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -321,13 +321,13 @@ describe('Workspace Tests', () => {
|
|||||||
]
|
]
|
||||||
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
||||||
|
|
||||||
const workspace = await readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
|
expect(projects[`${lib1}-data-access`]).toBeUndefined();
|
||||||
const project = readProjectConfig(newName);
|
const project = await readProjectConfig(newName);
|
||||||
expect(project).toBeTruthy();
|
expect(project).toBeTruthy();
|
||||||
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
||||||
expect(project.tags).toEqual([]);
|
expect(project.tags).toEqual([]);
|
||||||
const lib3Config = readProjectConfig(lib3);
|
const lib3Config = await readProjectConfig(lib3);
|
||||||
expect(lib3Config.implicitDependencies).toEqual([newName]);
|
expect(lib3Config.implicitDependencies).toEqual([newName]);
|
||||||
|
|
||||||
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
||||||
@ -384,7 +384,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib3, (config) => {
|
await updateProjectConfig(lib3, (config) => {
|
||||||
config.implicitDependencies = [`${lib1}-data-access`];
|
config.implicitDependencies = [`${lib1}-data-access`];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -454,9 +454,9 @@ describe('Workspace Tests', () => {
|
|||||||
]
|
]
|
||||||
).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]);
|
).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]);
|
||||||
|
|
||||||
const workspace = await readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
|
expect(projects[`${lib1}-data-access`]).toBeUndefined();
|
||||||
const project = readProjectConfig(newName);
|
const project = await readProjectConfig(newName);
|
||||||
expect(project).toBeTruthy();
|
expect(project).toBeTruthy();
|
||||||
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
||||||
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
||||||
@ -513,7 +513,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib3, (config) => {
|
await updateProjectConfig(lib3, (config) => {
|
||||||
config.implicitDependencies = [lib1];
|
config.implicitDependencies = [lib1];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -572,13 +572,13 @@ describe('Workspace Tests', () => {
|
|||||||
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
||||||
checkFilesExist(rootClassPath);
|
checkFilesExist(rootClassPath);
|
||||||
|
|
||||||
let workspace = readResolvedConfiguration();
|
let projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[lib1]).toBeUndefined();
|
expect(projects[lib1]).toBeUndefined();
|
||||||
const newConfig = readProjectConfig(newName);
|
const newConfig = await readProjectConfig(newName);
|
||||||
expect(newConfig).toMatchObject({
|
expect(newConfig).toMatchObject({
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
const lib3Config = readProjectConfig(lib3);
|
const lib3Config = await readProjectConfig(lib3);
|
||||||
expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]);
|
expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]);
|
||||||
|
|
||||||
expect(moveOutput).toContain('UPDATE tsconfig.base.json');
|
expect(moveOutput).toContain('UPDATE tsconfig.base.json');
|
||||||
@ -590,9 +590,9 @@ describe('Workspace Tests', () => {
|
|||||||
rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}/data-access`]
|
rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}/data-access`]
|
||||||
).toEqual([`libs/${lib1}/data-access/src/index.ts`]);
|
).toEqual([`libs/${lib1}/data-access/src/index.ts`]);
|
||||||
|
|
||||||
workspace = readResolvedConfiguration();
|
projects = await readResolvedConfiguration();
|
||||||
expect(workspace.projects[lib1]).toBeUndefined();
|
expect(projects[lib1]).toBeUndefined();
|
||||||
const project = readProjectConfig(newName);
|
const project = await readProjectConfig(newName);
|
||||||
expect(project).toBeTruthy();
|
expect(project).toBeTruthy();
|
||||||
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
||||||
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
||||||
@ -655,7 +655,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib3, (config) => {
|
await updateProjectConfig(lib3, (config) => {
|
||||||
config.implicitDependencies = [`${lib1}-data-access`];
|
config.implicitDependencies = [`${lib1}-data-access`];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -686,11 +686,11 @@ describe('Workspace Tests', () => {
|
|||||||
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
|
||||||
checkFilesExist(rootClassPath);
|
checkFilesExist(rootClassPath);
|
||||||
|
|
||||||
const newConfig = readProjectConfig(newName);
|
const newConfig = await readProjectConfig(newName);
|
||||||
expect(newConfig).toMatchObject({
|
expect(newConfig).toMatchObject({
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
const lib3Config = readProjectConfig(lib3);
|
const lib3Config = await readProjectConfig(lib3);
|
||||||
expect(lib3Config.implicitDependencies).toEqual([
|
expect(lib3Config.implicitDependencies).toEqual([
|
||||||
`shared-${lib1}-data-access`,
|
`shared-${lib1}-data-access`,
|
||||||
]);
|
]);
|
||||||
@ -704,9 +704,9 @@ describe('Workspace Tests', () => {
|
|||||||
rootTsConfig.compilerOptions.paths[`shared/${lib1}/data-access`]
|
rootTsConfig.compilerOptions.paths[`shared/${lib1}/data-access`]
|
||||||
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
|
||||||
|
|
||||||
const projects = readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
expect(projects.projects[`${lib1}-data-access`]).toBeUndefined();
|
expect(projects[`${lib1}-data-access`]).toBeUndefined();
|
||||||
const project = readProjectConfig(newName);
|
const project = await readProjectConfig(newName);
|
||||||
expect(project).toBeTruthy();
|
expect(project).toBeTruthy();
|
||||||
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
expect(project.sourceRoot).toBe(`${newPath}/src`);
|
||||||
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
expect(project.targets.lint.options.lintFilePatterns).toEqual([
|
||||||
@ -741,7 +741,7 @@ describe('Workspace Tests', () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`);
|
runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`);
|
||||||
updateProjectConfig(lib2, (config) => {
|
await updateProjectConfig(lib2, (config) => {
|
||||||
config.implicitDependencies = [lib1];
|
config.implicitDependencies = [lib1];
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -775,12 +775,12 @@ describe('Workspace Tests', () => {
|
|||||||
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy();
|
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy();
|
||||||
|
|
||||||
expect(removeOutputForced).not.toContain(`UPDATE nx.json`);
|
expect(removeOutputForced).not.toContain(`UPDATE nx.json`);
|
||||||
const projectsConfigurations = readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
expect(projectsConfigurations.projects[`${lib1}`]).toBeUndefined();
|
expect(projects[`${lib1}`]).toBeUndefined();
|
||||||
const lib2Config = readProjectConfig(lib2);
|
const lib2Config = await readProjectConfig(lib2);
|
||||||
expect(lib2Config.implicitDependencies).toEqual([]);
|
expect(lib2Config.implicitDependencies).toEqual([]);
|
||||||
|
|
||||||
expect(projectsConfigurations.projects[`${lib1}`]).toBeUndefined();
|
expect(projects[`${lib1}`]).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -214,11 +214,11 @@ describe('Nx Affected and Graph Tests', () => {
|
|||||||
}
|
}
|
||||||
}, 1000000);
|
}, 1000000);
|
||||||
|
|
||||||
it('should detect changes to projects based on tags changes', () => {
|
it('should detect changes to projects based on tags changes', async () => {
|
||||||
// TODO: investigate why affected gives different results on windows
|
// TODO: investigate why affected gives different results on windows
|
||||||
if (isNotWindows()) {
|
if (isNotWindows()) {
|
||||||
generateAll();
|
generateAll();
|
||||||
updateProjectConfig(myapp, (config) => ({
|
await updateProjectConfig(myapp, (config) => ({
|
||||||
...config,
|
...config,
|
||||||
tags: ['tag'],
|
tags: ['tag'],
|
||||||
}));
|
}));
|
||||||
@ -229,9 +229,9 @@ describe('Nx Affected and Graph Tests', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should affect all projects by removing projects', () => {
|
it('should affect all projects by removing projects', async () => {
|
||||||
generateAll();
|
generateAll();
|
||||||
const root = readResolvedConfiguration().projects[mylib].root;
|
const root = (await readResolvedConfiguration())[mylib].root;
|
||||||
removeFile(root);
|
removeFile(root);
|
||||||
const output = runCLI('print-affected --select projects');
|
const output = runCLI('print-affected --select projects');
|
||||||
expect(output).toContain(myapp);
|
expect(output).toContain(myapp);
|
||||||
@ -239,9 +239,9 @@ describe('Nx Affected and Graph Tests', () => {
|
|||||||
expect(output).not.toContain(mylib);
|
expect(output).not.toContain(mylib);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect changes to implicitly dependant projects', () => {
|
it('should detect changes to implicitly dependant projects', async () => {
|
||||||
generateAll();
|
generateAll();
|
||||||
updateProjectConfig(myapp, (config) => ({
|
await updateProjectConfig(myapp, (config) => ({
|
||||||
...config,
|
...config,
|
||||||
implicitDependencies: ['*', `!${myapp2}`],
|
implicitDependencies: ['*', `!${myapp2}`],
|
||||||
}));
|
}));
|
||||||
@ -256,7 +256,7 @@ describe('Nx Affected and Graph Tests', () => {
|
|||||||
expect(output).toContain(mylib);
|
expect(output).toContain(mylib);
|
||||||
|
|
||||||
// Clear implicit deps to not interfere with other tests.
|
// Clear implicit deps to not interfere with other tests.
|
||||||
updateProjectConfig(myapp, (config) => ({
|
await updateProjectConfig(myapp, (config) => ({
|
||||||
...config,
|
...config,
|
||||||
implicitDependencies: [],
|
implicitDependencies: [],
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -156,7 +156,7 @@ describe('cache', () => {
|
|||||||
it('should support using globs as outputs', async () => {
|
it('should support using globs as outputs', async () => {
|
||||||
const mylib = uniq('mylib');
|
const mylib = uniq('mylib');
|
||||||
runCLI(`generate @nx/js:library ${mylib}`);
|
runCLI(`generate @nx/js:library ${mylib}`);
|
||||||
updateProjectConfig(mylib, (c) => {
|
await updateProjectConfig(mylib, (c) => {
|
||||||
c.targets.build = {
|
c.targets.build = {
|
||||||
executor: 'nx:run-commands',
|
executor: 'nx:run-commands',
|
||||||
outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'],
|
outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'],
|
||||||
|
|||||||
@ -16,7 +16,7 @@ describe('Invoke Runner', () => {
|
|||||||
it('should invoke runner imperatively ', async () => {
|
it('should invoke runner imperatively ', async () => {
|
||||||
const mylib = uniq('mylib');
|
const mylib = uniq('mylib');
|
||||||
runCLI(`generate @nx/js:lib ${mylib}`);
|
runCLI(`generate @nx/js:lib ${mylib}`);
|
||||||
updateProjectConfig(mylib, (c) => {
|
await updateProjectConfig(mylib, (c) => {
|
||||||
c.targets['prebuild'] = {
|
c.targets['prebuild'] = {
|
||||||
command: 'echo prebuild',
|
command: 'echo prebuild',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,9 +28,9 @@ describe('Nx Running Tests', () => {
|
|||||||
describe('running targets', () => {
|
describe('running targets', () => {
|
||||||
describe('(forwarding params)', () => {
|
describe('(forwarding params)', () => {
|
||||||
let proj = uniq('proj');
|
let proj = uniq('proj');
|
||||||
beforeAll(() => {
|
beforeAll(async () => {
|
||||||
runCLI(`generate @nx/js:lib ${proj}`);
|
runCLI(`generate @nx/js:lib ${proj}`);
|
||||||
updateProjectConfig(proj, (c) => {
|
await updateProjectConfig(proj, (c) => {
|
||||||
c.targets['echo'] = {
|
c.targets['echo'] = {
|
||||||
command: 'echo ECHO:',
|
command: 'echo ECHO:',
|
||||||
};
|
};
|
||||||
@ -57,7 +57,7 @@ describe('Nx Running Tests', () => {
|
|||||||
it('should execute long running tasks', async () => {
|
it('should execute long running tasks', async () => {
|
||||||
const myapp = uniq('myapp');
|
const myapp = uniq('myapp');
|
||||||
runCLI(`generate @nx/web:app ${myapp}`);
|
runCLI(`generate @nx/web:app ${myapp}`);
|
||||||
updateProjectConfig(myapp, (c) => {
|
await updateProjectConfig(myapp, (c) => {
|
||||||
c.targets['counter'] = {
|
c.targets['counter'] = {
|
||||||
executor: '@nx/workspace:counter',
|
executor: '@nx/workspace:counter',
|
||||||
options: {
|
options: {
|
||||||
@ -79,8 +79,8 @@ describe('Nx Running Tests', () => {
|
|||||||
runCLI(`generate @nx/node:lib ${mylib}`);
|
runCLI(`generate @nx/node:lib ${mylib}`);
|
||||||
|
|
||||||
// Used to restore targets to lib after test
|
// Used to restore targets to lib after test
|
||||||
const original = readProjectConfig(mylib);
|
const original = await readProjectConfig(mylib);
|
||||||
updateProjectConfig(mylib, (j) => {
|
await updateProjectConfig(mylib, (j) => {
|
||||||
delete j.targets;
|
delete j.targets;
|
||||||
return j;
|
return j;
|
||||||
});
|
});
|
||||||
@ -113,7 +113,7 @@ describe('Nx Running Tests', () => {
|
|||||||
`Cannot find configuration for task ${mylib}:echo:fail`
|
`Cannot find configuration for task ${mylib}:echo:fail`
|
||||||
);
|
);
|
||||||
|
|
||||||
updateProjectConfig(mylib, (c) => original);
|
await updateProjectConfig(mylib, (c) => original);
|
||||||
}, 1000000);
|
}, 1000000);
|
||||||
|
|
||||||
describe('tokens support', () => {
|
describe('tokens support', () => {
|
||||||
@ -125,7 +125,7 @@ describe('Nx Running Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should support using {projectRoot} in options blocks in project.json', async () => {
|
it('should support using {projectRoot} in options blocks in project.json', async () => {
|
||||||
updateProjectConfig(app, (c) => {
|
await updateProjectConfig(app, (c) => {
|
||||||
c.targets['echo'] = {
|
c.targets['echo'] = {
|
||||||
command: `node -e 'console.log("{projectRoot}")'`,
|
command: `node -e 'console.log("{projectRoot}")'`,
|
||||||
};
|
};
|
||||||
@ -137,7 +137,7 @@ describe('Nx Running Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should support using {projectName} in options blocks in project.json', async () => {
|
it('should support using {projectName} in options blocks in project.json', async () => {
|
||||||
updateProjectConfig(app, (c) => {
|
await updateProjectConfig(app, (c) => {
|
||||||
c.targets['echo'] = {
|
c.targets['echo'] = {
|
||||||
command: `node -e 'console.log("{projectName}")'`,
|
command: `node -e 'console.log("{projectName}")'`,
|
||||||
};
|
};
|
||||||
@ -157,7 +157,7 @@ describe('Nx Running Tests', () => {
|
|||||||
};
|
};
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
updateProjectConfig(app, (c) => {
|
await updateProjectConfig(app, (c) => {
|
||||||
c.targets['echo'] = {};
|
c.targets['echo'] = {};
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
@ -174,7 +174,7 @@ describe('Nx Running Tests', () => {
|
|||||||
};
|
};
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
updateProjectConfig(app, (c) => {
|
await updateProjectConfig(app, (c) => {
|
||||||
c.targets['echo'] = {};
|
c.targets['echo'] = {};
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
@ -190,13 +190,13 @@ describe('Nx Running Tests', () => {
|
|||||||
const myapp2 = uniq('b');
|
const myapp2 = uniq('b');
|
||||||
runCLI(`generate @nx/web:app ${myapp1}`);
|
runCLI(`generate @nx/web:app ${myapp1}`);
|
||||||
runCLI(`generate @nx/web:app ${myapp2}`);
|
runCLI(`generate @nx/web:app ${myapp2}`);
|
||||||
updateProjectConfig(myapp1, (c) => {
|
await updateProjectConfig(myapp1, (c) => {
|
||||||
c.targets['error'] = {
|
c.targets['error'] = {
|
||||||
command: 'echo boom1 && exit 1',
|
command: 'echo boom1 && exit 1',
|
||||||
};
|
};
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
updateProjectConfig(myapp2, (c) => {
|
await updateProjectConfig(myapp2, (c) => {
|
||||||
c.targets['error'] = {
|
c.targets['error'] = {
|
||||||
executor: 'nx:run-commands',
|
executor: 'nx:run-commands',
|
||||||
options: {
|
options: {
|
||||||
@ -431,9 +431,9 @@ describe('Nx Running Tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to include deps using dependsOn', () => {
|
it('should be able to include deps using dependsOn', async () => {
|
||||||
const originalWorkspace = readProjectConfig(myapp);
|
const originalWorkspace = await readProjectConfig(myapp);
|
||||||
updateProjectConfig(myapp, (config) => {
|
await updateProjectConfig(myapp, (config) => {
|
||||||
config.targets.prep = {
|
config.targets.prep = {
|
||||||
executor: 'nx:run-commands',
|
executor: 'nx:run-commands',
|
||||||
options: {
|
options: {
|
||||||
@ -453,12 +453,12 @@ describe('Nx Running Tests', () => {
|
|||||||
expect(output).toContain(mylib2);
|
expect(output).toContain(mylib2);
|
||||||
expect(output).toContain('PREP');
|
expect(output).toContain('PREP');
|
||||||
|
|
||||||
updateProjectConfig(myapp, () => originalWorkspace);
|
await updateProjectConfig(myapp, () => originalWorkspace);
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
it('should be able to include deps using target defaults defined at the root', () => {
|
it('should be able to include deps using target defaults defined at the root', async () => {
|
||||||
const nxJson = readJson('nx.json');
|
const nxJson = readJson('nx.json');
|
||||||
updateProjectConfig(myapp, (config) => {
|
await updateProjectConfig(myapp, (config) => {
|
||||||
config.targets.prep = {
|
config.targets.prep = {
|
||||||
command: 'echo PREP > one.txt',
|
command: 'echo PREP > one.txt',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -381,14 +381,14 @@ describe('Nx Plugin', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('--directory', () => {
|
describe('--directory', () => {
|
||||||
it('should create a plugin in the specified directory', () => {
|
it('should create a plugin in the specified directory', async () => {
|
||||||
const plugin = uniq('plugin');
|
const plugin = uniq('plugin');
|
||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest`
|
`generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest`
|
||||||
);
|
);
|
||||||
checkFilesExist(`libs/subdir/${plugin}/package.json`);
|
checkFilesExist(`libs/subdir/${plugin}/package.json`);
|
||||||
const pluginProject = readProjectConfig(`subdir-${plugin}`);
|
const pluginProject = await readProjectConfig(`subdir-${plugin}`);
|
||||||
const pluginE2EProject = readProjectConfig(`subdir-${plugin}-e2e`);
|
const pluginE2EProject = await readProjectConfig(`subdir-${plugin}-e2e`);
|
||||||
expect(pluginProject.targets).toBeDefined();
|
expect(pluginProject.targets).toBeDefined();
|
||||||
expect(pluginE2EProject).toBeTruthy();
|
expect(pluginE2EProject).toBeTruthy();
|
||||||
}, 90000);
|
}, 90000);
|
||||||
@ -399,7 +399,7 @@ describe('Nx Plugin', () => {
|
|||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage `
|
`generate @nx/plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage `
|
||||||
);
|
);
|
||||||
const pluginProject = readProjectConfig(plugin);
|
const pluginProject = await readProjectConfig(plugin);
|
||||||
expect(pluginProject.tags).toEqual(['e2etag', 'e2ePackage']);
|
expect(pluginProject.tags).toEqual(['e2etag', 'e2ePackage']);
|
||||||
}, 90000);
|
}, 90000);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -114,8 +114,8 @@ describe('React Module Federation', () => {
|
|||||||
// }
|
// }
|
||||||
}, 500_000);
|
}, 500_000);
|
||||||
|
|
||||||
function readPort(appName: string): number {
|
async function readPort(appName: string): Promise<number> {
|
||||||
const config = readProjectConfig(appName);
|
const config = await readProjectConfig(appName);
|
||||||
return config.targets.serve.options.port;
|
return config.targets.serve.options.port;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,7 +36,7 @@ describe('Build React libraries and apps', () => {
|
|||||||
|
|
||||||
let proj: string;
|
let proj: string;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
app = uniq('app');
|
app = uniq('app');
|
||||||
parentLib = uniq('parentlib');
|
parentLib = uniq('parentlib');
|
||||||
childLib = uniq('childlib');
|
childLib = uniq('childlib');
|
||||||
@ -99,7 +99,7 @@ describe('Build React libraries and apps', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add assets to child lib
|
// Add assets to child lib
|
||||||
updateProjectConfig(childLib, (json) => {
|
await updateProjectConfig(childLib, (json) => {
|
||||||
json.targets.build.options.assets = [`libs/${childLib}/src/assets`];
|
json.targets.build.options.assets = [`libs/${childLib}/src/assets`];
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -234,14 +234,14 @@ describe('React Applications', () => {
|
|||||||
${'scss'}
|
${'scss'}
|
||||||
${'less'}
|
${'less'}
|
||||||
${'styl'}
|
${'styl'}
|
||||||
`('should support global and css modules', ({ style }) => {
|
`('should support global and css modules', async ({ style }) => {
|
||||||
const appName = uniq('app');
|
const appName = uniq('app');
|
||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/react:app ${appName} --style=${style} --bundler=webpack --no-interactive`
|
`generate @nx/react:app ${appName} --style=${style} --bundler=webpack --no-interactive`
|
||||||
);
|
);
|
||||||
|
|
||||||
// make sure stylePreprocessorOptions works
|
// make sure stylePreprocessorOptions works
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets.build.options.stylePreprocessorOptions = {
|
config.targets.build.options.stylePreprocessorOptions = {
|
||||||
includePaths: ['libs/shared/lib'],
|
includePaths: ['libs/shared/lib'],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -17,7 +17,7 @@ describe('React Cypress Component Tests', () => {
|
|||||||
const usedInAppLibName = uniq('cy-react-lib');
|
const usedInAppLibName = uniq('cy-react-lib');
|
||||||
const buildableLibName = uniq('cy-react-buildable-lib');
|
const buildableLibName = uniq('cy-react-buildable-lib');
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(async () => {
|
||||||
projectName = newProject({ name: uniq('cy-react') });
|
projectName = newProject({ name: uniq('cy-react') });
|
||||||
ensureCypressInstallation();
|
ensureCypressInstallation();
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ export default Input;
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
|
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets['build'].options.assets.push({
|
config.targets['build'].options.assets.push({
|
||||||
glob: '**/*',
|
glob: '**/*',
|
||||||
input: 'libs/assets',
|
input: 'libs/assets',
|
||||||
@ -228,7 +228,7 @@ ${content}`;
|
|||||||
}
|
}
|
||||||
}, 300_000);
|
}, 300_000);
|
||||||
|
|
||||||
it('should work with async webpack config', () => {
|
it('should work with async webpack config', async () => {
|
||||||
// TODO: (caleb) for whatever reason the MF webpack config + CT is running, but cypress is not starting up?
|
// TODO: (caleb) for whatever reason the MF webpack config + CT is running, but cypress is not starting up?
|
||||||
// are they overriding some option on top of each other causing cypress to not see it's running?
|
// are they overriding some option on top of each other causing cypress to not see it's running?
|
||||||
createFile(
|
createFile(
|
||||||
@ -252,7 +252,7 @@ ${content}`;
|
|||||||
);
|
);
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets[
|
config.targets[
|
||||||
'build'
|
'build'
|
||||||
].options.webpackConfig = `apps/${appName}/webpack.config.js`;
|
].options.webpackConfig = `apps/${appName}/webpack.config.js`;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ describe('Rollup Plugin', () => {
|
|||||||
let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
|
let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
|
||||||
expect(output).toMatch(/Hello/);
|
expect(output).toMatch(/Hello/);
|
||||||
|
|
||||||
updateProjectConfig(myPkg, (config) => {
|
await updateProjectConfig(myPkg, (config) => {
|
||||||
delete config.targets.build;
|
delete config.targets.build;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -51,7 +51,7 @@ describe('Rollup Plugin', () => {
|
|||||||
output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
|
output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
|
||||||
expect(output).toMatch(/Hello/);
|
expect(output).toMatch(/Hello/);
|
||||||
|
|
||||||
updateProjectConfig(myPkg, (config) => {
|
await updateProjectConfig(myPkg, (config) => {
|
||||||
delete config.targets.build;
|
delete config.targets.build;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -66,13 +66,13 @@ describe('Rollup Plugin', () => {
|
|||||||
expect(output).toMatch(/Hello/);
|
expect(output).toMatch(/Hello/);
|
||||||
}, 500000);
|
}, 500000);
|
||||||
|
|
||||||
it('should support additional entry-points', () => {
|
it('should support additional entry-points', async () => {
|
||||||
const myPkg = uniq('my-pkg');
|
const myPkg = uniq('my-pkg');
|
||||||
runCLI(`generate @nx/js:lib ${myPkg} --bundler=none`);
|
runCLI(`generate @nx/js:lib ${myPkg} --bundler=none`);
|
||||||
runCLI(
|
runCLI(
|
||||||
`generate @nx/rollup:configuration ${myPkg} --target=node --tsConfig=libs/${myPkg}/tsconfig.lib.json --main=libs/${myPkg}/src/index.ts --compiler=tsc`
|
`generate @nx/rollup:configuration ${myPkg} --target=node --tsConfig=libs/${myPkg}/tsconfig.lib.json --main=libs/${myPkg}/src/index.ts --compiler=tsc`
|
||||||
);
|
);
|
||||||
updateProjectConfig(myPkg, (config) => {
|
await updateProjectConfig(myPkg, (config) => {
|
||||||
config.targets.build.options.format = ['cjs', 'esm'];
|
config.targets.build.options.format = ['cjs', 'esm'];
|
||||||
config.targets.build.options.generateExportsField = true;
|
config.targets.build.options.generateExportsField = true;
|
||||||
config.targets.build.options.additionalEntryPoints = [
|
config.targets.build.options.additionalEntryPoints = [
|
||||||
|
|||||||
@ -14,10 +14,11 @@ import { TargetConfiguration } from '@nx/devkit';
|
|||||||
import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process';
|
import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import * as isCI from 'is-ci';
|
import * as isCI from 'is-ci';
|
||||||
import { Workspaces } from '../../packages/nx/src/config/workspaces';
|
|
||||||
import { fileExists, readJson, updateFile } from './file-utils';
|
import { fileExists, readJson, updateFile } from './file-utils';
|
||||||
import { logError, stripConsoleColors } from './log-utils';
|
import { logError, stripConsoleColors } from './log-utils';
|
||||||
import { existsSync } from 'fs-extra';
|
import { existsSync } from 'fs-extra';
|
||||||
|
import { retrieveProjectConfigurationsSync } from '../../packages/nx/src/project-graph/utils/retrieve-workspace-files';
|
||||||
|
import { readNxJson } from '../../packages/nx/src/config/nx-json';
|
||||||
|
|
||||||
export interface RunCmdOpts {
|
export interface RunCmdOpts {
|
||||||
silenceError?: boolean;
|
silenceError?: boolean;
|
||||||
@ -36,11 +37,14 @@ export interface RunCmdOpts {
|
|||||||
*/
|
*/
|
||||||
export function setMaxWorkers() {
|
export function setMaxWorkers() {
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
const ws = new Workspaces(tmpProjPath());
|
const root = tmpProjPath();
|
||||||
const projectsConfigurations = ws.readProjectsConfigurations();
|
const projects = retrieveProjectConfigurationsSync(
|
||||||
|
root,
|
||||||
|
readNxJson(root)
|
||||||
|
).projectNodes;
|
||||||
|
|
||||||
Object.keys(projectsConfigurations.projects).forEach((appName) => {
|
Object.keys(projects).forEach((appName) => {
|
||||||
let project = projectsConfigurations.projects[appName];
|
let project = projects[appName];
|
||||||
const { build } = project.targets as {
|
const { build } = project.targets as {
|
||||||
[targetName: string]: TargetConfiguration<any>;
|
[targetName: string]: TargetConfiguration<any>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,27 +1,34 @@
|
|||||||
import { ProjectConfiguration, Workspaces } from '@nx/devkit';
|
import { ProjectConfiguration } from '@nx/devkit';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { tmpProjPath } from './create-project-utils';
|
import { tmpProjPath } from './create-project-utils';
|
||||||
import { readJson, updateFile } from './file-utils';
|
import { readJson, updateFile } from './file-utils';
|
||||||
|
import { retrieveProjectConfigurations } from '../../packages/nx/src/project-graph/utils/retrieve-workspace-files';
|
||||||
|
import { readNxJson } from '../../packages/nx/src/config/nx-json';
|
||||||
|
|
||||||
export function updateProjectConfig(
|
export async function updateProjectConfig(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
callback: (c: ProjectConfiguration) => ProjectConfiguration
|
callback: (c: ProjectConfiguration) => ProjectConfiguration
|
||||||
) {
|
) {
|
||||||
const workspace = readResolvedConfiguration();
|
const projects = await readResolvedConfiguration();
|
||||||
const root = workspace.projects[projectName].root;
|
const root = projects[projectName].root;
|
||||||
const path = join(root, 'project.json');
|
const path = join(root, 'project.json');
|
||||||
const current = readJson(path);
|
const current = readJson(path);
|
||||||
updateFile(path, JSON.stringify(callback(current), null, 2));
|
updateFile(path, JSON.stringify(callback(current), null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readResolvedConfiguration() {
|
export async function readResolvedConfiguration(): Promise<
|
||||||
|
Record<string, ProjectConfiguration>
|
||||||
|
> {
|
||||||
process.env.NX_PROJECT_GLOB_CACHE = 'false';
|
process.env.NX_PROJECT_GLOB_CACHE = 'false';
|
||||||
const ws = new Workspaces(tmpProjPath());
|
const root = tmpProjPath();
|
||||||
return ws.readProjectsConfigurations();
|
return (await retrieveProjectConfigurations(root, readNxJson(root)))
|
||||||
|
.projectNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readProjectConfig(projectName: string): ProjectConfiguration {
|
export async function readProjectConfig(
|
||||||
const root = readResolvedConfiguration().projects[projectName].root;
|
projectName: string
|
||||||
|
): Promise<ProjectConfiguration> {
|
||||||
|
const root = (await readResolvedConfiguration())[projectName].root;
|
||||||
const path = join(root, 'project.json');
|
const path = join(root, 'project.json');
|
||||||
return readJson(path);
|
return readJson(path);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ describe('Vite Plugin', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('set up new React app with --bundler=vite option', () => {
|
describe('set up new React app with --bundler=vite option', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
proj = newProject();
|
proj = newProject();
|
||||||
runCLI(`generate @nx/react:app ${myApp} --bundler=vite`);
|
runCLI(`generate @nx/react:app ${myApp} --bundler=vite`);
|
||||||
createFile(`apps/${myApp}/public/hello.md`, `# Hello World`);
|
createFile(`apps/${myApp}/public/hello.md`, `# Hello World`);
|
||||||
@ -99,7 +99,7 @@ describe('Vite Plugin', () => {
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
updateProjectConfig(myApp, (config) => {
|
await updateProjectConfig(myApp, (config) => {
|
||||||
config.targets.build.options.fileReplacements = [
|
config.targets.build.options.fileReplacements = [
|
||||||
{
|
{
|
||||||
replace: `apps/${myApp}/src/environments/environment.ts`,
|
replace: `apps/${myApp}/src/environments/environment.ts`,
|
||||||
@ -380,7 +380,7 @@ export default App;
|
|||||||
}, 100_000);
|
}, 100_000);
|
||||||
|
|
||||||
// TODO: This takes forever and times out everything - find out why
|
// TODO: This takes forever and times out everything - find out why
|
||||||
xit('should not delete the project directory when coverage is enabled', () => {
|
xit('should not delete the project directory when coverage is enabled', async () => {
|
||||||
// when coverage is enabled in the vite.config.ts but reportsDirectory is removed
|
// when coverage is enabled in the vite.config.ts but reportsDirectory is removed
|
||||||
// from the @nx/vite:test executor options, vite will delete the project root directory
|
// from the @nx/vite:test executor options, vite will delete the project root directory
|
||||||
runCLI(`generate @nx/react:lib ${lib} --unitTestRunner=vitest`);
|
runCLI(`generate @nx/react:lib ${lib} --unitTestRunner=vitest`);
|
||||||
@ -416,7 +416,7 @@ export default defineConfig({
|
|||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
updateProjectConfig(lib, (config) => {
|
await updateProjectConfig(lib, (config) => {
|
||||||
delete config.targets.test.options.reportsDirectory;
|
delete config.targets.test.options.reportsDirectory;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,7 +20,7 @@ describe('file-server', () => {
|
|||||||
const port = 4301;
|
const port = 4301;
|
||||||
|
|
||||||
runCLI(`generate @nx/web:app ${appName} --no-interactive`);
|
runCLI(`generate @nx/web:app ${appName} --no-interactive`);
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets['serve'].executor = '@nx/web:file-server';
|
config.targets['serve'].executor = '@nx/web:file-server';
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -262,7 +262,7 @@ describe('Web Components Applications', () => {
|
|||||||
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
|
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
|
||||||
);
|
);
|
||||||
|
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
config.targets.build.options.webpackConfig = `apps/${appName}/webpack.config.js`;
|
config.targets.build.options.webpackConfig = `apps/${appName}/webpack.config.js`;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -411,7 +411,7 @@ describe('CLI - Environment Variables', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Build Options', () => {
|
describe('Build Options', () => {
|
||||||
it('should inject/bundle external scripts and styles', () => {
|
it('should inject/bundle external scripts and styles', async () => {
|
||||||
newProject();
|
newProject();
|
||||||
|
|
||||||
const appName = uniq('app');
|
const appName = uniq('app');
|
||||||
@ -444,7 +444,7 @@ describe('Build Options', () => {
|
|||||||
const barScriptsBundleName = 'bar-scripts';
|
const barScriptsBundleName = 'bar-scripts';
|
||||||
const barStylesBundleName = 'bar-styles';
|
const barStylesBundleName = 'bar-styles';
|
||||||
|
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
const buildOptions = config.targets.build.options;
|
const buildOptions = config.targets.build.options;
|
||||||
|
|
||||||
buildOptions.scripts = [
|
buildOptions.scripts = [
|
||||||
@ -492,7 +492,7 @@ describe('Build Options', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('index.html interpolation', () => {
|
describe('index.html interpolation', () => {
|
||||||
test('should interpolate environment variables', () => {
|
test('should interpolate environment variables', async () => {
|
||||||
const appName = uniq('app');
|
const appName = uniq('app');
|
||||||
|
|
||||||
runCLI(
|
runCLI(
|
||||||
@ -530,7 +530,7 @@ describe('index.html interpolation', () => {
|
|||||||
updateFile(envFilePath, envFileContents);
|
updateFile(envFilePath, envFileContents);
|
||||||
updateFile(indexPath, indexContent);
|
updateFile(indexPath, indexContent);
|
||||||
|
|
||||||
updateProjectConfig(appName, (config) => {
|
await updateProjectConfig(appName, (config) => {
|
||||||
const buildOptions = config.targets.build.options;
|
const buildOptions = config.targets.build.options;
|
||||||
buildOptions.deployUrl = 'baz';
|
buildOptions.deployUrl = 'baz';
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ module.exports = composePlugins(withNx(), (config) => {
|
|||||||
expect(output).not.toMatch(/Conflicting/);
|
expect(output).not.toMatch(/Conflicting/);
|
||||||
expect(output).not.toMatch(/process.env.NODE_ENV/);
|
expect(output).not.toMatch(/process.env.NODE_ENV/);
|
||||||
|
|
||||||
updateProjectConfig(myPkg, (config) => {
|
await updateProjectConfig(myPkg, (config) => {
|
||||||
delete config.targets.build;
|
delete config.targets.build;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -59,7 +59,7 @@ module.exports = composePlugins(withNx(), (config) => {
|
|||||||
output = runCommand(`node dist/libs/${myPkg}/main.js`);
|
output = runCommand(`node dist/libs/${myPkg}/main.js`);
|
||||||
expect(output).toMatch(/Hello/);
|
expect(output).toMatch(/Hello/);
|
||||||
|
|
||||||
updateProjectConfig(myPkg, (config) => {
|
await updateProjectConfig(myPkg, (config) => {
|
||||||
delete config.targets.build;
|
delete config.targets.build;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -47,10 +47,7 @@ export type {
|
|||||||
*/
|
*/
|
||||||
export { Workspaces } from 'nx/src/config/workspaces';
|
export { Workspaces } from 'nx/src/config/workspaces';
|
||||||
|
|
||||||
export {
|
export { workspaceLayout } from 'nx/src/config/configuration';
|
||||||
readAllWorkspaceConfiguration,
|
|
||||||
workspaceLayout,
|
|
||||||
} from 'nx/src/config/configuration';
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
NxPlugin,
|
NxPlugin,
|
||||||
|
|||||||
@ -2,7 +2,11 @@ import type { Observable } from 'rxjs';
|
|||||||
import type { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces';
|
import type { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces';
|
||||||
import { requireNx } from '../../nx';
|
import { requireNx } from '../../nx';
|
||||||
|
|
||||||
const { Workspaces, readNxJsonFromDisk } = requireNx();
|
const {
|
||||||
|
Workspaces,
|
||||||
|
readNxJsonFromDisk,
|
||||||
|
retrieveProjectConfigurationsWithAngularProjects,
|
||||||
|
} = requireNx();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an Nx Executor into an Angular Devkit Builder
|
* Convert an Nx Executor into an Angular Devkit Builder
|
||||||
@ -17,11 +21,22 @@ export function convertNxExecutor(executor: Executor) {
|
|||||||
? readNxJsonFromDisk(builderContext.workspaceRoot)
|
? readNxJsonFromDisk(builderContext.workspaceRoot)
|
||||||
: // TODO(v18): remove readNxJson. This is to be backwards compatible with Nx 16.5 and below.
|
: // TODO(v18): remove readNxJson. This is to be backwards compatible with Nx 16.5 and below.
|
||||||
(workspaces as any).readNxJson();
|
(workspaces as any).readNxJson();
|
||||||
const projectsConfigurations = workspaces.readProjectsConfigurations({
|
|
||||||
_includeProjectsFromAngularJson: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const promise = async () => {
|
const promise = async () => {
|
||||||
|
const projectsConfigurations =
|
||||||
|
retrieveProjectConfigurationsWithAngularProjects
|
||||||
|
? {
|
||||||
|
version: 2,
|
||||||
|
projects: await retrieveProjectConfigurationsWithAngularProjects(
|
||||||
|
builderContext.workspaceRoot,
|
||||||
|
nxJsonConfiguration
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: // TODO(v18): remove retrieveProjectConfigurations. This is to be backwards compatible with Nx 16.5 and below.
|
||||||
|
(workspaces as any).readProjectsConfigurations({
|
||||||
|
_includeProjectsFromAngularJson: true,
|
||||||
|
});
|
||||||
|
|
||||||
const context: ExecutorContext = {
|
const context: ExecutorContext = {
|
||||||
root: builderContext.workspaceRoot,
|
root: builderContext.workspaceRoot,
|
||||||
projectName: builderContext.target.project,
|
projectName: builderContext.target.project,
|
||||||
|
|||||||
@ -44,7 +44,7 @@ export function calculateDefaultProjectName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function findMatchingProjectInCwd(
|
export function findMatchingProjectInCwd(
|
||||||
projects: { [projectName: string]: ProjectConfiguration },
|
projects: Record<string, ProjectConfiguration>,
|
||||||
relativeCwd: string
|
relativeCwd: string
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
const projectRootMappings = new Map<string, string>();
|
const projectRootMappings = new Map<string, string>();
|
||||||
|
|||||||
@ -1,18 +1,5 @@
|
|||||||
import { Workspaces } from './workspaces';
|
|
||||||
import { workspaceRoot } from '../utils/workspace-root';
|
|
||||||
import { NxJsonConfiguration } from './nx-json';
|
|
||||||
import { ProjectsConfigurations } from './workspace-json-project-json';
|
|
||||||
import { readNxJson } from './nx-json';
|
import { readNxJson } from './nx-json';
|
||||||
|
|
||||||
// TODO(vsavkin): Remove after Nx 16 is out
|
|
||||||
/**
|
|
||||||
* @deprecated Use readProjectsConfigurationFromProjectGraph(await createProjectGraphAsync())
|
|
||||||
*/
|
|
||||||
export function readAllWorkspaceConfiguration(): ProjectsConfigurations &
|
|
||||||
NxJsonConfiguration {
|
|
||||||
return new Workspaces(workspaceRoot).readProjectsConfigurations();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about where apps and libs will be created.
|
* Returns information about where apps and libs will be created.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { toProjectName, Workspaces } from './workspaces';
|
import { toProjectName, Workspaces } from './workspaces';
|
||||||
import { TempFs } from '../utils/testing/temp-fs';
|
import { TempFs } from '../utils/testing/temp-fs';
|
||||||
import { withEnvironmentVariables } from '../../internal-testing-utils/with-environment';
|
import { withEnvironmentVariables } from '../../internal-testing-utils/with-environment';
|
||||||
|
import { retrieveProjectConfigurations } from '../project-graph/utils/retrieve-workspace-files';
|
||||||
|
import { readNxJson } from './configuration';
|
||||||
|
|
||||||
const libConfig = (root, name?: string) => ({
|
const libConfig = (root, name?: string) => ({
|
||||||
name: name ?? toProjectName(`${root}/some-file`),
|
name: name ?? toProjectName(`${root}/some-file`),
|
||||||
@ -45,7 +47,7 @@ describe('Workspaces', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const workspaces = new Workspaces(fs.tempDir);
|
const workspaces = new Workspaces(fs.tempDir);
|
||||||
const resolved = workspaces.readProjectsConfigurations();
|
const resolved = workspaces.readWorkspaceConfiguration();
|
||||||
expect(resolved.projects.lib1).toEqual(standaloneConfig);
|
expect(resolved.projects.lib1).toEqual(standaloneConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ describe('Workspaces', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const workspaces = new Workspaces(fs.tempDir);
|
const workspaces = new Workspaces(fs.tempDir);
|
||||||
const { projects } = workspaces.readProjectsConfigurations();
|
const { projects } = workspaces.readWorkspaceConfiguration();
|
||||||
|
|
||||||
// projects got merged for lib1
|
// projects got merged for lib1
|
||||||
expect(projects['lib1']).toEqual({
|
expect(projects['lib1']).toEqual({
|
||||||
@ -112,10 +114,12 @@ describe('Workspaces', () => {
|
|||||||
{
|
{
|
||||||
NX_WORKSPACE_ROOT: fs.tempDir,
|
NX_WORKSPACE_ROOT: fs.tempDir,
|
||||||
},
|
},
|
||||||
() => {
|
async () => {
|
||||||
const workspaces = new Workspaces(fs.tempDir);
|
const resolved = await retrieveProjectConfigurations(
|
||||||
const resolved = workspaces.readProjectsConfigurations();
|
fs.tempDir,
|
||||||
expect(resolved.projects['my-package']).toEqual({
|
readNxJson(fs.tempDir)
|
||||||
|
);
|
||||||
|
expect(resolved.projectNodes['my-package']).toEqual({
|
||||||
name: 'my-package',
|
name: 'my-package',
|
||||||
root: 'packages/my-package',
|
root: 'packages/my-package',
|
||||||
sourceRoot: 'packages/my-package',
|
sourceRoot: 'packages/my-package',
|
||||||
|
|||||||
@ -1,110 +1,29 @@
|
|||||||
import { dirname, join } from 'path';
|
import { dirname } from 'path';
|
||||||
import { workspaceRoot } from '../utils/workspace-root';
|
|
||||||
import { readJsonFile } from '../utils/fileutils';
|
|
||||||
import { getNxRequirePaths } from '../utils/installation-directory';
|
|
||||||
import { loadNxPlugins, loadNxPluginsSync } from '../utils/nx-plugin';
|
|
||||||
|
|
||||||
import type { NxJsonConfiguration } from './nx-json';
|
import type { NxJsonConfiguration } from './nx-json';
|
||||||
import { readNxJson } from './nx-json';
|
import { readNxJson } from './nx-json';
|
||||||
import {
|
import { ProjectsConfigurations } from './workspace-json-project-json';
|
||||||
ProjectConfiguration,
|
import { retrieveProjectConfigurationsSync } from '../project-graph/utils/retrieve-workspace-files';
|
||||||
ProjectsConfigurations,
|
|
||||||
} from './workspace-json-project-json';
|
|
||||||
import {
|
|
||||||
mergeAngularJsonAndProjects,
|
|
||||||
shouldMergeAngularProjects,
|
|
||||||
} from '../adapter/angular-json';
|
|
||||||
import { retrieveProjectConfigurationPaths } from '../project-graph/utils/retrieve-workspace-files';
|
|
||||||
import {
|
|
||||||
buildProjectsConfigurationsFromProjectPathsAndPlugins,
|
|
||||||
mergeTargetConfigurations,
|
|
||||||
readTargetDefaultsForTarget,
|
|
||||||
} from '../project-graph/utils/project-configuration-utils';
|
|
||||||
|
|
||||||
|
// TODO(v18): remove this class
|
||||||
|
/**
|
||||||
|
* @deprecated This will be removed in v18. Use {@link readProjectsConfigurationFromProjectGraph} instead.
|
||||||
|
*/
|
||||||
export class Workspaces {
|
export class Workspaces {
|
||||||
private cachedProjectsConfig: ProjectsConfigurations;
|
|
||||||
|
|
||||||
constructor(private root: string) {}
|
constructor(private root: string) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated Use {@link readProjectsConfigurationFromProjectGraph} instead.
|
||||||
*/
|
*/
|
||||||
readProjectsConfigurations(opts?: {
|
readWorkspaceConfiguration(): ProjectsConfigurations & NxJsonConfiguration {
|
||||||
_includeProjectsFromAngularJson?: boolean;
|
|
||||||
}): ProjectsConfigurations {
|
|
||||||
if (
|
|
||||||
this.cachedProjectsConfig &&
|
|
||||||
process.env.NX_CACHE_PROJECTS_CONFIG !== 'false'
|
|
||||||
) {
|
|
||||||
return this.cachedProjectsConfig;
|
|
||||||
}
|
|
||||||
const nxJson = readNxJson(this.root);
|
const nxJson = readNxJson(this.root);
|
||||||
const projectPaths = retrieveProjectConfigurationPaths(this.root, nxJson);
|
|
||||||
let projectsConfigurations =
|
return {
|
||||||
buildProjectsConfigurationsFromProjectPathsAndPlugins(
|
|
||||||
nxJson,
|
|
||||||
projectPaths,
|
|
||||||
loadNxPluginsSync(
|
|
||||||
nxJson.plugins,
|
|
||||||
getNxRequirePaths(this.root),
|
|
||||||
this.root
|
|
||||||
),
|
|
||||||
this.root
|
|
||||||
).projects;
|
|
||||||
if (
|
|
||||||
shouldMergeAngularProjects(
|
|
||||||
this.root,
|
|
||||||
opts?._includeProjectsFromAngularJson
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
projectsConfigurations = mergeAngularJsonAndProjects(
|
|
||||||
projectsConfigurations,
|
|
||||||
this.root
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.cachedProjectsConfig = {
|
|
||||||
version: 2,
|
version: 2,
|
||||||
projects: projectsConfigurations,
|
projects: retrieveProjectConfigurationsSync(this.root, nxJson)
|
||||||
|
.projectNodes,
|
||||||
|
...nxJson,
|
||||||
};
|
};
|
||||||
return this.cachedProjectsConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated. Use readProjectsConfigurations
|
|
||||||
*/
|
|
||||||
readWorkspaceConfiguration(opts?: {
|
|
||||||
_ignorePluginInference?: boolean;
|
|
||||||
_includeProjectsFromAngularJson?: boolean;
|
|
||||||
}): ProjectsConfigurations & NxJsonConfiguration {
|
|
||||||
const nxJson = readNxJson(this.root);
|
|
||||||
return { ...this.readProjectsConfigurations(opts), ...nxJson };
|
|
||||||
}
|
|
||||||
|
|
||||||
private mergeTargetDefaultsIntoProjectDescriptions(
|
|
||||||
projects: Record<string, ProjectConfiguration>,
|
|
||||||
nxJson: NxJsonConfiguration
|
|
||||||
) {
|
|
||||||
for (const proj of Object.values(projects)) {
|
|
||||||
if (proj.targets) {
|
|
||||||
for (const targetName of Object.keys(proj.targets ?? {})) {
|
|
||||||
const projectTargetDefinition = proj.targets[targetName];
|
|
||||||
const defaults = readTargetDefaultsForTarget(
|
|
||||||
targetName,
|
|
||||||
nxJson.targetDefaults,
|
|
||||||
projectTargetDefinition.executor
|
|
||||||
);
|
|
||||||
|
|
||||||
if (defaults) {
|
|
||||||
proj.targets[targetName] = mergeTargetConfigurations(
|
|
||||||
proj,
|
|
||||||
targetName,
|
|
||||||
defaults
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return projects;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import {
|
|||||||
import { fileExists } from '../../utils/fileutils';
|
import { fileExists } from '../../utils/fileutils';
|
||||||
import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
|
import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
|
||||||
import { serverLogger } from './logger';
|
import { serverLogger } from './logger';
|
||||||
import { Workspaces } from '../../config/workspaces';
|
|
||||||
import { workspaceRoot } from '../../utils/workspace-root';
|
import { workspaceRoot } from '../../utils/workspace-root';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { fileHasher, hashArray } from '../../hasher/file-hasher';
|
import { fileHasher, hashArray } from '../../hasher/file-hasher';
|
||||||
@ -23,7 +22,10 @@ import {
|
|||||||
retrieveWorkspaceFiles,
|
retrieveWorkspaceFiles,
|
||||||
retrieveProjectConfigurations,
|
retrieveProjectConfigurations,
|
||||||
} from '../../project-graph/utils/retrieve-workspace-files';
|
} from '../../project-graph/utils/retrieve-workspace-files';
|
||||||
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
import {
|
||||||
|
ProjectConfiguration,
|
||||||
|
ProjectsConfigurations,
|
||||||
|
} from '../../config/workspace-json-project-json';
|
||||||
import { readNxJson } from '../../config/nx-json';
|
import { readNxJson } from '../../config/nx-json';
|
||||||
|
|
||||||
let cachedSerializedProjectGraphPromise: Promise<{
|
let cachedSerializedProjectGraphPromise: Promise<{
|
||||||
@ -173,7 +175,7 @@ async function processCollectedUpdatedAndDeletedFiles() {
|
|||||||
);
|
);
|
||||||
fileHasher.incrementalUpdate(updatedFiles, deletedFiles);
|
fileHasher.incrementalUpdate(updatedFiles, deletedFiles);
|
||||||
|
|
||||||
let nxJson = readNxJson(workspaceRoot);
|
const nxJson = readNxJson(workspaceRoot);
|
||||||
|
|
||||||
const { projectNodes } = await retrieveProjectConfigurations(
|
const { projectNodes } = await retrieveProjectConfigurations(
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
@ -264,16 +266,17 @@ async function createAndSerializeProjectGraph(): Promise<{
|
|||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
performance.mark('create-project-graph-start');
|
performance.mark('create-project-graph-start');
|
||||||
const projectsConfigurations = new Workspaces(
|
const projectConfigurations = await retrieveProjectConfigurations(
|
||||||
workspaceRoot
|
workspaceRoot,
|
||||||
).readProjectsConfigurations();
|
readNxJson(workspaceRoot)
|
||||||
|
);
|
||||||
const projectFileMap = copyFileMap(projectFileMapWithFiles.projectFileMap);
|
const projectFileMap = copyFileMap(projectFileMapWithFiles.projectFileMap);
|
||||||
const allWorkspaceFiles = copyFileData(
|
const allWorkspaceFiles = copyFileData(
|
||||||
projectFileMapWithFiles.allWorkspaceFiles
|
projectFileMapWithFiles.allWorkspaceFiles
|
||||||
);
|
);
|
||||||
const { projectGraph, projectFileMapCache } =
|
const { projectGraph, projectFileMapCache } =
|
||||||
await buildProjectGraphUsingProjectFileMap(
|
await buildProjectGraphUsingProjectFileMap(
|
||||||
projectsConfigurations,
|
projectConfigurations.projectNodes,
|
||||||
knownExternalNodes,
|
knownExternalNodes,
|
||||||
projectFileMap,
|
projectFileMap,
|
||||||
allWorkspaceFiles,
|
allWorkspaceFiles,
|
||||||
|
|||||||
@ -37,15 +37,13 @@ export type {
|
|||||||
HasherContext,
|
HasherContext,
|
||||||
} from './config/misc-interfaces';
|
} from './config/misc-interfaces';
|
||||||
|
|
||||||
|
// TODO(v18): Remove this export
|
||||||
/**
|
/**
|
||||||
* @category Workspace
|
* @category Workspace
|
||||||
*/
|
*/
|
||||||
export { Workspaces } from './config/workspaces';
|
export { Workspaces } from './config/workspaces';
|
||||||
|
|
||||||
export {
|
export { workspaceLayout } from './config/configuration';
|
||||||
readAllWorkspaceConfiguration,
|
|
||||||
workspaceLayout,
|
|
||||||
} from './config/configuration';
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
NxPlugin,
|
NxPlugin,
|
||||||
@ -208,6 +206,7 @@ export { reverse } from './project-graph/operators';
|
|||||||
export {
|
export {
|
||||||
createProjectGraphAsync,
|
createProjectGraphAsync,
|
||||||
readCachedProjectGraph,
|
readCachedProjectGraph,
|
||||||
|
readProjectsConfigurationFromProjectGraph,
|
||||||
} from './project-graph/project-graph';
|
} from './project-graph/project-graph';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -7,3 +7,4 @@ export { createTempNpmDirectory } from './utils/package-manager';
|
|||||||
export { getExecutorInformation } from './command-line/run/executor-utils';
|
export { getExecutorInformation } from './command-line/run/executor-utils';
|
||||||
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';
|
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';
|
||||||
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
|
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
|
||||||
|
export { retrieveProjectConfigurationsWithAngularProjects } from './project-graph/utils/retrieve-workspace-files';
|
||||||
|
|||||||
@ -3,9 +3,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Observable } from 'rxjs';
|
import type { Observable } from 'rxjs';
|
||||||
import { Workspaces } from '../../config/workspaces';
|
|
||||||
import { readNxJson } from '../../config/nx-json';
|
import { readNxJson } from '../../config/nx-json';
|
||||||
import { Executor, ExecutorContext } from '../../config/misc-interfaces';
|
import { Executor, ExecutorContext } from '../../config/misc-interfaces';
|
||||||
|
import { retrieveProjectConfigurations } from '../../project-graph/utils/retrieve-workspace-files';
|
||||||
|
import { ProjectsConfigurations } from '../../config/workspace-json-project-json';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an Nx Executor into an Angular Devkit Builder
|
* Convert an Nx Executor into an Angular Devkit Builder
|
||||||
@ -14,11 +15,17 @@ import { Executor, ExecutorContext } from '../../config/misc-interfaces';
|
|||||||
*/
|
*/
|
||||||
export function convertNxExecutor(executor: Executor) {
|
export function convertNxExecutor(executor: Executor) {
|
||||||
const builderFunction = (options, builderContext) => {
|
const builderFunction = (options, builderContext) => {
|
||||||
const workspaces = new Workspaces(builderContext.workspaceRoot);
|
|
||||||
const projectsConfigurations = workspaces.readProjectsConfigurations();
|
|
||||||
|
|
||||||
const promise = async () => {
|
const promise = async () => {
|
||||||
const nxJsonConfiguration = readNxJson(builderContext.workspaceRoot);
|
const nxJsonConfiguration = readNxJson(builderContext.workspaceRoot);
|
||||||
|
const projectsConfigurations: ProjectsConfigurations = {
|
||||||
|
version: 2,
|
||||||
|
projects: (
|
||||||
|
await retrieveProjectConfigurations(
|
||||||
|
builderContext.workspaceRoot,
|
||||||
|
nxJsonConfiguration
|
||||||
|
)
|
||||||
|
).projectNodes,
|
||||||
|
};
|
||||||
const context: ExecutorContext = {
|
const context: ExecutorContext = {
|
||||||
root: builderContext.workspaceRoot,
|
root: builderContext.workspaceRoot,
|
||||||
projectName: builderContext.target.project,
|
projectName: builderContext.target.project,
|
||||||
|
|||||||
@ -587,7 +587,10 @@ async function createVirtualWorkspace(config: VirtualWorkspaceConfig) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
ctx: {
|
ctx: {
|
||||||
projectsConfigurations: projectConfigurations,
|
projectsConfigurations: {
|
||||||
|
version: 2,
|
||||||
|
projectConfigurations: projectConfigurations,
|
||||||
|
},
|
||||||
nxJsonConfiguration: nxJson,
|
nxJsonConfiguration: nxJson,
|
||||||
filesToProcess: projectFileMap,
|
filesToProcess: projectFileMap,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -23,10 +23,7 @@ import {
|
|||||||
import { readJsonFile } from '../utils/fileutils';
|
import { readJsonFile } from '../utils/fileutils';
|
||||||
import { NxJsonConfiguration } from '../config/nx-json';
|
import { NxJsonConfiguration } from '../config/nx-json';
|
||||||
import { ProjectGraphBuilder } from './project-graph-builder';
|
import { ProjectGraphBuilder } from './project-graph-builder';
|
||||||
import {
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
||||||
ProjectConfiguration,
|
|
||||||
ProjectsConfigurations,
|
|
||||||
} from '../config/workspace-json-project-json';
|
|
||||||
import { readNxJson } from '../config/configuration';
|
import { readNxJson } from '../config/configuration';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { PackageJson } from '../utils/package-json';
|
import { PackageJson } from '../utils/package-json';
|
||||||
@ -49,7 +46,7 @@ export function getProjectFileMap(): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function buildProjectGraphUsingProjectFileMap(
|
export async function buildProjectGraphUsingProjectFileMap(
|
||||||
projectsConfigurations: ProjectsConfigurations,
|
projects: Record<string, ProjectConfiguration>,
|
||||||
externalNodes: Record<string, ProjectGraphExternalNode>,
|
externalNodes: Record<string, ProjectGraphExternalNode>,
|
||||||
projectFileMap: ProjectFileMap,
|
projectFileMap: ProjectFileMap,
|
||||||
allWorkspaceFiles: FileData[],
|
allWorkspaceFiles: FileData[],
|
||||||
@ -64,7 +61,7 @@ export async function buildProjectGraphUsingProjectFileMap(
|
|||||||
|
|
||||||
const nxJson = readNxJson();
|
const nxJson = readNxJson();
|
||||||
const projectGraphVersion = '6.0';
|
const projectGraphVersion = '6.0';
|
||||||
assertWorkspaceValidity(projectsConfigurations, nxJson);
|
assertWorkspaceValidity(projects, nxJson);
|
||||||
const packageJsonDeps = readCombinedDeps();
|
const packageJsonDeps = readCombinedDeps();
|
||||||
const rootTsConfig = readRootTsConfig();
|
const rootTsConfig = readRootTsConfig();
|
||||||
|
|
||||||
@ -75,7 +72,7 @@ export async function buildProjectGraphUsingProjectFileMap(
|
|||||||
!shouldRecomputeWholeGraph(
|
!shouldRecomputeWholeGraph(
|
||||||
fileMap,
|
fileMap,
|
||||||
packageJsonDeps,
|
packageJsonDeps,
|
||||||
projectsConfigurations,
|
projects,
|
||||||
nxJson,
|
nxJson,
|
||||||
rootTsConfig
|
rootTsConfig
|
||||||
);
|
);
|
||||||
@ -89,7 +86,7 @@ export async function buildProjectGraphUsingProjectFileMap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const context = createContext(
|
const context = createContext(
|
||||||
projectsConfigurations,
|
projects,
|
||||||
nxJson,
|
nxJson,
|
||||||
projectFileMap,
|
projectFileMap,
|
||||||
filesToProcess
|
filesToProcess
|
||||||
@ -185,27 +182,27 @@ async function buildProjectGraphUsingContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createContext(
|
function createContext(
|
||||||
projectsConfigurations: ProjectsConfigurations,
|
projects: Record<string, ProjectConfiguration>,
|
||||||
nxJson: NxJsonConfiguration,
|
nxJson: NxJsonConfiguration,
|
||||||
fileMap: ProjectFileMap,
|
fileMap: ProjectFileMap,
|
||||||
filesToProcess: ProjectFileMap
|
filesToProcess: ProjectFileMap
|
||||||
): ProjectGraphProcessorContext {
|
): ProjectGraphProcessorContext {
|
||||||
const projects = Object.keys(projectsConfigurations.projects).reduce(
|
const clonedProjects = Object.keys(projects).reduce((map, projectName) => {
|
||||||
(map, projectName) => {
|
map[projectName] = {
|
||||||
map[projectName] = {
|
...projects[projectName],
|
||||||
...projectsConfigurations.projects[projectName],
|
};
|
||||||
};
|
return map;
|
||||||
return map;
|
}, {} as Record<string, ProjectConfiguration>);
|
||||||
},
|
|
||||||
{} as Record<string, ProjectConfiguration>
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
nxJsonConfiguration: nxJson,
|
nxJsonConfiguration: nxJson,
|
||||||
projectsConfigurations,
|
|
||||||
workspace: {
|
workspace: {
|
||||||
...projectsConfigurations,
|
version: 2,
|
||||||
|
projects: clonedProjects,
|
||||||
...nxJson,
|
...nxJson,
|
||||||
projects,
|
},
|
||||||
|
projectsConfigurations: {
|
||||||
|
version: 2,
|
||||||
|
projects: clonedProjects,
|
||||||
},
|
},
|
||||||
fileMap,
|
fileMap,
|
||||||
filesToProcess,
|
filesToProcess,
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { Workspaces } from '../config/workspaces';
|
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'fs';
|
||||||
import { extname, join, relative, sep } from 'path';
|
import { extname, join, relative, sep } from 'path';
|
||||||
@ -15,6 +14,7 @@ import {
|
|||||||
} from './project-graph';
|
} from './project-graph';
|
||||||
import { toOldFormat } from '../adapter/angular-json';
|
import { toOldFormat } from '../adapter/angular-json';
|
||||||
import { getIgnoreObject } from '../utils/ignore';
|
import { getIgnoreObject } from '../utils/ignore';
|
||||||
|
import { retrieveProjectConfigurationsSync } from './utils/retrieve-workspace-files';
|
||||||
|
|
||||||
export interface Change {
|
export interface Change {
|
||||||
type: string;
|
type: string;
|
||||||
@ -119,20 +119,28 @@ function defaultReadFileAtRevision(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO(v18): Remove this function
|
||||||
|
* @deprecated To get projects use {@link retrieveProjectConfigurations} instead
|
||||||
|
*/
|
||||||
export function readWorkspaceConfig(opts: {
|
export function readWorkspaceConfig(opts: {
|
||||||
format: 'angularCli' | 'nx';
|
format: 'angularCli' | 'nx';
|
||||||
path?: string;
|
path?: string;
|
||||||
}): ProjectsConfigurations {
|
}): ProjectsConfigurations {
|
||||||
let configuration: ProjectsConfigurations | null = null;
|
let configuration: ProjectsConfigurations | null = null;
|
||||||
|
const root = opts.path || process.cwd();
|
||||||
|
const nxJson = readNxJson(root);
|
||||||
try {
|
try {
|
||||||
const projectGraph = readCachedProjectGraph();
|
const projectGraph = readCachedProjectGraph();
|
||||||
configuration = {
|
configuration = {
|
||||||
...readNxJson(),
|
...nxJson,
|
||||||
...readProjectsConfigurationFromProjectGraph(projectGraph),
|
...readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
const ws = new Workspaces(opts.path || process.cwd());
|
configuration = {
|
||||||
configuration = ws.readProjectsConfigurations();
|
version: 2,
|
||||||
|
projects: retrieveProjectConfigurationsSync(root, nxJson).projectNodes,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (opts.format === 'angularCli') {
|
if (opts.format === 'angularCli') {
|
||||||
return toOldFormat(configuration);
|
return toOldFormat(configuration);
|
||||||
@ -155,8 +163,4 @@ export function readPackageJson(): any {
|
|||||||
// Original Exports
|
// Original Exports
|
||||||
export { FileData };
|
export { FileData };
|
||||||
// TODO(17): Remove these exports
|
// TODO(17): Remove these exports
|
||||||
export {
|
export { readNxJson, workspaceLayout } from '../config/configuration';
|
||||||
readNxJson,
|
|
||||||
readAllWorkspaceConfiguration,
|
|
||||||
workspaceLayout,
|
|
||||||
} from '../config/configuration';
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import {
|
|||||||
ProjectFileMapCache,
|
ProjectFileMapCache,
|
||||||
shouldRecomputeWholeGraph,
|
shouldRecomputeWholeGraph,
|
||||||
} from './nx-deps-cache';
|
} from './nx-deps-cache';
|
||||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
||||||
import { NxJsonConfiguration } from '../config/nx-json';
|
import { NxJsonConfiguration } from '../config/nx-json';
|
||||||
import { nxVersion } from '../utils/versions';
|
import { nxVersion } from '../utils/versions';
|
||||||
|
|
||||||
@ -299,11 +299,10 @@ describe('nx deps utils', () => {
|
|||||||
return { ...defaults, ...p };
|
return { ...defaults, ...p };
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProjectsConfiguration(p: any): ProjectsConfigurations {
|
function createProjectsConfiguration(
|
||||||
const defaults = {
|
p: any
|
||||||
projects: { mylib: {} },
|
): Record<string, ProjectConfiguration> {
|
||||||
} as any;
|
return { mylib: {}, ...p };
|
||||||
return { ...defaults, ...p };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNxJson(p: Partial<NxJsonConfiguration>): NxJsonConfiguration {
|
function createNxJson(p: Partial<NxJsonConfiguration>): NxJsonConfiguration {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
ProjectFileMap,
|
ProjectFileMap,
|
||||||
ProjectGraph,
|
ProjectGraph,
|
||||||
} from '../config/project-graph';
|
} from '../config/project-graph';
|
||||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
||||||
import { projectGraphCacheDirectory } from '../utils/cache-directory';
|
import { projectGraphCacheDirectory } from '../utils/cache-directory';
|
||||||
import {
|
import {
|
||||||
directoryExists,
|
directoryExists,
|
||||||
@ -171,7 +171,7 @@ export function writeCache(
|
|||||||
export function shouldRecomputeWholeGraph(
|
export function shouldRecomputeWholeGraph(
|
||||||
cache: ProjectFileMapCache,
|
cache: ProjectFileMapCache,
|
||||||
packageJsonDeps: Record<string, string>,
|
packageJsonDeps: Record<string, string>,
|
||||||
projects: ProjectsConfigurations,
|
projects: Record<string, ProjectConfiguration>,
|
||||||
nxJson: NxJsonConfiguration,
|
nxJson: NxJsonConfiguration,
|
||||||
tsConfig: { compilerOptions: { paths: { [k: string]: any } } }
|
tsConfig: { compilerOptions: { paths: { [k: string]: any } } }
|
||||||
): boolean {
|
): boolean {
|
||||||
@ -184,7 +184,7 @@ export function shouldRecomputeWholeGraph(
|
|||||||
|
|
||||||
// we have a cached project that is no longer present
|
// we have a cached project that is no longer present
|
||||||
const cachedNodes = Object.keys(cache.projectFileMap);
|
const cachedNodes = Object.keys(cache.projectFileMap);
|
||||||
if (cachedNodes.some((p) => projects.projects[p] === undefined)) {
|
if (cachedNodes.some((p) => projects[p] === undefined)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,9 @@ export function readCachedProjectConfiguration(
|
|||||||
return node.data;
|
return node.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link ProjectsConfigurations} from the {@link ProjectGraph}
|
||||||
|
*/
|
||||||
export function readProjectsConfigurationFromProjectGraph(
|
export function readProjectsConfigurationFromProjectGraph(
|
||||||
projectGraph: ProjectGraph
|
projectGraph: ProjectGraph
|
||||||
): ProjectsConfigurations {
|
): ProjectsConfigurations {
|
||||||
@ -81,7 +84,7 @@ export async function buildProjectGraphWithoutDaemon() {
|
|||||||
const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
|
const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
|
||||||
return (
|
return (
|
||||||
await buildProjectGraphUsingProjectFileMap(
|
await buildProjectGraphUsingProjectFileMap(
|
||||||
projectConfigurations,
|
projectConfigurations.projects,
|
||||||
externalNodes,
|
externalNodes,
|
||||||
projectFileMap,
|
projectFileMap,
|
||||||
allWorkspaceFiles,
|
allWorkspaceFiles,
|
||||||
|
|||||||
@ -99,20 +99,75 @@ export async function retrieveProjectConfigurations(
|
|||||||
externalNodes: Record<string, ProjectGraphExternalNode>;
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
||||||
projectNodes: Record<string, ProjectConfiguration>;
|
projectNodes: Record<string, ProjectConfiguration>;
|
||||||
}> {
|
}> {
|
||||||
const { getProjectConfigurations } =
|
|
||||||
require('../../native') as typeof import('../../native');
|
|
||||||
const plugins = await loadNxPlugins(
|
const plugins = await loadNxPlugins(
|
||||||
nxJson?.plugins ?? [],
|
nxJson?.plugins ?? [],
|
||||||
getNxRequirePaths(workspaceRoot),
|
getNxRequirePaths(workspaceRoot),
|
||||||
workspaceRoot
|
workspaceRoot
|
||||||
);
|
);
|
||||||
const globs = configurationGlobs(workspaceRoot, plugins);
|
const globs = configurationGlobs(workspaceRoot, plugins);
|
||||||
|
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins, globs);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function retrieveProjectConfigurationsWithAngularProjects(
|
||||||
|
workspaceRoot: string,
|
||||||
|
nxJson: NxJsonConfiguration
|
||||||
|
): Promise<{
|
||||||
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
||||||
|
projectNodes: Record<string, ProjectConfiguration>;
|
||||||
|
}> {
|
||||||
|
const plugins = await loadNxPlugins(
|
||||||
|
nxJson?.plugins ?? [],
|
||||||
|
getNxRequirePaths(workspaceRoot),
|
||||||
|
workspaceRoot
|
||||||
|
);
|
||||||
|
const globs = configurationGlobs(workspaceRoot, plugins);
|
||||||
|
return _retrieveProjectConfigurations(
|
||||||
|
workspaceRoot,
|
||||||
|
nxJson,
|
||||||
|
plugins,
|
||||||
|
globs,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link retrieveProjectConfigurations} instead.
|
||||||
|
*/
|
||||||
|
export function retrieveProjectConfigurationsSync(
|
||||||
|
workspaceRoot: string,
|
||||||
|
nxJson: NxJsonConfiguration
|
||||||
|
): {
|
||||||
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
||||||
|
projectNodes: Record<string, ProjectConfiguration>;
|
||||||
|
} {
|
||||||
|
const plugins = loadNxPluginsSync(
|
||||||
|
nxJson?.plugins ?? [],
|
||||||
|
getNxRequirePaths(workspaceRoot),
|
||||||
|
workspaceRoot
|
||||||
|
);
|
||||||
|
const globs = configurationGlobs(workspaceRoot, plugins);
|
||||||
|
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins, globs);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _retrieveProjectConfigurations(
|
||||||
|
workspaceRoot: string,
|
||||||
|
nxJson: NxJsonConfiguration,
|
||||||
|
plugins: NxPluginV2[],
|
||||||
|
globs: string[],
|
||||||
|
includeProjectsFromAngularJson: boolean = false
|
||||||
|
): {
|
||||||
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
||||||
|
projectNodes: Record<string, ProjectConfiguration>;
|
||||||
|
} {
|
||||||
|
const { getProjectConfigurations } =
|
||||||
|
require('../../native') as typeof import('../../native');
|
||||||
return getProjectConfigurations(workspaceRoot, globs, (configs: string[]) => {
|
return getProjectConfigurations(workspaceRoot, globs, (configs: string[]) => {
|
||||||
const projectConfigurations = createProjectConfigurations(
|
const projectConfigurations = createProjectConfigurations(
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
nxJson,
|
nxJson,
|
||||||
configs,
|
configs,
|
||||||
plugins
|
plugins,
|
||||||
|
includeProjectsFromAngularJson
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -210,7 +265,8 @@ function createProjectConfigurations(
|
|||||||
workspaceRoot: string,
|
workspaceRoot: string,
|
||||||
nxJson: NxJsonConfiguration,
|
nxJson: NxJsonConfiguration,
|
||||||
configFiles: string[],
|
configFiles: string[],
|
||||||
plugins: NxPluginV2[]
|
plugins: NxPluginV2[],
|
||||||
|
includeProjectsFromAngularJson: boolean = false
|
||||||
): {
|
): {
|
||||||
projects: Record<string, ProjectConfiguration>;
|
projects: Record<string, ProjectConfiguration>;
|
||||||
externalNodes: Record<string, ProjectGraphExternalNode>;
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
||||||
@ -227,7 +283,9 @@ function createProjectConfigurations(
|
|||||||
|
|
||||||
let projectConfigurations = projects;
|
let projectConfigurations = projects;
|
||||||
|
|
||||||
if (shouldMergeAngularProjects(workspaceRoot, false)) {
|
if (
|
||||||
|
shouldMergeAngularProjects(workspaceRoot, includeProjectsFromAngularJson)
|
||||||
|
) {
|
||||||
projectConfigurations = mergeAngularJsonAndProjects(
|
projectConfigurations = mergeAngularJsonAndProjects(
|
||||||
projectConfigurations,
|
projectConfigurations,
|
||||||
workspaceRoot
|
workspaceRoot
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import { createTaskGraph } from './create-task-graph';
|
|||||||
import { findCycle, makeAcyclic } from './task-graph-utils';
|
import { findCycle, makeAcyclic } from './task-graph-utils';
|
||||||
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
|
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
|
||||||
import { handleErrors } from '../utils/params';
|
import { handleErrors } from '../utils/params';
|
||||||
import { Workspaces } from '../config/workspaces';
|
|
||||||
import {
|
import {
|
||||||
DaemonBasedTaskHasher,
|
DaemonBasedTaskHasher,
|
||||||
InProcessTaskHasher,
|
InProcessTaskHasher,
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { TasksSchedule } from './tasks-schedule';
|
import { TasksSchedule } from './tasks-schedule';
|
||||||
import { Workspaces } from '../config/workspaces';
|
|
||||||
import { removeTasksFromTaskGraph } from './utils';
|
import { removeTasksFromTaskGraph } from './utils';
|
||||||
import { Task, TaskGraph } from '../config/task-graph';
|
import { Task, TaskGraph } from '../config/task-graph';
|
||||||
import { DependencyType, ProjectGraph } from '../config/project-graph';
|
import { DependencyType, ProjectGraph } from '../config/project-graph';
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import { Workspaces } from '../config/workspaces';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
calculateReverseDeps,
|
calculateReverseDeps,
|
||||||
getExecutorForTask,
|
getExecutorForTask,
|
||||||
@ -10,7 +8,6 @@ import { DefaultTasksRunnerOptions } from './default-tasks-runner';
|
|||||||
import { TaskHasher } from '../hasher/task-hasher';
|
import { TaskHasher } from '../hasher/task-hasher';
|
||||||
import { Task, TaskGraph } from '../config/task-graph';
|
import { Task, TaskGraph } from '../config/task-graph';
|
||||||
import { ProjectGraph } from '../config/project-graph';
|
import { ProjectGraph } from '../config/project-graph';
|
||||||
import { NxJsonConfiguration } from '../config/nx-json';
|
|
||||||
import { hashTask } from '../hasher/hash-task';
|
import { hashTask } from '../hasher/hash-task';
|
||||||
import { findAllProjectNodeDependencies } from '../utils/project-graph-utils';
|
import { findAllProjectNodeDependencies } from '../utils/project-graph-utils';
|
||||||
import { reverse } from '../project-graph/operators';
|
import { reverse } from '../project-graph/operators';
|
||||||
|
|||||||
@ -1,38 +1,36 @@
|
|||||||
import { assertWorkspaceValidity } from './assert-workspace-validity';
|
import { assertWorkspaceValidity } from './assert-workspace-validity';
|
||||||
|
|
||||||
describe('assertWorkspaceValidity', () => {
|
describe('assertWorkspaceValidity', () => {
|
||||||
let mockWorkspaceJson: any;
|
let mockProjects: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockWorkspaceJson = {
|
mockProjects = {
|
||||||
projects: {
|
app1: {},
|
||||||
app1: {},
|
'app1-e2e': {},
|
||||||
'app1-e2e': {},
|
app2: {},
|
||||||
app2: {},
|
'app2-e2e': {},
|
||||||
'app2-e2e': {},
|
lib1: {},
|
||||||
lib1: {},
|
lib2: {},
|
||||||
lib2: {},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw for a valid workspace', () => {
|
it('should not throw for a valid workspace', () => {
|
||||||
assertWorkspaceValidity(mockWorkspaceJson, {});
|
assertWorkspaceValidity(mockProjects, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw for a project-level implicit dependency with a glob', () => {
|
it('should not throw for a project-level implicit dependency with a glob', () => {
|
||||||
mockWorkspaceJson.projects.app2.implicitDependencies = ['lib*'];
|
mockProjects.app2.implicitDependencies = ['lib*'];
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
assertWorkspaceValidity(mockWorkspaceJson, {});
|
assertWorkspaceValidity(mockProjects, {});
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw for an invalid project-level implicit dependency', () => {
|
it('should throw for an invalid project-level implicit dependency', () => {
|
||||||
mockWorkspaceJson.projects.app2.implicitDependencies = ['invalidproj'];
|
mockProjects.app2.implicitDependencies = ['invalidproj'];
|
||||||
mockWorkspaceJson.projects.lib1.implicitDependencies = '*';
|
mockProjects.lib1.implicitDependencies = '*';
|
||||||
|
|
||||||
expect(() => assertWorkspaceValidity(mockWorkspaceJson, {}))
|
expect(() => assertWorkspaceValidity(mockProjects, {}))
|
||||||
.toThrowErrorMatchingInlineSnapshot(`
|
.toThrowErrorMatchingInlineSnapshot(`
|
||||||
"Configuration Error
|
"Configuration Error
|
||||||
The following implicitDependencies should be an array of strings:
|
The following implicitDependencies should be an array of strings:
|
||||||
@ -45,10 +43,10 @@ describe('assertWorkspaceValidity', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw for an invalid project-level implicit dependency with glob', () => {
|
it('should throw for an invalid project-level implicit dependency with glob', () => {
|
||||||
mockWorkspaceJson.projects.app2.implicitDependencies = ['invalid*'];
|
mockProjects.app2.implicitDependencies = ['invalid*'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertWorkspaceValidity(mockWorkspaceJson, {});
|
assertWorkspaceValidity(mockProjects, {});
|
||||||
fail('should not reach');
|
fail('should not reach');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toContain(
|
expect(e.message).toContain(
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
||||||
import { NxJsonConfiguration } from '../config/nx-json';
|
import { NxJsonConfiguration } from '../config/nx-json';
|
||||||
import { findMatchingProjects } from './find-matching-projects';
|
import { findMatchingProjects } from './find-matching-projects';
|
||||||
import { output } from './output';
|
import { output } from './output';
|
||||||
import { ProjectGraphProjectNode } from '../config/project-graph';
|
import { ProjectGraphProjectNode } from '../config/project-graph';
|
||||||
|
|
||||||
export function assertWorkspaceValidity(
|
export function assertWorkspaceValidity(
|
||||||
projectsConfigurations: ProjectsConfigurations,
|
projects: Record<string, ProjectConfiguration>,
|
||||||
nxJson: NxJsonConfiguration
|
nxJson: NxJsonConfiguration
|
||||||
) {
|
) {
|
||||||
const projectNames = Object.keys(projectsConfigurations.projects);
|
const projectNames = Object.keys(projects);
|
||||||
const projectGraphNodes = projectNames.reduce((graph, project) => {
|
const projectGraphNodes = projectNames.reduce((graph, project) => {
|
||||||
const projectConfiguration = projectsConfigurations.projects[project];
|
const projectConfiguration = projects[project];
|
||||||
graph[project] = {
|
graph[project] = {
|
||||||
name: project,
|
name: project,
|
||||||
type: projectConfiguration.projectType === 'library' ? 'lib' : 'app', // missing fallback to `e2e`
|
type: projectConfiguration.projectType === 'library' ? 'lib' : 'app', // missing fallback to `e2e`
|
||||||
@ -21,10 +21,6 @@ export function assertWorkspaceValidity(
|
|||||||
return graph;
|
return graph;
|
||||||
}, {} as Record<string, ProjectGraphProjectNode>);
|
}, {} as Record<string, ProjectGraphProjectNode>);
|
||||||
|
|
||||||
const projects = {
|
|
||||||
...projectsConfigurations.projects,
|
|
||||||
};
|
|
||||||
|
|
||||||
const invalidImplicitDependencies = new Map<string, string[]>();
|
const invalidImplicitDependencies = new Map<string, string[]>();
|
||||||
|
|
||||||
if (nxJson.implicitDependencies) {
|
if (nxJson.implicitDependencies) {
|
||||||
@ -110,7 +106,7 @@ function detectAndSetInvalidProjectGlobValues(
|
|||||||
map: Map<string, string[]>,
|
map: Map<string, string[]>,
|
||||||
sourceName: string,
|
sourceName: string,
|
||||||
desiredImplicitDeps: string[],
|
desiredImplicitDeps: string[],
|
||||||
projectConfigurations: ProjectsConfigurations['projects'],
|
projectConfigurations: Record<string, ProjectConfiguration>,
|
||||||
projects: Record<string, ProjectGraphProjectNode>
|
projects: Record<string, ProjectGraphProjectNode>
|
||||||
) {
|
) {
|
||||||
const invalidProjectsOrGlobs = desiredImplicitDeps.filter((implicit) => {
|
const invalidProjectsOrGlobs = desiredImplicitDeps.filter((implicit) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user