chore(core): remove readProjectsConfigurations from workspaces (#18329)

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
Emily Xiong 2023-08-15 14:48:40 -04:00 committed by GitHub
parent 37fd20b706
commit 40d66ec715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 388 additions and 434 deletions

View File

@ -138,12 +138,12 @@ It only uses language primitives and immutable objects
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
- [parseJson](../../devkit/documents/parseJson)
- [parseTargetString](../../devkit/documents/parseTargetString)
- [readAllWorkspaceConfiguration](../../devkit/documents/readAllWorkspaceConfiguration)
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
- [readJson](../../devkit/documents/readJson)
- [readJsonFile](../../devkit/documents/readJsonFile)
- [readNxJson](../../devkit/documents/readNxJson)
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
- [readTargetOptions](../../devkit/documents/readTargetOptions)
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)

View File

@ -1,5 +1,9 @@
# Class: Workspaces
**`Deprecated`**
This will be removed in v18. Use [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) instead.
## Table of contents
### Constructors
@ -8,13 +12,10 @@
### Properties
- [cachedProjectsConfig](../../devkit/documents/Workspaces#cachedprojectsconfig)
- [root](../../devkit/documents/Workspaces#root)
### Methods
- [mergeTargetDefaultsIntoProjectDescriptions](../../devkit/documents/Workspaces#mergetargetdefaultsintoprojectdescriptions)
- [readProjectsConfigurations](../../devkit/documents/Workspaces#readprojectsconfigurations)
- [readWorkspaceConfiguration](../../devkit/documents/Workspaces#readworkspaceconfiguration)
## Constructors
@ -31,67 +32,19 @@
## Properties
### cachedProjectsConfig
`Private` **cachedProjectsConfig**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
---
### root
`Private` **root**: `string`
## Methods
### mergeTargetDefaultsIntoProjectDescriptions
### readWorkspaceConfiguration
`Private` **mergeTargetDefaultsIntoProjectDescriptions**(`projects`, `nxJson`): `Record`<`string`, [`ProjectConfiguration`](../../devkit/documents/ProjectConfiguration)\>
#### 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)
**readWorkspaceConfiguration**(): [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\>
**`Deprecated`**
#### Parameters
| 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` |
Use [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) instead.
#### Returns

View File

@ -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)

View File

@ -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)

View File

@ -138,12 +138,12 @@ It only uses language primitives and immutable objects
- [offsetFromRoot](../../devkit/documents/offsetFromRoot)
- [parseJson](../../devkit/documents/parseJson)
- [parseTargetString](../../devkit/documents/parseTargetString)
- [readAllWorkspaceConfiguration](../../devkit/documents/readAllWorkspaceConfiguration)
- [readCachedProjectGraph](../../devkit/documents/readCachedProjectGraph)
- [readJson](../../devkit/documents/readJson)
- [readJsonFile](../../devkit/documents/readJsonFile)
- [readNxJson](../../devkit/documents/readNxJson)
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
- [readTargetOptions](../../devkit/documents/readTargetOptions)
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)

View File

@ -173,8 +173,10 @@ describe('Angular Module Federation', () => {
// ports
const hostPort = 4500;
const remote1Port = readProjectConfig(remote1).targets.serve.options.port;
const remote2Port = readProjectConfig(remote2).targets.serve.options.port;
const remote1Port = (await readProjectConfig(remote1)).targets.serve.options
.port;
const remote2Port = (await readProjectConfig(remote2)).targets.serve.options
.port;
const process = await runCommandUntil(
`serve-ssr ${host} --port=${hostPort}`,

View File

@ -268,7 +268,7 @@ describe('Angular Projects', () => {
);
// update the angular.json
updateProjectConfig(app1, (config) => {
await updateProjectConfig(app1, (config) => {
config.targets.build.executor = '@nx/angular:webpack-browser';
config.targets.build.options = {
...config.targets.build.options,
@ -276,7 +276,7 @@ describe('Angular Projects', () => {
};
return config;
});
updateProjectConfig(esbuildApp, (config) => {
await updateProjectConfig(esbuildApp, (config) => {
config.targets.build.executor = '@nx/angular:browser-esbuild';
config.targets.build.options = {
...config.targets.build.options,

View File

@ -30,7 +30,7 @@ describe('Angular Cypress Component Tests', () => {
createBuildableLib(projectName, buildableLibName);
useWorkspaceAssetsInApp(appName);
await useWorkspaceAssetsInApp(appName);
});
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.
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
createFile(
@ -279,7 +279,7 @@ function useWorkspaceAssetsInApp(appName: string) {
}
`
);
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
config.targets['build'].options.stylePreprocessorOptions = {
includePaths: ['assets/styles'],
};

View File

@ -360,7 +360,7 @@ describe('Tailwind support', () => {
runCLI(
`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.options = {
...config.targets.build.options,

View File

@ -6,7 +6,6 @@ import {
packageInstall,
readFile,
readJson,
rmDist,
runCLI,
runCommand,
runCommandUntil,
@ -27,7 +26,7 @@ describe('EsBuild Plugin', () => {
const myPkg = uniq('my-pkg');
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
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/*`];
return json;
});
@ -179,12 +178,12 @@ describe('EsBuild Plugin', () => {
expect(runCommand(`node dist/libs/${myPkg}`)).toMatch(/Hello/);
}, 300_000);
it('should support additional entry points', () => {
it('should support additional entry points', async () => {
const myPkg = uniq('my-pkg');
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\n`);
updateFile(`libs/${myPkg}/src/extra.ts`, `console.log('extra');\n`);
updateProjectConfig(myPkg, (json) => {
await updateProjectConfig(myPkg, (json) => {
json.targets.build.options.additionalEntryPoints = [
`libs/${myPkg}/src/extra.ts`,
];
@ -212,7 +211,7 @@ describe('EsBuild Plugin', () => {
`libs/${myPkg}/esbuild.config.js`,
`console.log('custom config loaded');\nmodule.exports = {};\n`
);
updateProjectConfig(myPkg, (json) => {
await updateProjectConfig(myPkg, (json) => {
delete json.targets.build.options.esbuildOptions;
json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`;
return json;

View File

@ -85,8 +85,8 @@ describe('expo', () => {
it('should prebuild', async () => {
// run prebuild command with git check disable
// set a mock package name for ios and android in expo's app.json
const workspace = readResolvedConfiguration();
const root = workspace.projects[appName].root;
const projects = await readResolvedConfiguration();
const root = projects[appName].root;
const appJsonPath = join(root, `app.json`);
const appJson = await readJson(appJsonPath);
if (appJson.expo.ios) {

View File

@ -16,7 +16,7 @@ describe('js:node error handling', () => {
afterEach(() => cleanupProject());
it('should log out the error', () => {
it('should log out the error', async () => {
const esbuildLib = uniq('esbuildlib');
runCLI(
@ -30,7 +30,7 @@ describe('js:node error handling', () => {
`;
});
updateProjectConfig(esbuildLib, (config) => {
await updateProjectConfig(esbuildLib, (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
@ -48,7 +48,7 @@ describe('js:node error handling', () => {
expect(output).toContain('This is an error');
}, 240_000);
it('should execute library compiled with rollup', () => {
it('should execute library compiled with rollup', async () => {
const rollupLib = uniq('rolluplib');
runCLI(
@ -61,7 +61,7 @@ describe('js:node error handling', () => {
`;
});
updateProjectConfig(rollupLib, (config) => {
await updateProjectConfig(rollupLib, (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
@ -76,7 +76,7 @@ describe('js:node error handling', () => {
expect(output).toContain('Hello from my library!');
}, 240_000);
it('should execute library compiled with tsc', () => {
it('should execute library compiled with tsc', async () => {
const tscLib = uniq('tsclib');
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'] = {
executor: '@nx/js:node',
options: {
@ -102,7 +102,7 @@ describe('js:node error handling', () => {
expect(output).toContain('Hello from my tsc library!');
}, 240_000);
it('should execute library compiled with swc', () => {
it('should execute library compiled with swc', async () => {
const swcLib = uniq('swclib');
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'] = {
executor: '@nx/js:node',
options: {
@ -128,7 +128,7 @@ describe('js:node error handling', () => {
expect(output).toContain('Hello from my swc library!');
}, 240_000);
it('should execute webpack app', () => {
it('should execute webpack app', async () => {
const webpackProject = uniq('webpackproject');
runCLI(
@ -141,7 +141,7 @@ describe('js:node error handling', () => {
`;
});
updateProjectConfig(webpackProject, (config) => {
await updateProjectConfig(webpackProject, (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {

View File

@ -123,7 +123,7 @@ describe('bundling libs', () => {
expect(output).toContain(rollupLib);
}, 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 swcLib = uniq('swclib');
const tscEsmLib = uniq('tscesmlib');
@ -154,7 +154,7 @@ describe('bundling libs', () => {
);
// Add additional entry points for `exports` field
updateProjectConfig(tscLib, (json) => {
await updateProjectConfig(tscLib, (json) => {
json.targets.build.options.additionalEntryPoints = [
`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/faz.ts`, `export const faz = 'faz';`);
updateProjectConfig(swcLib, (json) => {
await updateProjectConfig(swcLib, (json) => {
json.targets.build.options.additionalEntryPoints = [
`libs/${swcLib}/src/foo/*.ts`,
];

View File

@ -67,7 +67,7 @@ describe('Next.js Applications', () => {
// Additional assets that should be copied to dist
const sharedLib = uniq('sharedLib');
updateProjectConfig(appName, (json) => {
await updateProjectConfig(appName, (json) => {
json.targets.build.options.assets = [
{
glob: '**/*',
@ -367,7 +367,7 @@ describe('Next.js Applications', () => {
checkFilesExist(`dist/apps/${appName}/next.config.js`);
// Make sure withNx works with run-commands.
updateProjectConfig(appName, (json) => {
await updateProjectConfig(appName, (json) => {
json.targets.build = {
command: 'npx next build',
outputs: [`apps/${appName}/.next`],

View File

@ -151,7 +151,7 @@ describe('Node Applications + webpack', () => {
runCLI(
`generate @nx/node:app ${nodeApp2} --framework=none --no-interactive`
);
updateProjectConfig(nodeApp1, (config) => {
await updateProjectConfig(nodeApp1, (config) => {
config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`];
return config;
});

View File

@ -55,7 +55,7 @@ describe('Node Applications + webpack', () => {
const lib = uniq('nodelib');
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.
config.targets.build.options.buildLibsFromSource = false;
config.targets.serve.options.runBuildTargetDependencies = true;

View File

@ -75,7 +75,7 @@ describe('Node Applications', () => {
const nodeapp = uniq('nodeapp');
runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`);
updateProjectConfig(nodeapp, (config) => {
await updateProjectConfig(nodeapp, (config) => {
config.targets.build.options.outputFileName = 'index.js';
return config;
});
@ -94,7 +94,7 @@ describe('Node Applications', () => {
const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.');
updateProjectConfig(nodeapp, (config) => {
await updateProjectConfig(nodeapp, (config) => {
config.targets.build.options.additionalEntryPoints = [
{
entryName: 'additional-main',
@ -254,7 +254,7 @@ describe('Node Applications', () => {
config.target = 'es2020';
return config;
});
updateProjectConfig(esmapp, (config) => {
await updateProjectConfig(esmapp, (config) => {
config.targets.build.options.outputFileName = 'main.mjs';
config.targets.build.options.assets = [];
return config;
@ -436,7 +436,7 @@ ${jslib}();
packageInstall('@nestjs/swagger', undefined, '^6.0.0');
updateProjectConfig(nestapp, (config) => {
await updateProjectConfig(nestapp, (config) => {
config.targets.build.options.tsPlugins = ['@nestjs/swagger/plugin'];
return config;
});
@ -549,7 +549,7 @@ describe('nest libraries', function () {
packageInstall('@nestjs/swagger', undefined, '~6.3.0');
updateProjectConfig(nestlib, (config) => {
await updateProjectConfig(nestlib, (config) => {
config.targets.build.options.transformers = [
{
name: '@nestjs/swagger/plugin',

View File

@ -18,7 +18,7 @@ describe('Extra Nx Misc Tests', () => {
it('should stream output', async () => {
const myapp = 'abcdefghijklmon';
runCLI(`generate @nx/web:app ${myapp}`);
updateProjectConfig(myapp, (c) => {
await updateProjectConfig(myapp, (c) => {
c.targets['inner'] = {
command: 'echo inner',
};
@ -122,7 +122,7 @@ describe('Extra Nx Misc Tests', () => {
process.platform === 'win32'
? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows
: `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`;
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
config.targets.echoEnvVariables.options.command += ` ${command}`;
return config;
});
@ -135,7 +135,7 @@ describe('Extra Nx Misc Tests', () => {
}, 120000);
it('should pass options', async () => {
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
config.targets.echo = {
command: 'echo --var1={args.var1}',
options: {
@ -151,7 +151,7 @@ describe('Extra Nx Misc Tests', () => {
it('should interpolate provided arguments', async () => {
const echoTarget = uniq('echo');
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
config.targets[echoTarget] = {
executor: 'nx:run-commands',
options: {
@ -186,7 +186,7 @@ describe('Extra Nx Misc Tests', () => {
}, 120000);
it('should fail when a process exits non-zero', async () => {
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
config.targets.error = {
executor: 'nx:run-commands',
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 () => {
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
config.targets.lint.outputs = ['{options.outputFile}'];
return config;
});
@ -241,7 +241,7 @@ describe('Extra Nx Misc Tests', () => {
: `mkdir -p ${folder}`,
`echo dummy > ${folder}/dummy.txt`,
];
updateProjectConfig(mylib, (config) => {
await updateProjectConfig(mylib, (config) => {
delete config.targets.build.options.command;
config.targets.build.options = {
...config.targets.build.options,

View File

@ -113,7 +113,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
updateProjectConfig(lib3, (config) => {
await updateProjectConfig(lib3, (config) => {
config.implicitDependencies = [`${lib1}-data-access`];
return config;
});
@ -172,13 +172,13 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath);
let workspace = await readResolvedConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const newConfig = readProjectConfig(newName);
let projects = await readResolvedConfiguration();
expect(projects[`${lib1}-data-access`]).toBeUndefined();
const newConfig = await readProjectConfig(newName);
expect(newConfig).toMatchObject({
tags: [],
});
const lib3Config = readProjectConfig(lib3);
const lib3Config = await readProjectConfig(lib3);
expect(lib3Config.implicitDependencies).toEqual([
`shared-${lib1}-data-access`,
]);
@ -194,9 +194,9 @@ describe('Workspace Tests', () => {
]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
workspace = readResolvedConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
projects = await readResolvedConfiguration();
expect(projects[`${lib1}-data-access`]).toBeUndefined();
const project = await readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -251,7 +251,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
updateProjectConfig(lib3, (config) => {
await updateProjectConfig(lib3, (config) => {
config.implicitDependencies = [`${lib1}-data-access`];
return config;
});
@ -321,13 +321,13 @@ describe('Workspace Tests', () => {
]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
const workspace = await readResolvedConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
const projects = await readResolvedConfiguration();
expect(projects[`${lib1}-data-access`]).toBeUndefined();
const project = await readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.tags).toEqual([]);
const lib3Config = readProjectConfig(lib3);
const lib3Config = await readProjectConfig(lib3);
expect(lib3Config.implicitDependencies).toEqual([newName]);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -384,7 +384,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
updateProjectConfig(lib3, (config) => {
await updateProjectConfig(lib3, (config) => {
config.implicitDependencies = [`${lib1}-data-access`];
return config;
});
@ -454,9 +454,9 @@ describe('Workspace Tests', () => {
]
).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]);
const workspace = await readResolvedConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
const projects = await readResolvedConfiguration();
expect(projects[`${lib1}-data-access`]).toBeUndefined();
const project = await readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -513,7 +513,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
updateProjectConfig(lib3, (config) => {
await updateProjectConfig(lib3, (config) => {
config.implicitDependencies = [lib1];
return config;
});
@ -572,13 +572,13 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath);
let workspace = readResolvedConfiguration();
expect(workspace.projects[lib1]).toBeUndefined();
const newConfig = readProjectConfig(newName);
let projects = await readResolvedConfiguration();
expect(projects[lib1]).toBeUndefined();
const newConfig = await readProjectConfig(newName);
expect(newConfig).toMatchObject({
tags: [],
});
const lib3Config = readProjectConfig(lib3);
const lib3Config = await readProjectConfig(lib3);
expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]);
expect(moveOutput).toContain('UPDATE tsconfig.base.json');
@ -590,9 +590,9 @@ describe('Workspace Tests', () => {
rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}/data-access`]
).toEqual([`libs/${lib1}/data-access/src/index.ts`]);
workspace = readResolvedConfiguration();
expect(workspace.projects[lib1]).toBeUndefined();
const project = readProjectConfig(newName);
projects = await readResolvedConfiguration();
expect(projects[lib1]).toBeUndefined();
const project = await readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -655,7 +655,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`);
updateProjectConfig(lib3, (config) => {
await updateProjectConfig(lib3, (config) => {
config.implicitDependencies = [`${lib1}-data-access`];
return config;
});
@ -686,11 +686,11 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath);
const newConfig = readProjectConfig(newName);
const newConfig = await readProjectConfig(newName);
expect(newConfig).toMatchObject({
tags: [],
});
const lib3Config = readProjectConfig(lib3);
const lib3Config = await readProjectConfig(lib3);
expect(lib3Config.implicitDependencies).toEqual([
`shared-${lib1}-data-access`,
]);
@ -704,9 +704,9 @@ describe('Workspace Tests', () => {
rootTsConfig.compilerOptions.paths[`shared/${lib1}/data-access`]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);
const projects = readResolvedConfiguration();
expect(projects.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
const projects = await readResolvedConfiguration();
expect(projects[`${lib1}-data-access`]).toBeUndefined();
const project = await readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -741,7 +741,7 @@ describe('Workspace Tests', () => {
*/
runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`);
updateProjectConfig(lib2, (config) => {
await updateProjectConfig(lib2, (config) => {
config.implicitDependencies = [lib1];
return config;
});
@ -775,12 +775,12 @@ describe('Workspace Tests', () => {
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy();
expect(removeOutputForced).not.toContain(`UPDATE nx.json`);
const projectsConfigurations = readResolvedConfiguration();
expect(projectsConfigurations.projects[`${lib1}`]).toBeUndefined();
const lib2Config = readProjectConfig(lib2);
const projects = await readResolvedConfiguration();
expect(projects[`${lib1}`]).toBeUndefined();
const lib2Config = await readProjectConfig(lib2);
expect(lib2Config.implicitDependencies).toEqual([]);
expect(projectsConfigurations.projects[`${lib1}`]).toBeUndefined();
expect(projects[`${lib1}`]).toBeUndefined();
});
});
});

View File

@ -214,11 +214,11 @@ describe('Nx Affected and Graph Tests', () => {
}
}, 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
if (isNotWindows()) {
generateAll();
updateProjectConfig(myapp, (config) => ({
await updateProjectConfig(myapp, (config) => ({
...config,
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();
const root = readResolvedConfiguration().projects[mylib].root;
const root = (await readResolvedConfiguration())[mylib].root;
removeFile(root);
const output = runCLI('print-affected --select projects');
expect(output).toContain(myapp);
@ -239,9 +239,9 @@ describe('Nx Affected and Graph Tests', () => {
expect(output).not.toContain(mylib);
});
it('should detect changes to implicitly dependant projects', () => {
it('should detect changes to implicitly dependant projects', async () => {
generateAll();
updateProjectConfig(myapp, (config) => ({
await updateProjectConfig(myapp, (config) => ({
...config,
implicitDependencies: ['*', `!${myapp2}`],
}));
@ -256,7 +256,7 @@ describe('Nx Affected and Graph Tests', () => {
expect(output).toContain(mylib);
// Clear implicit deps to not interfere with other tests.
updateProjectConfig(myapp, (config) => ({
await updateProjectConfig(myapp, (config) => ({
...config,
implicitDependencies: [],
}));

View File

@ -156,7 +156,7 @@ describe('cache', () => {
it('should support using globs as outputs', async () => {
const mylib = uniq('mylib');
runCLI(`generate @nx/js:library ${mylib}`);
updateProjectConfig(mylib, (c) => {
await updateProjectConfig(mylib, (c) => {
c.targets.build = {
executor: 'nx:run-commands',
outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'],

View File

@ -16,7 +16,7 @@ describe('Invoke Runner', () => {
it('should invoke runner imperatively ', async () => {
const mylib = uniq('mylib');
runCLI(`generate @nx/js:lib ${mylib}`);
updateProjectConfig(mylib, (c) => {
await updateProjectConfig(mylib, (c) => {
c.targets['prebuild'] = {
command: 'echo prebuild',
};

View File

@ -28,9 +28,9 @@ describe('Nx Running Tests', () => {
describe('running targets', () => {
describe('(forwarding params)', () => {
let proj = uniq('proj');
beforeAll(() => {
beforeAll(async () => {
runCLI(`generate @nx/js:lib ${proj}`);
updateProjectConfig(proj, (c) => {
await updateProjectConfig(proj, (c) => {
c.targets['echo'] = {
command: 'echo ECHO:',
};
@ -57,7 +57,7 @@ describe('Nx Running Tests', () => {
it('should execute long running tasks', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nx/web:app ${myapp}`);
updateProjectConfig(myapp, (c) => {
await updateProjectConfig(myapp, (c) => {
c.targets['counter'] = {
executor: '@nx/workspace:counter',
options: {
@ -79,8 +79,8 @@ describe('Nx Running Tests', () => {
runCLI(`generate @nx/node:lib ${mylib}`);
// Used to restore targets to lib after test
const original = readProjectConfig(mylib);
updateProjectConfig(mylib, (j) => {
const original = await readProjectConfig(mylib);
await updateProjectConfig(mylib, (j) => {
delete j.targets;
return j;
});
@ -113,7 +113,7 @@ describe('Nx Running Tests', () => {
`Cannot find configuration for task ${mylib}:echo:fail`
);
updateProjectConfig(mylib, (c) => original);
await updateProjectConfig(mylib, (c) => original);
}, 1000000);
describe('tokens support', () => {
@ -125,7 +125,7 @@ describe('Nx Running Tests', () => {
});
it('should support using {projectRoot} in options blocks in project.json', async () => {
updateProjectConfig(app, (c) => {
await updateProjectConfig(app, (c) => {
c.targets['echo'] = {
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 () => {
updateProjectConfig(app, (c) => {
await updateProjectConfig(app, (c) => {
c.targets['echo'] = {
command: `node -e 'console.log("{projectName}")'`,
};
@ -157,7 +157,7 @@ describe('Nx Running Tests', () => {
};
return json;
});
updateProjectConfig(app, (c) => {
await updateProjectConfig(app, (c) => {
c.targets['echo'] = {};
return c;
});
@ -174,7 +174,7 @@ describe('Nx Running Tests', () => {
};
return json;
});
updateProjectConfig(app, (c) => {
await updateProjectConfig(app, (c) => {
c.targets['echo'] = {};
return c;
});
@ -190,13 +190,13 @@ describe('Nx Running Tests', () => {
const myapp2 = uniq('b');
runCLI(`generate @nx/web:app ${myapp1}`);
runCLI(`generate @nx/web:app ${myapp2}`);
updateProjectConfig(myapp1, (c) => {
await updateProjectConfig(myapp1, (c) => {
c.targets['error'] = {
command: 'echo boom1 && exit 1',
};
return c;
});
updateProjectConfig(myapp2, (c) => {
await updateProjectConfig(myapp2, (c) => {
c.targets['error'] = {
executor: 'nx:run-commands',
options: {
@ -431,9 +431,9 @@ describe('Nx Running Tests', () => {
);
});
it('should be able to include deps using dependsOn', () => {
const originalWorkspace = readProjectConfig(myapp);
updateProjectConfig(myapp, (config) => {
it('should be able to include deps using dependsOn', async () => {
const originalWorkspace = await readProjectConfig(myapp);
await updateProjectConfig(myapp, (config) => {
config.targets.prep = {
executor: 'nx:run-commands',
options: {
@ -453,12 +453,12 @@ describe('Nx Running Tests', () => {
expect(output).toContain(mylib2);
expect(output).toContain('PREP');
updateProjectConfig(myapp, () => originalWorkspace);
await updateProjectConfig(myapp, () => originalWorkspace);
}, 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');
updateProjectConfig(myapp, (config) => {
await updateProjectConfig(myapp, (config) => {
config.targets.prep = {
command: 'echo PREP > one.txt',
};

View File

@ -381,14 +381,14 @@ describe('Nx Plugin', () => {
});
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');
runCLI(
`generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest`
);
checkFilesExist(`libs/subdir/${plugin}/package.json`);
const pluginProject = readProjectConfig(`subdir-${plugin}`);
const pluginE2EProject = readProjectConfig(`subdir-${plugin}-e2e`);
const pluginProject = await readProjectConfig(`subdir-${plugin}`);
const pluginE2EProject = await readProjectConfig(`subdir-${plugin}-e2e`);
expect(pluginProject.targets).toBeDefined();
expect(pluginE2EProject).toBeTruthy();
}, 90000);
@ -399,7 +399,7 @@ describe('Nx Plugin', () => {
runCLI(
`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']);
}, 90000);
});

View File

@ -114,8 +114,8 @@ describe('React Module Federation', () => {
// }
}, 500_000);
function readPort(appName: string): number {
const config = readProjectConfig(appName);
async function readPort(appName: string): Promise<number> {
const config = await readProjectConfig(appName);
return config.targets.serve.options.port;
}
});

View File

@ -36,7 +36,7 @@ describe('Build React libraries and apps', () => {
let proj: string;
beforeEach(() => {
beforeEach(async () => {
app = uniq('app');
parentLib = uniq('parentlib');
childLib = uniq('childlib');
@ -99,7 +99,7 @@ describe('Build React libraries and apps', () => {
);
// Add assets to child lib
updateProjectConfig(childLib, (json) => {
await updateProjectConfig(childLib, (json) => {
json.targets.build.options.assets = [`libs/${childLib}/src/assets`];
return json;
});

View File

@ -234,14 +234,14 @@ describe('React Applications', () => {
${'scss'}
${'less'}
${'styl'}
`('should support global and css modules', ({ style }) => {
`('should support global and css modules', async ({ style }) => {
const appName = uniq('app');
runCLI(
`generate @nx/react:app ${appName} --style=${style} --bundler=webpack --no-interactive`
);
// make sure stylePreprocessorOptions works
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
config.targets.build.options.stylePreprocessorOptions = {
includePaths: ['libs/shared/lib'],
};

View File

@ -17,7 +17,7 @@ describe('React Cypress Component Tests', () => {
const usedInAppLibName = uniq('cy-react-lib');
const buildableLibName = uniq('cy-react-buildable-lib');
beforeAll(() => {
beforeAll(async () => {
projectName = newProject({ name: uniq('cy-react') });
ensureCypressInstallation();
@ -131,7 +131,7 @@ export default Input;
`
);
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
config.targets['build'].options.assets.push({
glob: '**/*',
input: 'libs/assets',
@ -228,7 +228,7 @@ ${content}`;
}
}, 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?
// are they overriding some option on top of each other causing cypress to not see it's running?
createFile(
@ -252,7 +252,7 @@ ${content}`;
);
`
);
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
config.targets[
'build'
].options.webpackConfig = `apps/${appName}/webpack.config.js`;

View File

@ -37,7 +37,7 @@ describe('Rollup Plugin', () => {
let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
expect(output).toMatch(/Hello/);
updateProjectConfig(myPkg, (config) => {
await updateProjectConfig(myPkg, (config) => {
delete config.targets.build;
return config;
});
@ -51,7 +51,7 @@ describe('Rollup Plugin', () => {
output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
expect(output).toMatch(/Hello/);
updateProjectConfig(myPkg, (config) => {
await updateProjectConfig(myPkg, (config) => {
delete config.targets.build;
return config;
});
@ -66,13 +66,13 @@ describe('Rollup Plugin', () => {
expect(output).toMatch(/Hello/);
}, 500000);
it('should support additional entry-points', () => {
it('should support additional entry-points', async () => {
const myPkg = uniq('my-pkg');
runCLI(`generate @nx/js:lib ${myPkg} --bundler=none`);
runCLI(
`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.generateExportsField = true;
config.targets.build.options.additionalEntryPoints = [

View File

@ -14,10 +14,11 @@ import { TargetConfiguration } from '@nx/devkit';
import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process';
import { join } from 'path';
import * as isCI from 'is-ci';
import { Workspaces } from '../../packages/nx/src/config/workspaces';
import { fileExists, readJson, updateFile } from './file-utils';
import { logError, stripConsoleColors } from './log-utils';
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 {
silenceError?: boolean;
@ -36,11 +37,14 @@ export interface RunCmdOpts {
*/
export function setMaxWorkers() {
if (isCI) {
const ws = new Workspaces(tmpProjPath());
const projectsConfigurations = ws.readProjectsConfigurations();
const root = tmpProjPath();
const projects = retrieveProjectConfigurationsSync(
root,
readNxJson(root)
).projectNodes;
Object.keys(projectsConfigurations.projects).forEach((appName) => {
let project = projectsConfigurations.projects[appName];
Object.keys(projects).forEach((appName) => {
let project = projects[appName];
const { build } = project.targets as {
[targetName: string]: TargetConfiguration<any>;
};

View File

@ -1,27 +1,34 @@
import { ProjectConfiguration, Workspaces } from '@nx/devkit';
import { ProjectConfiguration } from '@nx/devkit';
import { join } from 'path';
import { tmpProjPath } from './create-project-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,
callback: (c: ProjectConfiguration) => ProjectConfiguration
) {
const workspace = readResolvedConfiguration();
const root = workspace.projects[projectName].root;
const projects = await readResolvedConfiguration();
const root = projects[projectName].root;
const path = join(root, 'project.json');
const current = readJson(path);
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';
const ws = new Workspaces(tmpProjPath());
return ws.readProjectsConfigurations();
const root = tmpProjPath();
return (await retrieveProjectConfigurations(root, readNxJson(root)))
.projectNodes;
}
export function readProjectConfig(projectName: string): ProjectConfiguration {
const root = readResolvedConfiguration().projects[projectName].root;
export async function readProjectConfig(
projectName: string
): Promise<ProjectConfiguration> {
const root = (await readResolvedConfiguration())[projectName].root;
const path = join(root, 'project.json');
return readJson(path);
}

View File

@ -64,7 +64,7 @@ describe('Vite Plugin', () => {
});
describe('set up new React app with --bundler=vite option', () => {
beforeEach(() => {
beforeEach(async () => {
proj = newProject();
runCLI(`generate @nx/react:app ${myApp} --bundler=vite`);
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 = [
{
replace: `apps/${myApp}/src/environments/environment.ts`,
@ -380,7 +380,7 @@ export default App;
}, 100_000);
// 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
// from the @nx/vite:test executor options, vite will delete the project root directory
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;
return config;
});

View File

@ -20,7 +20,7 @@ describe('file-server', () => {
const port = 4301;
runCLI(`generate @nx/web:app ${appName} --no-interactive`);
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
config.targets['serve'].executor = '@nx/web:file-server';
return config;
});

View File

@ -262,7 +262,7 @@ describe('Web Components Applications', () => {
`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`;
return config;
});
@ -411,7 +411,7 @@ describe('CLI - Environment Variables', () => {
});
describe('Build Options', () => {
it('should inject/bundle external scripts and styles', () => {
it('should inject/bundle external scripts and styles', async () => {
newProject();
const appName = uniq('app');
@ -444,7 +444,7 @@ describe('Build Options', () => {
const barScriptsBundleName = 'bar-scripts';
const barStylesBundleName = 'bar-styles';
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
const buildOptions = config.targets.build.options;
buildOptions.scripts = [
@ -492,7 +492,7 @@ describe('Build Options', () => {
});
describe('index.html interpolation', () => {
test('should interpolate environment variables', () => {
test('should interpolate environment variables', async () => {
const appName = uniq('app');
runCLI(
@ -530,7 +530,7 @@ describe('index.html interpolation', () => {
updateFile(envFilePath, envFileContents);
updateFile(indexPath, indexContent);
updateProjectConfig(appName, (config) => {
await updateProjectConfig(appName, (config) => {
const buildOptions = config.targets.build.options;
buildOptions.deployUrl = 'baz';
return config;

View File

@ -45,7 +45,7 @@ module.exports = composePlugins(withNx(), (config) => {
expect(output).not.toMatch(/Conflicting/);
expect(output).not.toMatch(/process.env.NODE_ENV/);
updateProjectConfig(myPkg, (config) => {
await updateProjectConfig(myPkg, (config) => {
delete config.targets.build;
return config;
});
@ -59,7 +59,7 @@ module.exports = composePlugins(withNx(), (config) => {
output = runCommand(`node dist/libs/${myPkg}/main.js`);
expect(output).toMatch(/Hello/);
updateProjectConfig(myPkg, (config) => {
await updateProjectConfig(myPkg, (config) => {
delete config.targets.build;
return config;
});

View File

@ -47,10 +47,7 @@ export type {
*/
export { Workspaces } from 'nx/src/config/workspaces';
export {
readAllWorkspaceConfiguration,
workspaceLayout,
} from 'nx/src/config/configuration';
export { workspaceLayout } from 'nx/src/config/configuration';
export type {
NxPlugin,

View File

@ -2,7 +2,11 @@ import type { Observable } from 'rxjs';
import type { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces';
import { requireNx } from '../../nx';
const { Workspaces, readNxJsonFromDisk } = requireNx();
const {
Workspaces,
readNxJsonFromDisk,
retrieveProjectConfigurationsWithAngularProjects,
} = requireNx();
/**
* Convert an Nx Executor into an Angular Devkit Builder
@ -17,11 +21,22 @@ export function convertNxExecutor(executor: Executor) {
? readNxJsonFromDisk(builderContext.workspaceRoot)
: // TODO(v18): remove readNxJson. This is to be backwards compatible with Nx 16.5 and below.
(workspaces as any).readNxJson();
const projectsConfigurations = workspaces.readProjectsConfigurations({
_includeProjectsFromAngularJson: true,
});
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 = {
root: builderContext.workspaceRoot,
projectName: builderContext.target.project,

View File

@ -44,7 +44,7 @@ export function calculateDefaultProjectName(
}
export function findMatchingProjectInCwd(
projects: { [projectName: string]: ProjectConfiguration },
projects: Record<string, ProjectConfiguration>,
relativeCwd: string
): string | undefined {
const projectRootMappings = new Map<string, string>();

View File

@ -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';
// 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.
*/

View File

@ -1,6 +1,8 @@
import { toProjectName, Workspaces } from './workspaces';
import { TempFs } from '../utils/testing/temp-fs';
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) => ({
name: name ?? toProjectName(`${root}/some-file`),
@ -45,7 +47,7 @@ describe('Workspaces', () => {
});
const workspaces = new Workspaces(fs.tempDir);
const resolved = workspaces.readProjectsConfigurations();
const resolved = workspaces.readWorkspaceConfiguration();
expect(resolved.projects.lib1).toEqual(standaloneConfig);
});
@ -74,7 +76,7 @@ describe('Workspaces', () => {
});
const workspaces = new Workspaces(fs.tempDir);
const { projects } = workspaces.readProjectsConfigurations();
const { projects } = workspaces.readWorkspaceConfiguration();
// projects got merged for lib1
expect(projects['lib1']).toEqual({
@ -112,10 +114,12 @@ describe('Workspaces', () => {
{
NX_WORKSPACE_ROOT: fs.tempDir,
},
() => {
const workspaces = new Workspaces(fs.tempDir);
const resolved = workspaces.readProjectsConfigurations();
expect(resolved.projects['my-package']).toEqual({
async () => {
const resolved = await retrieveProjectConfigurations(
fs.tempDir,
readNxJson(fs.tempDir)
);
expect(resolved.projectNodes['my-package']).toEqual({
name: 'my-package',
root: 'packages/my-package',
sourceRoot: 'packages/my-package',

View File

@ -1,110 +1,29 @@
import { dirname, join } 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 { dirname } from 'path';
import type { NxJsonConfiguration } from './nx-json';
import { readNxJson } from './nx-json';
import {
ProjectConfiguration,
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';
import { ProjectsConfigurations } from './workspace-json-project-json';
import { retrieveProjectConfigurationsSync } from '../project-graph/utils/retrieve-workspace-files';
// TODO(v18): remove this class
/**
* @deprecated This will be removed in v18. Use {@link readProjectsConfigurationFromProjectGraph} instead.
*/
export class Workspaces {
private cachedProjectsConfig: ProjectsConfigurations;
constructor(private root: string) {}
/**
* @deprecated
* @deprecated Use {@link readProjectsConfigurationFromProjectGraph} instead.
*/
readProjectsConfigurations(opts?: {
_includeProjectsFromAngularJson?: boolean;
}): ProjectsConfigurations {
if (
this.cachedProjectsConfig &&
process.env.NX_CACHE_PROJECTS_CONFIG !== 'false'
) {
return this.cachedProjectsConfig;
}
readWorkspaceConfiguration(): ProjectsConfigurations & NxJsonConfiguration {
const nxJson = readNxJson(this.root);
const projectPaths = retrieveProjectConfigurationPaths(this.root, nxJson);
let projectsConfigurations =
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 = {
return {
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;
}
}

View File

@ -15,7 +15,6 @@ import {
import { fileExists } from '../../utils/fileutils';
import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
import { serverLogger } from './logger';
import { Workspaces } from '../../config/workspaces';
import { workspaceRoot } from '../../utils/workspace-root';
import { execSync } from 'child_process';
import { fileHasher, hashArray } from '../../hasher/file-hasher';
@ -23,7 +22,10 @@ import {
retrieveWorkspaceFiles,
retrieveProjectConfigurations,
} 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';
let cachedSerializedProjectGraphPromise: Promise<{
@ -173,7 +175,7 @@ async function processCollectedUpdatedAndDeletedFiles() {
);
fileHasher.incrementalUpdate(updatedFiles, deletedFiles);
let nxJson = readNxJson(workspaceRoot);
const nxJson = readNxJson(workspaceRoot);
const { projectNodes } = await retrieveProjectConfigurations(
workspaceRoot,
@ -264,16 +266,17 @@ async function createAndSerializeProjectGraph(): Promise<{
}> {
try {
performance.mark('create-project-graph-start');
const projectsConfigurations = new Workspaces(
workspaceRoot
).readProjectsConfigurations();
const projectConfigurations = await retrieveProjectConfigurations(
workspaceRoot,
readNxJson(workspaceRoot)
);
const projectFileMap = copyFileMap(projectFileMapWithFiles.projectFileMap);
const allWorkspaceFiles = copyFileData(
projectFileMapWithFiles.allWorkspaceFiles
);
const { projectGraph, projectFileMapCache } =
await buildProjectGraphUsingProjectFileMap(
projectsConfigurations,
projectConfigurations.projectNodes,
knownExternalNodes,
projectFileMap,
allWorkspaceFiles,

View File

@ -37,15 +37,13 @@ export type {
HasherContext,
} from './config/misc-interfaces';
// TODO(v18): Remove this export
/**
* @category Workspace
*/
export { Workspaces } from './config/workspaces';
export {
readAllWorkspaceConfiguration,
workspaceLayout,
} from './config/configuration';
export { workspaceLayout } from './config/configuration';
export type {
NxPlugin,
@ -208,6 +206,7 @@ export { reverse } from './project-graph/operators';
export {
createProjectGraphAsync,
readCachedProjectGraph,
readProjectsConfigurationFromProjectGraph,
} from './project-graph/project-graph';
/**

View File

@ -7,3 +7,4 @@ export { createTempNpmDirectory } from './utils/package-manager';
export { getExecutorInformation } from './command-line/run/executor-utils';
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
export { retrieveProjectConfigurationsWithAngularProjects } from './project-graph/utils/retrieve-workspace-files';

View File

@ -3,9 +3,10 @@
*/
import type { Observable } from 'rxjs';
import { Workspaces } from '../../config/workspaces';
import { readNxJson } from '../../config/nx-json';
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
@ -14,11 +15,17 @@ import { Executor, ExecutorContext } from '../../config/misc-interfaces';
*/
export function convertNxExecutor(executor: Executor) {
const builderFunction = (options, builderContext) => {
const workspaces = new Workspaces(builderContext.workspaceRoot);
const projectsConfigurations = workspaces.readProjectsConfigurations();
const promise = async () => {
const nxJsonConfiguration = readNxJson(builderContext.workspaceRoot);
const projectsConfigurations: ProjectsConfigurations = {
version: 2,
projects: (
await retrieveProjectConfigurations(
builderContext.workspaceRoot,
nxJsonConfiguration
)
).projectNodes,
};
const context: ExecutorContext = {
root: builderContext.workspaceRoot,
projectName: builderContext.target.project,

View File

@ -587,7 +587,10 @@ async function createVirtualWorkspace(config: VirtualWorkspaceConfig) {
return {
ctx: {
projectsConfigurations: projectConfigurations,
projectsConfigurations: {
version: 2,
projectConfigurations: projectConfigurations,
},
nxJsonConfiguration: nxJson,
filesToProcess: projectFileMap,
},

View File

@ -23,10 +23,7 @@ import {
import { readJsonFile } from '../utils/fileutils';
import { NxJsonConfiguration } from '../config/nx-json';
import { ProjectGraphBuilder } from './project-graph-builder';
import {
ProjectConfiguration,
ProjectsConfigurations,
} from '../config/workspace-json-project-json';
import { ProjectConfiguration } from '../config/workspace-json-project-json';
import { readNxJson } from '../config/configuration';
import { existsSync } from 'fs';
import { PackageJson } from '../utils/package-json';
@ -49,7 +46,7 @@ export function getProjectFileMap(): {
}
export async function buildProjectGraphUsingProjectFileMap(
projectsConfigurations: ProjectsConfigurations,
projects: Record<string, ProjectConfiguration>,
externalNodes: Record<string, ProjectGraphExternalNode>,
projectFileMap: ProjectFileMap,
allWorkspaceFiles: FileData[],
@ -64,7 +61,7 @@ export async function buildProjectGraphUsingProjectFileMap(
const nxJson = readNxJson();
const projectGraphVersion = '6.0';
assertWorkspaceValidity(projectsConfigurations, nxJson);
assertWorkspaceValidity(projects, nxJson);
const packageJsonDeps = readCombinedDeps();
const rootTsConfig = readRootTsConfig();
@ -75,7 +72,7 @@ export async function buildProjectGraphUsingProjectFileMap(
!shouldRecomputeWholeGraph(
fileMap,
packageJsonDeps,
projectsConfigurations,
projects,
nxJson,
rootTsConfig
);
@ -89,7 +86,7 @@ export async function buildProjectGraphUsingProjectFileMap(
}
const context = createContext(
projectsConfigurations,
projects,
nxJson,
projectFileMap,
filesToProcess
@ -185,27 +182,27 @@ async function buildProjectGraphUsingContext(
}
function createContext(
projectsConfigurations: ProjectsConfigurations,
projects: Record<string, ProjectConfiguration>,
nxJson: NxJsonConfiguration,
fileMap: ProjectFileMap,
filesToProcess: ProjectFileMap
): ProjectGraphProcessorContext {
const projects = Object.keys(projectsConfigurations.projects).reduce(
(map, projectName) => {
map[projectName] = {
...projectsConfigurations.projects[projectName],
};
return map;
},
{} as Record<string, ProjectConfiguration>
);
const clonedProjects = Object.keys(projects).reduce((map, projectName) => {
map[projectName] = {
...projects[projectName],
};
return map;
}, {} as Record<string, ProjectConfiguration>);
return {
nxJsonConfiguration: nxJson,
projectsConfigurations,
workspace: {
...projectsConfigurations,
version: 2,
projects: clonedProjects,
...nxJson,
projects,
},
projectsConfigurations: {
version: 2,
projects: clonedProjects,
},
fileMap,
filesToProcess,

View File

@ -1,4 +1,3 @@
import { Workspaces } from '../config/workspaces';
import { execSync } from 'child_process';
import { existsSync, readFileSync } from 'fs';
import { extname, join, relative, sep } from 'path';
@ -15,6 +14,7 @@ import {
} from './project-graph';
import { toOldFormat } from '../adapter/angular-json';
import { getIgnoreObject } from '../utils/ignore';
import { retrieveProjectConfigurationsSync } from './utils/retrieve-workspace-files';
export interface Change {
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: {
format: 'angularCli' | 'nx';
path?: string;
}): ProjectsConfigurations {
let configuration: ProjectsConfigurations | null = null;
const root = opts.path || process.cwd();
const nxJson = readNxJson(root);
try {
const projectGraph = readCachedProjectGraph();
configuration = {
...readNxJson(),
...nxJson,
...readProjectsConfigurationFromProjectGraph(projectGraph),
};
} catch {
const ws = new Workspaces(opts.path || process.cwd());
configuration = ws.readProjectsConfigurations();
configuration = {
version: 2,
projects: retrieveProjectConfigurationsSync(root, nxJson).projectNodes,
};
}
if (opts.format === 'angularCli') {
return toOldFormat(configuration);
@ -155,8 +163,4 @@ export function readPackageJson(): any {
// Original Exports
export { FileData };
// TODO(17): Remove these exports
export {
readNxJson,
readAllWorkspaceConfiguration,
workspaceLayout,
} from '../config/configuration';
export { readNxJson, workspaceLayout } from '../config/configuration';

View File

@ -4,7 +4,7 @@ import {
ProjectFileMapCache,
shouldRecomputeWholeGraph,
} 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 { nxVersion } from '../utils/versions';
@ -299,11 +299,10 @@ describe('nx deps utils', () => {
return { ...defaults, ...p };
}
function createProjectsConfiguration(p: any): ProjectsConfigurations {
const defaults = {
projects: { mylib: {} },
} as any;
return { ...defaults, ...p };
function createProjectsConfiguration(
p: any
): Record<string, ProjectConfiguration> {
return { mylib: {}, ...p };
}
function createNxJson(p: Partial<NxJsonConfiguration>): NxJsonConfiguration {

View File

@ -8,7 +8,7 @@ import {
ProjectFileMap,
ProjectGraph,
} 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 {
directoryExists,
@ -171,7 +171,7 @@ export function writeCache(
export function shouldRecomputeWholeGraph(
cache: ProjectFileMapCache,
packageJsonDeps: Record<string, string>,
projects: ProjectsConfigurations,
projects: Record<string, ProjectConfiguration>,
nxJson: NxJsonConfiguration,
tsConfig: { compilerOptions: { paths: { [k: string]: any } } }
): boolean {
@ -184,7 +184,7 @@ export function shouldRecomputeWholeGraph(
// we have a cached project that is no longer present
const cachedNodes = Object.keys(cache.projectFileMap);
if (cachedNodes.some((p) => projects.projects[p] === undefined)) {
if (cachedNodes.some((p) => projects[p] === undefined)) {
return true;
}

View File

@ -54,6 +54,9 @@ export function readCachedProjectConfiguration(
return node.data;
}
/**
* Get the {@link ProjectsConfigurations} from the {@link ProjectGraph}
*/
export function readProjectsConfigurationFromProjectGraph(
projectGraph: ProjectGraph
): ProjectsConfigurations {
@ -81,7 +84,7 @@ export async function buildProjectGraphWithoutDaemon() {
const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
return (
await buildProjectGraphUsingProjectFileMap(
projectConfigurations,
projectConfigurations.projects,
externalNodes,
projectFileMap,
allWorkspaceFiles,

View File

@ -99,20 +99,75 @@ export async function retrieveProjectConfigurations(
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
}> {
const { getProjectConfigurations } =
require('../../native') as typeof import('../../native');
const plugins = await loadNxPlugins(
nxJson?.plugins ?? [],
getNxRequirePaths(workspaceRoot),
workspaceRoot
);
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[]) => {
const projectConfigurations = createProjectConfigurations(
workspaceRoot,
nxJson,
configs,
plugins
plugins,
includeProjectsFromAngularJson
);
return {
@ -210,7 +265,8 @@ function createProjectConfigurations(
workspaceRoot: string,
nxJson: NxJsonConfiguration,
configFiles: string[],
plugins: NxPluginV2[]
plugins: NxPluginV2[],
includeProjectsFromAngularJson: boolean = false
): {
projects: Record<string, ProjectConfiguration>;
externalNodes: Record<string, ProjectGraphExternalNode>;
@ -227,7 +283,9 @@ function createProjectConfigurations(
let projectConfigurations = projects;
if (shouldMergeAngularProjects(workspaceRoot, false)) {
if (
shouldMergeAngularProjects(workspaceRoot, includeProjectsFromAngularJson)
) {
projectConfigurations = mergeAngularJsonAndProjects(
projectConfigurations,
workspaceRoot

View File

@ -24,7 +24,6 @@ import { createTaskGraph } from './create-task-graph';
import { findCycle, makeAcyclic } from './task-graph-utils';
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
import { handleErrors } from '../utils/params';
import { Workspaces } from '../config/workspaces';
import {
DaemonBasedTaskHasher,
InProcessTaskHasher,

View File

@ -1,5 +1,4 @@
import { TasksSchedule } from './tasks-schedule';
import { Workspaces } from '../config/workspaces';
import { removeTasksFromTaskGraph } from './utils';
import { Task, TaskGraph } from '../config/task-graph';
import { DependencyType, ProjectGraph } from '../config/project-graph';

View File

@ -1,5 +1,3 @@
import { Workspaces } from '../config/workspaces';
import {
calculateReverseDeps,
getExecutorForTask,
@ -10,7 +8,6 @@ import { DefaultTasksRunnerOptions } from './default-tasks-runner';
import { TaskHasher } from '../hasher/task-hasher';
import { Task, TaskGraph } from '../config/task-graph';
import { ProjectGraph } from '../config/project-graph';
import { NxJsonConfiguration } from '../config/nx-json';
import { hashTask } from '../hasher/hash-task';
import { findAllProjectNodeDependencies } from '../utils/project-graph-utils';
import { reverse } from '../project-graph/operators';

View File

@ -1,38 +1,36 @@
import { assertWorkspaceValidity } from './assert-workspace-validity';
describe('assertWorkspaceValidity', () => {
let mockWorkspaceJson: any;
let mockProjects: any;
beforeEach(() => {
mockWorkspaceJson = {
projects: {
app1: {},
'app1-e2e': {},
app2: {},
'app2-e2e': {},
lib1: {},
lib2: {},
},
mockProjects = {
app1: {},
'app1-e2e': {},
app2: {},
'app2-e2e': {},
lib1: {},
lib2: {},
};
});
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', () => {
mockWorkspaceJson.projects.app2.implicitDependencies = ['lib*'];
mockProjects.app2.implicitDependencies = ['lib*'];
expect(() => {
assertWorkspaceValidity(mockWorkspaceJson, {});
assertWorkspaceValidity(mockProjects, {});
}).not.toThrow();
});
it('should throw for an invalid project-level implicit dependency', () => {
mockWorkspaceJson.projects.app2.implicitDependencies = ['invalidproj'];
mockWorkspaceJson.projects.lib1.implicitDependencies = '*';
mockProjects.app2.implicitDependencies = ['invalidproj'];
mockProjects.lib1.implicitDependencies = '*';
expect(() => assertWorkspaceValidity(mockWorkspaceJson, {}))
expect(() => assertWorkspaceValidity(mockProjects, {}))
.toThrowErrorMatchingInlineSnapshot(`
"Configuration Error
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', () => {
mockWorkspaceJson.projects.app2.implicitDependencies = ['invalid*'];
mockProjects.app2.implicitDependencies = ['invalid*'];
try {
assertWorkspaceValidity(mockWorkspaceJson, {});
assertWorkspaceValidity(mockProjects, {});
fail('should not reach');
} catch (e) {
expect(e.message).toContain(

View File

@ -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 { findMatchingProjects } from './find-matching-projects';
import { output } from './output';
import { ProjectGraphProjectNode } from '../config/project-graph';
export function assertWorkspaceValidity(
projectsConfigurations: ProjectsConfigurations,
projects: Record<string, ProjectConfiguration>,
nxJson: NxJsonConfiguration
) {
const projectNames = Object.keys(projectsConfigurations.projects);
const projectNames = Object.keys(projects);
const projectGraphNodes = projectNames.reduce((graph, project) => {
const projectConfiguration = projectsConfigurations.projects[project];
const projectConfiguration = projects[project];
graph[project] = {
name: project,
type: projectConfiguration.projectType === 'library' ? 'lib' : 'app', // missing fallback to `e2e`
@ -21,10 +21,6 @@ export function assertWorkspaceValidity(
return graph;
}, {} as Record<string, ProjectGraphProjectNode>);
const projects = {
...projectsConfigurations.projects,
};
const invalidImplicitDependencies = new Map<string, string[]>();
if (nxJson.implicitDependencies) {
@ -110,7 +106,7 @@ function detectAndSetInvalidProjectGlobValues(
map: Map<string, string[]>,
sourceName: string,
desiredImplicitDeps: string[],
projectConfigurations: ProjectsConfigurations['projects'],
projectConfigurations: Record<string, ProjectConfiguration>,
projects: Record<string, ProjectGraphProjectNode>
) {
const invalidProjectsOrGlobs = desiredImplicitDeps.filter((implicit) => {