unplugin-isolated-decl 0.4.7 → 0.5.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/README.md CHANGED
@@ -90,6 +90,9 @@ export interface Options {
90
90
  /** Only for typescript transformer */
91
91
  transformOptions?: TranspileOptions
92
92
  ignoreErrors?: boolean
93
+
94
+ /** An extra directory layer for output files. */
95
+ extraOutdir?: string
93
96
  }
94
97
  ```
95
98
 
package/dist/api.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-wFl7-Qrk.cjs');
2
+ const require_transformer = require('./transformer-ZZscAG9G.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-69vts78l.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-2hVUBpkW.js";
2
2
 
3
3
  export { oxcTransform, swcTransform, tsTransform };
@@ -5,11 +5,12 @@ export type Options = {
5
5
  exclude?: FilterPattern;
6
6
  enforce?: "pre" | "post" | undefined;
7
7
  ignoreErrors?: boolean;
8
+ extraOutdir?: string;
8
9
  } & ({transformer?: "oxc" | "swc"} | {
9
10
  transformer: "typescript";
10
11
  transformOptions?: TranspileOptions;
11
12
  });
12
13
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
13
- export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
14
+ export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce" | "extraOutdir">>;
14
15
  export declare function resolveOptions(options: Options): OptionsResolved;
15
16
  export {};
@@ -5,11 +5,12 @@ export type Options = {
5
5
  exclude?: FilterPattern;
6
6
  enforce?: "pre" | "post" | undefined;
7
7
  ignoreErrors?: boolean;
8
+ extraOutdir?: string;
8
9
  } & ({transformer?: "oxc" | "swc"} | {
9
10
  transformer: "typescript";
10
11
  transformOptions?: TranspileOptions;
11
12
  });
12
13
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
13
- export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
14
+ export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce" | "extraOutdir">>;
14
15
  export declare function resolveOptions(options: Options): OptionsResolved;
15
16
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { TranspileOptions } from "typescript";
2
2
  export interface TransformResult {
3
- sourceText: string;
3
+ code: string;
4
4
  errors: Array<string>;
5
5
  }
6
6
  export declare function oxcTransform(id: string, code: string): TransformResult;
@@ -1,6 +1,6 @@
1
1
  import type { TranspileOptions } from "typescript";
2
2
  export interface TransformResult {
3
- sourceText: string;
3
+ code: string;
4
4
  errors: Array<string>;
5
5
  }
6
6
  export declare function oxcTransform(id: string, code: string): TransformResult;
package/dist/esbuild.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-wFl7-Qrk.cjs');
3
- const require_src_index = require('./src_index-t9_prpkU.cjs');
2
+ require('./transformer-ZZscAG9G.cjs');
3
+ const require_src_index = require('./src_index-xmclay4j.cjs');
4
4
 
5
5
  //#region src/esbuild.ts
6
6
  var esbuild_default = require_src_index.IsolatedDecl.esbuild;
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-69vts78l.js";
2
- import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
1
+ import "./transformer-2hVUBpkW.js";
2
+ import { IsolatedDecl } from "./src_index-0hJHBHCG.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
- require('./transformer-wFl7-Qrk.cjs');
3
- const require_src_index = require('./src_index-t9_prpkU.cjs');
2
+ require('./transformer-ZZscAG9G.cjs');
3
+ const require_src_index = require('./src_index-xmclay4j.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-69vts78l.js";
2
- import { IsolatedDecl, lowestCommonAncestor } from "./src_index-IB8kj2gH.js";
1
+ import "./transformer-2hVUBpkW.js";
2
+ import { IsolatedDecl, lowestCommonAncestor } from "./src_index-0hJHBHCG.js";
3
3
 
4
4
  export { IsolatedDecl, lowestCommonAncestor };
package/dist/rolldown.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-wFl7-Qrk.cjs');
3
- const require_src_index = require('./src_index-t9_prpkU.cjs');
2
+ require('./transformer-ZZscAG9G.cjs');
3
+ const require_src_index = require('./src_index-xmclay4j.cjs');
4
4
 
5
5
  //#region src/rolldown.ts
6
6
  var rolldown_default = require_src_index.IsolatedDecl.rolldown;
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-69vts78l.js";
2
- import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
1
+ import "./transformer-2hVUBpkW.js";
2
+ import { IsolatedDecl } from "./src_index-0hJHBHCG.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-wFl7-Qrk.cjs');
3
- const require_src_index = require('./src_index-t9_prpkU.cjs');
2
+ require('./transformer-ZZscAG9G.cjs');
3
+ const require_src_index = require('./src_index-xmclay4j.cjs');
4
4
 
5
5
  //#region src/rollup.ts
6
6
  var rollup_default = require_src_index.IsolatedDecl.rollup;
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-69vts78l.js";
2
- import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
1
+ import "./transformer-2hVUBpkW.js";
2
+ import { IsolatedDecl } from "./src_index-0hJHBHCG.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -1,4 +1,4 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-69vts78l.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-2hVUBpkW.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";
@@ -12,19 +12,17 @@ function resolveOptions(options) {
12
12
  exclude: options.exclude || [/node_modules/],
13
13
  enforce: "enforce" in options ? options.enforce : "pre",
14
14
  transformer: options.transformer || "oxc",
15
- ignoreErrors: options.ignoreErrors || false
15
+ ignoreErrors: options.ignoreErrors || false,
16
+ extraOutdir: options.extraOutdir
16
17
  };
17
18
  }
18
19
 
19
20
  //#endregion
20
21
  //#region src/index.ts
21
- const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
22
+ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
22
23
  const options = resolveOptions(rawOptions);
23
24
  const filter = createFilter(options.include, options.exclude);
24
25
  const outputFiles = {};
25
- function stripExt(filename) {
26
- return filename.replace(/\.(.?)[jt]s$/, "");
27
- }
28
26
  function addOutput(filename, source) {
29
27
  outputFiles[stripExt(filename)] = source;
30
28
  }
@@ -38,7 +36,10 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
38
36
  if (typeof outputOptions.entryFileNames !== "string") {
39
37
  return this.error("entryFileNames must be a string");
40
38
  }
41
- const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
39
+ let entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
40
+ if (options.extraOutdir) {
41
+ entryFileNames = path.join(options.extraOutdir, entryFileNames);
42
+ }
42
43
  for (const [filename, source] of Object.entries(outputFiles)) {
43
44
  this.emitFile({
44
45
  type: "asset",
@@ -53,52 +54,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
53
54
  return filter(id);
54
55
  },
55
56
  transform(code, id) {
56
- return transform.call(this, code, id);
57
+ return transform(this, code, id);
57
58
  },
58
- esbuild: { setup(build) {
59
- build.onEnd(async (result) => {
60
- const esbuildOptions = build.initialOptions;
61
- const entries = esbuildOptions.entryPoints;
62
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
63
- const outBase = lowestCommonAncestor(...entries);
64
- const jsExt = esbuildOptions.outExtension?.[".js"];
65
- let outExt;
66
- switch (jsExt) {
67
- case ".cjs":
68
- outExt = "cts";
69
- break;
70
- case ".mjs":
71
- outExt = "mts";
72
- break;
73
- default:
74
- outExt = "ts";
75
- break;
76
- }
77
- const write = build.initialOptions.write ?? true;
78
- if (write) {
79
- if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
80
- } else {
81
- result.outputFiles ||= [];
82
- }
83
- const textEncoder = new TextEncoder();
84
- for (const [filename, source] of Object.entries(outputFiles)) {
85
- const outDir = build.initialOptions.outdir;
86
- const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
87
- const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
88
- if (write) {
89
- await mkdir(path.dirname(filePath), { recursive: true });
90
- await writeFile(filePath, source);
91
- } else {
92
- result.outputFiles.push({
93
- path: filePath,
94
- contents: textEncoder.encode(source),
95
- hash: "",
96
- text: source
97
- });
98
- }
99
- }
100
- });
101
- } },
59
+ esbuild: { setup: esbuildSetup },
102
60
  rollup,
103
61
  rolldown: rollup,
104
62
  vite: {
@@ -107,7 +65,7 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
107
65
  ...rollup
108
66
  }
109
67
  };
110
- async function transform(code, id) {
68
+ async function transform(context, code, id) {
111
69
  let result;
112
70
  switch (options.transformer) {
113
71
  case "oxc":
@@ -118,12 +76,12 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
118
76
  break;
119
77
  case "typescript": result = await tsTransform(id, code, options.transformOptions);
120
78
  }
121
- const { sourceText, errors } = result;
79
+ const { code: sourceText, errors } = result;
122
80
  if (errors.length) {
123
81
  if (options.ignoreErrors) {
124
- this.warn(errors[0]);
82
+ context.warn(errors[0]);
125
83
  } else {
126
- this.error(errors[0]);
84
+ context.error(errors[0]);
127
85
  return;
128
86
  }
129
87
  }
@@ -139,18 +97,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
139
97
  if (node.importKind === "type") return true;
140
98
  return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
141
99
  });
142
- const resolve = async (id$1, importer) => {
143
- if (meta.framework === "esbuild") {
144
- return (await meta.build.resolve(id$1, {
145
- importer,
146
- resolveDir: path.dirname(importer),
147
- kind: "import-statement"
148
- })).path;
149
- }
150
- return (await this.resolve(id$1, importer))?.id;
151
- };
152
100
  for (const i of typeImports) {
153
- const resolved = await resolve(i.source.value, id);
101
+ const resolved = await resolve(context, i.source.value, id);
154
102
  if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
155
103
  let source;
156
104
  try {
@@ -158,11 +106,72 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
158
106
  } catch {
159
107
  continue;
160
108
  }
161
- await transform.call(this, source, resolved);
109
+ await transform(context, source, resolved);
162
110
  }
163
111
  }
164
112
  }
113
+ function esbuildSetup(build) {
114
+ build.onEnd(async (result) => {
115
+ const esbuildOptions = build.initialOptions;
116
+ const entries = esbuildOptions.entryPoints;
117
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
118
+ const outBase = lowestCommonAncestor(...entries);
119
+ const jsExt = esbuildOptions.outExtension?.[".js"];
120
+ let outExt;
121
+ switch (jsExt) {
122
+ case ".cjs":
123
+ outExt = "cts";
124
+ break;
125
+ case ".mjs":
126
+ outExt = "mts";
127
+ break;
128
+ default:
129
+ outExt = "ts";
130
+ break;
131
+ }
132
+ const write = build.initialOptions.write ?? true;
133
+ if (write) {
134
+ if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
135
+ } else {
136
+ result.outputFiles ||= [];
137
+ }
138
+ const textEncoder = new TextEncoder();
139
+ for (const [filename, source] of Object.entries(outputFiles)) {
140
+ const outDir = build.initialOptions.outdir;
141
+ let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
142
+ if (options.extraOutdir) {
143
+ outFile = path.join(options.extraOutdir, outFile);
144
+ }
145
+ const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
146
+ if (write) {
147
+ await mkdir(path.dirname(filePath), { recursive: true });
148
+ await writeFile(filePath, source);
149
+ } else {
150
+ result.outputFiles.push({
151
+ path: filePath,
152
+ contents: textEncoder.encode(source),
153
+ hash: "",
154
+ text: source
155
+ });
156
+ }
157
+ }
158
+ });
159
+ }
165
160
  });
161
+ const resolve = async (context, id, importer) => {
162
+ const nativeContext = context.getNativeBuildContext?.();
163
+ if (nativeContext?.framework === "esbuild") {
164
+ return (await nativeContext.build.resolve(id, {
165
+ importer,
166
+ resolveDir: path.dirname(importer),
167
+ kind: "import-statement"
168
+ })).path;
169
+ }
170
+ return (await context.resolve(id, importer))?.id;
171
+ };
172
+ function stripExt(filename) {
173
+ return filename.replace(/\.(.?)[jt]s$/, "");
174
+ }
166
175
  function lowestCommonAncestor(...filepaths) {
167
176
  if (filepaths.length === 0) return "";
168
177
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const require_transformer = require('./transformer-wFl7-Qrk.cjs');
2
+ const require_transformer = require('./transformer-ZZscAG9G.cjs');
3
3
  const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
4
4
  const { default: path } = __toESM(require("node:path"));
5
5
  const { createFilter } = __toESM(require("@rollup/pluginutils"));
@@ -13,19 +13,17 @@ function resolveOptions(options) {
13
13
  exclude: options.exclude || [/node_modules/],
14
14
  enforce: "enforce" in options ? options.enforce : "pre",
15
15
  transformer: options.transformer || "oxc",
16
- ignoreErrors: options.ignoreErrors || false
16
+ ignoreErrors: options.ignoreErrors || false,
17
+ extraOutdir: options.extraOutdir
17
18
  };
18
19
  }
19
20
 
20
21
  //#endregion
21
22
  //#region src/index.ts
22
- const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
23
+ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
23
24
  const options = resolveOptions(rawOptions);
24
25
  const filter = createFilter(options.include, options.exclude);
25
26
  const outputFiles = {};
26
- function stripExt(filename) {
27
- return filename.replace(/\.(.?)[jt]s$/, "");
28
- }
29
27
  function addOutput(filename, source) {
30
28
  outputFiles[stripExt(filename)] = source;
31
29
  }
@@ -39,7 +37,10 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
39
37
  if (typeof outputOptions.entryFileNames !== "string") {
40
38
  return this.error("entryFileNames must be a string");
41
39
  }
42
- const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
40
+ let entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
41
+ if (options.extraOutdir) {
42
+ entryFileNames = path.join(options.extraOutdir, entryFileNames);
43
+ }
43
44
  for (const [filename, source] of Object.entries(outputFiles)) {
44
45
  this.emitFile({
45
46
  type: "asset",
@@ -54,52 +55,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
54
55
  return filter(id);
55
56
  },
56
57
  transform(code, id) {
57
- return transform.call(this, code, id);
58
+ return transform(this, code, id);
58
59
  },
59
- esbuild: { setup(build) {
60
- build.onEnd(async (result) => {
61
- const esbuildOptions = build.initialOptions;
62
- const entries = esbuildOptions.entryPoints;
63
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
64
- const outBase = lowestCommonAncestor(...entries);
65
- const jsExt = esbuildOptions.outExtension?.[".js"];
66
- let outExt;
67
- switch (jsExt) {
68
- case ".cjs":
69
- outExt = "cts";
70
- break;
71
- case ".mjs":
72
- outExt = "mts";
73
- break;
74
- default:
75
- outExt = "ts";
76
- break;
77
- }
78
- const write = build.initialOptions.write ?? true;
79
- if (write) {
80
- if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
81
- } else {
82
- result.outputFiles ||= [];
83
- }
84
- const textEncoder = new TextEncoder();
85
- for (const [filename, source] of Object.entries(outputFiles)) {
86
- const outDir = build.initialOptions.outdir;
87
- const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
88
- const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
89
- if (write) {
90
- await mkdir(path.dirname(filePath), { recursive: true });
91
- await writeFile(filePath, source);
92
- } else {
93
- result.outputFiles.push({
94
- path: filePath,
95
- contents: textEncoder.encode(source),
96
- hash: "",
97
- text: source
98
- });
99
- }
100
- }
101
- });
102
- } },
60
+ esbuild: { setup: esbuildSetup },
103
61
  rollup,
104
62
  rolldown: rollup,
105
63
  vite: {
@@ -108,7 +66,7 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
108
66
  ...rollup
109
67
  }
110
68
  };
111
- async function transform(code, id) {
69
+ async function transform(context, code, id) {
112
70
  let result;
113
71
  switch (options.transformer) {
114
72
  case "oxc":
@@ -119,12 +77,12 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
119
77
  break;
120
78
  case "typescript": result = await require_transformer.tsTransform(id, code, options.transformOptions);
121
79
  }
122
- const { sourceText, errors } = result;
80
+ const { code: sourceText, errors } = result;
123
81
  if (errors.length) {
124
82
  if (options.ignoreErrors) {
125
- this.warn(errors[0]);
83
+ context.warn(errors[0]);
126
84
  } else {
127
- this.error(errors[0]);
85
+ context.error(errors[0]);
128
86
  return;
129
87
  }
130
88
  }
@@ -140,18 +98,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
140
98
  if (node.importKind === "type") return true;
141
99
  return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
142
100
  });
143
- const resolve = async (id$1, importer) => {
144
- if (meta.framework === "esbuild") {
145
- return (await meta.build.resolve(id$1, {
146
- importer,
147
- resolveDir: path.dirname(importer),
148
- kind: "import-statement"
149
- })).path;
150
- }
151
- return (await this.resolve(id$1, importer))?.id;
152
- };
153
101
  for (const i of typeImports) {
154
- const resolved = await resolve(i.source.value, id);
102
+ const resolved = await resolve(context, i.source.value, id);
155
103
  if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
156
104
  let source;
157
105
  try {
@@ -159,11 +107,72 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
159
107
  } catch {
160
108
  continue;
161
109
  }
162
- await transform.call(this, source, resolved);
110
+ await transform(context, source, resolved);
163
111
  }
164
112
  }
165
113
  }
114
+ function esbuildSetup(build) {
115
+ build.onEnd(async (result) => {
116
+ const esbuildOptions = build.initialOptions;
117
+ const entries = esbuildOptions.entryPoints;
118
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
119
+ const outBase = lowestCommonAncestor(...entries);
120
+ const jsExt = esbuildOptions.outExtension?.[".js"];
121
+ let outExt;
122
+ switch (jsExt) {
123
+ case ".cjs":
124
+ outExt = "cts";
125
+ break;
126
+ case ".mjs":
127
+ outExt = "mts";
128
+ break;
129
+ default:
130
+ outExt = "ts";
131
+ break;
132
+ }
133
+ const write = build.initialOptions.write ?? true;
134
+ if (write) {
135
+ if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
136
+ } else {
137
+ result.outputFiles ||= [];
138
+ }
139
+ const textEncoder = new TextEncoder();
140
+ for (const [filename, source] of Object.entries(outputFiles)) {
141
+ const outDir = build.initialOptions.outdir;
142
+ let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
143
+ if (options.extraOutdir) {
144
+ outFile = path.join(options.extraOutdir, outFile);
145
+ }
146
+ const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
147
+ if (write) {
148
+ await mkdir(path.dirname(filePath), { recursive: true });
149
+ await writeFile(filePath, source);
150
+ } else {
151
+ result.outputFiles.push({
152
+ path: filePath,
153
+ contents: textEncoder.encode(source),
154
+ hash: "",
155
+ text: source
156
+ });
157
+ }
158
+ }
159
+ });
160
+ }
166
161
  });
162
+ const resolve = async (context, id, importer) => {
163
+ const nativeContext = context.getNativeBuildContext?.();
164
+ if (nativeContext?.framework === "esbuild") {
165
+ return (await nativeContext.build.resolve(id, {
166
+ importer,
167
+ resolveDir: path.dirname(importer),
168
+ kind: "import-statement"
169
+ })).path;
170
+ }
171
+ return (await context.resolve(id, importer))?.id;
172
+ };
173
+ function stripExt(filename) {
174
+ return filename.replace(/\.(.?)[jt]s$/, "");
175
+ }
167
176
  function lowestCommonAncestor(...filepaths) {
168
177
  if (filepaths.length === 0) return "";
169
178
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
@@ -2,7 +2,7 @@ import { isolatedDeclaration } from "oxc-transform";
2
2
 
3
3
  //#region src/core/transformer.ts
4
4
  function oxcTransform(id, code) {
5
- return isolatedDeclaration(id, code);
5
+ return isolatedDeclaration(id, code, { sourcemap: false });
6
6
  }
7
7
  async function swcTransform(id, code) {
8
8
  let swc;
@@ -10,7 +10,7 @@ async function swcTransform(id, code) {
10
10
  swc = await import("@swc/core");
11
11
  } catch {
12
12
  return {
13
- sourceText: "",
13
+ code: "",
14
14
  errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
15
15
  };
16
16
  }
@@ -27,12 +27,12 @@ async function swcTransform(id, code) {
27
27
  });
28
28
  const output = JSON.parse(result.output);
29
29
  return {
30
- sourceText: output.__swc_isolated_declarations__,
30
+ code: output.__swc_isolated_declarations__,
31
31
  errors: []
32
32
  };
33
33
  } catch (error) {
34
34
  return {
35
- sourceText: "",
35
+ code: "",
36
36
  errors: [error.toString()]
37
37
  };
38
38
  }
@@ -43,13 +43,13 @@ async function tsTransform(id, code, transformOptions) {
43
43
  ts = await import("typescript");
44
44
  } catch {
45
45
  return {
46
- sourceText: "",
46
+ code: "",
47
47
  errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
48
48
  };
49
49
  }
50
50
  if (!ts.transpileDeclaration) {
51
51
  return {
52
- sourceText: "",
52
+ code: "",
53
53
  errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
54
54
  };
55
55
  }
@@ -64,7 +64,7 @@ async function tsTransform(id, code, transformOptions) {
64
64
  getNewLine: () => ts.sys.newLine
65
65
  }),] : [];
66
66
  return {
67
- sourceText: outputText,
67
+ code: outputText,
68
68
  errors
69
69
  };
70
70
  }
@@ -26,7 +26,7 @@ const { isolatedDeclaration } = __toESM(require("oxc-transform"));
26
26
 
27
27
  //#region src/core/transformer.ts
28
28
  function oxcTransform(id, code) {
29
- return isolatedDeclaration(id, code);
29
+ return isolatedDeclaration(id, code, { sourcemap: false });
30
30
  }
31
31
  async function swcTransform(id, code) {
32
32
  let swc;
@@ -34,7 +34,7 @@ async function swcTransform(id, code) {
34
34
  swc = await import("@swc/core");
35
35
  } catch {
36
36
  return {
37
- sourceText: "",
37
+ code: "",
38
38
  errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
39
39
  };
40
40
  }
@@ -51,12 +51,12 @@ async function swcTransform(id, code) {
51
51
  });
52
52
  const output = JSON.parse(result.output);
53
53
  return {
54
- sourceText: output.__swc_isolated_declarations__,
54
+ code: output.__swc_isolated_declarations__,
55
55
  errors: []
56
56
  };
57
57
  } catch (error) {
58
58
  return {
59
- sourceText: "",
59
+ code: "",
60
60
  errors: [error.toString()]
61
61
  };
62
62
  }
@@ -67,13 +67,13 @@ async function tsTransform(id, code, transformOptions) {
67
67
  ts = await import("typescript");
68
68
  } catch {
69
69
  return {
70
- sourceText: "",
70
+ code: "",
71
71
  errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
72
72
  };
73
73
  }
74
74
  if (!ts.transpileDeclaration) {
75
75
  return {
76
- sourceText: "",
76
+ code: "",
77
77
  errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
78
78
  };
79
79
  }
@@ -88,7 +88,7 @@ async function tsTransform(id, code, transformOptions) {
88
88
  getNewLine: () => ts.sys.newLine
89
89
  }),] : [];
90
90
  return {
91
- sourceText: outputText,
91
+ code: outputText,
92
92
  errors
93
93
  };
94
94
  }
package/dist/vite.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- require('./transformer-wFl7-Qrk.cjs');
3
- const require_src_index = require('./src_index-t9_prpkU.cjs');
2
+ require('./transformer-ZZscAG9G.cjs');
3
+ const require_src_index = require('./src_index-xmclay4j.cjs');
4
4
 
5
5
  //#region src/vite.ts
6
6
  var vite_default = require_src_index.IsolatedDecl.vite;
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-69vts78l.js";
2
- import { IsolatedDecl } from "./src_index-IB8kj2gH.js";
1
+ import "./transformer-2hVUBpkW.js";
2
+ import { IsolatedDecl } from "./src_index-0hJHBHCG.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.4.7",
3
+ "version": "0.5.1",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -81,27 +81,27 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@rollup/pluginutils": "^5.1.0",
84
- "oxc-parser": "^0.25.0",
85
- "oxc-transform": "^0.24.3",
86
- "unplugin": "^1.12.2"
84
+ "oxc-parser": "^0.27.0",
85
+ "oxc-transform": "^0.27.0",
86
+ "unplugin": "^1.14.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@swc/core": "^1.7.11",
90
- "@sxzz/eslint-config": "^3.17.2",
89
+ "@swc/core": "^1.7.24",
90
+ "@sxzz/eslint-config": "^4.2.0",
91
91
  "@sxzz/prettier-config": "^2.0.2",
92
- "@types/node": "^20.16.0",
93
- "bumpp": "^9.5.1",
92
+ "@types/node": "^22.5.4",
93
+ "bumpp": "^9.5.2",
94
94
  "esbuild": "^0.23.1",
95
- "eslint": "^9.9.0",
95
+ "eslint": "^9.10.0",
96
96
  "fast-glob": "^3.3.2",
97
97
  "prettier": "^3.3.3",
98
98
  "rolldown": "nightly",
99
- "rollup": "^4.21.0",
99
+ "rollup": "^4.21.2",
100
100
  "rollup-plugin-esbuild": "^6.1.1",
101
- "tsdown": "^0.2.6",
102
- "tsx": "^4.17.0",
103
- "typescript": "^5.5.4",
104
- "vite": "^5.4.1",
101
+ "tsdown": "^0.2.15",
102
+ "tsx": "^4.19.0",
103
+ "typescript": "^5.6.2",
104
+ "vite": "^5.4.3",
105
105
  "vitest": "^2.0.5"
106
106
  },
107
107
  "engines": {