unplugin-isolated-decl 0.9.2 → 0.9.4

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,4 +1,4 @@
1
- const require_transformer = require('./transformer-BI1dF8s7.cjs');
1
+ const require_transformer = require('./transformer-ApyMa6QO.cjs');
2
2
 
3
3
  exports.oxcTransform = require_transformer.oxcTransform
4
4
  exports.swcTransform = require_transformer.swcTransform
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-DfgXLWZQ.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-CHqAqBjB.js";
2
2
 
3
3
  export { oxcTransform, swcTransform, tsTransform };
@@ -2,7 +2,7 @@ import type * as OxcTypes from '@oxc-project/types';
2
2
  import type MagicString from 'magic-string';
3
3
  export type OxcImport = (OxcTypes.ImportDeclaration | OxcTypes.ExportAllDeclaration | OxcTypes.ExportNamedDeclaration) & {
4
4
  source: OxcTypes.StringLiteral;
5
- ext?: string;
5
+ suffix?: string;
6
6
  };
7
7
  export declare function filterImports(program: OxcTypes.Program): OxcImport[];
8
8
  export declare function rewriteImports(s: MagicString, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
@@ -2,7 +2,7 @@ import type * as OxcTypes from '@oxc-project/types';
2
2
  import type MagicString from 'magic-string';
3
3
  export type OxcImport = (OxcTypes.ImportDeclaration | OxcTypes.ExportAllDeclaration | OxcTypes.ExportNamedDeclaration) & {
4
4
  source: OxcTypes.StringLiteral;
5
- ext?: string;
5
+ suffix?: string;
6
6
  };
7
7
  export declare function filterImports(program: OxcTypes.Program): OxcImport[];
8
8
  export declare function rewriteImports(s: MagicString, imports: OxcImport[], entryMap: Record<string, string> | undefined, inputBase: string, entryFileNames: string, srcFilename: string): string;
@@ -36,7 +36,7 @@ export type Options = {
36
36
  * `typescript` should be installed yourself.
37
37
  * @default 'typescript'
38
38
  */
39
- transformer: 'typescript';
39
+ transformer?: 'typescript';
40
40
  /** Only for typescript transformer */
41
41
  transformOptions?: TranspileOptions;
42
42
  });
@@ -36,7 +36,7 @@ export type Options = {
36
36
  * `typescript` should be installed yourself.
37
37
  * @default 'typescript'
38
38
  */
39
- transformer: 'typescript';
39
+ transformer?: 'typescript';
40
40
  /** Only for typescript transformer */
41
41
  transformOptions?: TranspileOptions;
42
42
  });
@@ -6,4 +6,4 @@ export declare function resolveEntry(input: string | string[] | Record<string, s
6
6
  entryMap: Record<string, string> | undefined;
7
7
  inputBase: string;
8
8
  };
9
- export declare function guessExt(filename: string): string;
9
+ export declare function guessSuffix(id: string, resolved: string): string;
@@ -6,4 +6,4 @@ export declare function resolveEntry(input: string | string[] | Record<string, s
6
6
  entryMap: Record<string, string> | undefined;
7
7
  inputBase: string;
8
8
  };
9
- export declare function guessExt(filename: string): string;
9
+ export declare function guessSuffix(id: string, resolved: string): string;
package/dist/esbuild.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-BI1dF8s7.cjs');
3
- const require_src = require('./src-DVALVxuy.cjs');
2
+ require('./transformer-ApyMa6QO.cjs');
3
+ const require_src = require('./src-Dk3pOZcL.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
6
6
  var esbuild_default = require_src.IsolatedDecl.esbuild;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Esbuild plugin
9
9
  *
package/dist/esbuild.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Esbuild plugin
9
9
  *
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/farm.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-BI1dF8s7.cjs');
3
- const require_src = require('./src-DVALVxuy.cjs');
2
+ require('./transformer-ApyMa6QO.cjs');
3
+ const require_src = require('./src-Dk3pOZcL.cjs');
4
4
 
5
5
  //#region src/farm.ts
6
6
  var farm_default = require_src.IsolatedDecl.farm;
package/dist/farm.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Farm plugin
9
9
  *
package/dist/farm.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Farm plugin
9
9
  *
package/dist/farm.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.js";
3
3
 
4
4
  //#region src/farm.ts
5
5
  var farm_default = IsolatedDecl.farm;
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- require('./transformer-BI1dF8s7.cjs');
2
- const require_src = require('./src-DVALVxuy.cjs');
1
+ require('./transformer-ApyMa6QO.cjs');
2
+ const require_src = require('./src-Dk3pOZcL.cjs');
3
3
 
4
4
  exports.IsolatedDecl = require_src.IsolatedDecl
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.js";
3
3
 
4
4
  export { IsolatedDecl };
package/dist/rolldown.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-BI1dF8s7.cjs');
3
- const require_src = require('./src-DVALVxuy.cjs');
2
+ require('./transformer-ApyMa6QO.cjs');
3
+ const require_src = require('./src-Dk3pOZcL.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
6
6
  var rolldown_default = require_src.IsolatedDecl.rolldown;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Rolldown plugin
9
9
  *
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Rolldown plugin
9
9
  *
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.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
- require('./transformer-BI1dF8s7.cjs');
3
- const require_src = require('./src-DVALVxuy.cjs');
2
+ require('./transformer-ApyMa6QO.cjs');
3
+ const require_src = require('./src-Dk3pOZcL.cjs');
4
4
 
5
5
  //#region src/rollup.ts
6
6
  var rollup_default = require_src.IsolatedDecl.rollup;
package/dist/rollup.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Rollup plugin
9
9
  *
package/dist/rollup.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Rollup plugin
9
9
  *
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-BI1dF8s7.cjs');
2
+ const require_transformer = require('./transformer-ApyMa6QO.cjs');
3
3
  const node_path = require_transformer.__toESM(require("node:path"));
4
4
  const node_fs_promises = require_transformer.__toESM(require("node:fs/promises"));
5
5
  const __rollup_pluginutils = require_transformer.__toESM(require("@rollup/pluginutils"));
@@ -41,9 +41,15 @@ function resolveEntry(input, userInputBase) {
41
41
  inputBase
42
42
  };
43
43
  }
44
- function guessExt(filename) {
45
- const ext = node_path.default.extname(filename).slice(1);
46
- return ext.replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
44
+ function endsWithIndex(s) {
45
+ return /(?:^|[/\\])index\..+$/.test(s);
46
+ }
47
+ function guessSuffix(id, resolved) {
48
+ let suffix = "";
49
+ if (!endsWithIndex(id) && endsWithIndex(resolved)) suffix += "/index";
50
+ const ext = node_path.default.extname(resolved).slice(1).replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
51
+ suffix += `.${ext}`;
52
+ return suffix;
47
53
  }
48
54
 
49
55
  //#endregion
@@ -73,12 +79,13 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
73
79
  const resolved = stripExt(entryFileNames.replaceAll("[name]", importAlias));
74
80
  id = pathRelative(srcDirRel, resolved);
75
81
  } else id = stripExt(entryFileNames.replaceAll("[name]", srcIdRel));
76
- const ext = i.ext || guessExt(source.value);
77
- if (ext) id += `.${ext}`;
82
+ const suffix = i.suffix || guessSuffix(source.value, source.value);
83
+ if (suffix) id += suffix;
78
84
  let final = node_path.default.normalize(node_path.default.join(offset, id));
79
85
  if (final !== node_path.default.normalize(source.value)) {
80
86
  debug$1("Patch import in", srcRel, ":", srcIdRel, "->", final);
81
87
  final = final.replaceAll("\\", "/");
88
+ if (final.startsWith("/")) final = `.${final}`;
82
89
  if (!/^\.\.?\//.test(final)) final = `./${final}`;
83
90
  s.overwrite(i.source.start + 1, i.source.end - 1, final);
84
91
  }
@@ -166,7 +173,7 @@ else {
166
173
  context.error(errors[0]);
167
174
  return;
168
175
  }
169
- const { program } = await (0, oxc_parser.parseAsync)(dts, { sourceFilename: id });
176
+ const { program } = await (0, oxc_parser.parseAsync)(id, dts);
170
177
  const imports = filterImports(program);
171
178
  const s = new magic_string.default(dts);
172
179
  if (options.autoAddExts || options.rewriteImports) for (const i of imports) {
@@ -182,7 +189,7 @@ else {
182
189
  if (options.autoAddExts && (node_path.default.isAbsolute(value) || value[0] === ".")) {
183
190
  const resolved = await resolve(context, value, stripExt(id));
184
191
  if (!resolved || resolved.external) continue;
185
- i.ext = guessExt(resolved.id);
192
+ i.suffix = guessSuffix(value, resolved.id);
186
193
  }
187
194
  }
188
195
  addOutput(id, {
@@ -1,4 +1,4 @@
1
- import { appendMapUrl, generateDtsMap, oxcTransform, swcTransform, tsTransform } from "./transformer-DfgXLWZQ.js";
1
+ import { appendMapUrl, generateDtsMap, oxcTransform, swcTransform, tsTransform } from "./transformer-CHqAqBjB.js";
2
2
  import path, { default as path$1, default as path$2 } from "node:path";
3
3
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import { createFilter } from "@rollup/pluginutils";
@@ -40,9 +40,15 @@ function resolveEntry(input, userInputBase) {
40
40
  inputBase
41
41
  };
42
42
  }
43
- function guessExt(filename) {
44
- const ext = path$2.extname(filename).slice(1);
45
- return ext.replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
43
+ function endsWithIndex(s) {
44
+ return /(?:^|[/\\])index\..+$/.test(s);
45
+ }
46
+ function guessSuffix(id, resolved) {
47
+ let suffix = "";
48
+ if (!endsWithIndex(id) && endsWithIndex(resolved)) suffix += "/index";
49
+ const ext = path$2.extname(resolved).slice(1).replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
50
+ suffix += `.${ext}`;
51
+ return suffix;
46
52
  }
47
53
 
48
54
  //#endregion
@@ -72,12 +78,13 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
72
78
  const resolved = stripExt(entryFileNames.replaceAll("[name]", importAlias));
73
79
  id = pathRelative(srcDirRel, resolved);
74
80
  } else id = stripExt(entryFileNames.replaceAll("[name]", srcIdRel));
75
- const ext = i.ext || guessExt(source.value);
76
- if (ext) id += `.${ext}`;
81
+ const suffix = i.suffix || guessSuffix(source.value, source.value);
82
+ if (suffix) id += suffix;
77
83
  let final = path$1.normalize(path$1.join(offset, id));
78
84
  if (final !== path$1.normalize(source.value)) {
79
85
  debug("Patch import in", srcRel, ":", srcIdRel, "->", final);
80
86
  final = final.replaceAll("\\", "/");
87
+ if (final.startsWith("/")) final = `.${final}`;
81
88
  if (!/^\.\.?\//.test(final)) final = `./${final}`;
82
89
  s.overwrite(i.source.start + 1, i.source.end - 1, final);
83
90
  }
@@ -165,7 +172,7 @@ else {
165
172
  context.error(errors[0]);
166
173
  return;
167
174
  }
168
- const { program } = await parseAsync(dts, { sourceFilename: id });
175
+ const { program } = await parseAsync(id, dts);
169
176
  const imports = filterImports(program);
170
177
  const s = new MagicString(dts);
171
178
  if (options.autoAddExts || options.rewriteImports) for (const i of imports) {
@@ -181,7 +188,7 @@ else {
181
188
  if (options.autoAddExts && (path.isAbsolute(value) || value[0] === ".")) {
182
189
  const resolved = await resolve(context, value, stripExt(id));
183
190
  if (!resolved || resolved.external) continue;
184
- i.ext = guessExt(resolved.id);
191
+ i.suffix = guessSuffix(value, resolved.id);
185
192
  }
186
193
  }
187
194
  addOutput(id, {
@@ -26,11 +26,7 @@ const node_path = __toESM(require("node:path"));
26
26
 
27
27
  //#region src/core/transformer.ts
28
28
  function tryImport(pkg) {
29
- try {
30
- return import(pkg);
31
- } catch {
32
- return Promise.resolve(null);
33
- }
29
+ return import(pkg).catch(() => null);
34
30
  }
35
31
  async function oxcTransform(id, code, sourceMap) {
36
32
  const oxc = await tryImport("oxc-transform");
@@ -2,11 +2,7 @@ import path from "node:path";
2
2
 
3
3
  //#region src/core/transformer.ts
4
4
  function tryImport(pkg) {
5
- try {
6
- return import(pkg);
7
- } catch {
8
- return Promise.resolve(null);
9
- }
5
+ return import(pkg).catch(() => null);
10
6
  }
11
7
  async function oxcTransform(id, code, sourceMap) {
12
8
  const oxc = await tryImport("oxc-transform");
package/dist/vite.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-BI1dF8s7.cjs');
3
- const require_src = require('./src-DVALVxuy.cjs');
2
+ require('./transformer-ApyMa6QO.cjs');
3
+ const require_src = require('./src-Dk3pOZcL.cjs');
4
4
 
5
5
  //#region src/vite.ts
6
6
  var vite_default = require_src.IsolatedDecl.vite;
package/dist/vite.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Vite plugin
9
9
  *
package/dist/vite.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IsolatedDecl } from './index.js';
6
+ import { IsolatedDecl } from './index/index.js';
7
7
  /**
8
8
  * Vite plugin
9
9
  *
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-DfgXLWZQ.js";
2
- import { IsolatedDecl } from "./src-CoC_1xj6.js";
1
+ import "./transformer-CHqAqBjB.js";
2
+ import { IsolatedDecl } from "./src-Jtg_38T1.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.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "A blazing-fast tool for generating isolated declarations.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -91,14 +91,14 @@
91
91
  "@rollup/pluginutils": "^5.1.3",
92
92
  "debug": "^4.3.7",
93
93
  "magic-string": "^0.30.14",
94
- "oxc-parser": "^0.38.0",
95
- "unplugin": "^2.0.0-beta.1"
94
+ "oxc-parser": "^0.39.0",
95
+ "unplugin": "^2.0.0"
96
96
  },
97
97
  "devDependencies": {
98
- "@farmfe/core": "^1.4.5",
99
- "@oxc-project/types": "^0.38.0",
98
+ "@farmfe/core": "^1.4.7",
99
+ "@oxc-project/types": "^0.39.0",
100
100
  "@rollup/plugin-alias": "^5.1.1",
101
- "@swc/core": "^1.9.3",
101
+ "@swc/core": "^1.10.0",
102
102
  "@sxzz/eslint-config": "^4.5.1",
103
103
  "@sxzz/prettier-config": "^2.0.2",
104
104
  "@sxzz/test-utils": "^0.3.8",
@@ -108,17 +108,17 @@
108
108
  "esbuild": "^0.24.0",
109
109
  "eslint": "^9.16.0",
110
110
  "fast-glob": "^3.3.2",
111
- "oxc-transform": "^0.38.0",
112
- "prettier": "^3.4.1",
111
+ "oxc-transform": "^0.39.0",
112
+ "prettier": "^3.4.2",
113
113
  "rolldown": "nightly",
114
114
  "rollup": "^4.28.0",
115
115
  "rollup-plugin-esbuild": "^6.1.1",
116
116
  "tinyglobby": "^0.2.10",
117
- "tsdown": "^0.3.1",
117
+ "tsdown": "^0.4.1",
118
118
  "tsx": "^4.19.2",
119
119
  "typescript": "^5.7.2",
120
- "vite": "^6.0.1",
121
- "vitest": "^2.1.6"
120
+ "vite": "^6.0.2",
121
+ "vitest": "^2.1.8"
122
122
  },
123
123
  "engines": {
124
124
  "node": ">=18.12.0"