unplugin-isolated-decl 0.6.1 → 0.6.2
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/dist/core/options.d.cts +2 -0
- package/dist/core/options.d.ts +2 -0
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.d.cts +1 -1
- package/dist/rolldown.js +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.js +1 -1
- package/dist/{src_index-Q6qrrUBW.cjs → src_index-94OZIa2J.cjs} +15 -4
- package/dist/{src_index-g0Uyr2cn.js → src_index-_h3SFnKA.js} +15 -4
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
package/dist/core/options.d.cts
CHANGED
|
@@ -9,6 +9,8 @@ export type Options = {
|
|
|
9
9
|
extraOutdir?: string;
|
|
10
10
|
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
11
11
|
autoAddExts?: boolean;
|
|
12
|
+
/** Patch `export default` in `.d.cts` to `export = ` */
|
|
13
|
+
patchCjsDefaultExport?: boolean;
|
|
12
14
|
} & ({
|
|
13
15
|
/**
|
|
14
16
|
* `oxc-transform` or `@swc/core` should be installed yourself
|
package/dist/core/options.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type Options = {
|
|
|
9
9
|
extraOutdir?: string;
|
|
10
10
|
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
11
11
|
autoAddExts?: boolean;
|
|
12
|
+
/** Patch `export default` in `.d.cts` to `export = ` */
|
|
13
|
+
patchCjsDefaultExport?: boolean;
|
|
12
14
|
} & ({
|
|
13
15
|
/**
|
|
14
16
|
* `oxc-transform` or `@swc/core` should be installed yourself
|
package/dist/esbuild.cjs
CHANGED
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/dist/rolldown.cjs
CHANGED
package/dist/rolldown.d.cts
CHANGED
package/dist/rolldown.js
CHANGED
package/dist/rollup.cjs
CHANGED
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.js
CHANGED
|
@@ -39,7 +39,8 @@ function resolveOptions(options) {
|
|
|
39
39
|
transformer: options.transformer || "typescript",
|
|
40
40
|
ignoreErrors: options.ignoreErrors || false,
|
|
41
41
|
extraOutdir: options.extraOutdir,
|
|
42
|
-
autoAddExts: options.autoAddExts || false
|
|
42
|
+
autoAddExts: options.autoAddExts || false,
|
|
43
|
+
patchCjsDefaultExport: options.patchCjsDefaultExport || false
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -66,10 +67,14 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
66
67
|
if (options.extraOutdir) {
|
|
67
68
|
entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
68
69
|
}
|
|
69
|
-
for (
|
|
70
|
+
for (let [outname, source] of Object.entries(outputFiles)) {
|
|
71
|
+
const fileName = entryFileNames.replace("[name]", path.relative(outBase, outname));
|
|
72
|
+
if (options.patchCjsDefaultExport && fileName.endsWith(".d.cts")) {
|
|
73
|
+
source = patchCjsDefaultExport(source);
|
|
74
|
+
}
|
|
70
75
|
this.emitFile({
|
|
71
76
|
type: "asset",
|
|
72
|
-
fileName
|
|
77
|
+
fileName,
|
|
73
78
|
source
|
|
74
79
|
});
|
|
75
80
|
}
|
|
@@ -183,13 +188,16 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
183
188
|
result.outputFiles ||= [];
|
|
184
189
|
}
|
|
185
190
|
const textEncoder = new TextEncoder();
|
|
186
|
-
for (
|
|
191
|
+
for (let [filename, source] of Object.entries(outputFiles)) {
|
|
187
192
|
const outDir = build.initialOptions.outdir;
|
|
188
193
|
let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
189
194
|
if (options.extraOutdir) {
|
|
190
195
|
outFile = path.join(options.extraOutdir, outFile);
|
|
191
196
|
}
|
|
192
197
|
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
198
|
+
if (options.patchCjsDefaultExport && filePath.endsWith(".d.cts")) {
|
|
199
|
+
source = patchCjsDefaultExport(source);
|
|
200
|
+
}
|
|
193
201
|
if (write) {
|
|
194
202
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
195
203
|
await writeFile(filePath, source);
|
|
@@ -228,6 +236,9 @@ async function resolve(context, id, importer) {
|
|
|
228
236
|
function stripExt(filename) {
|
|
229
237
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
230
238
|
}
|
|
239
|
+
function patchCjsDefaultExport(source) {
|
|
240
|
+
return source.replace(/(?<=(?:[;}]|^)\s*export\s*)(?:\{\s*([\w$]+)\s*as\s+default\s*\}|default\s+([\w$]+))/, (_, s1, s2) => `= ${s1 || s2}`);
|
|
241
|
+
}
|
|
231
242
|
function lowestCommonAncestor(...filepaths) {
|
|
232
243
|
if (filepaths.length === 0) return "";
|
|
233
244
|
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
|
@@ -15,7 +15,8 @@ function resolveOptions(options) {
|
|
|
15
15
|
transformer: options.transformer || "typescript",
|
|
16
16
|
ignoreErrors: options.ignoreErrors || false,
|
|
17
17
|
extraOutdir: options.extraOutdir,
|
|
18
|
-
autoAddExts: options.autoAddExts || false
|
|
18
|
+
autoAddExts: options.autoAddExts || false,
|
|
19
|
+
patchCjsDefaultExport: options.patchCjsDefaultExport || false
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -42,10 +43,14 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
42
43
|
if (options.extraOutdir) {
|
|
43
44
|
entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
44
45
|
}
|
|
45
|
-
for (
|
|
46
|
+
for (let [outname, source] of Object.entries(outputFiles)) {
|
|
47
|
+
const fileName = entryFileNames.replace("[name]", path.relative(outBase, outname));
|
|
48
|
+
if (options.patchCjsDefaultExport && fileName.endsWith(".d.cts")) {
|
|
49
|
+
source = patchCjsDefaultExport(source);
|
|
50
|
+
}
|
|
46
51
|
this.emitFile({
|
|
47
52
|
type: "asset",
|
|
48
|
-
fileName
|
|
53
|
+
fileName,
|
|
49
54
|
source
|
|
50
55
|
});
|
|
51
56
|
}
|
|
@@ -159,13 +164,16 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
159
164
|
result.outputFiles ||= [];
|
|
160
165
|
}
|
|
161
166
|
const textEncoder = new TextEncoder();
|
|
162
|
-
for (
|
|
167
|
+
for (let [filename, source] of Object.entries(outputFiles)) {
|
|
163
168
|
const outDir = build.initialOptions.outdir;
|
|
164
169
|
let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
165
170
|
if (options.extraOutdir) {
|
|
166
171
|
outFile = path.join(options.extraOutdir, outFile);
|
|
167
172
|
}
|
|
168
173
|
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
174
|
+
if (options.patchCjsDefaultExport && filePath.endsWith(".d.cts")) {
|
|
175
|
+
source = patchCjsDefaultExport(source);
|
|
176
|
+
}
|
|
169
177
|
if (write) {
|
|
170
178
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
171
179
|
await writeFile(filePath, source);
|
|
@@ -204,6 +212,9 @@ async function resolve(context, id, importer) {
|
|
|
204
212
|
function stripExt(filename) {
|
|
205
213
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
206
214
|
}
|
|
215
|
+
function patchCjsDefaultExport(source) {
|
|
216
|
+
return source.replace(/(?<=(?:[;}]|^)\s*export\s*)(?:\{\s*([\w$]+)\s*as\s+default\s*\}|default\s+([\w$]+))/, (_, s1, s2) => `= ${s1 || s2}`);
|
|
217
|
+
}
|
|
207
218
|
function lowestCommonAncestor(...filepaths) {
|
|
208
219
|
if (filepaths.length === 0) return "";
|
|
209
220
|
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
package/dist/vite.cjs
CHANGED
package/dist/vite.d.cts
CHANGED
package/dist/vite.js
CHANGED