Skip to content

Commit

Permalink
build: Generate .d.mts files
Browse files Browse the repository at this point in the history
Fix the issue that `@kosko/env` cannot be resolved correctly
when `moduleResolution=nodenext` is set in `tsconfig.json`.

microsoft/TypeScript#50058
  • Loading branch information
tommy351 committed Apr 5, 2023
1 parent f1e0bb7 commit addb05c
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 37 deletions.
16 changes: 15 additions & 1 deletion internal/build-scripts/bin/build-scripts.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -192,4 +205,5 @@ await Promise.all([
await execa(tsc, ["--outDir", distDir]);
await mkdir(fullOutPath, { recursive: true });
await runApiExtractor();
await copyEsmDts();
await generatePack();
11 changes: 9 additions & 2 deletions internal/jest-serializer-path/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 9 additions & 2 deletions internal/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/aggregate-error/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AggregateError as default } from "./dist/index.d";
12 changes: 10 additions & 2 deletions packages/aggregate-error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
Expand Down
11 changes: 9 additions & 2 deletions packages/common-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/exec-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/generate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/helm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/kustomize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/require/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions packages/template-deployed-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 9 additions & 2 deletions packages/template-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading

0 comments on commit addb05c

Please sign in to comment.