From 156e4e85029bb05ef237581e09ec2eed3176f834 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:08:31 -0400 Subject: [PATCH 01/10] test: use portal for referencing the main package --- test/package.json | 3 ++- test/tsconfig.json | 2 +- test/yarn.lock | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/package.json b/test/package.json index 5c8ce619..b3acb053 100755 --- a/test/package.json +++ b/test/package.json @@ -12,6 +12,7 @@ "@nrwl/js": "^15.9.7", "@nrwl/node": "^15.9.7", "@nrwl/workspace": "^15.9.7", + "@tsconfig/node18": "^18.2.4", "@types/jest": "^29.5.12", "jest": "^29.7.0", "nx": "^15.9.7", @@ -25,7 +26,7 @@ "typescript": "^5.5.4", "typescript-four-seven": "npm:typescript@4.7.4", "typescript-three": "npm:typescript@3.6.5", - "typescript-transform-paths": "../package.tgz" + "typescript-transform-paths": "portal:../" }, "workspaces": [ "projects/*" diff --git a/test/tsconfig.json b/test/tsconfig.json index e40bf64a..65bb1c4b 100755 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.base", + "extends": "@tsconfig/node18", "include": ["tests", "utils"], "compilerOptions": { diff --git a/test/yarn.lock b/test/yarn.lock index 6ee072ba..c22adeac 100644 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -2210,6 +2210,13 @@ __metadata: languageName: node linkType: hard +"@tsconfig/node18@npm:^18.2.4": + version: 18.2.4 + resolution: "@tsconfig/node18@npm:18.2.4" + checksum: 10c0/cdfd17f212660374eb2765cd5907b2252e43cfa2623cd52307a49f004327ef49bbe7d53c78b0aca57f33e9a5cb0d7d2eb5ded9be1235e6212f65c9f0699322b6 + languageName: node + linkType: hard + "@types/babel__core@npm:^7.1.14": version: 7.20.5 resolution: "@types/babel__core@npm:7.20.5" @@ -8065,6 +8072,7 @@ __metadata: "@nrwl/js": "npm:^15.9.7" "@nrwl/node": "npm:^15.9.7" "@nrwl/workspace": "npm:^15.9.7" + "@tsconfig/node18": "npm:^18.2.4" "@types/jest": "npm:^29.5.12" jest: "npm:^29.7.0" nx: "npm:^15.9.7" @@ -8078,7 +8086,7 @@ __metadata: typescript: "npm:^5.5.4" typescript-four-seven: "npm:typescript@4.7.4" typescript-three: "npm:typescript@3.6.5" - typescript-transform-paths: ../package.tgz + typescript-transform-paths: "portal:../" languageName: unknown linkType: soft @@ -9243,16 +9251,15 @@ __metadata: languageName: node linkType: hard -"typescript-transform-paths@file:../package.tgz::locator=root-workspace-0b6124%40workspace%3A.": - version: 3.4.9 - resolution: "typescript-transform-paths@file:../package.tgz#../package.tgz::hash=396016&locator=root-workspace-0b6124%40workspace%3A." +"typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A.": + version: 0.0.0-use.local + resolution: "typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A." dependencies: minimatch: "npm:^3.1.2" peerDependencies: typescript: ">=3.6.5" - checksum: 10c0/14b7936f4491a916375e3aa18bc771d3b02c8267526ad04e5562414098b29e07be9fa2ca0b46207c412ba5c5d0a35ae9543d56634a6c8672d92ca8ff46e3610f languageName: node - linkType: hard + linkType: soft "typescript@npm:^5.5.4": version: 5.5.4 From 077499fa0917d3655a6c04b024fd1b95ed59ecae Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:09:07 -0400 Subject: [PATCH 02/10] test: use esm for prepare script --- test/package.json | 2 +- test/prepare.js | 29 ----------------------------- test/prepare.mjs | 33 +++++++++++++++++++++++++++++++++ test/tsconfig.json | 1 + 4 files changed, 35 insertions(+), 30 deletions(-) delete mode 100755 test/prepare.js create mode 100755 test/prepare.mjs diff --git a/test/package.json b/test/package.json index b3acb053..595d648c 100755 --- a/test/package.json +++ b/test/package.json @@ -5,7 +5,7 @@ "test": "jest", "g:ts-node": "cd $INIT_CWD && ts-node", "add-package": "yarn ../ pack && yarn add ../package.tgz", - "postinstall": "node prepare.js" + "postinstall": "node prepare.mjs" }, "devDependencies": { "@nrwl/cli": "^15.9.7", diff --git a/test/prepare.js b/test/prepare.js deleted file mode 100755 index dcf0e089..00000000 --- a/test/prepare.js +++ /dev/null @@ -1,29 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const tsPatch = require("ts-patch"); -const tsp1 = require("tsp1"); -const tsp2 = require("tsp2"); - -/* ****************************************************************************************************************** * - * Config - * ****************************************************************************************************************** */ - -const rootDir = __dirname; -const tsDirs = ["typescript-three", "typescript-four-seven", "typescript"]; - -/* ****************************************************************************************************************** * - * Patch TS Modules - * ****************************************************************************************************************** */ - -const baseDirs = new Map(); - -for (const tsDirName of tsDirs) { - const mainDir = path.resolve(rootDir, "node_modules", tsDirName); - if (!fs.existsSync(path.join(mainDir, "lib-backup"))) baseDirs.set(tsDirName, mainDir); -} - -// Patch discovered modules -for (const [dirName, dir] of baseDirs) - if (dirName === "typescript-three") tsp1.patch(["tsc.js", "typescript.js"], { basedir: dir }); - else if (dirName === "typescript-four-seven") tsp2.patch(["tsc.js", "typescript.js"], { dir }); - else tsPatch.patch(["tsc.js", "typescript.js"], { dir }); diff --git a/test/prepare.mjs b/test/prepare.mjs new file mode 100755 index 00000000..699747fb --- /dev/null +++ b/test/prepare.mjs @@ -0,0 +1,33 @@ +// @ts-check +import { existsSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { patch } from "ts-patch"; +import { patch as _patch } from "tsp1"; +import { patch as __patch } from "tsp2"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const rootDir = __dirname; +const tsDirs = ["typescript-three", "typescript-four-seven", "typescript"]; + +/* ****************************************************************************************************************** * + * Patch TS Modules + * ****************************************************************************************************************** */ + +const baseDirs = new Map(); + +for (const tsDirName of tsDirs) { + const mainDir = resolve(rootDir, "node_modules", tsDirName); + if (!existsSync(join(mainDir, "lib-backup"))) baseDirs.set(tsDirName, mainDir); +} + +// Patch discovered modules +for (const [dirName, dir] of baseDirs) + if (dirName === "typescript-three") _patch(["tsc.js", "typescript.js"], { basedir: dir }); + else if (dirName === "typescript-four-seven") __patch(["tsc.js", "typescript.js"], { dir }); + else patch(["tsc.js", "typescript.js"], { dir }); diff --git a/test/tsconfig.json b/test/tsconfig.json index 65bb1c4b..527b4629 100755 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -3,6 +3,7 @@ "include": ["tests", "utils"], "compilerOptions": { + "types": ["jest", "node"], "noEmit": true, "strict": true, "esModuleInterop": true From ef05990530f5dda5bb2c5f7ed7d077100fde6311 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:09:18 -0400 Subject: [PATCH 03/10] remove yarn pack workaround --- .github/workflows/main.yml | 5 ----- package.json | 2 +- test/package.json | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf7a1c01..096bd331 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,14 +39,9 @@ jobs: - run: yarn build - - name: Generate package archive - run: yarn pack - - name: Install dependencies for testing run: yarn install working-directory: test - env: - YARN_ENABLE_IMMUTABLE_INSTALLS: false - name: Test working-directory: test diff --git a/package.json b/package.json index d6402132..451021d7 100755 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "compile": "tsc", "build": "rm -rf dist && yarn run clean && yarn run compile", - "test": "yarn test/ install && yarn test/ add-package && yarn test/ test", + "test": "yarn test/ install && yarn test/ test", "release": "changelogen --release --push", "--------------": "", "format": "prettier --write .", diff --git a/test/package.json b/test/package.json index 595d648c..e460c70f 100755 --- a/test/package.json +++ b/test/package.json @@ -4,7 +4,6 @@ "scripts": { "test": "jest", "g:ts-node": "cd $INIT_CWD && ts-node", - "add-package": "yarn ../ pack && yarn add ../package.tgz", "postinstall": "node prepare.mjs" }, "devDependencies": { From 6c0f3a53434f467b6948a5acfb7a9474942e4265 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:21:40 -0400 Subject: [PATCH 04/10] symlink ts-node --- test/prepare.mjs | 49 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/test/prepare.mjs b/test/prepare.mjs index 699747fb..6bb42a1d 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -1,33 +1,44 @@ // @ts-check import { existsSync } from "node:fs"; +import { symlink } from "node:fs/promises"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { patch } from "ts-patch"; -import { patch as _patch } from "tsp1"; -import { patch as __patch } from "tsp2"; +import { patch as patch1 } from "tsp1"; +import { patch as patch2 } from "tsp2"; const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules -/* ****************************************************************************************************************** * - * Config - * ****************************************************************************************************************** */ +async function symlinkTsNode() { + const target = resolve(__dirname, "node_modules/ts-node"); + const path = resolve(__dirname, "../node_modules/ts-node"); -const rootDir = __dirname; -const tsDirs = ["typescript-three", "typescript-four-seven", "typescript"]; + if (!existsSync(path)) await symlink(target, path); +} + +function patchTsModules() { + /* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + const rootDir = __dirname; + const tsDirs = ["typescript-three", "typescript-four-seven", "typescript"]; + /* ****************************************************************************************************************** * + * Patch TS Modules + * ****************************************************************************************************************** */ -/* ****************************************************************************************************************** * - * Patch TS Modules - * ****************************************************************************************************************** */ + const baseDirs = new Map(); -const baseDirs = new Map(); + for (const tsDirName of tsDirs) { + const mainDir = resolve(rootDir, "node_modules", tsDirName); + if (!existsSync(join(mainDir, "lib-backup"))) baseDirs.set(tsDirName, mainDir); + } -for (const tsDirName of tsDirs) { - const mainDir = resolve(rootDir, "node_modules", tsDirName); - if (!existsSync(join(mainDir, "lib-backup"))) baseDirs.set(tsDirName, mainDir); + // Patch discovered modules + for (const [dirName, dir] of baseDirs) + if (dirName === "typescript-three") patch1(["tsc.js", "typescript.js"], { basedir: dir }); + else if (dirName === "typescript-four-seven") patch2(["tsc.js", "typescript.js"], { dir }); + else patch(["tsc.js", "typescript.js"], { dir }); } -// Patch discovered modules -for (const [dirName, dir] of baseDirs) - if (dirName === "typescript-three") _patch(["tsc.js", "typescript.js"], { basedir: dir }); - else if (dirName === "typescript-four-seven") __patch(["tsc.js", "typescript.js"], { dir }); - else patch(["tsc.js", "typescript.js"], { dir }); +patchTsModules(); +await symlinkTsNode(); From eaadb7721007dad29d189641e4cb5db09c49eb59 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:26:25 -0400 Subject: [PATCH 05/10] update package.json --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 451021d7..08d3bab8 100755 --- a/package.json +++ b/package.json @@ -6,14 +6,14 @@ "types": "types/index.d.ts", "scripts": { "compile": "tsc", - "build": "rm -rf dist && yarn run clean && yarn run compile", - "test": "yarn test/ install && yarn test/ test", + "build": "rm -rf dist && yarn compile", + "test": "yarn test/ test", "release": "changelogen --release --push", "--------------": "", "format": "prettier --write .", - "clean": "rm -rf dist \"**/*.tsbuildinfo\" ./test/projects/nx/dist", - "clean:all": "yarn run clean && rm -rf node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock", - "reset": "yarn run clean:all && yarn install && yarn build", + "clean": "rm -rf ./test/projects/nx/dist", + "clean:all": "yarn clean && rm -rf node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock", + "reset": "yarn clean:all && yarn install && yarn build", "-------------- ": "", "prepack": "yarn build" }, From c41b542813642b30ad6aaf859c790e045736c7fd Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:27:45 -0400 Subject: [PATCH 06/10] update --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 08d3bab8..95fc81e8 100755 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "types": "types/index.d.ts", "scripts": { "compile": "tsc", - "build": "rm -rf dist && yarn compile", + "build": "yarn clean && yarn compile", "test": "yarn test/ test", "release": "changelogen --release --push", "--------------": "", "format": "prettier --write .", - "clean": "rm -rf ./test/projects/nx/dist", + "clean": "rm -rf \"**/dist\"", "clean:all": "yarn clean && rm -rf node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock", "reset": "yarn clean:all && yarn install && yarn build", "-------------- ": "", From de632f92f2c6449466bc39d523c5531fe8725209 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:30:02 -0400 Subject: [PATCH 07/10] add comment explaining why we need to symlink --- test/prepare.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/prepare.mjs b/test/prepare.mjs index 6bb42a1d..d1ed0111 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -10,6 +10,9 @@ import { patch as patch2 } from "tsp2"; const __dirname = dirname(fileURLToPath(import.meta.url)); // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules async function symlinkTsNode() { + // we need to patch the root package node_modules in order for it to locate ts-node for the register tests. + // installing ts-node as a depenency in the root is not an option since it would create two copies of ts-node + // thus messing with the mocks in the tests const target = resolve(__dirname, "node_modules/ts-node"); const path = resolve(__dirname, "../node_modules/ts-node"); From 052b0dcc64ff352acc908f8642ee919cd635df94 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:32:11 -0400 Subject: [PATCH 08/10] use junction linking for windows --- test/prepare.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/prepare.mjs b/test/prepare.mjs index d1ed0111..9a6e9b49 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -16,7 +16,7 @@ async function symlinkTsNode() { const target = resolve(__dirname, "node_modules/ts-node"); const path = resolve(__dirname, "../node_modules/ts-node"); - if (!existsSync(path)) await symlink(target, path); + if (!existsSync(path)) await symlink(target, path, "function"); } function patchTsModules() { From f214bb1b7aae45012e1504441f31d495fdc70b7b Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:33:11 -0400 Subject: [PATCH 09/10] fix typo --- test/prepare.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/prepare.mjs b/test/prepare.mjs index 9a6e9b49..e4574919 100755 --- a/test/prepare.mjs +++ b/test/prepare.mjs @@ -16,7 +16,7 @@ async function symlinkTsNode() { const target = resolve(__dirname, "node_modules/ts-node"); const path = resolve(__dirname, "../node_modules/ts-node"); - if (!existsSync(path)) await symlink(target, path, "function"); + if (!existsSync(path)) await symlink(target, path, "junction"); } function patchTsModules() { From b4a4601fab8f6b5e76322c1cde8f3f39fd576afb Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 00:36:25 -0400 Subject: [PATCH 10/10] remove package.tgz from .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index b6516936..6cfcd46f 100644 --- a/.gitignore +++ b/.gitignore @@ -75,5 +75,3 @@ fabric.properties # Editor-based Rest Client .idea/httpRequests - -package.tgz