unplugin-isolated-decl 0.8.0 → 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-BpqQm19o.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-CLCa83Ij.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-BpqQm19o.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-CLCa83Ij.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-BpqQm19o.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-CLCa83Ij.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-BpqQm19o.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-CLCa83Ij.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-BpqQm19o.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-CLCa83Ij.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
@@ -83,7 +87,7 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
83
87
  const offset = node_path.default.relative(emitDir, srcDirRel);
84
88
  for (const i of imports) {
85
89
  const { source } = i;
86
- const { value: srcIdRel } = source;
90
+ const srcIdRel = stripExt(source.value);
87
91
  if (srcIdRel[0] !== ".") continue;
88
92
  const srcId = node_path.default.resolve(srcDir, srcIdRel);
89
93
  const importAlias = entryMap?.[srcId];
@@ -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}`;
@@ -181,19 +186,19 @@ else {
181
186
  const s = new magic_string.default(dts);
182
187
  if (options.autoAddExts || options.rewriteImports) for (const i of imports) {
183
188
  const { source } = i;
184
- const { value } = source;
185
- if (options.autoAddExts && (node_path.default.isAbsolute(value) || value[0] === ".") && !node_path.default.basename(value).includes(".")) {
186
- const resolved = await resolve(context, value, id);
187
- if (!resolved || resolved.external) continue;
188
- if (resolved.id.endsWith(".ts") || resolved.id.endsWith(".tsx")) i.suffix = ".js";
189
- }
189
+ let { value } = source;
190
190
  if (options.rewriteImports) {
191
191
  const result$1 = options.rewriteImports(value, id);
192
192
  if (typeof result$1 === "string") {
193
- source.value = result$1;
193
+ source.value = value = result$1;
194
194
  s.overwrite(source.start + 1, source.end - 1, result$1);
195
195
  }
196
196
  }
197
+ if (options.autoAddExts && (node_path.default.isAbsolute(value) || value[0] === ".")) {
198
+ const resolved = await resolve(context, value, stripExt(id));
199
+ if (!resolved || resolved.external) continue;
200
+ i.ext = guessExt(resolved.id);
201
+ }
197
202
  }
198
203
  addOutput(id, {
199
204
  s,
@@ -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
@@ -59,7 +63,7 @@ function rewriteImports(s, imports, entryMap, inputBase, entryFileNames, srcFile
59
63
  const offset = path$1.relative(emitDir, srcDirRel);
60
64
  for (const i of imports) {
61
65
  const { source } = i;
62
- const { value: srcIdRel } = source;
66
+ const srcIdRel = stripExt(source.value);
63
67
  if (srcIdRel[0] !== ".") continue;
64
68
  const srcId = path$1.resolve(srcDir, srcIdRel);
65
69
  const importAlias = entryMap?.[srcId];
@@ -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}`;
@@ -157,19 +162,19 @@ else {
157
162
  const s = new MagicString(dts);
158
163
  if (options.autoAddExts || options.rewriteImports) for (const i of imports) {
159
164
  const { source } = i;
160
- const { value } = source;
161
- if (options.autoAddExts && (path.isAbsolute(value) || value[0] === ".") && !path.basename(value).includes(".")) {
162
- const resolved = await resolve(context, value, id);
163
- if (!resolved || resolved.external) continue;
164
- if (resolved.id.endsWith(".ts") || resolved.id.endsWith(".tsx")) i.suffix = ".js";
165
- }
165
+ let { value } = source;
166
166
  if (options.rewriteImports) {
167
167
  const result$1 = options.rewriteImports(value, id);
168
168
  if (typeof result$1 === "string") {
169
- source.value = result$1;
169
+ source.value = value = result$1;
170
170
  s.overwrite(source.start + 1, source.end - 1, result$1);
171
171
  }
172
172
  }
173
+ if (options.autoAddExts && (path.isAbsolute(value) || value[0] === ".")) {
174
+ const resolved = await resolve(context, value, stripExt(id));
175
+ if (!resolved || resolved.external) continue;
176
+ i.ext = guessExt(resolved.id);
177
+ }
173
178
  }
174
179
  addOutput(id, {
175
180
  s,
@@ -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-BpqQm19o.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-CLCa83Ij.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.0",
3
+ "version": "0.8.2",
4
4
  "description": "A blazing-fast tool for generating isolated declarations.",
5
5
  "type": "module",
6
6
  "keywords": [