Skip to content

Commit d170344

Browse files
committed
fix: fix import extensions in dts files
1 parent d6938d8 commit d170344

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

fix-dts.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Need this fix up script due to https://github.com/microsoft/TypeScript/issues/61037
2+
3+
/* eslint-disable import/no-extraneous-dependencies */
4+
/* eslint-disable no-console */
5+
/* eslint-disable no-await-in-loop */
6+
/* eslint-disable no-restricted-syntax */
7+
import fs from 'fs/promises';
8+
import { glob } from 'glob';
9+
10+
const folders = ['cjs/*.d.ts', 'esm/*.d.ts'];
11+
const importRegex = /(import\s.*?from\s+['"])(.*?\.ts)(['"])/g;
12+
13+
async function fixImportsInFile(filePath) {
14+
let content = await fs.readFile(filePath, 'utf8');
15+
const newContent = content.replace(importRegex, (match, p1, p2, p3) => {
16+
return `${p1}${p2.replace(/\.ts$/, '.d.ts')}${p3}`;
17+
});
18+
if (content !== newContent) {
19+
await fs.writeFile(filePath, newContent, 'utf8');
20+
console.log(`Fixed imports in: ${filePath}`);
21+
}
22+
}
23+
24+
async function main() {
25+
for (const folder of folders) {
26+
const files = glob.sync(folder, { nodir: true });
27+
for (const file of files) {
28+
await fixImportsInFile(file);
29+
}
30+
}
31+
}
32+
33+
main().catch((err) => {
34+
console.error(err);
35+
process.exit(1);
36+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"scripts": {
6060
"test": "karma start --single-run",
6161
"tdd": "karma start",
62-
"build": "yarn build:cjs && yarn build:esm",
62+
"build": "yarn build:cjs && yarn build:esm && node fix-dts.mjs",
6363
"build:cjs": "rimraf cjs && babel src --out-dir cjs --delete-dir-on-start --env-name cjs --extensions .ts && yarn build:cjs:types && echo '{\"type\": \"commonjs\"}' > cjs/package.json",
6464
"build:esm": "rimraf esm && babel src --out-dir esm --delete-dir-on-start --env-name esm --extensions .ts && yarn build:esm:types && echo '{\"type\": \"module\"}' > esm/package.json",
6565
"build:cjs:types": "tsc --emitDeclarationOnly --module commonjs --outDir cjs",

src/types.d.ts renamed to src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as CSS from 'csstype';
22

3-
type Styles = keyof CSSStyleDeclaration;
4-
53
export type HyphenProperty = keyof CSS.PropertiesHyphen;
64
export type CamelProperty = keyof CSS.Properties;
75

yarn.lock

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,18 @@
11051105
minimatch "^3.0.4"
11061106
strip-json-comments "^3.1.1"
11071107

1108+
"@isaacs/balanced-match@^4.0.1":
1109+
version "4.0.1"
1110+
resolved "https://registry.yarnpkg.com/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz#3081dadbc3460661b751e7591d7faea5df39dd29"
1111+
integrity sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==
1112+
1113+
"@isaacs/brace-expansion@^5.0.0":
1114+
version "5.0.0"
1115+
resolved "https://registry.yarnpkg.com/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz#4b3dabab7d8e75a429414a96bd67bf4c1d13e0f3"
1116+
integrity sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==
1117+
dependencies:
1118+
"@isaacs/balanced-match" "^4.0.1"
1119+
11081120
"@isaacs/cliui@^8.0.2":
11091121
version "8.0.2"
11101122
resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
@@ -3579,7 +3591,7 @@ for-in@^1.0.2:
35793591
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
35803592
integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=
35813593

3582-
foreground-child@^3.1.0:
3594+
foreground-child@^3.1.0, foreground-child@^3.3.1:
35833595
version "3.3.1"
35843596
resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-3.3.1.tgz#32e8e9ed1b68a3497befb9ac2b6adf92a638576f"
35853597
integrity sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==
@@ -3787,6 +3799,18 @@ glob@^11.0.0:
37873799
package-json-from-dist "^1.0.0"
37883800
path-scurry "^2.0.0"
37893801

3802+
glob@^11.0.3:
3803+
version "11.0.3"
3804+
resolved "https://registry.yarnpkg.com/glob/-/glob-11.0.3.tgz#9d8087e6d72ddb3c4707b1d2778f80ea3eaefcd6"
3805+
integrity sha512-2Nim7dha1KVkaiF4q6Dj+ngPPMdfvLJEOpZk/jKiUAkqKebpGAWQXAq9z1xu9HKu5lWfqw/FASuccEjyznjPaA==
3806+
dependencies:
3807+
foreground-child "^3.3.1"
3808+
jackspeak "^4.1.1"
3809+
minimatch "^10.0.3"
3810+
minipass "^7.1.2"
3811+
package-json-from-dist "^1.0.0"
3812+
path-scurry "^2.0.0"
3813+
37903814
glob@^7.0.0, glob@^7.1.3:
37913815
version "7.1.6"
37923816
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
@@ -4530,7 +4554,7 @@ jackspeak@^3.1.2:
45304554
optionalDependencies:
45314555
"@pkgjs/parseargs" "^0.11.0"
45324556

4533-
jackspeak@^4.0.1:
4557+
jackspeak@^4.0.1, jackspeak@^4.1.1:
45344558
version "4.1.1"
45354559
resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-4.1.1.tgz#96876030f450502047fc7e8c7fcf8ce8124e43ae"
45364560
integrity sha512-zptv57P3GpL+O0I7VdMJNBZCu+BPHVQUk55Ft8/QCJjTVxrnJHuVuX/0Bl2A6/+2oyR/ZMEuFKwmzqqZ/U5nPQ==
@@ -5207,6 +5231,13 @@ minimatch@^10.0.0:
52075231
dependencies:
52085232
brace-expansion "^2.0.1"
52095233

5234+
minimatch@^10.0.3:
5235+
version "10.0.3"
5236+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.3.tgz#cf7a0314a16c4d9ab73a7730a0e8e3c3502d47aa"
5237+
integrity sha512-IPZ167aShDZZUMdRk66cyQAW3qr0WzbHkPdMYa8bzZhlHhO3jALbKdxcaak7W9FfT2rZNpQuUu4Od7ILEpXSaw==
5238+
dependencies:
5239+
"@isaacs/brace-expansion" "^5.0.0"
5240+
52105241
minimatch@^3.0.4:
52115242
version "3.0.4"
52125243
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"

0 commit comments

Comments
 (0)