rsbuild-plugin-dts 0.18.2 → 0.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/utils.js +12 -13
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -233,7 +233,7 @@ const defaultRedirect = {
|
|
|
233
233
|
};
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
Controls the redirect of the import paths of
|
|
236
|
+
Controls the redirect of the import paths of TypeScript declaration output files.
|
|
237
237
|
|
|
238
238
|
```js
|
|
239
239
|
pluginDts({
|
|
@@ -269,9 +269,9 @@ import { foo } from '../foo'; // expected output './dist/utils/index.d.ts'
|
|
|
269
269
|
- **Type:** `boolean`
|
|
270
270
|
- **Default:** `false`
|
|
271
271
|
|
|
272
|
-
Whether to automatically redirect the file extension
|
|
272
|
+
Whether to automatically redirect the file extension of import paths based on the TypeScript declaration output files.
|
|
273
273
|
|
|
274
|
-
- When set to `true`, the import
|
|
274
|
+
- When set to `true`, the file extension of the import path in the declaration file will be automatically completed or replaced with the corresponding JavaScript file extension that can be resolved to the corresponding declaration file. The extension of the declaration output file is related to the `dtsExtension` configuration.
|
|
275
275
|
|
|
276
276
|
```ts
|
|
277
277
|
// `dtsExtension` is set to `.d.mts`
|
|
@@ -282,7 +282,7 @@ import { foo } from './foo.ts'; // source code of './src/bar.ts' ↓
|
|
|
282
282
|
import { foo } from './foo.mjs'; // expected output of './dist/bar.d.mts'
|
|
283
283
|
```
|
|
284
284
|
|
|
285
|
-
- When set to `false`,
|
|
285
|
+
- When set to `false`, import paths will retain their original file extensions.
|
|
286
286
|
|
|
287
287
|
### tsgo
|
|
288
288
|
|
package/dist/utils.js
CHANGED
|
@@ -127,12 +127,14 @@ async function addBannerAndFooter(dtsFile, banner, footer) {
|
|
|
127
127
|
if (footer && !content.trimEnd().endsWith(footer.trim())) code.append(`\n${footer}\n`);
|
|
128
128
|
if (code.hasChanged()) await promises.writeFile(dtsFile, code.toString());
|
|
129
129
|
}
|
|
130
|
-
async function addExtension(redirect, dtsFile, path,
|
|
130
|
+
async function addExtension(redirect, dtsFile, path, jsExtension, dtsExtension) {
|
|
131
131
|
if (!redirect.extension) return path;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (await isDirectory(join(dirname(dtsFile),
|
|
135
|
-
|
|
132
|
+
if (!isAbsolute(path) && !path.startsWith('.')) return path;
|
|
133
|
+
const candidatePaths = [];
|
|
134
|
+
if (await isDirectory(join(dirname(dtsFile), path))) candidatePaths.push(`${path.replace(/\/+$/, '')}/index`);
|
|
135
|
+
candidatePaths.push(path);
|
|
136
|
+
for (const candidatePath of candidatePaths)if (await pathExists(join(dirname(dtsFile), `${candidatePath}${dtsExtension}`))) return `${candidatePath}${jsExtension}`;
|
|
137
|
+
return path;
|
|
136
138
|
}
|
|
137
139
|
async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, outDir, rootDir) {
|
|
138
140
|
const content = await promises.readFile(dtsFile, 'utf-8');
|
|
@@ -204,7 +206,7 @@ async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, ou
|
|
|
204
206
|
e: matchNode.range().end.index
|
|
205
207
|
};
|
|
206
208
|
});
|
|
207
|
-
const
|
|
209
|
+
const jsExtension = dtsExtension.replace(/\.d\.ts$/, '.js').replace(/\.d\.cts$/, '.cjs').replace(/\.d\.mts$/, '.mjs');
|
|
208
210
|
for (const imp of matchModule){
|
|
209
211
|
const { n: importPath, s: start, e: end } = imp;
|
|
210
212
|
if (importPath) try {
|
|
@@ -235,14 +237,11 @@ async function redirectDtsImports(dtsFile, dtsExtension, redirect, matchPath, ou
|
|
|
235
237
|
}
|
|
236
238
|
const ext = extname(redirectImportPath);
|
|
237
239
|
if (ext) if (JS_EXTENSIONS_PATTERN.test(redirectImportPath)) {
|
|
238
|
-
if (redirect.extension) redirectImportPath = redirectImportPath.replace(/\.[^.]+$/,
|
|
239
|
-
} else
|
|
240
|
-
const candidatePath = await addExtension(redirect, dtsFile, redirectImportPath, extension);
|
|
241
|
-
if (await pathExists(node_path.join(dirname(dtsFile), candidatePath.replace(/\.[^.]+$/, dtsExtension)))) redirectImportPath = candidatePath;
|
|
242
|
-
}
|
|
240
|
+
if (redirect.extension) redirectImportPath = redirectImportPath.replace(/\.[^.]+$/, jsExtension);
|
|
241
|
+
} else redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, jsExtension, dtsExtension);
|
|
243
242
|
else {
|
|
244
|
-
if (absoluteImportPath && normalize(absoluteImportPath).startsWith(normalize(rootDir))) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath,
|
|
245
|
-
if (!absoluteImportPath && importPath.startsWith('.')) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath,
|
|
243
|
+
if (absoluteImportPath && normalize(absoluteImportPath).startsWith(normalize(rootDir))) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, jsExtension, dtsExtension);
|
|
244
|
+
if (!absoluteImportPath && importPath.startsWith('.')) redirectImportPath = await addExtension(redirect, dtsFile, redirectImportPath, jsExtension, dtsExtension);
|
|
246
245
|
}
|
|
247
246
|
const normalizedRedirectImportPath = redirectImportPath.split(node_path.sep).join('/');
|
|
248
247
|
code.overwrite(start, end, normalizedRedirectImportPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsbuild-plugin-dts",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "Rsbuild plugin that supports emitting declaration files for TypeScript.",
|
|
5
5
|
"homepage": "https://rslib.rs",
|
|
6
6
|
"bugs": {
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@microsoft/api-extractor": "^7.55.1",
|
|
33
|
-
"@rsbuild/core": "~1.6.
|
|
34
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
33
|
+
"@rsbuild/core": "~1.6.12",
|
|
34
|
+
"@typescript/native-preview": "7.0.0-dev.20251130.1",
|
|
35
35
|
"magic-string": "^0.30.21",
|
|
36
36
|
"picocolors": "1.1.1",
|
|
37
37
|
"prebundle": "1.6.0",
|
|
38
38
|
"rsbuild-plugin-publint": "^0.3.3",
|
|
39
|
-
"rslib": "npm:@rslib/core@0.18.
|
|
39
|
+
"rslib": "npm:@rslib/core@0.18.2",
|
|
40
40
|
"tinyglobby": "0.2.14",
|
|
41
41
|
"tsconfig-paths": "^4.2.0",
|
|
42
42
|
"typescript": "^5.9.3",
|