Skip to content

Commit

Permalink
feat(misc): stop generating empty apps/libs/packages libs in new work… (
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Sep 5, 2023
1 parent 99eebfb commit 9fbfe4a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 37 deletions.
5 changes: 5 additions & 0 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ export function newProject({
});

if (unsetProjectNameAndRootFormat) {
console.warn(
'ATTENTION: The workspace generated for this e2e test does not use the new as-provided project name/root format. Please update this test'
);
updateJson<NxJsonConfiguration>('nx.json', (nxJson) => {
delete nxJson.workspaceLayout;
return nxJson;
});
createFile('apps/.gitkeep');
createFile('libs/.gitkeep');
}

// Temporary hack to prevent installing with `--frozen-lockfile`
Expand Down
28 changes: 21 additions & 7 deletions e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/angular:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/angular:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -78,7 +80,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() =>
runCLI(`generate @nx/js:library ${libName} --no-interactive`)
runCLI(
`generate @nx/js:library ${libName} --directory packages/${libName} --no-interactive`
)
).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand Down Expand Up @@ -115,7 +119,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/react:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/react:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -141,7 +147,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/next:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/next:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand Down Expand Up @@ -170,7 +178,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/react-native:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/react-native:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -196,7 +206,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/node:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/node:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -222,7 +234,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');

expect(() => {
runCLI(`generate @nx/nest:lib ${libName} --no-interactive`);
runCLI(
`generate @nx/nest:lib ${libName} --directory packages/${libName} --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
Expand Down
7 changes: 1 addition & 6 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ describe('create-nx-workspace', () => {
packageManager,
});

checkFilesExist(
'package.json',
packageManagerLockFile[packageManager],
'apps/.gitkeep',
'libs/.gitkeep'
);
checkFilesExist('package.json', packageManagerLockFile[packageManager]);

expectNoAngularDevkit();
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
packageManager: 'npm',
isCustomPreset: false,
});
expect(tree.exists('/proj/packages/.gitkeep')).toBe(true);
expect(tree.exists('/proj/apps/.gitkeep')).toBe(false);
expect(tree.exists('/proj/libs/.gitkeep')).toBe(false);
const nx = readJson(tree, '/proj/nx.json');
expect(nx).toMatchInlineSnapshot(`
{
Expand All @@ -247,6 +244,9 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
"runner": "nx/tasks-runners/default",
},
},
"workspaceLayout": {
"projectNameAndRootFormat": "as-provided",
},
}
`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export async function generateWorkspaceFiles(
}
setPresetProperty(tree, options);
addNpmScripts(tree, options);
createAppsAndLibsFolders(tree, options);
setUpWorkspacesInPackageJson(tree, options);

await formatFiles(tree);
Expand All @@ -57,7 +56,6 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json');
delete json.implicitDependencies;
delete json.targetDefaults;
delete json.workspaceLayout;
}
return json;
});
Expand Down
8 changes: 1 addition & 7 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
installPackagesTask,
names,
readNxJson,
Tree,
updateNxJson,
} from '@nx/devkit';
import { installPackagesTask, names, Tree } from '@nx/devkit';
import { Schema } from './schema';
import { Preset } from '../utils/presets';
import { join } from 'path';
Expand Down

0 comments on commit 9fbfe4a

Please sign in to comment.