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.
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
2
+ const require_src_index = require('./src_index-94OZIa2J.cjs');
3
3
  require('./transformer-ZHFQTLaY.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
@@ -1,3 +1,3 @@
1
1
  import { IsolatedDecl } from "./index.js";
2
2
  declare const _default: typeof IsolatedDecl.esbuild;
3
- export default _default;
3
+ export = _default;
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
2
+ import { IsolatedDecl } from "./src_index-_h3SFnKA.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
2
+ const require_src_index = require('./src_index-94OZIa2J.cjs');
3
3
  require('./transformer-ZHFQTLaY.cjs');
4
4
 
5
5
  Object.defineProperty(exports, 'IsolatedDecl', {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl, lowestCommonAncestor } from "./src_index-g0Uyr2cn.js";
2
+ import { IsolatedDecl, lowestCommonAncestor } from "./src_index-_h3SFnKA.js";
3
3
 
4
4
  export { IsolatedDecl, lowestCommonAncestor };
package/dist/rolldown.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
2
+ const require_src_index = require('./src_index-94OZIa2J.cjs');
3
3
  require('./transformer-ZHFQTLaY.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
@@ -1,3 +1,3 @@
1
1
  import { IsolatedDecl } from "./index.js";
2
2
  declare const _default: typeof IsolatedDecl.rolldown;
3
- export default _default;
3
+ export = _default;
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
2
+ import { IsolatedDecl } from "./src_index-_h3SFnKA.js";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  var rolldown_default = IsolatedDecl.rolldown;
package/dist/rollup.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
2
+ const require_src_index = require('./src_index-94OZIa2J.cjs');
3
3
  require('./transformer-ZHFQTLaY.cjs');
4
4
 
5
5
  //#region src/rollup.ts
package/dist/rollup.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { IsolatedDecl } from "./index.js";
2
2
  declare const _default: typeof IsolatedDecl.rollup;
3
- export default _default;
3
+ export = _default;
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
2
+ import { IsolatedDecl } from "./src_index-_h3SFnKA.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -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 (const [filename, source] of Object.entries(outputFiles)) {
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: entryFileNames.replace("[name]", path.relative(outBase, 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 (const [filename, source] of Object.entries(outputFiles)) {
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 (const [filename, source] of Object.entries(outputFiles)) {
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: entryFileNames.replace("[name]", path.relative(outBase, 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 (const [filename, source] of Object.entries(outputFiles)) {
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
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
2
+ const require_src_index = require('./src_index-94OZIa2J.cjs');
3
3
  require('./transformer-ZHFQTLaY.cjs');
4
4
 
5
5
  //#region src/vite.ts
package/dist/vite.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { IsolatedDecl } from "./index.js";
2
2
  declare const _default: typeof IsolatedDecl.vite;
3
- export default _default;
3
+ export = _default;
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
2
+ import { IsolatedDecl } from "./src_index-_h3SFnKA.js";
3
3
 
4
4
  //#region src/vite.ts
5
5
  var vite_default = IsolatedDecl.vite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-isolated-decl",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [