Skip to content

Commit 8e15117

Browse files
fix: create CTS definition aliases for NodeNext (#343)
1 parent 7555435 commit 8e15117

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
"main": "./index.cjs",
2424
"module": "./index.js",
2525
"exports": {
26-
"types": "./index.d.ts",
27-
"require": "./index.cjs",
28-
"import": "./index.js"
26+
"require": {
27+
"types": "./index.d.cts",
28+
"default": "./index.cjs"
29+
},
30+
"default": {
31+
"types": "./index.d.ts",
32+
"default": "./index.js"
33+
}
2934
},
3035
"sideEffects": false,
3136
"devDependencies": {
@@ -35,6 +40,7 @@
3540
"json": "^11.0.0",
3641
"prettier": "^2.2.1",
3742
"rimraf": "^3.0.2",
43+
"shelljs": "^0.8.5",
3844
"three": "^0.128.0",
3945
"typescript": "^4.7.4",
4046
"vite": "^4.3.8"
@@ -51,7 +57,7 @@
5157
"three": ">=0.128.0"
5258
},
5359
"scripts": {
54-
"build": "rimraf dist && vite build && tsc --emitDeclarationOnly && copyfiles -u 1 \"src/**/*.d.ts\" dist && copyfiles package.json README.md LICENSE dist && json -I -f dist/package.json -e \"this.private=undefined;this.type=\\\"module\\\";\"",
60+
"build": "rimraf dist && vite build && tsc --emitDeclarationOnly && copyfiles -u 1 \"src/**/*.d.ts\" dist && copyfiles package.json README.md LICENSE dist && json -I -f dist/package.json -e \"this.private=undefined;this.type=\\\"module\\\";\" && node patch-ts.js",
5561
"lint": "tsc --noEmit"
5662
}
5763
}

patch-ts.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const shell = require('shelljs')
2+
const fs = require('fs')
3+
4+
const files = shell.find('dist/**/*.d.ts')
5+
6+
for (const file of files) {
7+
const cts = file.replace('.d.ts', '.d.cts')
8+
9+
// Add type qualifiers in annotations
10+
shell.sed('-i', /(import|export [*{])\s+(?!type\b)/, '$1 type ', file)
11+
// Remove .js extensions
12+
shell.sed('-i', /from '(\.[^.]+)\.js'/, "from '$1'", file)
13+
14+
fs.copyFileSync(file, cts)
15+
16+
// Add explicit .d.ts extensions for ESM
17+
shell.sed('-i', / from '(\.[^']+)'/, " from '$1.d.ts'", file)
18+
shell.sed('-i', /^declare module '(\.[^']+)'/, "declare module '$1.d.ts'", file)
19+
20+
// Add explicit .d.cts extensions for CJS
21+
shell.sed('-i', / from '(\.[^']+)'/, " from '$1.d.cts'", cts)
22+
shell.sed('-i', /^declare module '(\.[^']+)'/, "declare module '$1.d.cts'", cts)
23+
}

yarn.lock

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,28 @@ fsevents@~2.3.2:
264264
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
265265
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
266266

267+
function-bind@^1.1.2:
268+
version "1.1.2"
269+
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
270+
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==
271+
267272
get-caller-file@^2.0.5:
268273
version "2.0.5"
269274
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
270275
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
271276

277+
glob@^7.0.0:
278+
version "7.2.3"
279+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
280+
integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
281+
dependencies:
282+
fs.realpath "^1.0.0"
283+
inflight "^1.0.4"
284+
inherits "2"
285+
minimatch "^3.1.1"
286+
once "^1.3.0"
287+
path-is-absolute "^1.0.0"
288+
272289
glob@^7.0.5, glob@^7.1.3:
273290
version "7.1.6"
274291
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
@@ -281,6 +298,13 @@ glob@^7.0.5, glob@^7.1.3:
281298
once "^1.3.0"
282299
path-is-absolute "^1.0.0"
283300

301+
hasown@^2.0.0:
302+
version "2.0.0"
303+
resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.0.tgz#f4c513d454a57b7c7e1650778de226b11700546c"
304+
integrity sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==
305+
dependencies:
306+
function-bind "^1.1.2"
307+
284308
inflight@^1.0.4:
285309
version "1.0.6"
286310
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
@@ -294,6 +318,18 @@ inherits@2, inherits@^2.0.1, inherits@~2.0.1, inherits@~2.0.3:
294318
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
295319
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
296320

321+
interpret@^1.0.0:
322+
version "1.4.0"
323+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
324+
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
325+
326+
is-core-module@^2.13.0:
327+
version "2.13.1"
328+
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384"
329+
integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==
330+
dependencies:
331+
hasown "^2.0.0"
332+
297333
is-fullwidth-code-point@^3.0.0:
298334
version "3.0.0"
299335
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
@@ -321,6 +357,13 @@ minimatch@^3.0.3, minimatch@^3.0.4:
321357
dependencies:
322358
brace-expansion "^1.1.7"
323359

360+
minimatch@^3.1.1:
361+
version "3.1.2"
362+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
363+
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
364+
dependencies:
365+
brace-expansion "^1.1.7"
366+
324367
mkdirp@^1.0.4:
325368
version "1.0.4"
326369
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
@@ -351,6 +394,11 @@ path-is-absolute@^1.0.0:
351394
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
352395
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
353396

397+
path-parse@^1.0.7:
398+
version "1.0.7"
399+
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
400+
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
401+
354402
picocolors@^1.0.0:
355403
version "1.0.0"
356404
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
@@ -403,11 +451,27 @@ readable-stream@~2.3.6:
403451
string_decoder "~1.1.1"
404452
util-deprecate "~1.0.1"
405453

454+
rechoir@^0.6.2:
455+
version "0.6.2"
456+
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
457+
integrity sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==
458+
dependencies:
459+
resolve "^1.1.6"
460+
406461
require-directory@^2.1.1:
407462
version "2.1.1"
408463
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
409464
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
410465

466+
resolve@^1.1.6:
467+
version "1.22.8"
468+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
469+
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
470+
dependencies:
471+
is-core-module "^2.13.0"
472+
path-parse "^1.0.7"
473+
supports-preserve-symlinks-flag "^1.0.0"
474+
411475
rimraf@^3.0.2:
412476
version "3.0.2"
413477
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
@@ -427,6 +491,15 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
427491
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
428492
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
429493

494+
shelljs@^0.8.5:
495+
version "0.8.5"
496+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
497+
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
498+
dependencies:
499+
glob "^7.0.0"
500+
interpret "^1.0.0"
501+
rechoir "^0.6.2"
502+
430503
source-map-js@^1.0.2:
431504
version "1.0.2"
432505
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
@@ -460,6 +533,11 @@ strip-ansi@^6.0.0:
460533
dependencies:
461534
ansi-regex "^5.0.0"
462535

536+
supports-preserve-symlinks-flag@^1.0.0:
537+
version "1.0.0"
538+
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
539+
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
540+
463541
three@^0.128.0:
464542
version "0.128.0"
465543
resolved "https://registry.yarnpkg.com/three/-/three-0.128.0.tgz#884dacca6a330e45600a09ec5439283f50b76aa6"

0 commit comments

Comments
 (0)