From 126a4e506aa9bea9499936d6952fb53d9792aaf5 Mon Sep 17 00:00:00 2001 From: Sven Wuendrich Date: Wed, 23 Mar 2022 22:35:03 +0100 Subject: [PATCH 1/2] feat(core): add option importPath to workspace remove If importPath was specified on library creation time you should importPath also specify on deletion. --- .../api-workspace/generators/remove.md | 6 +++ .../remove/lib/update-tsconfig.spec.ts | 37 +++++++++++++++++++ .../generators/remove/lib/update-tsconfig.ts | 15 ++++---- .../src/generators/remove/schema.d.ts | 1 + .../src/generators/remove/schema.json | 4 ++ 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/docs/generated/api-workspace/generators/remove.md b/docs/generated/api-workspace/generators/remove.md index 494639ce2632c..d1bb97ebc948d 100644 --- a/docs/generated/api-workspace/generators/remove.md +++ b/docs/generated/api-workspace/generators/remove.md @@ -65,6 +65,12 @@ Type: `boolean` When true, forces removal even if the project is still in use. +### importPath + +Type: `string` + +The library name used at creation time + ### skipFormat Alias(es): skip-format diff --git a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts index 6e75027d1206b..9b358e98750bd 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts @@ -7,6 +7,7 @@ import { libraryGenerator } from '../../library/library'; describe('updateTsconfig', () => { let tree: Tree; let schema: Schema; + let schemaWithImportPath: Schema; beforeEach(async () => { tree = createTreeWithEmptyWorkspace(); @@ -16,6 +17,13 @@ describe('updateTsconfig', () => { skipFormat: false, forceRemove: false, }; + + schemaWithImportPath = { + projectName: 'my-lib', + skipFormat: false, + forceRemove: false, + importPath: '@proj/whatever-name', + }; }); it('should delete project ref from the root tsconfig.base.json', async () => { @@ -31,6 +39,20 @@ describe('updateTsconfig', () => { expect(tsConfig.compilerOptions.paths).toEqual({}); }); + it('should delete project ref with importPath from the root tsconfig.base.json', async () => { + await libraryGenerator(tree, { + name: 'my-lib', + standaloneConfig: false, + importPath: '@proj/whatever-name', + }); + const project = readProjectConfiguration(tree, 'my-lib'); + + updateTsconfig(tree, schemaWithImportPath, project); + + const tsConfig = readJson(tree, '/tsconfig.base.json'); + expect(tsConfig.compilerOptions.paths).toEqual({}); + }); + it('should delete project ref from the root tsconfig.json when no tsconfig.base.json', async () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await libraryGenerator(tree, { @@ -44,4 +66,19 @@ describe('updateTsconfig', () => { const tsConfig = readJson(tree, '/tsconfig.json'); expect(tsConfig.compilerOptions.paths).toEqual({}); }); + + it('should delete project ref with importPath from the root tsconfig.json when no tsconfig.base.json', async () => { + tree.rename('tsconfig.base.json', 'tsconfig.json'); + await libraryGenerator(tree, { + name: 'my-lib', + standaloneConfig: false, + importPath: '@proj/whatever-name', + }); + const project = readProjectConfiguration(tree, 'my-lib'); + + updateTsconfig(tree, schemaWithImportPath, project); + + const tsConfig = readJson(tree, '/tsconfig.json'); + expect(tsConfig.compilerOptions.paths).toEqual({}); + }); }); diff --git a/packages/workspace/src/generators/remove/lib/update-tsconfig.ts b/packages/workspace/src/generators/remove/lib/update-tsconfig.ts index 96f16c5aabf63..a3f8145e7a1cf 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.ts @@ -20,16 +20,15 @@ export function updateTsconfig( const { appsDir, libsDir, npmScope } = getWorkspaceLayout(tree); const tsConfigPath = getRootTsConfigPathInTree(tree); + const defaultImportPath = `@${npmScope}/${project.root.substr( + project.projectType === 'application' + ? appsDir.length + 1 + : libsDir.length + 1 + )}`; + const importPath = schema.importPath || defaultImportPath; if (tree.exists(tsConfigPath)) { updateJson(tree, tsConfigPath, (json) => { - delete json.compilerOptions.paths[ - `@${npmScope}/${project.root.substr( - project.projectType === 'application' - ? appsDir.length + 1 - : libsDir.length + 1 - )}` - ]; - + delete json.compilerOptions.paths[importPath]; return json; }); } diff --git a/packages/workspace/src/generators/remove/schema.d.ts b/packages/workspace/src/generators/remove/schema.d.ts index d69859109639e..bfc6a591bb1ad 100644 --- a/packages/workspace/src/generators/remove/schema.d.ts +++ b/packages/workspace/src/generators/remove/schema.d.ts @@ -6,4 +6,5 @@ export interface Schema extends Json { projectName: string; skipFormat: boolean; forceRemove: boolean; + importPath?: string; } diff --git a/packages/workspace/src/generators/remove/schema.json b/packages/workspace/src/generators/remove/schema.json index 922e707f0354d..4c9c3374923eb 100644 --- a/packages/workspace/src/generators/remove/schema.json +++ b/packages/workspace/src/generators/remove/schema.json @@ -36,6 +36,10 @@ "aliases": ["skip-format"], "description": "Skip formatting files.", "default": false + }, + "importPath": { + "type": "string", + "description": "The library name used at creation time" } }, "required": ["projectName"] From 08e4bbc3743021fb7987241924b08f68ab362dd1 Mon Sep 17 00:00:00 2001 From: Sven Wuendrich Date: Fri, 25 Mar 2022 21:08:31 +0100 Subject: [PATCH 2/2] fix(core): fix workspace.json after merging master. --- docs/generated/packages/workspace.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/generated/packages/workspace.json b/docs/generated/packages/workspace.json index 416b5a6e7ada9..6c7f15bd35e94 100644 --- a/docs/generated/packages/workspace.json +++ b/docs/generated/packages/workspace.json @@ -276,6 +276,10 @@ "aliases": ["skip-format"], "description": "Skip formatting files.", "default": false + }, + "importPath": { + "type": "string", + "description": "The library name used at creation time" } }, "required": ["projectName"],