Skip to content

Commit a924ed3

Browse files
committed
Fix package types
Fixes #29
1 parent dedc15c commit a924ed3

File tree

13 files changed

+123
-34
lines changed

13 files changed

+123
-34
lines changed

mts-types.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { readFileSync, writeFileSync, readdirSync, unlinkSync } from 'node:fs';
2+
3+
const packagePath = process.cwd();
4+
const typesDir = `${packagePath}/types`;
5+
6+
function rename(path, ext) {
7+
return path.replace(/\.ts(\.map)?$/, `.${ext}$1`);
8+
}
9+
10+
const from = /\bfrom (['"])(\.[^'"]*)\1;/g;
11+
for (const file of readdirSync(typesDir)) {
12+
if (!file.endsWith('.d.ts') && !file.endsWith('.d.ts.map')) continue;
13+
14+
const path = `${typesDir}/${file}`;
15+
const contents = readFileSync(path, 'utf8');
16+
17+
const cts = contents.replace(/^export default/gm, 'export =').replace(from, 'from $1$2.cts$1;');
18+
const mts = contents.replace(from, 'from $1$2.mts$1;');
19+
20+
unlinkSync(path);
21+
writeFileSync(rename(path, 'cts'), cts);
22+
writeFileSync(rename(path, 'mts'), mts);
23+
}

packages/gen-mapping/package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"main": "dist/gen-mapping.umd.js",
1010
"module": "dist/gen-mapping.mjs",
11-
"types": "types/gen-mapping.d.ts",
11+
"types": "types/gen-mapping.d.cts",
1212
"files": [
1313
"dist",
1414
"src",
@@ -17,10 +17,18 @@
1717
"exports": {
1818
".": [
1919
{
20-
"types": "./types/gen-mapping.d.ts",
21-
"browser": "./dist/gen-mapping.umd.js",
22-
"require": "./dist/gen-mapping.umd.js",
23-
"import": "./dist/gen-mapping.mjs"
20+
"browser": {
21+
"types": "./types/gen-mapping.d.cts",
22+
"default": "./dist/gen-mapping.umd.js"
23+
},
24+
"require": {
25+
"types": "./types/gen-mapping.d.cts",
26+
"default": "./dist/gen-mapping.umd.js"
27+
},
28+
"import": {
29+
"types": "./types/gen-mapping.d.mts",
30+
"default": "./dist/gen-mapping.mjs"
31+
}
2432
},
2533
"./dist/gen-mapping.umd.js"
2634
],
@@ -32,7 +40,10 @@
3240
"benchmark:only": "node --expose-gc benchmark/index.js",
3341
"build": "run-s -n build:code build:types",
3442
"build:code": "node ../../esbuild.mjs gen-mapping.ts",
35-
"build:types": "tsc --project tsconfig.build.json",
43+
"build:types": "run-s build:types:force build:types:emit build:types:mts",
44+
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
45+
"build:types:emit": "tsc --project tsconfig.build.json",
46+
"build:types:mts": "node ../../mts-types.mjs",
3647
"clean": "run-s -n clean:code clean:types",
3748
"clean:code": "tsc --build --clean tsconfig.build.json",
3849
"clean:types": "rimraf dist types",

packages/gen-mapping/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"allowImportingTsExtensions": true,
5+
"emitDeclarationOnly": true,
46
"declarationDir": "types",
57
"outDir": "dist"
68
},

packages/remapping/package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"main": "dist/remapping.umd.js",
1111
"module": "dist/remapping.mjs",
12-
"types": "types/remapping.d.ts",
12+
"types": "types/remapping.d.cts",
1313
"files": [
1414
"dist",
1515
"src",
@@ -18,10 +18,18 @@
1818
"exports": {
1919
".": [
2020
{
21-
"types": "./types/remapping.d.ts",
22-
"browser": "./dist/remapping.umd.js",
23-
"require": "./dist/remapping.umd.js",
24-
"import": "./dist/remapping.mjs"
21+
"browser": {
22+
"types": "./types/remapping.d.cts",
23+
"default": "./dist/remapping.umd.js"
24+
},
25+
"require": {
26+
"types": "./types/remapping.d.cts",
27+
"default": "./dist/remapping.umd.js"
28+
},
29+
"import": {
30+
"types": "./types/remapping.d.mts",
31+
"default": "./dist/remapping.mjs"
32+
}
2533
},
2634
"./dist/remapping.umd.js"
2735
],
@@ -33,7 +41,10 @@
3341
"benchmark:only": "node --expose-gc benchmark/index.js",
3442
"build": "run-s -n build:code build:types",
3543
"build:code": "node ../../esbuild.mjs remapping.ts",
36-
"build:types": "tsc --project tsconfig.build.json",
44+
"build:types": "run-s build:types:force build:types:emit build:types:mts",
45+
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
46+
"build:types:emit": "tsc --project tsconfig.build.json",
47+
"build:types:mts": "node ../../mts-types.mjs",
3748
"clean": "run-s -n clean:code clean:types",
3849
"clean:code": "tsc --build --clean tsconfig.build.json",
3950
"clean:types": "rimraf dist types",

packages/remapping/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"allowImportingTsExtensions": true,
5+
"emitDeclarationOnly": true,
46
"declarationDir": "types",
57
"outDir": "dist"
68
},

packages/source-map/package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"main": "dist/source-map.umd.js",
1111
"module": "dist/source-map.mjs",
12-
"types": "types/source-map.d.ts",
12+
"types": "types/source-map.d.cts",
1313
"files": [
1414
"dist",
1515
"src",
@@ -18,10 +18,18 @@
1818
"exports": {
1919
".": [
2020
{
21-
"types": "./types/source-map.d.ts",
22-
"browser": "./dist/source-map.umd.js",
23-
"require": "./dist/source-map.umd.js",
24-
"import": "./dist/source-map.mjs"
21+
"browser": {
22+
"types": "./types/source-map.d.cts",
23+
"default": "./dist/source-map.umd.js"
24+
},
25+
"require": {
26+
"types": "./types/source-map.d.cts",
27+
"default": "./dist/source-map.umd.js"
28+
},
29+
"import": {
30+
"types": "./types/source-map.d.mts",
31+
"default": "./dist/source-map.mjs"
32+
}
2533
},
2634
"./dist/source-map.umd.js"
2735
],
@@ -33,7 +41,10 @@
3341
"benchmark:only": "node --expose-gc benchmark/index.js",
3442
"build": "run-s -n build:code build:types",
3543
"build:code": "node ../../esbuild.mjs source-map.ts",
36-
"build:types": "tsc --project tsconfig.build.json",
44+
"build:types": "run-s build:types:force build:types:emit build:types:mts",
45+
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
46+
"build:types:emit": "tsc --project tsconfig.build.json",
47+
"build:types:mts": "node ../../mts-types.mjs",
3748
"clean": "run-s -n clean:code clean:types",
3849
"clean:code": "tsc --build --clean tsconfig.build.json",
3950
"clean:types": "rimraf dist types",

packages/source-map/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"allowImportingTsExtensions": true,
5+
"emitDeclarationOnly": true,
46
"declarationDir": "types",
57
"outDir": "dist"
68
},

packages/sourcemap-codec/package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"main": "dist/sourcemap-codec.umd.js",
1010
"module": "dist/sourcemap-codec.mjs",
11-
"types": "types/sourcemap-codec.d.ts",
11+
"types": "types/sourcemap-codec.d.cts",
1212
"files": [
1313
"dist",
1414
"src",
@@ -17,10 +17,18 @@
1717
"exports": {
1818
".": [
1919
{
20-
"types": "./types/sourcemap-codec.d.ts",
21-
"browser": "./dist/sourcemap-codec.umd.js",
22-
"require": "./dist/sourcemap-codec.umd.js",
23-
"import": "./dist/sourcemap-codec.mjs"
20+
"browser": {
21+
"types": "./types/sourcemap-codec.d.cts",
22+
"default": "./dist/sourcemap-codec.umd.js"
23+
},
24+
"require": {
25+
"types": "./types/sourcemap-codec.d.cts",
26+
"default": "./dist/sourcemap-codec.umd.js"
27+
},
28+
"import": {
29+
"types": "./types/sourcemap-codec.d.mts",
30+
"default": "./dist/sourcemap-codec.mjs"
31+
}
2432
},
2533
"./dist/sourcemap-codec.umd.js"
2634
],
@@ -32,7 +40,10 @@
3240
"benchmark:only": "node --expose-gc benchmark/index.js",
3341
"build": "run-s -n build:code build:types",
3442
"build:code": "node ../../esbuild.mjs sourcemap-codec.ts",
35-
"build:types": "tsc --project tsconfig.build.json",
43+
"build:types": "run-s build:types:force build:types:emit build:types:mts",
44+
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
45+
"build:types:emit": "tsc --project tsconfig.build.json",
46+
"build:types:mts": "node ../../mts-types.mjs",
3647
"clean": "run-s -n clean:code clean:types",
3748
"clean:code": "tsc --build --clean tsconfig.build.json",
3849
"clean:types": "rimraf dist types",

packages/sourcemap-codec/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"allowImportingTsExtensions": true,
5+
"emitDeclarationOnly": true,
46
"declarationDir": "types",
57
"outDir": "dist"
68
},

packages/trace-mapping/package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"main": "dist/trace-mapping.umd.js",
1010
"module": "dist/trace-mapping.mjs",
11-
"types": "types/trace-mapping.d.ts",
11+
"types": "types/trace-mapping.d.cts",
1212
"files": [
1313
"dist",
1414
"src",
@@ -17,10 +17,18 @@
1717
"exports": {
1818
".": [
1919
{
20-
"types": "./types/trace-mapping.d.ts",
21-
"browser": "./dist/trace-mapping.umd.js",
22-
"require": "./dist/trace-mapping.umd.js",
23-
"import": "./dist/trace-mapping.mjs"
20+
"browser": {
21+
"types": "./types/trace-mapping.d.cts",
22+
"default": "./dist/trace-mapping.umd.js"
23+
},
24+
"require": {
25+
"types": "./types/trace-mapping.d.cts",
26+
"default": "./dist/trace-mapping.umd.js"
27+
},
28+
"import": {
29+
"types": "./types/trace-mapping.d.mts",
30+
"default": "./dist/trace-mapping.mjs"
31+
}
2432
},
2533
"./dist/trace-mapping.umd.js"
2634
],
@@ -32,7 +40,10 @@
3240
"benchmark:only": "node --expose-gc benchmark/index.js",
3341
"build": "run-s -n build:code build:types",
3442
"build:code": "node ../../esbuild.mjs trace-mapping.ts",
35-
"build:types": "tsc --project tsconfig.build.json",
43+
"build:types": "run-s build:types:force build:types:emit build:types:mts",
44+
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
45+
"build:types:emit": "tsc --project tsconfig.build.json",
46+
"build:types:mts": "node ../../mts-types.mjs",
3647
"clean": "run-s -n clean:code clean:types",
3748
"clean:code": "tsc --build --clean tsconfig.build.json",
3849
"clean:types": "rimraf dist types",

0 commit comments

Comments
 (0)