Skip to content

Commit

Permalink
feat(core): don't generate workspace.json for v2 workspaces (#12127)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Sep 27, 2022
1 parent beef424 commit 9b63ce1
Show file tree
Hide file tree
Showing 77 changed files with 573 additions and 454 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ CHANGELOG.md

# Next.js
.next

# Local dev files
.env
16 changes: 0 additions & 16 deletions e2e/angular-core/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ describe('Angular Config', () => {
beforeAll(() => newProject());
afterAll(() => cleanupProject());

it('should support workspaces w/o workspace config file', async () => {
if (isNotWindows()) {
const oldWorkspaceJson = readJson('workspace.json');
removeFile('workspace.json');
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --directory=myDir --routing`);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
expect(() =>
checkFilesDoNotExist('workspace.json', 'angular.json')
).not.toThrow();
createFile('workspace.json', JSON.stringify(oldWorkspaceJson, null, 2));
}
}, 1000000);

it('should upgrade the config correctly', async () => {
const previousCI = process.env.SELECTED_CLI;
process.env.SELECTED_CLI = 'angular';
Expand Down
2 changes: 1 addition & 1 deletion e2e/angular-core/src/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('Angular Projects', () => {
}
}, 1000000);

it('should build the dependent buildable lib and its child lib, as well as the app', () => {
it('should build the dependent buildable lib and its child lib, as well as the app', async () => {
// ARRANGE
const app = uniq('app');
const buildableLib = uniq('buildlib1');
Expand Down
2 changes: 1 addition & 1 deletion e2e/angular-extensions/src/cypress-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Angular Cypress Component Tests', () => {
const usedInAppLibName = uniq('cy-angular-lib');
const buildableLibName = uniq('cy-angular-buildable-lib');

beforeAll(() => {
beforeAll(async () => {
projectName = newProject({ name: uniq('cy-ng') });
runCLI(`generate @nrwl/angular:app ${appName} --no-interactive`);
runCLI(
Expand Down
1 change: 0 additions & 1 deletion e2e/angular-extensions/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('Move Angular Project', () => {
expect(moveOutput).toContain(
`CREATE apps/${newPath}/src/environments/environment.ts`
);
expect(moveOutput).toContain(`UPDATE workspace.json`);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion e2e/angular-extensions/src/tailwind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('Tailwind support', () => {
expect(mainBundle).toMatch(expectedStylesRegex);
};

it('should build correctly and only output the tailwind utilities used', () => {
it('should build correctly and only output the tailwind utilities used', async () => {
const appWithTailwind = uniq('app-with-tailwind');
runCLI(
`generate @nrwl/angular:app ${appWithTailwind} --add-tailwind --no-interactive`
Expand Down
11 changes: 0 additions & 11 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,6 @@ exports.FooModel = FooModel;
);
}, 300000);

it('should support workspaces w/o workspace config file', async () => {
removeFile('workspace.json');
const app2 = uniq('app2');
runCLI(`generate @nrwl/node:app ${app2} --directory=myDir`);

runCLI(`build my-dir-${app2}`);
expect(() =>
checkFilesDoNotExist('workspace.json', 'angular.json')
).not.toThrow();
}, 1000000);

it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/node:lib');
}, 100000);
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-misc/src/extras.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Extra Nx Misc Tests', () => {
expect(resultArgs).toContain('camel: d');
}, 120000);

it('ttt should fail when a process exits non-zero', () => {
it('ttt should fail when a process exits non-zero', async () => {
updateProjectConfig(mylib, (config) => {
config.targets.error = {
executor: '@nrwl/workspace:run-commands',
Expand All @@ -209,7 +209,7 @@ describe('Extra Nx Misc Tests', () => {
}
});

it('run command should not break if output property is missing in options and arguments', () => {
it('run command should not break if output property is missing in options and arguments', async () => {
updateProjectConfig(mylib, (config) => {
config.targets.lint.outputs = ['{options.outputFile}'];
return config;
Expand Down
61 changes: 36 additions & 25 deletions e2e/nx-misc/src/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
expectJestTestsToPass,
readFile,
exists,
workspaceConfigName,
renameFile,
updateProjectConfig,
readProjectConfig,
tmpProjPath,
readResolvedWorkspaceConfiguration,
removeFile,
} from '@nrwl/e2e/utils';

let proj: string;
Expand All @@ -23,7 +24,9 @@ describe('Workspace Tests', () => {
proj = newProject();
});

afterAll(() => cleanupProject());
afterAll(() => {
cleanupProject();
});

describe('@nrwl/workspace:library', () => {
it('should create a library that can be tested and linted', async () => {
Expand Down Expand Up @@ -211,13 +214,14 @@ describe('Workspace Tests', () => {
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d`
);
expect(exists(`libs/dir/${workspace}/src/index.ts`)).toEqual(false);
expect(dryRunOutput).toContain(`UPDATE ${workspaceConfigName()}`);
expect(dryRunOutput).toContain(
`CREATE libs/dir/${workspace}/src/index.ts`
);

const output = runCLI(
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir`
);
checkFilesExist(`libs/dir/${workspace}/src/index.ts`);
expect(output).toContain(`UPDATE ${workspaceConfigName()}`);
expect(output).not.toContain('UPDATE nx.json');

const jsonFailing = readJson(`tools/generators/${failing}/schema.json`);
Expand Down Expand Up @@ -281,7 +285,7 @@ describe('Workspace Tests', () => {
/**
* Tries moving a library from ${lib}/data-access -> shared/${lib}/data-access
*/
it('should work for libraries', () => {
it('should work for libraries', async () => {
const lib1 = uniq('mylib');
const lib2 = uniq('mylib');
const lib3 = uniq('mylib');
Expand Down Expand Up @@ -374,8 +378,8 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath);

let workspaceJson = readJson(workspaceConfigName());
expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined();
let workspace = await readResolvedWorkspaceConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const newConfig = readProjectConfig(newName);
expect(newConfig).toMatchObject({
tags: [],
Expand All @@ -396,9 +400,8 @@ describe('Workspace Tests', () => {
]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);

expect(moveOutput).toContain(`UPDATE workspace.json`);
workspaceJson = readJson(workspaceConfigName());
expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined();
workspace = readResolvedWorkspaceConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
Expand All @@ -416,7 +419,7 @@ describe('Workspace Tests', () => {
);
});

it('should work for libs created with --importPath', () => {
it('should work for libs created with --importPath', async () => {
const importPath = '@wibble/fish';
const lib1 = uniq('mylib');
const lib2 = uniq('mylib');
Expand Down Expand Up @@ -523,9 +526,8 @@ describe('Workspace Tests', () => {
]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);

expect(moveOutput).toContain(`UPDATE workspace.json`);
const workspaceJson = readJson(workspaceConfigName());
expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined();
const workspace = await readResolvedWorkspaceConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
Expand All @@ -547,7 +549,7 @@ describe('Workspace Tests', () => {
);
});

it('should work for custom workspace layouts', () => {
it('should work for custom workspace layouts', async () => {
const lib1 = uniq('mylib');
const lib2 = uniq('mylib');
const lib3 = uniq('mylib');
Expand Down Expand Up @@ -656,9 +658,8 @@ describe('Workspace Tests', () => {
]
).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]);

expect(moveOutput).toContain(`UPDATE workspace.json`);
const workspaceJson = readJson(workspaceConfigName());
expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined();
const workspace = await readResolvedWorkspaceConfiguration();
expect(workspace.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
Expand All @@ -681,7 +682,7 @@ describe('Workspace Tests', () => {
updateFile('nx.json', JSON.stringify(nxJson));
});

it('should work for libraries when scope is unset', () => {
it('should work for libraries when scope is unset', async () => {
const json = readJson('nx.json');
delete json.npmScope;
updateFile('nx.json', JSON.stringify(json));
Expand Down Expand Up @@ -775,8 +776,7 @@ describe('Workspace Tests', () => {
rootTsConfig.compilerOptions.paths[`shared/${lib1}/data-access`]
).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]);

expect(moveOutput).toContain(`UPDATE workspace.json`);
const workspaceJson = readJson(workspaceConfigName());
const workspaceJson = readResolvedWorkspaceConfiguration();
expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined();
const project = readProjectConfig(newName);
expect(project).toBeTruthy();
Expand All @@ -800,7 +800,7 @@ describe('Workspace Tests', () => {
/**
* Tries creating then deleting a lib
*/
it('should work', () => {
it('should work', async () => {
const lib1 = uniq('myliba');
const lib2 = uniq('mylibb');

Expand Down Expand Up @@ -848,20 +848,31 @@ describe('Workspace Tests', () => {
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy();

expect(removeOutputForced).not.toContain(`UPDATE nx.json`);
const workspaceJson = readJson(workspaceConfigName());
const workspaceJson = readResolvedWorkspaceConfiguration();
expect(workspaceJson.projects[`${lib1}`]).toBeUndefined();
const lib2Config = readProjectConfig(lib2);
expect(lib2Config.implicitDependencies).toEqual([]);

expect(removeOutputForced).toContain(`UPDATE workspace.json`);
expect(workspaceJson.projects[`${lib1}`]).toBeUndefined();
});
});

describe('workspace-lint', () => {
it('should identify issues with the workspace', () => {
beforeAll(() => {
// Unfortunately, this is required as this test is testing a different workspace layout
// workspace-lint only picks up missing projects and such when workspace.json exists.
newProject();
updateFile(
'workspace.json',
JSON.stringify({ version: 2, projects: {} })
);
});

afterAll(() => {
removeFile('workspace.json');
});

it('should identify issues with the workspace', () => {
const appBefore = uniq('before');
const appAfter = uniq('after');

Expand Down
7 changes: 0 additions & 7 deletions e2e/nx-plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,6 @@ describe('Nx Plugin', () => {
});

it('should be able to infer projects and targets', async () => {
// Cache workspace json, to test inference and restore afterwards
const workspaceJsonContents = readFile('workspace.json');
removeFile('workspace.json');

// Setup project inference + target inference
updateFile(
`libs/${plugin}/src/index.ts`,
Expand Down Expand Up @@ -327,9 +323,6 @@ describe('Nx Plugin', () => {
expect(runCLI(`build ${inferredProject}`)).toContain(
'custom registered target'
);

// Restore workspace.json
createFile('workspace.json', workspaceJsonContents);
});

it('should be able to use local generators and executors', async () => {
Expand Down
12 changes: 4 additions & 8 deletions e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ import type { NxJsonConfiguration } from '@nrwl/devkit';
import {
getPackageManagerCommand,
isNotWindows,
listFiles,
newProject,
readFile,
readJson,
readProjectConfig,
cleanupProject,
rmDist,
runCLI,
runCLIAsync,
runCommand,
uniq,
updateFile,
updateProjectConfig,
workspaceConfigName,
checkFilesExist,
isWindows,
fileExists,
removeFile,
readResolvedWorkspaceConfiguration,
} from '@nrwl/e2e/utils';

describe('Nx Affected and Graph Tests', () => {
Expand Down Expand Up @@ -253,11 +252,8 @@ describe('Nx Affected and Graph Tests', () => {

it('should affect all projects by removing projects', () => {
generateAll();
updateFile(workspaceConfigName(), (old) => {
const workspaceJson = JSON.parse(old);
delete workspaceJson.projects[mylib];
return JSON.stringify(workspaceJson, null, 2);
});
const root = readResolvedWorkspaceConfiguration().projects[mylib].root;
removeFile(root);
expect(runCLI('affected:apps')).toContain(myapp);
expect(runCLI('affected:apps')).toContain(myapp2);
expect(runCLI('affected:libs')).not.toContain(mylib);
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('Nx Running Tests', () => {
env: { ...process.env, NX_DAEMON: 'true' },
});

expect(buildAgain).toContain('local cache');
expect(buildAgain).toContain('[local cache]');
}, 10000);

it('should build the project when within the project root', () => {
Expand Down
12 changes: 10 additions & 2 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
createProjectGraphAsync,
joinPathFragments,
parseJson,
ProjectConfiguration,
Expand Down Expand Up @@ -89,12 +90,19 @@ export function updateProjectConfig(
projectName: string,
callback: (c: ProjectConfiguration) => ProjectConfiguration
) {
const root = readJson(workspaceConfigName()).projects[projectName];
const workspace = readResolvedWorkspaceConfiguration();
const root = workspace.projects[projectName].root;
const path = join(root, 'project.json');
const current = readJson(path);
updateFile(path, JSON.stringify(callback(current), null, 2));
}

export function readResolvedWorkspaceConfiguration() {
process.env.NX_PROJECT_GLOB_CACHE = 'false';
const ws = new Workspaces(tmpProjPath());
return ws.readWorkspaceConfiguration();
}

/**
* Use readProjectConfig or readInlineProjectConfig instead
* if you need a project's configuration.
Expand All @@ -109,7 +117,7 @@ export function readWorkspaceConfig(): Omit<
}

export function readProjectConfig(projectName: string): ProjectConfiguration {
const root = readJson(workspaceConfigName()).projects[projectName];
const root = readResolvedWorkspaceConfiguration().projects[projectName].root;
const path = join(root, 'project.json');
return readJson(path);
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe('create-nx-plugin', () => {
});

checkFilesExist(
'workspace.json',
'package.json',
packageManagerLockFile[packageManager],
`packages/${pluginName}/package.json`
`packages/${pluginName}/package.json`,
`packages/${pluginName}/project.json`
);

expect(() => runCLI(`e2e ${pluginName}-e2e`)).not.toThrow();
Expand Down
Loading

1 comment on commit 9b63ce1

@vercel
Copy link

@vercel vercel bot commented on 9b63ce1 Sep 27, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

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

Please sign in to comment.