From 1ce78cebc440ecc6a7cb3c7e475d29a97e557179 Mon Sep 17 00:00:00 2001 From: Mirko Kruschke Date: Wed, 29 Nov 2023 15:04:16 +0100 Subject: [PATCH 1/2] fix: include eventual compilerOptions.paths changes to the check option --- src/update-ts-references.js | 11 +- .../ts-paths/workspace-a/tsconfig.json | 13 +- .../package.json | 14 + .../tsconfig.json | 19 + .../utils/foos/foo-a/package.json | 7 + .../utils/foos/foo-a/tsconfig.json | 6 + .../utils/foos/foo-b/package.json | 4 + .../workspace-a/package.json | 10 + .../workspace-a/tsconfig.json | 15 + .../workspace-b/package.json | 10 + .../workspace-b/tsconfig.json | 6 + .../yarn-ws-check-paths-no-changes/yarn.lock | 72 ++++ .../yarn-ws-check-paths/package.json | 14 + .../yarn-ws-check-paths/tsconfig.json | 17 + .../utils/foos/foo-a/package.json | 7 + .../utils/foos/foo-a/tsconfig.json | 7 + .../utils/foos/foo-b/package.json | 4 + .../workspace-a/package.json | 10 + .../workspace-a/tsconfig.json | 14 + .../workspace-b/package.json | 10 + .../workspace-b/tsconfig.json | 6 + test-scenarios/yarn-ws-check-paths/yarn.lock | 72 ++++ tests/setup.js | 2 +- tests/update-ts-references.check.test.js | 336 ++++++++++++++++++ tests/update-ts-references.test.js | 57 +-- 25 files changed, 680 insertions(+), 63 deletions(-) create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/package.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/package.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-b/package.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/package.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/package.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths-no-changes/yarn.lock create mode 100644 test-scenarios/yarn-ws-check-paths/package.json create mode 100644 test-scenarios/yarn-ws-check-paths/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/package.json create mode 100644 test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths/utils/foos/foo-b/package.json create mode 100644 test-scenarios/yarn-ws-check-paths/workspace-a/package.json create mode 100644 test-scenarios/yarn-ws-check-paths/workspace-a/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths/workspace-b/package.json create mode 100644 test-scenarios/yarn-ws-check-paths/workspace-b/tsconfig.json create mode 100644 test-scenarios/yarn-ws-check-paths/yarn.lock create mode 100644 tests/update-ts-references.check.test.js diff --git a/src/update-ts-references.js b/src/update-ts-references.js index 58fa022..38d89ae 100644 --- a/src/update-ts-references.js +++ b/src/update-ts-references.js @@ -187,6 +187,8 @@ const updateTsConfig = ( let isEqual = false; try { assert.deepEqual(JSON.parse(JSON.stringify(currentReferences)), mergedReferences); + if (createPathMappings) + assert.deepEqual(JSON.parse(JSON.stringify(config?.compilerOptions?.paths ?? {})), paths); isEqual = true; } catch (e) { // ignore me @@ -195,10 +197,11 @@ const updateTsConfig = ( if (check === false) { const compilerOptions = config?.compilerOptions ?? {}; - if (createPathMappings && paths && Object.keys(paths).length > 0) - assign(compilerOptions, { - paths - }) + if (createPathMappings && paths) + assign(compilerOptions, + paths && Object.keys(paths).length > 0 ? { + paths + } : {paths: undefined}) const newTsConfig = assign(config, { diff --git a/test-scenarios/ts-paths/workspace-a/tsconfig.json b/test-scenarios/ts-paths/workspace-a/tsconfig.json index 1dd8e13..40169b3 100644 --- a/test-scenarios/ts-paths/workspace-a/tsconfig.json +++ b/test-scenarios/ts-paths/workspace-a/tsconfig.json @@ -1,6 +1,15 @@ { "compilerOptions": { "outDir": "dist", - "rootDir": "src" - } + "rootDir": "src", + "paths": { "replace-me": ["../utils/old-one/src"]}, + }, + "references": [ + { + "path": "../utils/foos/foo-a" + }, + { + "path": "../workspace-b" + } + ] } diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/package.json b/test-scenarios/yarn-ws-check-paths-no-changes/package.json new file mode 100644 index 0000000..f5aeb24 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/package.json @@ -0,0 +1,14 @@ +{ + "name": "yarn-workspace", + "version": "0.0.1", + "private": true, + "workspaces": [ + "workspace-a", + "workspace-b", + "shared/*", + "utils/**" + ], + "devDependencies": { + "typescript": "latest" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/tsconfig.json b/test-scenarios/yarn-ws-check-paths-no-changes/tsconfig.json new file mode 100644 index 0000000..9da7d45 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/tsconfig.json @@ -0,0 +1,19 @@ +{ + "files": [], + "compilerOptions": { + "composite": true, + "paths": { "foo-b": ["utils/foos/foo-b/src"] } + }, + "references": [ + { + "path": "workspace-a" + }, + { + "path": "workspace-b" + }, + { + "path": "utils/foos/foo-a" + }, + + ] +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/package.json b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/package.json new file mode 100644 index 0000000..699ec9c --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "foo-a", + "version": "1.0.0", + "dependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/tsconfig.json b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-a/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-b/package.json b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-b/package.json new file mode 100644 index 0000000..2c997b8 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/utils/foos/foo-b/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo-b", + "version": "1.0.0" +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/package.json b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/package.json new file mode 100644 index 0000000..f35aa29 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-a", + "version": "1.0.0", + "dependencies": { + "workspace-b": "1.0.0" + }, + "devDependencies": { + "foo-a": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/tsconfig.json b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/tsconfig.json new file mode 100644 index 0000000..5050c66 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-a/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "paths": { "foo-a": ["../utils/foos/foo-a/src"], "workspace-b": ["../workspace-b/src"]} + }, + "references": [ + { + "path": "../utils/foos/foo-a" + }, + { + "path": "../workspace-b" + } + ] +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/package.json b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/package.json new file mode 100644 index 0000000..552cf0e --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-b", + "version": "1.0.0", + "dependencies": { + "cross-env": "5.0.5" + }, + "devDependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/tsconfig.json b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/workspace-b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/yarn-ws-check-paths-no-changes/yarn.lock b/test-scenarios/yarn-ws-check-paths-no-changes/yarn.lock new file mode 100644 index 0000000..da3e0c5 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths-no-changes/yarn.lock @@ -0,0 +1,72 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +cross-env@5.0.5: + version "5.0.5" + resolved "https://registry.npmjs.org/cross-env/-/cross-env-5.0.5.tgz#4383d364d9660873dd185b398af3bfef5efffef3" + integrity sha1-Q4PTZNlmCHPdGFs5ivO/717//vM= + dependencies: + cross-spawn "^5.1.0" + is-windows "^1.0.0" + +cross-spawn@^5.1.0: + version "5.1.0" + resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" + integrity sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk= + dependencies: + lru-cache "^4.0.1" + shebang-command "^1.2.0" + which "^1.2.9" + +is-windows@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +lru-cache@^4.0.1: + version "4.1.5" + resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" + integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== + dependencies: + pseudomap "^1.0.2" + yallist "^2.1.2" + +pseudomap@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= + +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= + dependencies: + shebang-regex "^1.0.0" + +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= + +typescript@latest: + version "4.0.5" + resolved "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" + integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== + +which@^1.2.9: + version "1.3.1" + resolved "https://registry.npmjs.org/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +yallist@^2.1.2: + version "2.1.2" + resolved "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" + integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= diff --git a/test-scenarios/yarn-ws-check-paths/package.json b/test-scenarios/yarn-ws-check-paths/package.json new file mode 100644 index 0000000..f5aeb24 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/package.json @@ -0,0 +1,14 @@ +{ + "name": "yarn-workspace", + "version": "0.0.1", + "private": true, + "workspaces": [ + "workspace-a", + "workspace-b", + "shared/*", + "utils/**" + ], + "devDependencies": { + "typescript": "latest" + } +} diff --git a/test-scenarios/yarn-ws-check-paths/tsconfig.json b/test-scenarios/yarn-ws-check-paths/tsconfig.json new file mode 100644 index 0000000..c2a531b --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/tsconfig.json @@ -0,0 +1,17 @@ +{ + "files": [], + "compilerOptions": { + "composite": true + }, + "references": [ + { + "path": "workspace-a" + }, + { + "path": "workspace-b" + }, + { + "path": "utils/foos/foo-a" + }, + ] +} diff --git a/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/package.json b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/package.json new file mode 100644 index 0000000..699ec9c --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "foo-a", + "version": "1.0.0", + "dependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/tsconfig.json b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/tsconfig.json new file mode 100644 index 0000000..bbc9912 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-a/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "paths": { "remove-me": ["../utils/remove/src"]} + } +} diff --git a/test-scenarios/yarn-ws-check-paths/utils/foos/foo-b/package.json b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-b/package.json new file mode 100644 index 0000000..2c997b8 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/utils/foos/foo-b/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo-b", + "version": "1.0.0" +} diff --git a/test-scenarios/yarn-ws-check-paths/workspace-a/package.json b/test-scenarios/yarn-ws-check-paths/workspace-a/package.json new file mode 100644 index 0000000..f35aa29 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/workspace-a/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-a", + "version": "1.0.0", + "dependencies": { + "workspace-b": "1.0.0" + }, + "devDependencies": { + "foo-a": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths/workspace-a/tsconfig.json b/test-scenarios/yarn-ws-check-paths/workspace-a/tsconfig.json new file mode 100644 index 0000000..1b15d3f --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/workspace-a/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + }, + "references": [ + { + "path": "../utils/foos/foo-a" + }, + { + "path": "../workspace-b" + } + ] +} diff --git a/test-scenarios/yarn-ws-check-paths/workspace-b/package.json b/test-scenarios/yarn-ws-check-paths/workspace-b/package.json new file mode 100644 index 0000000..552cf0e --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/workspace-b/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-b", + "version": "1.0.0", + "dependencies": { + "cross-env": "5.0.5" + }, + "devDependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/yarn-ws-check-paths/workspace-b/tsconfig.json b/test-scenarios/yarn-ws-check-paths/workspace-b/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/workspace-b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/yarn-ws-check-paths/yarn.lock b/test-scenarios/yarn-ws-check-paths/yarn.lock new file mode 100644 index 0000000..da3e0c5 --- /dev/null +++ b/test-scenarios/yarn-ws-check-paths/yarn.lock @@ -0,0 +1,72 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +cross-env@5.0.5: + version "5.0.5" + resolved "https://registry.npmjs.org/cross-env/-/cross-env-5.0.5.tgz#4383d364d9660873dd185b398af3bfef5efffef3" + integrity sha1-Q4PTZNlmCHPdGFs5ivO/717//vM= + dependencies: + cross-spawn "^5.1.0" + is-windows "^1.0.0" + +cross-spawn@^5.1.0: + version "5.1.0" + resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" + integrity sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk= + dependencies: + lru-cache "^4.0.1" + shebang-command "^1.2.0" + which "^1.2.9" + +is-windows@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +lru-cache@^4.0.1: + version "4.1.5" + resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" + integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== + dependencies: + pseudomap "^1.0.2" + yallist "^2.1.2" + +pseudomap@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= + +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= + dependencies: + shebang-regex "^1.0.0" + +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= + +typescript@latest: + version "4.0.5" + resolved "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" + integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== + +which@^1.2.9: + version "1.3.1" + resolved "https://registry.npmjs.org/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +yallist@^2.1.2: + version "2.1.2" + resolved "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" + integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= diff --git a/tests/setup.js b/tests/setup.js index 96868d1..6c9ce0b 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -8,7 +8,7 @@ const setup = async (rootFolder, configName, rootConfigName, createTsConfig, cre try { await execSh( - `npx update-ts-references --verbose${ + `npx update-ts-references ${process.env.DEBUG ? '--verbose':'' }${ configName ? ` --configName ${configName}` : '' }${ rootConfigName ? ` --rootConfigName ${rootConfigName}` : '' diff --git a/tests/update-ts-references.check.test.js b/tests/update-ts-references.check.test.js new file mode 100644 index 0000000..541e85c --- /dev/null +++ b/tests/update-ts-references.check.test.js @@ -0,0 +1,336 @@ +const path = require('path'); +const fs = require('fs'); +const {parse} = require("comment-json") +const {promise: execSh} = require("exec-sh"); + +const rootFolderYarnCheck = path.join( + process.cwd(), + 'test-run', + 'yarn-ws-check' +); +const rootFolderYarnCheckNoChanges = path.join( + process.cwd(), + 'test-run', + 'yarn-ws-check-no-changes' +); +const rootFolderYarnCheckPaths = path.join( + process.cwd(), + 'test-run', + 'yarn-ws-check-paths' +); +const rootFolderYarnCheckPathsNoChanges = path.join( + process.cwd(), + 'test-run', + 'yarn-ws-check-paths-no-changes' +); + +const compilerOptions = {outDir: 'dist', rootDir: 'src'}; + +const rootTsConfig = [ + '.', + { + compilerOptions: { + composite: true, + }, + files: [], + references: [ + { + path: 'workspace-a', + }, + { + path: 'workspace-b', + }, + { + path: 'shared/workspace-c', + }, + { + path: 'shared/workspace-d', + }, + { + path: 'utils/foos/foo-a', + }, + { + path: 'utils/foos/foo-b', + }, + ], + }, +]; + +const wsATsConfig = [ + './workspace-a', + { + compilerOptions, + references: [ + { + path: '../utils/foos/foo-a', + }, + { + path: '../workspace-b', + }, + ], + }, +]; + +const wsBTsConfig = [ + './workspace-b', + { + compilerOptions, + + references: [ + { + path: '../utils/foos/foo-b', + }, + ], + }, +]; + +const wsCTsConfig = [ + './shared/workspace-c', + { + compilerOptions, + + references: [ + { + path: '../../utils/foos/foo-a', + }, + ], + }, +]; + +const wsDTsConfig = [ + './shared/workspace-d', + { + compilerOptions, + + references: [ + { + path: '../workspace-c', + }, + ], + }, +]; + +const fooATsConfig = [ + './utils/foos/foo-a', + { + compilerOptions, + references: [ + { + path: '../foo-b', + }, + ], + }, +]; + +const fooBTsConfig = [ + './utils/foos/foo-b', + { + compilerOptions, + references: undefined, + }, +]; + +const tsconfigs = [ + rootTsConfig, + wsATsConfig, + wsBTsConfig, + wsCTsConfig, + wsDTsConfig, + fooATsConfig, + fooBTsConfig, +]; + + +test('Detect changes in references with the --check option', async () => { + let errorCode = 0; + try { + await execSh('npx update-ts-references --check', { + stdio: null, + cwd: rootFolderYarnCheck, + }); + } catch (e) { + errorCode = e.code; + } + + expect(errorCode).toBe(6); + + tsconfigs.forEach((tsconfig) => { + const [configPath] = tsconfig; + + expect( + parse(fs.readFileSync(path.join(rootFolderYarnCheck, configPath, 'tsconfig.json')).toString()).references + ).toBeFalsy(); + }); +}); + +test('No changes in references detected with the --check option', async () => { + let errorCode = 0; + try { + await execSh('npx update-ts-references --check', { + stdio: null, + cwd: rootFolderYarnCheckNoChanges, + }); + } catch (e) { + errorCode = e.code; + } + + expect(errorCode).toBe(0); + + tsconfigs.forEach((tsconfig) => { + const [configPath, config] = tsconfig; + + expect( + parse(fs.readFileSync(path.join(rootFolderYarnCheckNoChanges, configPath, 'tsconfig.json')).toString()) + ).toEqual(config); + }); +}); + + +test('Detect changes in paths with the --check option', async () => { + let errorCode = 0; + try { + await execSh('npx update-ts-references --check --createPathMappings', { + stdio: null, + cwd: rootFolderYarnCheckPaths, + }); + } catch (e) { + errorCode = e.code; + } + + expect(errorCode).toBe(3); + const root = [ + '.', + { + compilerOptions: { + composite: true, + }, + files: [], + references: [ + { + path: 'workspace-a', + }, + { + path: 'workspace-b', + }, + { + path: 'utils/foos/foo-a', + }, + ], + }, + ]; + + const a = [ + './workspace-a', + { + compilerOptions, + references: [ + { + "path": "../utils/foos/foo-a", + }, + { + path: '../workspace-b', + }, + ], + }, + ]; + + const b = [ + './workspace-b', + { + compilerOptions, + }, + ]; + + const fooA = [ + './utils/foos/foo-a', + { + compilerOptions: {...compilerOptions, "paths": { "remove-me": ["../utils/remove/src"]}}, + }, + ]; + [root,a,b,fooA].forEach((tsconfig) => { + const [configPath,config] = tsconfig; + + expect( + parse(fs.readFileSync(path.join(rootFolderYarnCheckPaths, configPath, 'tsconfig.json')).toString()) + ).toEqual(config) + }); +}); + +test('No changes paths detected with the --check option', async () => { + let errorCode = 0; + try { + await execSh('npx update-ts-references --check', { + stdio: null, + cwd: rootFolderYarnCheckPathsNoChanges, + }); + } catch (e) { + errorCode = e.code; + } + + expect(errorCode).toBe(0); + + + const root = [ + '.', + { + compilerOptions: { + composite: true, + paths: { "foo-b": ["utils/foos/foo-b/src"]} + }, + files: [], + references: [ + { + path: 'workspace-a', + }, + { + path: 'workspace-b', + }, + { + path: 'utils/foos/foo-a', + }, + ], + }, + ]; + + const a = [ + './workspace-a', + { + compilerOptions: { + ...compilerOptions, + paths: { "foo-a": ["../utils/foos/foo-a/src"], "workspace-b": ["../workspace-b/src"], } + }, + references: [ + { + "path": "../utils/foos/foo-a", + }, + { + path: '../workspace-b', + }, + ], + }, + ]; + + const b = [ + './workspace-b', + { + compilerOptions, + }, + ]; + + const fooA = [ + './utils/foos/foo-a', + { + compilerOptions, + }, + ]; + + [root, a, b, fooA].forEach((tsconfig) => { + const [configPath, config] = tsconfig; + + expect( + parse(fs.readFileSync(path.join(rootFolderYarnCheckPathsNoChanges, configPath, 'tsconfig.json')).toString()) + ).toEqual(config); + }); +}); + + diff --git a/tests/update-ts-references.test.js b/tests/update-ts-references.test.js index a16119f..82786ec 100644 --- a/tests/update-ts-references.test.js +++ b/tests/update-ts-references.test.js @@ -1,5 +1,4 @@ const path = require('path'); -const execSh = require('exec-sh').promise; const fs = require('fs'); const {parse} = require("comment-json") const {setup} = require('./setup'); @@ -18,16 +17,7 @@ const rootFolderYarnCreate = path.join( ); const rootFolderPnpm = path.join(process.cwd(), 'test-run', 'pnpm'); const rootFolderTsPaths = path.join(process.cwd(), 'test-run', 'ts-paths'); -const rootFolderYarnCheck = path.join( - process.cwd(), - 'test-run', - 'yarn-ws-check' -); -const rootFolderYarnCheckNoChanges = path.join( - process.cwd(), - 'test-run', - 'yarn-ws-check-no-changes' -); + const rootFolderLerna = path.join(process.cwd(), 'test-run', 'lerna'); const rootFolderConfigName = path.join( process.cwd(), @@ -374,51 +364,6 @@ test('Test create tsconfig', async () => { expect(fs.existsSync(path.join(rootFolderYarnCreate, 'workspace-c', 'tsconfig.json'))).toBeFalsy(); }); -test('Detect changes with the --check option', async () => { - let errorCode = 0; - try { - await execSh('npx update-ts-references --check', { - stdio: null, - cwd: rootFolderYarnCheck, - }); - } catch (e) { - errorCode = e.code; - } - - expect(errorCode).toBe(6); - - tsconfigs.forEach((tsconfig) => { - const [configPath] = tsconfig; - - expect( - parse(fs.readFileSync(path.join(rootFolderYarnCheck, configPath, 'tsconfig.json')).toString()).references - ).toBeFalsy(); - }); -}); - -test('No changes detected with the --check option', async () => { - let errorCode = 0; - try { - await execSh('npx update-ts-references --check', { - stdio: null, - cwd: rootFolderYarnCheckNoChanges, - }); - } catch (e) { - errorCode = e.code; - } - - expect(errorCode).toBe(0); - - tsconfigs.forEach((tsconfig) => { - const [configPath, config] = tsconfig; - - expect( - parse(fs.readFileSync(path.join(rootFolderYarnCheckNoChanges, configPath, 'tsconfig.json')).toString()) - ).toEqual(config); - }); -}); - - test('Support custom tsconfig names', async () => { const configName = 'tsconfig.dev.json'; const rootConfigName = 'tsconfig.ref.json'; From f3de077348480dcc0a0a1865834d8289f5c3c1d0 Mon Sep 17 00:00:00 2001 From: Mirko Kruschke Date: Wed, 29 Nov 2023 15:18:22 +0100 Subject: [PATCH 2/2] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21f9607..bcb8872 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "update-ts-references", - "version": "3.2.0", + "version": "3.2.1", "description": "Updates TypeScript references automatically while using workspaces", "bin": "src/index.js", "scripts": {