Skip to content

Commit

Permalink
chore: move from ts-node to swc-loader
Browse files Browse the repository at this point in the history
fix: integration tests

fix: use swc for both v18 & v20

refactor: remove ts-node
  • Loading branch information
doc-han committed Dec 13, 2024
1 parent 535da76 commit f857884
Show file tree
Hide file tree
Showing 26 changed files with 470 additions and 440 deletions.
77 changes: 58 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ jobs:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
Expand All @@ -20,74 +23,92 @@ jobs:
# See the configuration reference documentation for more details on using restore_cache and save_cache steps
# https://circleci.com/docs/2.0/configuration-reference/?section=reference#save_cache
keys:
- deps-v1-{{ .Branch }}-{{checksum "pnpm-lock.yaml"}}
- deps-v1-{{ .Branch }}-{{checksum "pnpm-lock.yaml"}}-<< parameters.node_version >>
- run:
name: Install
command: pnpm install --frozen-lockfile
- save_cache:
key: deps-v1-{{ .Branch }}-{{checksum "pnpm-lock.yaml"}}
key: deps-v1-{{ .Branch }}-{{checksum "pnpm-lock.yaml"}}-<< parameters.node_version >>
paths:
- node_modules
- run:
name: Ensure workspace exists
command: mkdir -p -m 777 ~/project-<< parameters.node_version >>
- persist_to_workspace:
root: ~/project
root: ~/project-<< parameters.node_version >>
paths:
- .

build:
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
steps:
- attach_workspace:
at: ~/project
at: ~/project-<< parameters.node_version >>
- run:
name: Build packages
command: pnpm build
- persist_to_workspace:
root: ~/project
root: ~/project-<< parameters.node_version >>
paths:
- .

unit_test:
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
steps:
- attach_workspace:
at: ~/project
at: ~/project-<< parameters.node_version >>
- run:
name: Run Tests
command: pnpm test

format:
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
steps:
- attach_workspace:
at: ~/project
at: ~/project-<< parameters.node_version >>
- run:
name: Check formatting
command: pnpm test:format

type_check:
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
steps:
- attach_workspace:
at: ~/project
at: ~/project-<< parameters.node_version >>
- run:
name: Type check
command: pnpm test:types

integration_test:
docker:
- image: cimg/node:18.18
- image: cimg/node:<< parameters.node_version >>
resource_class: medium
parameters:
node_version:
type: string
steps:
- attach_workspace:
at: ~/project
at: ~/project-<< parameters.node_version >>
- run:
name: Build local tarballs
command: pnpm pack:local dist --no-version
Expand All @@ -107,22 +128,40 @@ workflows:
build_and_test:
jobs:
- install:
filters:
branches:
ignore:
- main
matrix:
parameters:
node_version: ["18.18", "20.12"]
filters:
branches:
ignore:
- main
- build:
matrix:
parameters:
node_version: ["18.18", "20.12"]
requires:
- install
- unit_test:
matrix:
parameters:
node_version: ["18.18", "20.12"]
requires:
- build
- type_check:
matrix:
parameters:
node_version: ["18.18", "20.12"]
requires:
- build
- format:
matrix:
parameters:
node_version: ["18.18", "20.12"]
requires:
- build
- integration_test:
matrix:
parameters:
node_version: ["18.18", "20.12"]
requires:
- build
5 changes: 4 additions & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const semver = require("semver")

const loader_arg = semver.lte(process.version, 'v20.5.0') ? '--loader=@swc-node/register/esm' : '--import=@swc-node/register/esm-register'
module.exports = {
extensions: {
ts: 'module',
Expand All @@ -8,7 +11,7 @@ module.exports = {
},

nodeArguments: [
'--loader=ts-node/esm',
loader_arg,
'--no-warnings', // Disable experimental module warnings
'--experimental-vm-modules',
],
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/cli/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import semver from "semver"

const loader_arg = semver.lte(process.version, 'v20.5.0') ? '--loader=@swc-node/register/esm' : '--import=@swc-node/register/esm-register'

export default {
extensions: {
ts: 'module',
Expand All @@ -7,7 +11,7 @@ export default {
TS_NODE_TRANSPILE_ONLY: 'true',
},

nodeArguments: ['--loader=ts-node/esm', '--no-warnings'],
nodeArguments: [loader_arg, '--no-warnings'],

files: ['test/**/*test.ts'],
};
1 change: 0 additions & 1 deletion integration-tests/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"ava": "5.3.1",
"date-fns": "^2.30.0",
"rimraf": "^3.0.2",
"ts-node": "10.8.1",
"tslib": "^2.4.0",
"typescript": "^5.1.6"
},
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ts-node": {
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "es2020",
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/execute/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import semver from "semver"

const loader_arg = semver.lte(process.version, 'v20.5.0') ? '--loader=@swc-node/register/esm' : '--import=@swc-node/register/esm-register'

export default {
extensions: {
ts: 'module',
Expand All @@ -7,7 +11,7 @@ export default {
TS_NODE_TRANSPILE_ONLY: 'true',
},

nodeArguments: ['--loader=ts-node/esm', '--no-warnings', '--experimental-vm-modules'],
nodeArguments: [loader_arg, '--no-warnings', '--experimental-vm-modules'],

files: ['test/**/*test.ts'],
};
1 change: 0 additions & 1 deletion integration-tests/execute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"ava": "5.3.1",
"date-fns": "^2.30.0",
"rimraf": "^3.0.2",
"ts-node": "10.8.1",
"tslib": "^2.4.0",
"typescript": "^5.1.6"
},
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/execute/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ts-node": {
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "es2020",
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/worker/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import semver from "semver"

const loader_arg = semver.lte(process.version, 'v20.5.0') ? '--loader=@swc-node/register/esm' : '--import=@swc-node/register/esm-register'

export default {
extensions: {
ts: 'module',
Expand All @@ -7,7 +11,7 @@ export default {
TS_NODE_TRANSPILE_ONLY: 'true',
},

nodeArguments: ['--loader=ts-node/esm', '--no-warnings'],
nodeArguments: [loader_arg, '--no-warnings'],

files: ['test/**/*test.ts'],
};
1 change: 0 additions & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"date-fns": "^2.30.0",
"koa": "^2.13.4",
"rimraf": "^3.0.2",
"ts-node": "10.8.1",
"tslib": "^2.4.0",
"typescript": "^5.1.6"
},
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ts-node": {
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "es2020",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@slack/web-api": "^6.12.1",
"@swc-node/register": "^1.10.9",
"@types/gunzip-maybe": "^1.4.0",
"@types/rimraf": "^3.0.2",
"@types/tar-stream": "^2.2.2",
"gunzip-maybe": "^1.4.2",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"semver": "^7.5.4",
"tar-stream": "^3.0.0",
"typesync": "^0.13.0"
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"@types/ws": "^8.5.10",
"@types/yargs": "^17.0.24",
"ava": "5.3.1",
"mock-fs": "^5.1.4",
"ts-node": "^10.9.1",
"mock-fs": "^5.4.1",
"tslib": "^2.4.0",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
Expand Down
5 changes: 2 additions & 3 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
"test:types": "pnpm tsc --noEmit --project tsconfig.json",
"build": "tsup --config ../../tsup.config.js src/index.ts",
"build:watch": "pnpm build --watch",
"parse": "ts-node-esm src/cli/parse.ts",
"parse": "node --loader @swc-node/register/esm src/cli/parse.ts",
"pack": "pnpm pack --pack-destination ../../dist"
},
"keywords": [],
"devDependencies": {
"@types/node": "^18.15.13",
"@types/yargs": "^17.0.24",
"ava": "5.3.1",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tsup": "^7.2.0",
"typescript": "^5.1.6",
Expand All @@ -50,4 +49,4 @@
"dist",
"README.md"
]
}
}
1 change: 0 additions & 1 deletion packages/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ava": "5.3.1",
"jsonpath": "^1.1.1",
"mock-fs": "^5.1.4",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
Expand Down
3 changes: 2 additions & 1 deletion packages/deploy/src/stateTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ function idKeyPairs<P extends { id: string }, S extends { id: string }>(
stateItems: Record<keyof S, S>
): [key: string, projectItem: P, stateItem: S][] {
let pairs: [string, P, S][] = [];
for (const projectItem of projectItems) {
for (let i = 0; i < projectItems.length; i++) {
const projectItem = projectItems[i];
for (const [key, stateItem] of Object.entries(stateItems)) {
if (projectItem.id === stateItem.id) {
pairs.push([key, projectItem, stateItem]);
Expand Down
1 change: 0 additions & 1 deletion packages/describe-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"esbuild": "^0.18.14",
"rimraf": "^3.0.2",
"threads": "1.7.0",
"ts-node": "^10.9.2",
"tslib": "^2.4.0",
"tsm": "^2.2.1",
"tsup": "^7.2.0"
Expand Down
1 change: 0 additions & 1 deletion packages/engine-multi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"devDependencies": {
"@types/node": "^18.15.13",
"ava": "5.3.1",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tsm": "^2.2.2",
"tsup": "^7.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test:types": "pnpm tsc --noEmit --project tsconfig.json",
"build": "tsup --config ../../tsup.config.js src/index.ts --no-splitting",
"build:watch": "pnpm build --watch",
"start": "ts-node-esm --transpile-only src/start.ts",
"start": "node --loader @swc-node/register/esm src/start.ts",
"pack": "pnpm pack --pack-destination ../../dist"
},
"author": "Open Function Group <admin@openfn.org>",
Expand Down Expand Up @@ -45,7 +45,6 @@
"koa-route": "^3.2.0",
"koa-websocket": "^7.0.0",
"query-string": "^8.1.0",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tsup": "^6.2.3",
"typescript": "^4.6.4",
Expand Down
1 change: 0 additions & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"devDependencies": {
"@types/node": "^18.15.13",
"ava": "5.3.1",
"ts-node": "10.8.1",
"tslib": "^2.4.0",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/memtest.ava.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},

nodeArguments: [
'--loader=ts-node/esm',
'--loader=@swc-node/register/esm',
'--no-warnings',
'--experimental-vm-modules',
'--expose-gc',
Expand Down
Loading

0 comments on commit f857884

Please sign in to comment.