diff --git a/docs/angular/api-angular/schematics/move.md b/docs/angular/api-angular/schematics/move.md index 9950c8661e844..194b230d65270 100644 --- a/docs/angular/api-angular/schematics/move.md +++ b/docs/angular/api-angular/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the Angular project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the Angular project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/docs/angular/api-workspace/schematics/move.md b/docs/angular/api-workspace/schematics/move.md index 6b835910aae33..8f330cc62bf7a 100644 --- a/docs/angular/api-workspace/schematics/move.md +++ b/docs/angular/api-workspace/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/docs/node/api-angular/schematics/move.md b/docs/node/api-angular/schematics/move.md index b5b4a8632cfbc..835e09dc50248 100644 --- a/docs/node/api-angular/schematics/move.md +++ b/docs/node/api-angular/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the Angular project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the Angular project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/docs/node/api-workspace/schematics/move.md b/docs/node/api-workspace/schematics/move.md index efd16148a2033..8f7f38a34e9e5 100644 --- a/docs/node/api-workspace/schematics/move.md +++ b/docs/node/api-workspace/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/docs/react/api-angular/schematics/move.md b/docs/react/api-angular/schematics/move.md index b5b4a8632cfbc..835e09dc50248 100644 --- a/docs/react/api-angular/schematics/move.md +++ b/docs/react/api-angular/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the Angular project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the Angular project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/docs/react/api-workspace/schematics/move.md b/docs/react/api-workspace/schematics/move.md index efd16148a2033..8f7f38a34e9e5 100644 --- a/docs/react/api-workspace/schematics/move.md +++ b/docs/react/api-workspace/schematics/move.md @@ -42,6 +42,12 @@ Type: `string` The folder to move the project into +### importPath + +Type: `string` + +The new import path to use in the tsconfig.base.json + ### projectName Alias(es): project @@ -49,3 +55,11 @@ Alias(es): project Type: `string` The name of the project to move + +### updateImportPath + +Default: `true` + +Type: `boolean` + +Should the schematic update the import path to reflect the new location? diff --git a/e2e/workspace/src/workspace-aux-commands.test.ts b/e2e/workspace/src/workspace-aux-commands.test.ts index b92042d79fb25..c78ee04b75a31 100644 --- a/e2e/workspace/src/workspace-aux-commands.test.ts +++ b/e2e/workspace/src/workspace-aux-commands.test.ts @@ -1,5 +1,3 @@ -import { NxJson } from '@nrwl/workspace'; -import { classify } from '@nrwl/workspace/src/utils/strings'; import { checkFilesExist, ensureProject, @@ -16,6 +14,8 @@ import { updateFile, workspaceConfigName, } from '@nrwl/e2e/utils'; +import { NxJson } from '@nrwl/workspace'; +import { classify } from '@nrwl/workspace/src/utils/strings'; forEachCli((cli) => { describe('lint', () => { @@ -718,7 +718,146 @@ forEachCli((cli) => { `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, `import { fromLibOne } from '@proj/${lib1}/data-access'; - export const fromLibTwo = () => fromLibOne(); }` + export const fromLibTwo = () => fromLibOne();` + ); + + /** + * Create a library which has an implicit dependency on lib1 + */ + + runCLI(`generate @nrwl/workspace:lib ${lib3}`); + let nxJson = JSON.parse(readFile('nx.json')) as NxJson; + nxJson.projects[lib3].implicitDependencies = [`${lib1}-data-access`]; + updateFile(`nx.json`, JSON.stringify(nxJson)); + + /** + * Now try to move lib1 + */ + + const moveOutput = runCLI( + `generate @nrwl/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access` + ); + + expect(moveOutput).toContain(`DELETE libs/${lib1}/data-access`); + expect(exists(`libs/${lib1}/data-access`)).toBeFalsy(); + + const newPath = `libs/shared/${lib1}/data-access`; + const newName = `shared-${lib1}-data-access`; + + const readmePath = `${newPath}/README.md`; + expect(moveOutput).toContain(`CREATE ${readmePath}`); + checkFilesExist(readmePath); + + const jestConfigPath = `${newPath}/jest.config.js`; + expect(moveOutput).toContain(`CREATE ${jestConfigPath}`); + checkFilesExist(jestConfigPath); + const jestConfig = readFile(jestConfigPath); + expect(jestConfig).toContain(`name: 'shared-${lib1}-data-access'`); + expect(jestConfig).toContain(`preset: '../../../../jest.config.js'`); + expect(jestConfig).toContain( + `coverageDirectory: '../../../../coverage/${newPath}'` + ); + + const tsConfigPath = `${newPath}/tsconfig.json`; + expect(moveOutput).toContain(`CREATE ${tsConfigPath}`); + checkFilesExist(tsConfigPath); + + const tsConfigLibPath = `${newPath}/tsconfig.lib.json`; + expect(moveOutput).toContain(`CREATE ${tsConfigLibPath}`); + checkFilesExist(tsConfigLibPath); + const tsConfigLib = readJson(tsConfigLibPath); + expect(tsConfigLib.compilerOptions.outDir).toEqual( + '../../../../dist/out-tsc' + ); + + const tsConfigSpecPath = `${newPath}/tsconfig.spec.json`; + expect(moveOutput).toContain(`CREATE ${tsConfigSpecPath}`); + checkFilesExist(tsConfigSpecPath); + const tsConfigSpec = readJson(tsConfigSpecPath); + expect(tsConfigSpec.compilerOptions.outDir).toEqual( + '../../../../dist/out-tsc' + ); + + const indexPath = `${newPath}/src/index.ts`; + expect(moveOutput).toContain(`CREATE ${indexPath}`); + checkFilesExist(indexPath); + + const rootClassPath = `${newPath}/src/lib/${lib1}-data-access.ts`; + expect(moveOutput).toContain(`CREATE ${rootClassPath}`); + checkFilesExist(rootClassPath); + + expect(moveOutput).toContain('UPDATE nx.json'); + nxJson = JSON.parse(readFile('nx.json')) as NxJson; + expect(nxJson.projects[`${lib1}-data-access`]).toBeUndefined(); + expect(nxJson.projects[newName]).toEqual({ + tags: [], + }); + expect(nxJson.projects[lib3].implicitDependencies).toEqual([ + `shared-${lib1}-data-access`, + ]); + + expect(moveOutput).toContain('UPDATE tsconfig.base.json'); + const rootTsConfig = readJson('tsconfig.base.json'); + expect( + rootTsConfig.compilerOptions.paths[`@proj/${lib1}/data-access`] + ).toBeUndefined(); + expect( + rootTsConfig.compilerOptions.paths[`@proj/shared/${lib1}/data-access`] + ).toEqual([`libs/shared/${lib1}/data-access/src/index.ts`]); + + expect(moveOutput).toContain(`UPDATE ${workspace}.json`); + const workspaceJson = readJson(`${workspace}.json`); + expect(workspaceJson.projects[`${lib1}-data-access`]).toBeUndefined(); + const project = workspaceJson.projects[newName]; + expect(project).toBeTruthy(); + expect(project.root).toBe(newPath); + expect(project.sourceRoot).toBe(`${newPath}/src`); + expect(project.architect.lint.options.tsConfig).toEqual([ + `libs/shared/${lib1}/data-access/tsconfig.lib.json`, + `libs/shared/${lib1}/data-access/tsconfig.spec.json`, + ]); + + /** + * Check that the import in lib2 has been updated + */ + const lib2FilePath = `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`; + const lib2File = readFile(lib2FilePath); + expect(lib2File).toContain( + `import { fromLibOne } from '@proj/shared/${lib1}/data-access';` + ); + }); + + it('should work for libs created with --importPath', () => { + const importPath = '@wibble/fish'; + const lib1 = uniq('mylib'); + const lib2 = uniq('mylib'); + const lib3 = uniq('mylib'); + newProject(); + runCLI( + `generate @nrwl/workspace:lib ${lib1}/data-access --importPath=${importPath}` + ); + + updateFile( + `libs/${lib1}/data-access/src/lib/${lib1}-data-access.ts`, + `export function fromLibOne() { console.log('This is completely pointless'); }` + ); + + updateFile( + `libs/${lib1}/data-access/src/index.ts`, + `export * from './lib/${lib1}-data-access.ts'` + ); + + /** + * Create a library which imports a class from lib1 + */ + + runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + + updateFile( + `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, + `import { fromLibOne } from '${importPath}'; + + export const fromLibTwo = () => fromLibOne();` ); /** @@ -859,7 +998,7 @@ forEachCli((cli) => { `packages/${lib2}/ui/src/lib/${lib2}-ui.ts`, `import { fromLibOne } from '@proj/${lib1}/data-access'; - export const fromLibTwo = () => fromLibOne(); }` + export const fromLibTwo = () => fromLibOne();` ); /** diff --git a/packages/angular/src/schematics/move/lib/update-module-name.spec.ts b/packages/angular/src/schematics/move/lib/update-module-name.spec.ts index 777beb0141dce..993c42b7853f8 100644 --- a/packages/angular/src/schematics/move/lib/update-module-name.spec.ts +++ b/packages/angular/src/schematics/move/lib/update-module-name.spec.ts @@ -10,6 +10,7 @@ describe('updateModuleName Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'my-destination', + updateImportPath: true, }; const modulePath = '/libs/my-destination/src/lib/my-destination.module.ts'; diff --git a/packages/angular/src/schematics/move/schema.d.ts b/packages/angular/src/schematics/move/schema.d.ts index 50ed425b41447..14f247d3b7980 100644 --- a/packages/angular/src/schematics/move/schema.d.ts +++ b/packages/angular/src/schematics/move/schema.d.ts @@ -1,4 +1,6 @@ export interface Schema { projectName: string; destination: string; + importPath?: string; + updateImportPath: boolean; } diff --git a/packages/angular/src/schematics/move/schema.json b/packages/angular/src/schematics/move/schema.json index d9721794a064c..ddf778ca49aed 100644 --- a/packages/angular/src/schematics/move/schema.json +++ b/packages/angular/src/schematics/move/schema.json @@ -23,6 +23,15 @@ "$source": "argv", "index": 0 } + }, + "importPath": { + "type": "string", + "description": "The new import path to use in the tsconfig.base.json" + }, + "updateImportPath": { + "type": "boolean", + "description": "Should the schematic update the import path to reflect the new location?", + "default": true } }, "required": ["projectName", "destination"] diff --git a/packages/workspace/src/schematics/move/lib/check-destination.spec.ts b/packages/workspace/src/schematics/move/lib/check-destination.spec.ts index 167cc938e0e73..7b5bc518a2318 100644 --- a/packages/workspace/src/schematics/move/lib/check-destination.spec.ts +++ b/packages/workspace/src/schematics/move/lib/check-destination.spec.ts @@ -16,6 +16,8 @@ describe('checkDestination Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: '../apps/not-an-app', + importPath: undefined, + updateImportPath: true, }; await expect(callRule(checkDestination(schema), tree)).rejects.toThrow( @@ -29,6 +31,8 @@ describe('checkDestination Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: 'my-other-lib', + importPath: undefined, + updateImportPath: true, }; await expect(callRule(checkDestination(schema), tree)).rejects.toThrow( @@ -40,6 +44,8 @@ describe('checkDestination Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: 'my-other-lib', + importPath: undefined, + updateImportPath: true, }; await expect( @@ -51,6 +57,8 @@ describe('checkDestination Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: '/my-other-lib//wibble', + importPath: undefined, + updateImportPath: true, }; await callRule(checkDestination(schema), tree); diff --git a/packages/workspace/src/schematics/move/lib/move-project.spec.ts b/packages/workspace/src/schematics/move/lib/move-project.spec.ts index 6d4f3111e9d8e..29f95f9de1470 100644 --- a/packages/workspace/src/schematics/move/lib/move-project.spec.ts +++ b/packages/workspace/src/schematics/move/lib/move-project.spec.ts @@ -15,6 +15,8 @@ describe('moveProject Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; // TODO - Currently this test will fail due to diff --git a/packages/workspace/src/schematics/move/lib/update-cypress-json.spec.ts b/packages/workspace/src/schematics/move/lib/update-cypress-json.spec.ts index 766d352d4c776..2253603f2980e 100644 --- a/packages/workspace/src/schematics/move/lib/update-cypress-json.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-cypress-json.spec.ts @@ -22,6 +22,8 @@ describe('updateCypressJson Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; await expect( @@ -53,6 +55,8 @@ describe('updateCypressJson Rule', () => { const schema: Schema = { projectName: 'my-lib', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateCypressJson(schema), tree)) as UnitTestTree; diff --git a/packages/workspace/src/schematics/move/lib/update-imports.spec.ts b/packages/workspace/src/schematics/move/lib/update-imports.spec.ts index ea3d9bade5203..7a2019ffdd5be 100644 --- a/packages/workspace/src/schematics/move/lib/update-imports.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-imports.spec.ts @@ -17,6 +17,8 @@ describe('updateImports Rule', () => { schema = { projectName: 'my-source', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; }); @@ -32,10 +34,10 @@ describe('updateImports Rule', () => { tree.create( importerFilePath, ` - import { MyClass } from '@proj/my-source'; - - export MyExtendedClass extends MyClass {}; - ` + import { MyClass } from '@proj/my-source'; + + export MyExtendedClass extends MyClass {}; + ` ); tree = (await callRule(updateImports(schema), tree)) as UnitTestTree; @@ -45,6 +47,58 @@ describe('updateImports Rule', () => { ); }); + it('should not update project refs when --updateImportPath=false', async () => { + // this is a bit of a cheat - we expect to run this rule on an intermediate state + // tree where the workspace hasn't been updated yet, so just create libs representing + // source and destination to make sure that the workspace has libraries with those names. + tree = await runSchematic('lib', { name: 'my-destination' }, tree); + tree = await runSchematic('lib', { name: 'my-source' }, tree); + + tree = await runSchematic('lib', { name: 'my-importer' }, tree); + const importerFilePath = 'libs/my-importer/src/importer.ts'; + tree.create( + importerFilePath, + ` + import { MyClass } from '@proj/my-source'; + + export MyExtendedClass extends MyClass {}; + ` + ); + + schema.updateImportPath = false; + tree = (await callRule(updateImports(schema), tree)) as UnitTestTree; + + expect(tree.read(importerFilePath).toString()).toContain( + `import { MyClass } from '@proj/my-source';` + ); + }); + + it('should update project refs to --importPath when provided', async () => { + // this is a bit of a cheat - we expect to run this rule on an intermediate state + // tree where the workspace hasn't been updated yet, so just create libs representing + // source and destination to make sure that the workspace has libraries with those names. + tree = await runSchematic('lib', { name: 'my-destination' }, tree); + tree = await runSchematic('lib', { name: 'my-source' }, tree); + + tree = await runSchematic('lib', { name: 'my-importer' }, tree); + const importerFilePath = 'libs/my-importer/src/importer.ts'; + tree.create( + importerFilePath, + ` + import { MyClass } from '@proj/my-source'; + + export MyExtendedClass extends MyClass {}; + ` + ); + + schema.importPath = '@proj/wibble'; + tree = (await callRule(updateImports(schema), tree)) as UnitTestTree; + + expect(tree.read(importerFilePath).toString()).toContain( + `import { MyClass } from '${schema.importPath}';` + ); + }); + it('should update project ref in the tsconfig file', async () => { tree = await runSchematic('lib', { name: 'my-source' }, tree); @@ -60,4 +114,21 @@ describe('updateImports Rule', () => { '@proj/my-destination': ['libs/my-destination/src/index.ts'], }); }); + + it('should only update the project ref paths in the tsconfig file when --updateImportPath=false', async () => { + tree = await runSchematic('lib', { name: 'my-source' }, tree); + + let tsConfig = readJsonInTree(tree, '/tsconfig.base.json'); + expect(tsConfig.compilerOptions.paths).toEqual({ + '@proj/my-source': ['libs/my-source/src/index.ts'], + }); + + schema.updateImportPath = false; + tree = (await callRule(updateImports(schema), tree)) as UnitTestTree; + + tsConfig = readJsonInTree(tree, '/tsconfig.base.json'); + expect(tsConfig.compilerOptions.paths).toEqual({ + '@proj/my-source': ['libs/my-destination/src/index.ts'], + }); + }); }); diff --git a/packages/workspace/src/schematics/move/lib/update-imports.ts b/packages/workspace/src/schematics/move/lib/update-imports.ts index d91cdb34d82f6..b1507c762c64e 100644 --- a/packages/workspace/src/schematics/move/lib/update-imports.ts +++ b/packages/workspace/src/schematics/move/lib/update-imports.ts @@ -9,7 +9,6 @@ import { from, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { Schema } from '../schema'; import { normalizeSlashes } from './utils'; -import { ProjectType } from '@nrwl/workspace/src/utils/project-type'; /** * Updates all the imports in the workspace and modifies the tsconfig appropriately. @@ -31,33 +30,53 @@ export function updateImports(schema: Schema) { return tree; } + // use the source root to find the from location + // this attempts to account for libs that have been created with --importPath + const tsConfigPath = 'tsconfig.base.json'; + let tsConfig: any; + let fromPath: string; + if (tree.exists(tsConfigPath)) { + tsConfig = JSON.parse(tree.read(tsConfigPath).toString('utf-8')); + fromPath = Object.keys(tsConfig.compilerOptions.paths).find((path) => + tsConfig.compilerOptions.paths[path].some((x) => + x.startsWith(project.sourceRoot) + ) + ); + } + const projectRef = { - from: normalizeSlashes( - `@${nxJson.npmScope}/${project.root.substr(libsDir.length + 1)}` - ), - to: normalizeSlashes(`@${nxJson.npmScope}/${schema.destination}`), + from: + fromPath || + normalizeSlashes( + `@${nxJson.npmScope}/${project.root.substr(libsDir.length + 1)}` + ), + to: + schema.importPath || + normalizeSlashes(`@${nxJson.npmScope}/${schema.destination}`), }; - const replaceProjectRef = new RegExp(projectRef.from, 'g'); - - for (const [name, definition] of workspace.projects.entries()) { - if (name === schema.projectName) { - continue; - } + if (schema.updateImportPath) { + const replaceProjectRef = new RegExp(projectRef.from, 'g'); - const projectDir = tree.getDir(definition.root); - projectDir.visit((file) => { - const contents = tree.read(file).toString('utf-8'); - if (!replaceProjectRef.test(contents)) { - return; + for (const [name, definition] of workspace.projects.entries()) { + if (name === schema.projectName) { + continue; } - const updatedFile = tree - .read(file) - .toString() - .replace(replaceProjectRef, projectRef.to); - tree.overwrite(file, updatedFile); - }); + const projectDir = tree.getDir(definition.root); + projectDir.visit((file) => { + const contents = tree.read(file).toString('utf-8'); + if (!replaceProjectRef.test(contents)) { + return; + } + + const updatedFile = tree + .read(file) + .toString() + .replace(replaceProjectRef, projectRef.to); + tree.overwrite(file, updatedFile); + }); + } } const projectRoot = { @@ -65,19 +84,23 @@ export function updateImports(schema: Schema) { to: schema.destination, }; - const tsConfigPath = 'tsconfig.base.json'; - if (tree.exists(tsConfigPath)) { - let contents = JSON.parse(tree.read(tsConfigPath).toString('utf-8')); - const path = contents.compilerOptions.paths[ + if (tsConfig) { + const path = tsConfig.compilerOptions.paths[ projectRef.from ] as string[]; - contents.compilerOptions.paths[projectRef.to] = path.map((x) => + const updatedPath = path.map((x) => x.replace(new RegExp(projectRoot.from, 'g'), projectRoot.to) ); - delete contents.compilerOptions.paths[projectRef.from]; - tree.overwrite(tsConfigPath, serializeJson(contents)); + if (schema.updateImportPath) { + tsConfig.compilerOptions.paths[projectRef.to] = updatedPath; + delete tsConfig.compilerOptions.paths[projectRef.from]; + } else { + tsConfig.compilerOptions.paths[projectRef.from] = updatedPath; + } + + tree.overwrite(tsConfigPath, serializeJson(tsConfig)); } return tree; diff --git a/packages/workspace/src/schematics/move/lib/update-jest-config.spec.ts b/packages/workspace/src/schematics/move/lib/update-jest-config.spec.ts index 33b5b8b010bff..b78e3a7d7f9d5 100644 --- a/packages/workspace/src/schematics/move/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-jest-config.spec.ts @@ -19,6 +19,8 @@ describe('updateJestConfig Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; await expect( @@ -44,6 +46,8 @@ describe('updateJestConfig Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateJestConfig(schema), tree)) as UnitTestTree; diff --git a/packages/workspace/src/schematics/move/lib/update-nx-json.spec.ts b/packages/workspace/src/schematics/move/lib/update-nx-json.spec.ts index 716e2db06669f..4d9bf9559a3e8 100644 --- a/packages/workspace/src/schematics/move/lib/update-nx-json.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-nx-json.spec.ts @@ -20,6 +20,8 @@ describe('updateNxJson Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateNxJson(schema), tree)) as UnitTestTree; diff --git a/packages/workspace/src/schematics/move/lib/update-project-root-files.spec.ts b/packages/workspace/src/schematics/move/lib/update-project-root-files.spec.ts index 6ca9ffd6c55dd..7c5b1655dc1ce 100644 --- a/packages/workspace/src/schematics/move/lib/update-project-root-files.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-project-root-files.spec.ts @@ -31,6 +31,8 @@ describe('updateProjectRootFiles Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule( diff --git a/packages/workspace/src/schematics/move/lib/update-workspace.spec.ts b/packages/workspace/src/schematics/move/lib/update-workspace.spec.ts index da92346a572b4..9b184ecc3fc3b 100644 --- a/packages/workspace/src/schematics/move/lib/update-workspace.spec.ts +++ b/packages/workspace/src/schematics/move/lib/update-workspace.spec.ts @@ -146,6 +146,8 @@ describe('updateWorkspace Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree; @@ -160,6 +162,8 @@ describe('updateWorkspace Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree; @@ -173,6 +177,8 @@ describe('updateWorkspace Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree; @@ -193,6 +199,8 @@ describe('updateWorkspace Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree; @@ -213,6 +221,8 @@ describe('updateWorkspace Rule', () => { const schema: Schema = { projectName: 'my-source', destination: 'subfolder/my-destination', + importPath: undefined, + updateImportPath: true, }; tree = (await callRule( diff --git a/packages/workspace/src/schematics/move/schema.d.ts b/packages/workspace/src/schematics/move/schema.d.ts index 50ed425b41447..14f247d3b7980 100644 --- a/packages/workspace/src/schematics/move/schema.d.ts +++ b/packages/workspace/src/schematics/move/schema.d.ts @@ -1,4 +1,6 @@ export interface Schema { projectName: string; destination: string; + importPath?: string; + updateImportPath: boolean; } diff --git a/packages/workspace/src/schematics/move/schema.json b/packages/workspace/src/schematics/move/schema.json index 87563bed7e406..0ae7453591d4a 100644 --- a/packages/workspace/src/schematics/move/schema.json +++ b/packages/workspace/src/schematics/move/schema.json @@ -23,6 +23,15 @@ "$source": "argv", "index": 0 } + }, + "importPath": { + "type": "string", + "description": "The new import path to use in the tsconfig.base.json" + }, + "updateImportPath": { + "type": "boolean", + "description": "Should the schematic update the import path to reflect the new location?", + "default": true } }, "required": ["projectName", "destination"]