From bd370238473bb4b27d984d110ffd13e87e06e8bf Mon Sep 17 00:00:00 2001 From: Fleny Date: Fri, 22 Aug 2025 19:48:28 +0200 Subject: [PATCH] ESM-only build (#4227) Co-authored-by: Link --- package.json | 2 +- packages/benchmarks/package.json | 11 +++-------- packages/bot/package.json | 12 +++--------- packages/discordeno/package.json | 12 +++--------- packages/gateway/package.json | 12 +++--------- packages/rest/package.json | 12 +++--------- packages/types/package.json | 12 +++--------- packages/utils/package.json | 12 +++--------- scripts/fixCjsExtension.js | 12 ------------ turbo.json | 2 +- 10 files changed, 23 insertions(+), 76 deletions(-) delete mode 100644 scripts/fixCjsExtension.js diff --git a/package.json b/package.json index 2955fe705..2d7d3c6c7 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "typescript": "^5.9.2" }, "engines": { - "node": ">=18.0.0" + "node": ">=20.19.0" }, "lint-staged": { "*": "biome check --no-errors-on-unmatched --write" diff --git a/packages/benchmarks/package.json b/packages/benchmarks/package.json index 4506a1101..7439cbd72 100644 --- a/packages/benchmarks/package.json +++ b/packages/benchmarks/package.json @@ -2,12 +2,7 @@ "name": "benchmarks", "version": "0.0.0", "private": true, - "main": "./dist/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "import": "./dist/index.js", - "types": "./dist/types/index.d.ts" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -15,10 +10,10 @@ "url": "git+https://github.com/discordeno/discordeno.git" }, "scripts": { - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", - "build": "swc src --strip-leading-paths --delete-dir-on-start --out-dir dist", "build-message": "swc src/generateMessage.ts --strip-leading-paths -C sourceMaps=false --out-dir ../../scripts", "bench": "node dist/index.js" }, diff --git a/packages/bot/package.json b/packages/bot/package.json index 34a624be1..aae2aadf1 100644 --- a/packages/bot/package.json +++ b/packages/bot/package.json @@ -1,13 +1,7 @@ { "name": "@discordeno/bot", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'", diff --git a/packages/discordeno/package.json b/packages/discordeno/package.json index 6d13bec52..c4faa4109 100644 --- a/packages/discordeno/package.json +++ b/packages/discordeno/package.json @@ -1,13 +1,7 @@ { "name": "discordeno", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'", diff --git a/packages/gateway/package.json b/packages/gateway/package.json index 9cb884cd3..eb18b6f0d 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -1,13 +1,7 @@ { "name": "@discordeno/gateway", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'", diff --git a/packages/rest/package.json b/packages/rest/package.json index cfd125ba3..ee5ea7c7d 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,13 +1,7 @@ { "name": "@discordeno/rest", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'", diff --git a/packages/types/package.json b/packages/types/package.json index 038892979..e3275ebee 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,13 +1,7 @@ { "name": "@discordeno/types", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'", diff --git a/packages/utils/package.json b/packages/utils/package.json index 2054efcd7..fb8b0b635 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,13 +1,7 @@ { "name": "@discordeno/utils", "version": "21.0.0", - "main": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", - "exports": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.cjs" - }, + "exports": "./dist/index.js", "type": "module", "license": "Apache-2.0", "repository": { @@ -19,8 +13,8 @@ "!dist/.tsbuildinfo" ], "scripts": { - "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist/esm && swc --strip-leading-paths --delete-dir-on-start src --out-dir dist/cjs -C module.type=commonjs && node ../../scripts/fixCjsExtension.js", - "build:type": "tsc --skipDefaultLibCheck --declaration --emitDeclarationOnly --declarationDir dist/types", + "build": "swc src --strip-leading-paths --delete-dir-on-start src --out-dir dist", + "build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist", "release-build": "yarn build && yarn build:type", "check": "biome check --write", "test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'", diff --git a/scripts/fixCjsExtension.js b/scripts/fixCjsExtension.js deleted file mode 100644 index 680ca975e..000000000 --- a/scripts/fixCjsExtension.js +++ /dev/null @@ -1,12 +0,0 @@ -import { readdir, readFile, rm, writeFile } from 'node:fs/promises' - -const files = await readdir('dist/cjs', { recursive: true }) -const promises = files - .filter((f) => f.endsWith('.js')) - .map(async (file) => { - const content = await readFile(`dist/cjs/${file}`, 'utf-8') - await rm(`dist/cjs/${file}`) - await writeFile(`dist/cjs/${file.slice(0, -3)}.cjs`, content.replace(/\.js(?!on)/g, '.cjs')) - }) - -await Promise.all(promises) diff --git a/turbo.json b/turbo.json index a65608828..48e5c9456 100644 --- a/turbo.json +++ b/turbo.json @@ -7,7 +7,7 @@ }, "build:type": { "dependsOn": ["^build:type"], - "outputs": ["dist/types/**/*.d.ts", "dist/types/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"] + "outputs": ["dist/**/*.d.ts", "dist/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"] }, "test:unit-coverage": { "dependsOn": ["^build"],