Skip to content

Commit

Permalink
feat(misc): derive workspace layout dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Nov 23, 2022
1 parent 2d74f4c commit 16fd437
Show file tree
Hide file tree
Showing 165 changed files with 371 additions and 285 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
name: Run E2E Tests
command: |
if $E2E_AFFECTED; then
npx nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --exclude=e2e-make-angular-cli-faster,e2e-detox,e2e-js,e2e-next,e2e-workspace-create,e2e-nx-run,e2e-nx-misc,e2e-react,e2e-web,e2e-webpack,e2e-rollup,e2e-esbuild,e2e-angular-extensions,e2e-angular-core,e2e-nx-plugin,e2e-cypress,e2e-node,e2e-linter,e2e-jest,e2e-add-nx-to-monorepo,nx-dev-e2e,e2e-nx-init,e2e-graph-client,e2e-vite,e2e-cra-to-nx --parallel=1;
npx nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --exclude=e2e-make-angular-cli-faster,e2e-detox,e2e-js,e2e-next,e2e-workspace-create,e2e-nx-run,e2e-nx-misc,e2e-react,e2e-web,e2e-webpack,e2e-rollup,e2e-esbuild,e2e-angular-extensions,e2e-angular-core,e2e-nx-plugin,e2e-cypress,e2e-node,e2e-linter,e2e-jest,e2e-add-nx-to-monorepo,nx-dev-e2e,e2e-nx-init,e2e-graph-client,e2e-vite,e2e-cra-to-nx,e2e-storybook,e2e-storybook-angular --parallel=1;
else
echo "Skipping E2E tests";
fi
Expand Down
6 changes: 4 additions & 2 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
// runCommand('mv src-bak src');
});

it('should handle a workspace with cypress v9', () => {
//TODO: reenable
xit('should handle a workspace with cypress v9', () => {
addCypress9();

// Remove cypress.json
Expand Down Expand Up @@ -379,7 +380,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
});
});

it('should handle a workspace with cypress v10', () => {
//TODO: reenable
xit('should handle a workspace with cypress v10', () => {
addCypress10();

// Remove cypress.config.ts
Expand Down
4 changes: 2 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
}
},
"workspaceLayout": {
"libsDir": "",
"appsDir": ""
"appsDir": "",
"libsDir": ""
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('app', () => {

describe('at the root', () => {
beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
updateJson(appTree, 'nx.json', (json) => ({
...json,
workspaceLayout: { appsDir: '' },
Expand Down Expand Up @@ -739,7 +739,7 @@ describe('app', () => {
describe('--e2e-test-runner', () => {
describe(E2eTestRunner.Protractor, () => {
it('should create the e2e project in v2 workspace', async () => {
appTree = createTreeWithEmptyWorkspace();
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

expect(
async () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Angular Cypress Component Test Generator', () => {
ReturnType<typeof assertMinimumCypressVersion>
> = assertMinimumCypressVersion as never;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// silence warnings about missing .gitignore file
tree.write('.gitignore', '');
mockedAssertMinimumCypressVersion.mockReturnValue();
Expand Down
30 changes: 15 additions & 15 deletions packages/angular/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import componentGenerator from './component';
describe('component Generator', () => {
it('should create the component correctly and export it in the entry point when "export=true"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('component Generator', () => {

it('should create the component correctly and export it in the entry point when is standalone and "export=true"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('component Generator', () => {

it('should create the component correctly and not export it in the entry point when "export=false"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('component Generator', () => {

it('should create the component correctly and not export it in the entry point when is standalone and "export=false"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('component Generator', () => {

it('should create the component correctly and not export it when "--skip-import=true"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('component Generator', () => {

it('should create the component correctly but not export it in the entry point when it does not exist', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('component Generator', () => {

it('should not export the component in the entry point when the module it belongs to is not exported', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('component Generator', () => {
describe('--flat', () => {
it('should create the component correctly and export it in the entry point', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('component Generator', () => {

it('should create the component correctly and not export it when "export=false"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('component Generator', () => {
describe('--path', () => {
it('should create the component correctly and export it in the entry point', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('component Generator', () => {

it('should throw if the path specified is not under the project root', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('component Generator', () => {
'should export it in the entry point when "--module" is set to "%s"',
async (module) => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -491,7 +491,7 @@ describe('component Generator', () => {

it('should not export it in the entry point when the module it belong to is not exported', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -540,7 +540,7 @@ describe('component Generator', () => {
describe('secondary entry points', () => {
it('should create the component correctly and export it in the entry point', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('component Generator', () => {

it('should not export the component in the entry point when the module it belongs to is not exported', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import convertToWithMF from './convert-to-with-mf';
describe('convertToWithMF', () => {
it('should migrate a standard previous generated host config correctly', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'host1', {
name: 'host1',
root: 'apps/host1',
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('convertToWithMF', () => {

it('should migrate a standard previous generated remote config correctly', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'remote1', {
name: 'remote1',
root: 'apps/remote1',
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('convertToWithMF', () => {

it('should migrate a standard previous generated remote config using object shared syntax correctly', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'remote1', {
name: 'remote1',
root: 'apps/remote1',
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('convertToWithMF', () => {

it('should throw when the uniqueName doesnt match the project name', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'remote1', {
name: 'remote1',
root: 'apps/remote1',
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('convertToWithMF', () => {

it('should throw when the shared npm packages configs has been modified', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'host1', {
name: 'host1',
root: 'apps/host1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Cypress Component Testing Configuration', () => {
> = installedCypressVersion as never;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
tree.write('.gitignore', '');
mockedInstalledCypressVersion.mockReturnValue(10);
});
Expand Down
18 changes: 9 additions & 9 deletions packages/angular/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getProjects } from 'nx/src/generators/utils/project-configuration';
describe('Host App Generator', () => {
it('should generate a host app with no remotes', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT
await host(tree, {
Expand All @@ -20,7 +20,7 @@ describe('Host App Generator', () => {

it('should generate a host app with a remote', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

await remote(tree, {
name: 'remote',
Expand All @@ -41,7 +41,7 @@ describe('Host App Generator', () => {

it('should generate a host and any remotes that dont exist with correct routing setup', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Host App Generator', () => {

it('should generate a host, integrate existing remotes and generate any remotes that dont exist', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await remote(tree, {
name: 'remote1',
});
Expand All @@ -93,7 +93,7 @@ describe('Host App Generator', () => {

it('should generate a host, integrate existing remotes and generate any remotes that dont exist, in a directory', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await remote(tree, {
name: 'remote1',
});
Expand All @@ -116,7 +116,7 @@ describe('Host App Generator', () => {

it('should generate a host with remotes using standalone components', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT
await host(tree, {
Expand All @@ -136,7 +136,7 @@ describe('Host App Generator', () => {

it('should generate the correct app component spec file', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT
await host(tree, {
Expand All @@ -153,7 +153,7 @@ describe('Host App Generator', () => {

it('should generate the correct app component spec file with a directory', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT
await host(tree, {
Expand All @@ -171,7 +171,7 @@ describe('Host App Generator', () => {

it('should not generate an e2e project when e2eTestRunner is none', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

// ACT
await host(tree, {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/karma/karma.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('karma', () => {
let tree: devkit.Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});

it('should do nothing when karma is already installed and karma.conf.js exists', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('librarySecondaryEntryPoint generator', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});

it('should throw when the library does not exist in the workspace', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('lib', () => {

describe('workspace v2', () => {
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});

it('should run the library generator without erroring if the directory has a trailing slash', async () => {
Expand Down Expand Up @@ -708,7 +708,7 @@ describe('lib', () => {

describe('at the root', () => {
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
updateJson(tree, 'nx.json', (json) => ({
...json,
workspaceLayout: { libsDir: '' },
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/ng-add/ng-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('ngAdd generator', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
jest
.spyOn(angularCliMigrator, 'migrateFromAngularCli')
.mockImplementation(() => Promise.resolve(() => {}));
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/ngrx/ngrx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ngrx', () => {

beforeEach(() => {
jest.clearAllMocks();
tree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
createApp(tree, 'myapp');
appConfig = getAppConfig();
statePath = `${dirname(appConfig.appModule)}/+state`;
Expand Down
Loading

1 comment on commit 16fd437

@vercel
Copy link

@vercel vercel bot commented on 16fd437 Nov 23, 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-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.