From df197cf1943ba0bb5cd5b718c145d43cd57b5b3e Mon Sep 17 00:00:00 2001 From: Julien Saguet Date: Sat, 29 Feb 2020 16:27:33 +0100 Subject: [PATCH] fix(core): fix move schematic issues Use slashes as path separator even when used on windows environments to avoid mis-identifying escaped characters in file path Use slash as path separator even when used on windows to get a correct path in extends property Fix an issue when renaming jest project name where substrings were replaced as well in the file Fix an issue when renaming imports where substrings in imports where replaced too --- .../schematics/move/lib/update-module-name.ts | 2 +- .../schematics/move/lib/update-jest-config.ts | 4 ++-- .../move/lib/update-project-root-files.ts | 16 ++++++++-------- .../workspace/src/schematics/move/lib/utils.ts | 5 ++++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/angular/src/schematics/move/lib/update-module-name.ts b/packages/angular/src/schematics/move/lib/update-module-name.ts index 9abbc0a9bb..0aa4bf3e20 100644 --- a/packages/angular/src/schematics/move/lib/update-module-name.ts +++ b/packages/angular/src/schematics/move/lib/update-module-name.ts @@ -32,7 +32,7 @@ export function updateModuleName(schema: Schema) { to: classify(newProjectName) }; - const findModuleName = new RegExp(moduleName.from, 'g'); + const findModuleName = new RegExp(`\\b${moduleName.from}`, 'g'); const moduleFile = { from: `${schema.projectName}.module`, diff --git a/packages/workspace/src/schematics/move/lib/update-jest-config.ts b/packages/workspace/src/schematics/move/lib/update-jest-config.ts index f6d355d67d..9f2daf2397 100644 --- a/packages/workspace/src/schematics/move/lib/update-jest-config.ts +++ b/packages/workspace/src/schematics/move/lib/update-jest-config.ts @@ -31,11 +31,11 @@ export function updateJestConfig(schema: Schema): Rule { const oldContent = tree.read(jestConfigPath).toString('utf-8'); - const findName = new RegExp(schema.projectName, 'g'); + const findName = new RegExp(`'${schema.projectName}'`, 'g'); const findDir = new RegExp(project.root, 'g'); const newContent = oldContent - .replace(findName, newProjectName) + .replace(findName, `'${newProjectName}'`) .replace(findDir, destination); tree.overwrite(jestConfigPath, newContent); diff --git a/packages/workspace/src/schematics/move/lib/update-project-root-files.ts b/packages/workspace/src/schematics/move/lib/update-project-root-files.ts index ebb0874b21..d6ff8ce19c 100644 --- a/packages/workspace/src/schematics/move/lib/update-project-root-files.ts +++ b/packages/workspace/src/schematics/move/lib/update-project-root-files.ts @@ -22,14 +22,14 @@ export function updateProjectRootFiles(schema: Schema): Rule { const project = workspace.projects.get(schema.projectName); const destination = getDestination(schema, workspace); - const newRelativeRoot = path.relative( - path.join(appRootPath, destination), - appRootPath - ); - const oldRelativeRoot = path.relative( - path.join(appRootPath, project.root), - appRootPath - ); + const newRelativeRoot = path + .relative(path.join(appRootPath, destination), appRootPath) + .split(path.sep) + .join('/'); + const oldRelativeRoot = path + .relative(path.join(appRootPath, project.root), appRootPath) + .split(path.sep) + .join('/'); if (newRelativeRoot === oldRelativeRoot) { // nothing to do diff --git a/packages/workspace/src/schematics/move/lib/utils.ts b/packages/workspace/src/schematics/move/lib/utils.ts index 454f4c71da..b8b5e31ceb 100644 --- a/packages/workspace/src/schematics/move/lib/utils.ts +++ b/packages/workspace/src/schematics/move/lib/utils.ts @@ -27,7 +27,10 @@ export function getDestination( if (projectType === 'application') { rootFolder = 'apps'; } - return path.join(rootFolder, schema.destination); + return path + .join(rootFolder, schema.destination) + .split(path.sep) + .join('/'); } /**