unplugin-isolated-decl 0.6.1 → 0.6.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/dist/api.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-ZHFQTLaY.cjs');
2
+ const require_transformer = require('./transformer-9aaNC01N.cjs');
3
3
 
4
4
  Object.defineProperty(exports, 'oxcTransform', {
5
5
  enumerable: true,
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-YxBC7dLI.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-GSFmnEOV.js";
2
2
 
3
3
  export { oxcTransform, swcTransform, tsTransform };
@@ -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,6 +1,6 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
3
- require('./transformer-ZHFQTLaY.cjs');
2
+ const require_src_index = require('./src_index-G1xVigYS.cjs');
3
+ require('./transformer-9aaNC01N.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
6
6
  var esbuild_default = require_src_index.IsolatedDecl.esbuild;
@@ -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
- import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
1
+ import "./transformer-GSFmnEOV.js";
2
+ import { IsolatedDecl } from "./src_index-KJ4J0Bno.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
3
- require('./transformer-ZHFQTLaY.cjs');
2
+ const require_src_index = require('./src_index-G1xVigYS.cjs');
3
+ require('./transformer-9aaNC01N.cjs');
4
4
 
5
5
  Object.defineProperty(exports, 'IsolatedDecl', {
6
6
  enumerable: true,
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl, lowestCommonAncestor } from "./src_index-g0Uyr2cn.js";
1
+ import "./transformer-GSFmnEOV.js";
2
+ import { IsolatedDecl, lowestCommonAncestor } from "./src_index-KJ4J0Bno.js";
3
3
 
4
4
  export { IsolatedDecl, lowestCommonAncestor };
package/dist/rolldown.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
3
- require('./transformer-ZHFQTLaY.cjs');
2
+ const require_src_index = require('./src_index-G1xVigYS.cjs');
3
+ require('./transformer-9aaNC01N.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
6
6
  var rolldown_default = require_src_index.IsolatedDecl.rolldown;
@@ -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
- import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
1
+ import "./transformer-GSFmnEOV.js";
2
+ import { IsolatedDecl } from "./src_index-KJ4J0Bno.js";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  var rolldown_default = IsolatedDecl.rolldown;
package/dist/rollup.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
3
- require('./transformer-ZHFQTLaY.cjs');
2
+ const require_src_index = require('./src_index-G1xVigYS.cjs');
3
+ require('./transformer-9aaNC01N.cjs');
4
4
 
5
5
  //#region src/rollup.ts
6
6
  var rollup_default = require_src_index.IsolatedDecl.rollup;
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
- import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
1
+ import "./transformer-GSFmnEOV.js";
2
+ import { IsolatedDecl } from "./src_index-KJ4J0Bno.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -22,7 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  }) : target, mod));
23
23
 
24
24
  //#endregion
25
- const require_transformer = require('./transformer-ZHFQTLaY.cjs');
25
+ const require_transformer = require('./transformer-9aaNC01N.cjs');
26
26
  const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
27
27
  const { default: path } = __toESM(require("node:path"));
28
28
  const { createFilter } = __toESM(require("@rollup/pluginutils"));
@@ -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]);
@@ -1,4 +1,4 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-YxBC7dLI.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-GSFmnEOV.js";
2
2
  import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { default as path } from "node:path";
4
4
  import { createFilter } from "@rollup/pluginutils";
@@ -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]);
@@ -13,7 +13,7 @@ async function oxcTransform(id, code) {
13
13
  if (!oxc) {
14
14
  return {
15
15
  code: "",
16
- errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`.",]
16
+ errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`."]
17
17
  };
18
18
  }
19
19
  return oxc.isolatedDeclaration(id, code, { sourcemap: false });
@@ -23,7 +23,7 @@ async function swcTransform(id, code) {
23
23
  if (!swc) {
24
24
  return {
25
25
  code: "",
26
- errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
26
+ errors: ["SWC is required for transforming TypeScript, please install `@swc/core`."]
27
27
  };
28
28
  }
29
29
  try {
@@ -54,13 +54,13 @@ async function tsTransform(id, code, transformOptions) {
54
54
  if (!ts) {
55
55
  return {
56
56
  code: "",
57
- errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
57
+ errors: ["TypeScript is required for transforming TypeScript, please install `typescript`."]
58
58
  };
59
59
  }
60
60
  if (!ts.transpileDeclaration) {
61
61
  return {
62
62
  code: "",
63
- errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
63
+ errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+."]
64
64
  };
65
65
  }
66
66
  const { outputText, diagnostics } = ts.transpileDeclaration(code, {
@@ -72,7 +72,7 @@ async function tsTransform(id, code, transformOptions) {
72
72
  getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
73
73
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
74
74
  getNewLine: () => ts.sys.newLine
75
- }),] : [];
75
+ })] : [];
76
76
  return {
77
77
  code: outputText,
78
78
  errors
@@ -12,7 +12,7 @@ async function oxcTransform(id, code) {
12
12
  if (!oxc) {
13
13
  return {
14
14
  code: "",
15
- errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`.",]
15
+ errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`."]
16
16
  };
17
17
  }
18
18
  return oxc.isolatedDeclaration(id, code, { sourcemap: false });
@@ -22,7 +22,7 @@ async function swcTransform(id, code) {
22
22
  if (!swc) {
23
23
  return {
24
24
  code: "",
25
- errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
25
+ errors: ["SWC is required for transforming TypeScript, please install `@swc/core`."]
26
26
  };
27
27
  }
28
28
  try {
@@ -53,13 +53,13 @@ async function tsTransform(id, code, transformOptions) {
53
53
  if (!ts) {
54
54
  return {
55
55
  code: "",
56
- errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
56
+ errors: ["TypeScript is required for transforming TypeScript, please install `typescript`."]
57
57
  };
58
58
  }
59
59
  if (!ts.transpileDeclaration) {
60
60
  return {
61
61
  code: "",
62
- errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
62
+ errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+."]
63
63
  };
64
64
  }
65
65
  const { outputText, diagnostics } = ts.transpileDeclaration(code, {
@@ -71,7 +71,7 @@ async function tsTransform(id, code, transformOptions) {
71
71
  getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
72
72
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
73
73
  getNewLine: () => ts.sys.newLine
74
- }),] : [];
74
+ })] : [];
75
75
  return {
76
76
  code: outputText,
77
77
  errors
package/dist/vite.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const require_src_index = require('./src_index-Q6qrrUBW.cjs');
3
- require('./transformer-ZHFQTLaY.cjs');
2
+ const require_src_index = require('./src_index-G1xVigYS.cjs');
3
+ require('./transformer-9aaNC01N.cjs');
4
4
 
5
5
  //#region src/vite.ts
6
6
  var vite_default = require_src_index.IsolatedDecl.vite;
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
- import "./transformer-YxBC7dLI.js";
2
- import { IsolatedDecl } from "./src_index-g0Uyr2cn.js";
1
+ import "./transformer-GSFmnEOV.js";
2
+ import { IsolatedDecl } from "./src_index-KJ4J0Bno.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.3",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -86,29 +86,29 @@
86
86
  "dependencies": {
87
87
  "@rollup/pluginutils": "^5.1.0",
88
88
  "magic-string": "^0.30.11",
89
- "oxc-parser": "^0.27.0",
90
- "unplugin": "^1.14.0"
89
+ "oxc-parser": "^0.29.0",
90
+ "unplugin": "^1.14.1"
91
91
  },
92
92
  "devDependencies": {
93
- "@swc/core": "^1.7.24",
93
+ "@swc/core": "^1.7.26",
94
94
  "@sxzz/eslint-config": "^4.2.0",
95
95
  "@sxzz/prettier-config": "^2.0.2",
96
- "@types/node": "^22.5.4",
96
+ "@types/node": "^22.5.5",
97
97
  "@typescript-eslint/typescript-estree": "^8.5.0",
98
98
  "bumpp": "^9.5.2",
99
99
  "esbuild": "^0.23.1",
100
100
  "eslint": "^9.10.0",
101
101
  "fast-glob": "^3.3.2",
102
- "oxc-transform": "^0.27.0",
102
+ "oxc-transform": "^0.29.0",
103
103
  "prettier": "^3.3.3",
104
104
  "rolldown": "nightly",
105
- "rollup": "^4.21.2",
105
+ "rollup": "^4.21.3",
106
106
  "rollup-plugin-esbuild": "^6.1.1",
107
- "tsdown": "^0.2.15",
108
- "tsx": "^4.19.0",
107
+ "tsdown": "^0.2.16",
108
+ "tsx": "^4.19.1",
109
109
  "typescript": "^5.6.2",
110
- "vite": "^5.4.3",
111
- "vitest": "^2.0.5"
110
+ "vite": "^5.4.5",
111
+ "vitest": "^2.1.1"
112
112
  },
113
113
  "engines": {
114
114
  "node": ">=18.12.0"