unplugin-isolated-decl 0.8.1 → 0.8.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.
@@ -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
- suffix?: string;
5
+ ext?: 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
- suffix?: string;
5
+ ext?: 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;
@@ -6,3 +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;
@@ -6,3 +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;
package/dist/esbuild.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src = require('./src-D3Z1XJCx.cjs');
2
+ const require_src = require('./src-CUBv8HDT.cjs');
3
3
  require('./transformer-C4rLQvdl.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/farm.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src = require('./src-D3Z1XJCx.cjs');
2
+ const require_src = require('./src-CUBv8HDT.cjs');
3
3
  require('./transformer-C4rLQvdl.cjs');
4
4
 
5
5
  //#region src/farm.ts
package/dist/farm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.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
- const require_src = require('./src-D3Z1XJCx.cjs');
1
+ const require_src = require('./src-CUBv8HDT.cjs');
2
2
  require('./transformer-C4rLQvdl.cjs');
3
3
 
4
4
  exports.IsolatedDecl = require_src.IsolatedDecl
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.js";
3
3
 
4
4
  export { IsolatedDecl };
package/dist/rolldown.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src = require('./src-D3Z1XJCx.cjs');
2
+ const require_src = require('./src-CUBv8HDT.cjs');
3
3
  require('./transformer-C4rLQvdl.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.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 = require('./src-D3Z1XJCx.cjs');
2
+ const require_src = require('./src-CUBv8HDT.cjs');
3
3
  require('./transformer-C4rLQvdl.cjs');
4
4
 
5
5
  //#region src/rollup.ts
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -64,6 +64,10 @@ function resolveEntry(input) {
64
64
  inputBase
65
65
  };
66
66
  }
67
+ function guessExt(filename) {
68
+ const ext = node_path.default.extname(filename).slice(1);
69
+ return ext.replace(/^([cm]?)ts/, (_, $1) => `${$1}js`);
70
+ }
67
71
 
68
72
  //#endregion
69
73
  //#region src/core/ast.ts
@@ -92,9 +96,10 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
92
96
  const resolved = stripExt(entryFileNames.replaceAll("[name]", importAlias));
93
97
  id = pathRelative(srcDirRel, resolved);
94
98
  } else id = stripExt(entryFileNames.replaceAll("[name]", srcIdRel));
95
- if (i.suffix) id += i.suffix;
99
+ const ext = i.ext || guessExt(source.value);
100
+ if (ext) id += `.${ext}`;
96
101
  let final = node_path.default.normalize(node_path.default.join(offset, id));
97
- if (final !== source.value) {
102
+ if (final !== node_path.default.normalize(source.value)) {
98
103
  debug$1("Patch import in", srcRel, ":", srcIdRel, "->", final);
99
104
  final = final.replaceAll("\\", "/");
100
105
  if (!/^\.\.?\//.test(final)) final = `./${final}`;
@@ -192,7 +197,7 @@ else {
192
197
  if (options.autoAddExts && (node_path.default.isAbsolute(value) || value[0] === ".")) {
193
198
  const resolved = await resolve(context, value, stripExt(id));
194
199
  if (!resolved || resolved.external) continue;
195
- if (resolved.id.endsWith(".ts") || resolved.id.endsWith(".tsx")) i.suffix = ".js";
200
+ i.ext = guessExt(resolved.id);
196
201
  }
197
202
  }
198
203
  addOutput(id, {
@@ -206,8 +211,7 @@ else {
206
211
  if (node.type === "ImportDeclaration") return !!node.specifiers && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
207
212
  return node.type === "ExportNamedDeclaration" && node.specifiers && node.specifiers.every((spec) => spec.exportKind === "type");
208
213
  });
209
- for (const i of typeImports) {
210
- const { source } = i;
214
+ for (const { source } of typeImports) {
211
215
  const resolved = (await resolve(context, source.value, id))?.id;
212
216
  if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
213
217
  let source$1;
@@ -40,6 +40,10 @@ function resolveEntry(input) {
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`);
46
+ }
43
47
 
44
48
  //#endregion
45
49
  //#region src/core/ast.ts
@@ -68,9 +72,10 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
68
72
  const resolved = stripExt(entryFileNames.replaceAll("[name]", importAlias));
69
73
  id = pathRelative(srcDirRel, resolved);
70
74
  } else id = stripExt(entryFileNames.replaceAll("[name]", srcIdRel));
71
- if (i.suffix) id += i.suffix;
75
+ const ext = i.ext || guessExt(source.value);
76
+ if (ext) id += `.${ext}`;
72
77
  let final = path$1.normalize(path$1.join(offset, id));
73
- if (final !== source.value) {
78
+ if (final !== path$1.normalize(source.value)) {
74
79
  debug("Patch import in", srcRel, ":", srcIdRel, "->", final);
75
80
  final = final.replaceAll("\\", "/");
76
81
  if (!/^\.\.?\//.test(final)) final = `./${final}`;
@@ -168,7 +173,7 @@ else {
168
173
  if (options.autoAddExts && (path.isAbsolute(value) || value[0] === ".")) {
169
174
  const resolved = await resolve(context, value, stripExt(id));
170
175
  if (!resolved || resolved.external) continue;
171
- if (resolved.id.endsWith(".ts") || resolved.id.endsWith(".tsx")) i.suffix = ".js";
176
+ i.ext = guessExt(resolved.id);
172
177
  }
173
178
  }
174
179
  addOutput(id, {
@@ -182,8 +187,7 @@ else {
182
187
  if (node.type === "ImportDeclaration") return !!node.specifiers && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
183
188
  return node.type === "ExportNamedDeclaration" && node.specifiers && node.specifiers.every((spec) => spec.exportKind === "type");
184
189
  });
185
- for (const i of typeImports) {
186
- const { source } = i;
190
+ for (const { source } of typeImports) {
187
191
  const resolved = (await resolve(context, source.value, id))?.id;
188
192
  if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
189
193
  let source$1;
package/dist/vite.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_src = require('./src-D3Z1XJCx.cjs');
2
+ const require_src = require('./src-CUBv8HDT.cjs');
3
3
  require('./transformer-C4rLQvdl.cjs');
4
4
 
5
5
  //#region src/vite.ts
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./transformer-DDte86lZ.js";
2
- import { IsolatedDecl } from "./src-BiFhTk02.js";
2
+ import { IsolatedDecl } from "./src-DF97Tiay.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.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "A blazing-fast tool for generating isolated declarations.",
5
5
  "type": "module",
6
6
  "keywords": [