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/.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 diff --git a/package.json b/package.json index d6402132..95fc81e8 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/ add-package && yarn test/ test", + "build": "yarn clean && 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 \"**/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" }, diff --git a/test/package.json b/test/package.json index 5c8ce619..e460c70f 100755 --- a/test/package.json +++ b/test/package.json @@ -4,14 +4,14 @@ "scripts": { "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", "@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 +25,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/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..e4574919 --- /dev/null +++ b/test/prepare.mjs @@ -0,0 +1,47 @@ +// @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 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 + +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"); + + if (!existsSync(path)) await symlink(target, path, "junction"); +} + +function patchTsModules() { + /* ****************************************************************************************************************** * + * 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") 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 }); +} + +patchTsModules(); +await symlinkTsNode(); diff --git a/test/tsconfig.json b/test/tsconfig.json index e40bf64a..527b4629 100755 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,8 +1,9 @@ { - "extends": "../tsconfig.base", + "extends": "@tsconfig/node18", "include": ["tests", "utils"], "compilerOptions": { + "types": ["jest", "node"], "noEmit": true, "strict": true, "esModuleInterop": true 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