feat(angular): remove deprecated simpleModuleName option from library generator (#16219)
This commit is contained in:
parent
c4d9a5bd5c
commit
c8a2f50f36
@ -45,12 +45,6 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"x-priority": "internal"
|
"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": {
|
"simpleName": {
|
||||||
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
|
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@ -164,6 +164,12 @@
|
|||||||
"version": "15.9.0-beta.9",
|
"version": "15.9.0-beta.9",
|
||||||
"description": "Update the file-server executor to use @nrwl/web:file-server",
|
"description": "Update the file-server executor to use @nrwl/web:file-server",
|
||||||
"factory": "./src/migrations/update-15-9-0/update-file-server-executor"
|
"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": {
|
"packageJsonUpdates": {
|
||||||
|
|||||||
@ -47,8 +47,7 @@ export function normalizeOptions(host: Tree, schema: Schema): NormalizedSchema {
|
|||||||
const projectName = fullProjectDirectory
|
const projectName = fullProjectDirectory
|
||||||
.replace(new RegExp('/', 'g'), '-')
|
.replace(new RegExp('/', 'g'), '-')
|
||||||
.replace(/-\d+/g, '');
|
.replace(/-\d+/g, '');
|
||||||
const fileName =
|
const fileName = options.simpleName ? name : projectName;
|
||||||
options.simpleName || options.simpleModuleName ? name : projectName;
|
|
||||||
const projectRoot = joinPathFragments(libsDir, fullProjectDirectory);
|
const projectRoot = joinPathFragments(libsDir, fullProjectDirectory);
|
||||||
|
|
||||||
const moduleName = `${names(fileName).className}Module`;
|
const moduleName = `${names(fileName).className}Module`;
|
||||||
|
|||||||
@ -5,10 +5,6 @@ export interface Schema {
|
|||||||
name: string;
|
name: string;
|
||||||
addTailwind?: boolean;
|
addTailwind?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
/**
|
|
||||||
* @deprecated Use `simpleName` instead. It will be removed in v16.
|
|
||||||
*/
|
|
||||||
simpleModuleName?: boolean;
|
|
||||||
simpleName?: boolean;
|
simpleName?: boolean;
|
||||||
addModuleSpec?: boolean;
|
addModuleSpec?: boolean;
|
||||||
directory?: string;
|
directory?: string;
|
||||||
|
|||||||
@ -45,12 +45,6 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"x-priority": "internal"
|
"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": {
|
"simpleName": {
|
||||||
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
|
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
import type {
|
||||||
|
NxJsonConfiguration,
|
||||||
|
ProjectConfiguration,
|
||||||
|
Tree,
|
||||||
|
} from '@nrwl/devkit';
|
||||||
|
import {
|
||||||
|
formatFiles,
|
||||||
|
getProjects,
|
||||||
|
readNxJson,
|
||||||
|
updateNxJson,
|
||||||
|
updateProjectConfiguration,
|
||||||
|
} from '@nrwl/devkit';
|
||||||
|
|
||||||
|
export default async function removeLibraryGeneratorSimpleModuleNameOption(
|
||||||
|
tree: Tree
|
||||||
|
): Promise<void> {
|
||||||
|
const nxJson = readNxJson(tree);
|
||||||
|
|
||||||
|
// update global config
|
||||||
|
const nxJsonUpdated = replaceSimpleModuleNameInConfig(nxJson);
|
||||||
|
if (nxJsonUpdated) {
|
||||||
|
updateNxJson(tree, nxJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update project configs
|
||||||
|
const projects = getProjects(tree);
|
||||||
|
for (const [name, project] of projects) {
|
||||||
|
const projectUpdated = replaceSimpleModuleNameInConfig(project);
|
||||||
|
if (projectUpdated) {
|
||||||
|
updateProjectConfiguration(tree, name, project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await formatFiles(tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceSimpleModuleNameInConfig(
|
||||||
|
configObject: {
|
||||||
|
generators?:
|
||||||
|
| NxJsonConfiguration['generators']
|
||||||
|
| ProjectConfiguration['generators'];
|
||||||
|
} | null
|
||||||
|
): boolean {
|
||||||
|
if (!configObject?.generators) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let updated = false;
|
||||||
|
|
||||||
|
if (configObject.generators['@nrwl/angular']?.['library']?.simpleModuleName) {
|
||||||
|
configObject.generators['@nrwl/angular']['library'].simpleName ??=
|
||||||
|
configObject.generators['@nrwl/angular']['library'].simpleModuleName;
|
||||||
|
delete configObject.generators['@nrwl/angular']['library'].simpleModuleName;
|
||||||
|
updated = true;
|
||||||
|
} else if (
|
||||||
|
configObject.generators['@nrwl/angular:library']?.simpleModuleName
|
||||||
|
) {
|
||||||
|
configObject.generators['@nrwl/angular:library'].simpleName ??=
|
||||||
|
configObject.generators['@nrwl/angular:library'].simpleModuleName;
|
||||||
|
delete configObject.generators['@nrwl/angular:library'].simpleModuleName;
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user