Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add option importPath to workspace remove library #9486

Merged
merged 3 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/generated/packages/workspace.json
Expand Up @@ -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"],
Expand Down
Expand Up @@ -7,6 +7,7 @@ import { libraryGenerator } from '../../library/library';
describe('updateTsconfig', () => {
let tree: Tree;
let schema: Schema;
let schemaWithImportPath: Schema;

beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();
Expand All @@ -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 () => {
Expand All @@ -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, {
Expand All @@ -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({});
});
});
Expand Up @@ -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;
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/remove/schema.d.ts
Expand Up @@ -6,4 +6,5 @@ export interface Schema extends Json {
projectName: string;
skipFormat: boolean;
forceRemove: boolean;
importPath?: string;
}
4 changes: 4 additions & 0 deletions packages/workspace/src/generators/remove/schema.json
Expand Up @@ -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"]
Expand Down