unplugin-isolated-decl 0.16.0 → 0.17.1

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.mjs CHANGED
@@ -1,2 +1 @@
1
- import { a as tsTransform, i as swcTransform, r as oxcTransform } from "./transformer-UfUlpcf6.mjs";
2
- export { oxcTransform, swcTransform, tsTransform };
1
+ export { r as oxcTransform, i as swcTransform, a as tsTransform } from "./transformer-CZhoOHAY.mjs";
@@ -1,5 +1,5 @@
1
1
  import type * as OxcTypes from "@oxc-project/types";
2
- import type MagicString from "magic-string";
2
+ import type { MagicString } from "magic-string";
3
3
  export type OxcImport = (OxcTypes.ImportDeclaration | OxcTypes.ExportAllDeclaration | OxcTypes.ExportNamedDeclaration) & {
4
4
  source: OxcTypes.StringLiteral;
5
5
  shouldAddIndex?: boolean;
package/dist/esbuild.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- //#region src/esbuild.ts
1
+ import { t as IsolatedDecl } from "./src-C53dSqof.mjs";
2
+ // src/esbuild.ts
3
3
  /**
4
4
  * This entry file is for esbuild plugin.
5
5
  *
@@ -18,5 +18,4 @@ import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
18
18
  * ```
19
19
  */
20
20
  const esbuild = IsolatedDecl.esbuild;
21
- //#endregion
22
21
  export { esbuild as default, esbuild as "module.exports" };
package/dist/farm.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- //#region src/farm.ts
1
+ import { t as IsolatedDecl } from "./src-C53dSqof.mjs";
2
+ // src/farm.ts
3
3
  /**
4
4
  * This entry file is for Farm plugin.
5
5
  *
@@ -19,5 +19,4 @@ import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
19
19
  * ```
20
20
  */
21
21
  const farm = IsolatedDecl.farm;
22
- //#endregion
23
22
  export { farm as default, farm as "module.exports" };
package/dist/index.mjs CHANGED
@@ -1,2 +1 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- export { IsolatedDecl };
1
+ export { t as IsolatedDecl } from "./src-C53dSqof.mjs";
package/dist/rolldown.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- //#region src/rolldown.ts
1
+ import { t as IsolatedDecl } from "./src-C53dSqof.mjs";
2
+ // src/rolldown.ts
3
3
  /**
4
4
  * This entry file is for Rolldown plugin.
5
5
  *
@@ -19,5 +19,4 @@ import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
19
19
  * ```
20
20
  */
21
21
  const rolldown = IsolatedDecl.rolldown;
22
- //#endregion
23
22
  export { rolldown as default, rolldown as "module.exports" };
package/dist/rollup.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- //#region src/rollup.ts
1
+ import { t as IsolatedDecl } from "./src-C53dSqof.mjs";
2
+ // src/rollup.ts
3
3
  /**
4
4
  * This entry file is for Rollup plugin.
5
5
  *
@@ -19,5 +19,4 @@ import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
19
19
  * ```
20
20
  */
21
21
  const rollup = IsolatedDecl.rollup;
22
- //#endregion
23
22
  export { rollup as default, rollup as "module.exports" };
@@ -1,12 +1,14 @@
1
- import { a as tsTransform, i as swcTransform, n as generateDtsMap, r as oxcTransform, t as appendMapUrl } from "./transformer-UfUlpcf6.mjs";
2
- import path from "node:path";
3
1
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
- import MagicString from "magic-string";
2
+ import path from "node:path";
3
+ import { MagicString } from "magic-string";
5
4
  import { parse } from "oxc-parser";
6
5
  import { createUnplugin } from "unplugin";
7
6
  import { createFilter } from "unplugin-utils";
8
7
  import { createDebug } from "obug";
9
- //#region src/core/utils.ts
8
+ import { a as tsTransform, i as swcTransform, n as generateDtsMap, r as oxcTransform, t as appendMapUrl } from "./transformer-CZhoOHAY.mjs";
9
+ // src/core/utils.ts
10
+ const extensionRE = /\.(.?)[jt]sx?$/;
11
+ const indexRE = /(?:^|[/\\])index(?:\..+)?$/;
10
12
  const debug = createDebug("unplugin-isolated-decl");
11
13
  function lowestCommonAncestor(...filepaths) {
12
14
  if (filepaths.length === 0) return "";
@@ -27,7 +29,7 @@ function lowestCommonAncestor(...filepaths) {
27
29
  return ancestor.length <= 1 && ancestor[0] === "" ? `/${ancestor[0]}` : ancestor.join("/");
28
30
  }
29
31
  function stripExt(filename) {
30
- return filename.replace(/\.(.?)[jt]sx?$/, "");
32
+ return filename.replace(extensionRE, "");
31
33
  }
32
34
  function resolveEntry(input, userInputBase) {
33
35
  if (typeof input === "string") input = [input];
@@ -39,13 +41,14 @@ function resolveEntry(input, userInputBase) {
39
41
  };
40
42
  }
41
43
  function endsWithIndex(s) {
42
- return /(?:^|[/\\])index(?:\..+)?$/.test(s);
44
+ return indexRE.test(s);
43
45
  }
44
46
  function shouldAddIndex(id, resolved) {
45
47
  return !endsWithIndex(id) && endsWithIndex(resolved);
46
48
  }
47
- //#endregion
48
- //#region src/core/ast.ts
49
+ // src/core/ast.ts
50
+ const declarationExtRE = /\.(.)?[jt]sx?$/;
51
+ const relativePathRE = /^\.\.?\//;
49
52
  function filterImports(program) {
50
53
  return program.body.filter((node) => !!("source" in node && node.source));
51
54
  }
@@ -58,7 +61,7 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
58
61
  const entry = entryAlias || srcRel;
59
62
  const resolvedEntry = entryFileNames.replaceAll("[name]", entry);
60
63
  const emitDir = path.dirname(resolvedEntry);
61
- const emitDtsName = resolvedEntry.replace(/\.(.)?[jt]sx?$/, (_, s) => `.d.${s || ""}ts`);
64
+ const emitDtsName = resolvedEntry.replace(declarationExtRE, (_, s) => `.d.${s || ""}ts`);
62
65
  const offset = path.relative(emitDir, srcDirRel);
63
66
  for (const i of imports) {
64
67
  const { source } = i;
@@ -75,7 +78,7 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
75
78
  debug("Patch import in", srcRel, ":", srcIdRel, "->", final);
76
79
  final = final.replaceAll("\\", "/");
77
80
  if (final.startsWith("/")) final = `.${final}`;
78
- if (!/^\.\.?\//.test(final)) final = `./${final}`;
81
+ if (!relativePathRE.test(final)) final = `./${final}`;
79
82
  s.overwrite(i.source.start + 1, i.source.end - 1, final);
80
83
  }
81
84
  }
@@ -84,12 +87,13 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
84
87
  function pathRelative(from, to) {
85
88
  return path.join(path.relative(from, path.dirname(to)), path.basename(to));
86
89
  }
87
- //#endregion
88
- //#region src/core/options.ts
90
+ // src/core/options.ts
91
+ const defaultIncludeRE = /\.[cm]?tsx?$/;
92
+ const defaultExcludeRE = /node_modules/;
89
93
  function resolveOptions(options) {
90
94
  return {
91
- include: options.include || [/\.[cm]?tsx?$/],
92
- exclude: options.exclude || [/node_modules/],
95
+ include: options.include || [defaultIncludeRE],
96
+ exclude: options.exclude || [defaultExcludeRE],
93
97
  enforce: "enforce" in options ? options.enforce : "pre",
94
98
  sourceMap: options.sourceMap || false,
95
99
  transformer: options.transformer || "oxc",
@@ -101,8 +105,7 @@ function resolveOptions(options) {
101
105
  transformOptions: options.transformOptions
102
106
  };
103
107
  }
104
- //#endregion
105
- //#region src/index.ts
108
+ // src/index.ts
106
109
  /**
107
110
  * This entry file is for main unplugin.
108
111
  * @module
@@ -165,16 +168,16 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
165
168
  case "swc":
166
169
  result = await swcTransform(id, code);
167
170
  break;
168
- case "typescript":
169
- result = await tsTransform(id, code, options.transformOptions, options.sourceMap);
170
- break;
171
+ case "typescript": result = await tsTransform(id, code, options.transformOptions, options.sourceMap);
171
172
  }
172
173
  const { code: dts, errors, map } = result;
173
174
  debug(label, "transformed", id, errors.length ? "with errors" : "successfully");
174
- if (errors.length) if (options.ignoreErrors) context.warn(errors[0]);
175
- else {
176
- context.error(errors[0]);
177
- return;
175
+ if (errors.length) {
176
+ if (options.ignoreErrors) context.warn(errors[0]);
177
+ else {
178
+ context.error(errors[0]);
179
+ return;
180
+ }
178
181
  }
179
182
  const { program } = await parse(id, dts);
180
183
  const imports = filterImports(program);
@@ -256,42 +259,43 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
256
259
  const { inputBase, entryMap } = resolveEntry(input, options.inputBase);
257
260
  debug("[farm] input base:", inputBase);
258
261
  if (output && typeof output.entryFilename !== "string") return console.error("entryFileName must be a string");
259
- const extFormatMap = new Map([
262
+ const extFormatMap = /* @__PURE__ */ new Map([
260
263
  ["cjs", "cjs"],
261
264
  ["esm", "js"],
262
265
  ["mjs", "js"]
263
266
  ]);
264
- output.entryFilename = "[entryName].[ext]";
265
- output.entryFilename = output.entryFilename.replace("[ext]", extFormatMap.get(output.format || "esm") || "js");
266
- const entryFileNames = output.entryFilename;
267
- for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
268
- let emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
269
- let source = s.toString();
270
- if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
271
- if (options.extraOutdir) emitName = path.join(options.extraOutdir || "", emitName);
272
- debug("[farm] emit dts file:", emitName);
273
- const outDir = output.path;
274
- if (options.sourceMap && map && outDir) {
275
- source = appendMapUrl(source, emitName);
267
+ const formats = Array.isArray(output.format) ? output.format : [output.format || "esm"];
268
+ for (const format of formats) {
269
+ const entryFileNames = `[name].${extFormatMap.get(format) || "js"}`;
270
+ for (const [srcFilename, { s, imports, map, ext }] of Object.entries(outputFiles)) {
271
+ let emitName = rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFilename);
272
+ let source = s.toString();
273
+ if (options.patchCjsDefaultExport && emitName.endsWith(".d.cts")) source = patchCjsDefaultExport(source);
274
+ if (options.extraOutdir) emitName = path.join(options.extraOutdir || "", emitName);
275
+ debug("[farm] emit dts file:", emitName);
276
+ const outDir = output.path;
277
+ if (options.sourceMap && map && outDir) {
278
+ source = appendMapUrl(source, emitName);
279
+ farmPluginContext.emitFile({
280
+ type: "asset",
281
+ fileName: `${emitName}.map`,
282
+ source: generateDtsMap(map, srcFilename + ext, path.join(outDir, emitName))
283
+ });
284
+ }
276
285
  farmPluginContext.emitFile({
277
286
  type: "asset",
278
- fileName: `${emitName}.map`,
279
- source: generateDtsMap(map, srcFilename + ext, path.join(outDir, emitName))
287
+ fileName: emitName,
288
+ source
280
289
  });
281
290
  }
282
- farmPluginContext.emitFile({
283
- type: "asset",
284
- fileName: emitName,
285
- source
286
- });
287
291
  }
288
292
  }
289
293
  function esbuildSetup(build) {
290
294
  build.onEnd(async (result) => {
291
295
  const esbuildOptions = build.initialOptions;
292
296
  const entries = esbuildOptions.entryPoints;
293
- if (!entries || !Array.isArray(entries) || !entries.every((entry) => typeof entry === "string")) throw new Error("unsupported entryPoints, must be an string[]");
294
- const inputBase = options.inputBase || lowestCommonAncestor(...entries);
297
+ if (!entries || !Array.isArray(entries) || entries.some((entry) => typeof entry !== "string")) throw new Error("unsupported entryPoints, must be an string[]");
298
+ const inputBase = options.inputBase || lowestCommonAncestor(...entries.map((entry) => typeof entry === "string" ? entry : entry.in));
295
299
  debug("[esbuild] input base:", inputBase);
296
300
  const jsExt = esbuildOptions.outExtension?.[".js"];
297
301
  let outExt;
@@ -302,9 +306,7 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
302
306
  case ".mjs":
303
307
  outExt = "mts";
304
308
  break;
305
- default:
306
- outExt = "ts";
307
- break;
309
+ default: outExt = "ts";
308
310
  }
309
311
  const write = build.initialOptions.write ?? true;
310
312
  if (write) {
@@ -379,8 +381,8 @@ async function resolve(context, id, importer) {
379
381
  }
380
382
  } catch {}
381
383
  }
384
+ const cjsDefaultExportRE = /(?<=(?:[;}]|^)\s*export\s*)(?:\{\s*([\w$]+)\s*as\s+default\s*\}|default\s+([\w$]+))/;
382
385
  function patchCjsDefaultExport(source) {
383
- return source.replace(/(?<=(?:[;}]|^)\s*export\s*)(?:\{\s*([\w$]+)\s*as\s+default\s*\}|default\s+([\w$]+))/, (_, s1, s2) => `= ${s1 || s2}`);
386
+ return source.replace(cjsDefaultExportRE, (_, s1, s2) => `= ${s1 || s2}`);
384
387
  }
385
- //#endregion
386
388
  export { IsolatedDecl as t };
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- //#region src/core/transformer.ts
2
+ // src/core/transformer.ts
3
3
  function tryImport(pkg) {
4
4
  return import(pkg).catch(() => null);
5
5
  }
@@ -104,5 +104,4 @@ function generateDtsMap(mappings, src, dts) {
104
104
  mappings
105
105
  });
106
106
  }
107
- //#endregion
108
107
  export { tsTransform as a, swcTransform as i, generateDtsMap as n, oxcTransform as r, appendMapUrl as t };
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
2
- //#region src/vite.ts
1
+ import { t as IsolatedDecl } from "./src-C53dSqof.mjs";
2
+ // src/vite.ts
3
3
  /**
4
4
  * This entry file is for Vite plugin.
5
5
  *
@@ -19,5 +19,4 @@ import { t as IsolatedDecl } from "./src-C4IZ1TdD.mjs";
19
19
  * ```
20
20
  */
21
21
  const vite = IsolatedDecl.vite;
22
- //#endregion
23
22
  export { vite as default, vite as "module.exports" };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-isolated-decl",
3
3
  "type": "module",
4
- "version": "0.16.0",
4
+ "version": "0.17.1",
5
5
  "description": "A blazing-fast tool for generating isolated declarations.",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -21,6 +21,7 @@
21
21
  "esbuild",
22
22
  "webpack"
23
23
  ],
24
+ "sideEffects": false,
24
25
  "exports": {
25
26
  ".": "./dist/index.mjs",
26
27
  "./api": "./dist/api.mjs",
@@ -46,7 +47,7 @@
46
47
  "access": "public"
47
48
  },
48
49
  "engines": {
49
- "node": "^20.19.0 || >=22.12.0"
50
+ "node": "^22.18.0 || ^24.11.0 || >=26.0.0"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "@swc/core": "^1.6.6",
@@ -61,50 +62,47 @@
61
62
  }
62
63
  },
63
64
  "dependencies": {
64
- "magic-string": "^0.30.21",
65
- "obug": "^2.1.1",
66
- "oxc-parser": ">=0.127.0",
67
- "oxc-transform": ">=0.127.0",
68
- "unplugin": "^3.0.0",
69
- "unplugin-utils": "^0.3.1"
65
+ "magic-string": "^1.4.5",
66
+ "obug": "^3.0.0",
67
+ "oxc-parser": ">=0.160.0",
68
+ "oxc-transform": ">=0.160.0",
69
+ "unplugin": "^3.7.0",
70
+ "unplugin-utils": "^0.3.2"
70
71
  },
71
72
  "devDependencies": {
72
- "@arethetypeswrong/core": "^0.18.2",
73
- "@farmfe/core": "^1.7.11",
74
- "@oxc-project/types": "^0.127.0",
75
- "@rollup/plugin-alias": "^6.0.0",
76
- "@swc/core": "^1.15.30",
77
- "@sxzz/eslint-config": "^7.8.4",
78
- "@sxzz/prettier-config": "^2.3.1",
79
- "@sxzz/test-utils": "^0.5.16",
80
- "@types/node": "^25.6.0",
81
- "@typescript/native-preview": "7.0.0-dev.20260422.1",
82
- "bumpp": "^11.0.1",
83
- "esbuild": "^0.28.0",
84
- "eslint": "^10.2.1",
85
- "prettier": "^3.8.3",
86
- "publint": "^0.3.18",
87
- "rolldown": "^1.0.0-rc.17",
88
- "rollup": "^4.60.2",
89
- "tinyglobby": "^0.2.16",
90
- "tsdown": "^0.21.9",
73
+ "@arethetypeswrong/core": "^0.18.5",
74
+ "@farmfe/core": "^2.0.1",
75
+ "@oxc-project/types": "^0.160.0",
76
+ "@rollup/plugin-alias": "^6.0.1",
77
+ "@swc/core": "^1.16.22",
78
+ "@sxzz/eslint-config": "^8.9.2",
79
+ "@sxzz/prettier-config": "^2.4.0",
80
+ "@sxzz/test-utils": "^0.5.20",
81
+ "@types/node": "^26.6.11",
82
+ "bumpp": "^12.3.0",
83
+ "esbuild": "^0.28.2",
84
+ "eslint": "^10.16.0",
85
+ "prettier": "^3.10.1",
86
+ "publint": "^0.3.25",
87
+ "rolldown": "^1.3.4",
88
+ "rollup": "^4.69.0",
89
+ "tinyglobby": "^0.2.17",
90
+ "tsdown": "^0.23.7",
91
91
  "typescript": "^6.0.3",
92
- "unplugin-oxc": "^0.6.0",
93
- "vite": "^8.0.9",
94
- "vitest": "^4.1.5"
95
- },
96
- "resolutions": {
97
- "@changesets/cli": "-",
98
- "unplugin-isolated-decl": "-"
92
+ "typescript-next": "npm:typescript@^7.0.2",
93
+ "unplugin-oxc": "^0.6.2",
94
+ "vite": "^8.4.0",
95
+ "vitest": "^5.1.2"
99
96
  },
100
97
  "prettier": "@sxzz/prettier-config",
101
98
  "scripts": {
102
99
  "lint": "eslint --cache .",
103
100
  "lint:fix": "pnpm run lint --fix",
101
+ "format": "prettier --write .",
104
102
  "build": "tsdown",
105
103
  "dev": "tsdown --watch",
106
104
  "test": "vitest",
107
- "typecheck": "tsgo --noEmit",
105
+ "typecheck": "tsc",
108
106
  "release": "bumpp"
109
107
  }
110
108
  }