Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove yarn pack workaround #232

Merged
merged 10 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ fabric.properties

# Editor-based Rest Client
.idea/httpRequests

package.tgz
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/*"
Expand Down
29 changes: 0 additions & 29 deletions test/prepare.js

This file was deleted.

47 changes: 47 additions & 0 deletions test/prepare.mjs
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 2 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "../tsconfig.base",
"extends": "@tsconfig/node18",
"include": ["tests", "utils"],

"compilerOptions": {
"types": ["jest", "node"],
"noEmit": true,
"strict": true,
"esModuleInterop": true
Expand Down
19 changes: 13 additions & 6 deletions test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down