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"], 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 1dd6219c216b1..ab27686b603c4 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"]