Skip to content

Commit d8ad753

Browse files
authored
Convert a few more workspaces to ESM (#428)
1 parent 220f83a commit d8ad753

File tree

12 files changed

+52
-25
lines changed

12 files changed

+52
-25
lines changed

workspaces/adventure-pack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"goodies:typescript:install": "yarn",
4949
"goodies:typescript:test": "jest --color goodies/typescript",
5050
"build-app": "tsx src/scripts/build/main.ts",
51-
"build-chrome-extension": "ts-node src/scripts/build/buildChromeExtension.ts",
52-
"package-goodies:test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --color --testPathIgnorePatterns=\"/goodies/\"",
51+
"build-chrome-extension": "tsx src/scripts/build/buildChromeExtension.ts",
52+
"package-goodies:test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --color --testPathIgnorePatterns=\"/goodies/\"",
5353
"format": "yarn goodies:java:format && yarn goodies:kotlin:format && yarn goodies:python3:format && yarn goodies:typescript:format && prettier --color --write .",
5454
"lint": "eslint --color --max-warnings=0 .",
5555
"postinstall": "yarn goodies:java:install && yarn goodies:kotlin:install && yarn goodies:python3:install",
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import process from "node:process";
2+
3+
import { isStringEmptyOrWhitespaceOnly } from "@code-chronicles/util/isStringEmptyOrWhitespaceOnly";
14
import { spawnWithSafeStdio } from "@code-chronicles/util/spawnWithSafeStdio";
25

36
export async function runWebpack(): Promise<void> {
4-
await spawnWithSafeStdio("webpack", ["--color"]);
7+
await spawnWithSafeStdio("webpack", ["--color"], {
8+
env: {
9+
...process.env,
10+
NODE_OPTIONS: ["--import tsx", process.env.NODE_OPTIONS ?? ""]
11+
.filter((opt) => !isStringEmptyOrWhitespaceOnly(opt))
12+
.join(" "),
13+
},
14+
});
515
}

workspaces/adventure-pack/webpack.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const config: Configuration = {
3737

3838
resolve: {
3939
extensions: [".tsx", ".ts", "..."],
40+
extensionAlias: {
41+
".js": [".ts", ".tsx", ".js"],
42+
},
4043
},
4144

4245
plugins: [

workspaces/chrome-extension-hello-world/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
"url": "https://github.com/code-chronicles-code/leetcode-curriculum.git",
88
"directory": "workspaces/chrome-extension-hello-world"
99
},
10-
"main": "src/main.ts",
10+
"type": "module",
11+
"exports": "./src/main.ts",
1112
"scripts": {
12-
"build": "webpack",
13+
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
1314
"format": "prettier --color --write .",
1415
"lint": "eslint --color --max-warnings=0 .",
1516
"typecheck": "tsc --pretty --project ."
1617
},
1718
"devDependencies": {
1819
"@code-chronicles/eslint-config": "workspace:*",
1920
"@types/node": "22.5.5",
21+
"cross-env": "7.0.3",
2022
"prettier": "3.3.3",
2123
"ts-loader": "9.5.1",
24+
"tsx": "4.19.1",
2225
"typescript": "5.6.2",
2326
"webpack": "5.94.0",
2427
"webpack-cli": "5.1.4"

workspaces/chrome-extension-hello-world/webpack.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import path from "node:path";
22

33
import type { Configuration } from "webpack";
44

5-
import packageJson from "./package.json";
5+
import packageJson from "./package.json" with { type: "module" };
66

77
const config: Configuration = {
88
target: "web",
9-
entry: path.resolve(__dirname, packageJson.main),
9+
entry: path.resolve(__dirname, packageJson.exports),
1010
output: {
1111
filename: "[name].js",
1212
path: path.resolve(__dirname, "dist"),
@@ -33,6 +33,9 @@ const config: Configuration = {
3333

3434
resolve: {
3535
extensions: [".tsx", ".ts", "..."],
36+
extensionAlias: {
37+
".js": [".ts", ".tsx", ".js"],
38+
},
3639
},
3740

3841
optimization: {

workspaces/generate-health-report/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
"name": "Miorel-Lucian Palii",
1313
"url": "https://github.com/miorel"
1414
},
15+
"type": "module",
1516
"scripts": {
1617
"format": "prettier --color --write .",
1718
"lint": "eslint --color --max-warnings=0 .",
18-
"start": "ts-node src/main.ts",
19+
"start": "tsx src/main.ts",
1920
"typecheck": "tsc --pretty --project ."
2021
},
2122
"dependencies": {
2223
"@code-chronicles/util": "workspace:*",
23-
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch"
24+
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
25+
"tsx": "4.19.1"
2426
},
2527
"devDependencies": {
2628
"@code-chronicles/eslint-config": "workspace:*",
2729
"@types/node": "22.5.5",
2830
"eslint": "9.10.0",
2931
"prettier": "3.3.3",
30-
"ts-node": "10.9.2",
3132
"typescript": "5.6.2"
3233
}
3334
}

workspaces/javascript-leetcode-month/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
"name": "Miorel-Lucian Palii",
1313
"url": "https://github.com/miorel"
1414
},
15+
"type": "module",
1516
"scripts": {
1617
"format": "prettier --color --write .",
1718
"lint": "eslint --color --max-warnings=0 .",
18-
"prep-write-up-for-leetcode": "ts-node scripts/prep-write-up-for-leetcode.ts",
19+
"prep-write-up-for-leetcode": "tsx scripts/prep-write-up-for-leetcode.ts",
1920
"typecheck": "tsc --pretty --project ."
2021
},
2122
"devDependencies": {
@@ -27,7 +28,7 @@
2728
"mdast": "3.0.0",
2829
"prettier": "3.3.3",
2930
"remark": "15.0.1",
30-
"ts-node": "10.9.2",
31+
"tsx": "4.19.1",
3132
"typescript": "5.6.2",
3233
"unist-util-visit": "5.0.0"
3334
}

workspaces/javascript-leetcode-month/scripts/prep-write-up-for-leetcode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFile } from "node:fs/promises";
22
import process from "node:process";
33

4-
import { processWriteUpForLeetCode } from "./processWriteUpForLeetCode";
4+
import { processWriteUpForLeetCode } from "./processWriteUpForLeetCode.js";
55

66
async function main(): Promise<void> {
77
const [, , file] = process.argv as (string | undefined)[];

workspaces/repository-scripts/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
"name": "Miorel-Lucian Palii",
1313
"url": "https://github.com/miorel"
1414
},
15+
"type": "module",
1516
"scripts": {
1617
"format": "prettier --color --write .",
1718
"lint": "eslint --color --max-warnings=0 .",
18-
"start": "ts-node src/main.ts",
19+
"start": "tsx src/main.ts",
1920
"typecheck": "tsc --pretty --project ."
2021
},
2122
"dependencies": {
2223
"@code-chronicles/util": "workspace:*",
23-
"ts-node": "10.9.2"
24+
"tsx": "4.19.1"
2425
},
2526
"devDependencies": {
2627
"@code-chronicles/eslint-config": "workspace:*",
2728
"@types/node": "22.5.5",
2829
"eslint": "9.10.0",
2930
"prettier": "3.3.3",
30-
"ts-node": "10.9.2",
3131
"type-fest": "4.26.1",
3232
"typescript": "5.6.2"
3333
}

workspaces/repository-scripts/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from "node:process";
22

3-
import { runCommands } from "./runCommands";
4-
import { SCRIPTS, isScript } from "./scripts";
3+
import { runCommands } from "./runCommands.js";
4+
import { SCRIPTS, isScript } from "./scripts.js";
55

66
async function main() {
77
if (process.argv.length < 3) {

0 commit comments

Comments
 (0)