From 69729f869caa8f89c88ff29b8675467e0826000d Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Thu, 6 Apr 2023 06:48:23 +1000 Subject: [PATCH] build: Generate `.d.mts` files Fix the issue that `@kosko/env` cannot be resolved correctly when `moduleResolution=nodenext` is set in `tsconfig.json`. https://github.com/microsoft/TypeScript/issues/50058 --- .changeset/yellow-dots-add.md | 20 +++++++++++++++++++ internal/build-scripts/bin/build-scripts.js | 16 ++++++++++++++- internal/jest-serializer-path/package.json | 11 ++++++++-- internal/test-utils/package.json | 11 ++++++++-- packages/aggregate-error/index.d.mts | 1 + packages/aggregate-error/package.json | 12 +++++++++-- packages/cli/package.json | 11 ++++++++-- packages/common-utils/package.json | 11 ++++++++-- packages/config/package.json | 11 ++++++++-- packages/env/package.json | 11 ++++++++-- packages/exec-utils/package.json | 11 ++++++++-- packages/generate/package.json | 11 ++++++++-- packages/helm/package.json | 11 ++++++++-- packages/kustomize/package.json | 11 ++++++++-- packages/log/package.json | 11 ++++++++-- packages/migrate/package.json | 11 ++++++++-- packages/require/package.json | 11 ++++++++-- .../template-deployed-service/package.json | 11 ++++++++-- packages/template-environment/package.json | 11 ++++++++-- packages/template/package.json | 11 ++++++++-- packages/yaml/package.json | 11 ++++++++-- 21 files changed, 199 insertions(+), 37 deletions(-) create mode 100644 .changeset/yellow-dots-add.md create mode 100644 packages/aggregate-error/index.d.mts diff --git a/.changeset/yellow-dots-add.md b/.changeset/yellow-dots-add.md new file mode 100644 index 000000000..d13f9c28e --- /dev/null +++ b/.changeset/yellow-dots-add.md @@ -0,0 +1,20 @@ +--- +"@kosko/aggregate-error": minor +"@kosko/cli": minor +"@kosko/common-utils": minor +"@kosko/config": minor +"@kosko/env": minor +"@kosko/exec-utils": minor +"@kosko/generate": minor +"@kosko/helm": minor +"@kosko/kustomize": minor +"@kosko/log": minor +"@kosko/migrate": minor +"@kosko/require": minor +"@kosko/template": minor +"@kosko/template-deployed-service": minor +"@kosko/template-environment": minor +"@kosko/yaml": minor +--- + +Support TypeScript `nodenext` module resolution. diff --git a/internal/build-scripts/bin/build-scripts.js b/internal/build-scripts/bin/build-scripts.js index 097c79674..2d558f757 100755 --- a/internal/build-scripts/bin/build-scripts.js +++ b/internal/build-scripts/bin/build-scripts.js @@ -1,7 +1,7 @@ #!/usr/bin/env node // @ts-check -import { mkdir, readFile, rm, unlink } from "node:fs/promises"; +import { copyFile, mkdir, readFile, rm, unlink } from "node:fs/promises"; import { join, normalize } from "node:path"; import { rollup } from "rollup"; import nodeResolve from "@rollup/plugin-node-resolve"; @@ -149,6 +149,19 @@ async function runApiExtractor() { } } +async function copyEsmDts() { + const paths = await globby("**/*.d.ts", { + cwd: join(cwd, "dist"), + absolute: true + }); + + for (const path of paths) { + const dst = path.replace(/\.d\.ts$/, ".d.mts"); + console.log("Copying:", dst); + await copyFile(path, dst); + } +} + async function generatePack() { await execa("pnpm", ["pack", "--pack-destination", fullOutPath]); } @@ -192,4 +205,5 @@ await Promise.all([ await execa(tsc, ["--outDir", distDir]); await mkdir(fullOutPath, { recursive: true }); await runApiExtractor(); +await copyEsmDts(); await generatePack(); diff --git a/internal/jest-serializer-path/package.json b/internal/jest-serializer-path/package.json index a1714e5d5..9afd884aa 100644 --- a/internal/jest-serializer-path/package.json +++ b/internal/jest-serializer-path/package.json @@ -14,11 +14,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "dependencies": { diff --git a/internal/test-utils/package.json b/internal/test-utils/package.json index 65088c508..b1c48f089 100644 --- a/internal/test-utils/package.json +++ b/internal/test-utils/package.json @@ -14,11 +14,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "dependencies": { diff --git a/packages/aggregate-error/index.d.mts b/packages/aggregate-error/index.d.mts new file mode 100644 index 000000000..b2a41529b --- /dev/null +++ b/packages/aggregate-error/index.d.mts @@ -0,0 +1 @@ +export { AggregateError as default } from "./dist/index.d"; diff --git a/packages/aggregate-error/package.json b/packages/aggregate-error/package.json index 789c60eca..490b70751 100644 --- a/packages/aggregate-error/package.json +++ b/packages/aggregate-error/package.json @@ -14,17 +14,25 @@ "files": [ "dist", "index.d.ts", + "index.d.mts", "index.browser.mjs", "index.node.cjs", "index.node.mjs" ], "exports": { "node": { - "import": "./index.node.mjs", + "import": { + "types": "./index.d.mts", + "default": "./index.node.mjs" + }, + "types": "./index.d.ts", "require": "./index.node.cjs" }, + "import": { + "types": "./index.d.mts", + "default": "./index.browser.mjs" + }, "types": "./index.d.ts", - "import": "./index.browser.mjs", "require": "./index.node.cjs" }, "scripts": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 162911d7f..4558d16e0 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -20,11 +20,18 @@ "./bin/kosko.js": "./bin/kosko.js", ".": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" } }, diff --git a/packages/common-utils/package.json b/packages/common-utils/package.json index 8afb41e36..1f7d02379 100644 --- a/packages/common-utils/package.json +++ b/packages/common-utils/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/config/package.json b/packages/config/package.json index 2931837bc..ba5a36144 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/env/package.json b/packages/env/package.json index 82b74b24b..bcd86ef81 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -16,11 +16,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./index.node.cjs" }, "files": [ diff --git a/packages/exec-utils/package.json b/packages/exec-utils/package.json index ae621bf83..27ab67ea0 100644 --- a/packages/exec-utils/package.json +++ b/packages/exec-utils/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/generate/package.json b/packages/generate/package.json index 2b27462a2..506a372b4 100644 --- a/packages/generate/package.json +++ b/packages/generate/package.json @@ -16,11 +16,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/helm/package.json b/packages/helm/package.json index 53143d059..edfbbc0ed 100644 --- a/packages/helm/package.json +++ b/packages/helm/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/kustomize/package.json b/packages/kustomize/package.json index aa87ed220..e05e6a91c 100644 --- a/packages/kustomize/package.json +++ b/packages/kustomize/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/log/package.json b/packages/log/package.json index c7a393de4..a893254bc 100644 --- a/packages/log/package.json +++ b/packages/log/package.json @@ -16,11 +16,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/migrate/package.json b/packages/migrate/package.json index 3faedb20d..86de7312c 100644 --- a/packages/migrate/package.json +++ b/packages/migrate/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/require/package.json b/packages/require/package.json index 7e572e4a1..ae076f167 100644 --- a/packages/require/package.json +++ b/packages/require/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/template-deployed-service/package.json b/packages/template-deployed-service/package.json index de4973e93..0638ee13b 100644 --- a/packages/template-deployed-service/package.json +++ b/packages/template-deployed-service/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "bin": { diff --git a/packages/template-environment/package.json b/packages/template-environment/package.json index 8579bf0d1..877e78819 100644 --- a/packages/template-environment/package.json +++ b/packages/template-environment/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "bin": { diff --git a/packages/template/package.json b/packages/template/package.json index 488528bab..894c78871 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [ diff --git a/packages/yaml/package.json b/packages/yaml/package.json index 3c448ef39..19e28c217 100644 --- a/packages/yaml/package.json +++ b/packages/yaml/package.json @@ -15,11 +15,18 @@ }, "exports": { "node": { - "import": "./dist/index.node.mjs", + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.node.mjs" + }, + "types": "./dist/types.d.ts", "require": "./dist/index.node.cjs" }, + "import": { + "types": "./dist/types.d.mts", + "default": "./dist/index.base.mjs" + }, "types": "./dist/types.d.ts", - "import": "./dist/index.base.mjs", "require": "./dist/index.node.cjs" }, "files": [