Skip to content

Commit

Permalink
feat(angular): remove deprecated simpleModuleName option from library…
Browse files Browse the repository at this point in the history
… generator (#16219)
  • Loading branch information
leosvelperez authored Apr 12, 2023
1 parent c4d9a5b commit c8a2f50
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 18 deletions.
6 changes: 0 additions & 6 deletions docs/generated/packages/angular/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
"default": false,
"x-priority": "internal"
},
"simpleModuleName": {
"description": "Keep the module name simple (when using `--directory`).",
"type": "boolean",
"default": false,
"x-deprecated": "Use `simpleName` instead. It will be removed in v16."
},
"simpleName": {
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
"type": "boolean",
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
"version": "15.9.0-beta.9",
"description": "Update the file-server executor to use @nrwl/web:file-server",
"factory": "./src/migrations/update-15-9-0/update-file-server-executor"
},
"remove-library-generator-simple-module-name-option": {
"cli": "nx",
"version": "16.0.0-beta.1",
"description": "Replace the deprecated library generator 'simpleModuleName' option from generator defaults with 'simpleName'",
"factory": "./src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option"
}
},
"packageJsonUpdates": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export function normalizeOptions(host: Tree, schema: Schema): NormalizedSchema {
const projectName = fullProjectDirectory
.replace(new RegExp('/', 'g'), '-')
.replace(/-\d+/g, '');
const fileName =
options.simpleName || options.simpleModuleName ? name : projectName;
const fileName = options.simpleName ? name : projectName;
const projectRoot = joinPathFragments(libsDir, fullProjectDirectory);

const moduleName = `${names(fileName).className}Module`;
Expand Down
4 changes: 0 additions & 4 deletions packages/angular/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export interface Schema {
name: string;
addTailwind?: boolean;
skipFormat?: boolean;
/**
* @deprecated Use `simpleName` instead. It will be removed in v16.
*/
simpleModuleName?: boolean;
simpleName?: boolean;
addModuleSpec?: boolean;
directory?: string;
Expand Down
6 changes: 0 additions & 6 deletions packages/angular/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
"default": false,
"x-priority": "internal"
},
"simpleModuleName": {
"description": "Keep the module name simple (when using `--directory`).",
"type": "boolean",
"default": false,
"x-deprecated": "Use `simpleName` instead. It will be removed in v16."
},
"simpleName": {
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
import type { Tree } from '@nrwl/devkit';
import {
addProjectConfiguration,
readNxJson,
readProjectConfiguration,
updateNxJson,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import removeLibraryGeneratorSimpleModuleNameOption from './remove-library-generator-simple-module-name-option';

describe('removeLibraryGeneratorSimpleModuleNameOption', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

describe('nx.json', () => {
it('should replace simpleModuleName with simpleName', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
...nxJson,
generators: {
'@nrwl/angular:library': {
simpleModuleName: true,
},
},
});

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: true,
});
});

it('should support nested library generator default', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
...nxJson,
generators: {
'@nrwl/angular': {
library: {
simpleModuleName: true,
},
},
},
});

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators['@nrwl/angular']).toStrictEqual({
library: {
simpleName: true,
},
});
});

it('should keep simpleName if defined and remove simpleModuleName', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
...nxJson,
generators: {
'@nrwl/angular:library': {
simpleModuleName: true,
simpleName: false,
},
},
});

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: false,
});
});

it('should do nothing if simpleModuleName is not set', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
...nxJson,
generators: {
'@nrwl/angular:library': {
simpleName: true,
},
},
});

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: true,
});
});

it('should not throw when library generator defaults are not set', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
...nxJson,
generators: {
'@nrwl/angular:component': {
standalone: true,
},
},
});

await expect(
removeLibraryGeneratorSimpleModuleNameOption(tree)
).resolves.not.toThrow();

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators).toStrictEqual({
'@nrwl/angular:component': {
standalone: true,
},
});
});

it('should not throw when generators defaults are not set', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, { ...nxJson, generators: undefined });

await expect(
removeLibraryGeneratorSimpleModuleNameOption(tree)
).resolves.not.toThrow();

const updatedNxJson = readNxJson(tree);
expect(updatedNxJson.generators).toBeUndefined();
});

it('should not throw when nx.json does not exist', async () => {
tree.delete('nx.json');

await expect(
removeLibraryGeneratorSimpleModuleNameOption(tree)
).resolves.not.toThrow();

expect(tree.exists('nx.json')).toBe(false);
});
});

describe('project configs', () => {
it('should replace simpleModuleName with simpleName', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
generators: {
'@nrwl/angular:library': {
simpleModuleName: true,
},
},
};
addProjectConfiguration(tree, 'project', project);

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: true,
});
});

it('should support nested library generator default', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
generators: {
'@nrwl/angular': {
library: {
simpleModuleName: true,
},
},
},
};
addProjectConfiguration(tree, 'project', project);

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators['@nrwl/angular']).toStrictEqual({
library: {
simpleName: true,
},
});
});

it('should keep simpleName if defined and remove simpleModuleName', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
generators: {
'@nrwl/angular:library': {
simpleModuleName: true,
simpleName: false,
},
},
};
addProjectConfiguration(tree, 'project', project);

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: false,
});
});

it('should do nothing if simpleModuleName is not set', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
generators: {
'@nrwl/angular:library': {
simpleName: true,
},
},
};
addProjectConfiguration(tree, 'project', project);

await removeLibraryGeneratorSimpleModuleNameOption(tree);

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({
simpleName: true,
});
});

it('should not throw when library generator defaults are not set', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
generators: {
'@nrwl/angular:component': {
standalone: true,
},
},
};
addProjectConfiguration(tree, 'project', project);

await expect(
removeLibraryGeneratorSimpleModuleNameOption(tree)
).resolves.not.toThrow();

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators).toStrictEqual({
'@nrwl/angular:component': {
standalone: true,
},
});
});

it('should not throw when generators defaults are not set', async () => {
const project = {
name: 'project',
root: '/',
targets: {},
};
addProjectConfiguration(tree, 'project', project);

await expect(
removeLibraryGeneratorSimpleModuleNameOption(tree)
).resolves.not.toThrow();

const updatedProject = readProjectConfiguration(tree, 'project');
expect(updatedProject.generators).toBeUndefined();
});
});
});
Loading

0 comments on commit c8a2f50

Please sign in to comment.