unplugin-isolated-decl 0.4.1 → 0.4.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.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## Features
8
8
 
9
- - 🚀 **Fast**: Blazing-fast `.d.ts` generator, powered by Oxc.
9
+ - 🚀 **Fast**: Generates `.d.ts` files significantly faster than `tsc`.
10
10
  - 🎨 **Transformer**: Support Oxc, SWC, and TypeScript transformer.
11
11
  - 📦 **Zero Config**: No configuration required, works out of the box.
12
12
  - ✨ **Bundler Support**: Works with Vite, Rollup, and esbuild.
@@ -89,6 +89,7 @@ export interface Options {
89
89
  transformer?: 'oxc' | 'swc' | 'typescript'
90
90
  /** Only for typescript transformer */
91
91
  transformOptions?: TranspileOptions
92
+ ignoreErrors?: boolean
92
93
  }
93
94
  ```
94
95
 
package/dist/api.cjs CHANGED
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
2
3
 
3
- const { __export, __toCommonJS, oxcTransform, swcTransform, tsTransform } = require("./transformer-ZIY9xt38.cjs");
4
-
5
- //#region src/api.ts
6
- var api_ns = {};
7
- __export(api_ns, {
8
- oxcTransform: () => oxcTransform,
9
- swcTransform: () => swcTransform,
10
- tsTransform: () => tsTransform
4
+ Object.defineProperty(exports, 'oxcTransform', {
5
+ enumerable: true,
6
+ get: function () {
7
+ return require_transformer.oxcTransform;
8
+ }
11
9
  });
12
-
13
- //#endregion
14
- module.exports = __toCommonJS(api_ns)
10
+ Object.defineProperty(exports, 'swcTransform', {
11
+ enumerable: true,
12
+ get: function () {
13
+ return require_transformer.swcTransform;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, 'tsTransform', {
17
+ enumerable: true,
18
+ get: function () {
19
+ return require_transformer.tsTransform;
20
+ }
21
+ });
package/dist/api.d.cts CHANGED
@@ -1 +1 @@
1
- export { oxcTransform, swcTransform, tsTransform } from './core/transformer';
1
+ export { oxcTransform, swcTransform, tsTransform } from "./core/transformer";
package/dist/api.d.ts CHANGED
@@ -1 +1 @@
1
- export { oxcTransform, swcTransform, tsTransform } from './core/transformer';
1
+ export { oxcTransform, swcTransform, tsTransform } from "./core/transformer";
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-m4c_uotZ.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-ScZEjI0h.js";
2
2
 
3
3
  export { oxcTransform, swcTransform, tsTransform };
@@ -1,14 +1,15 @@
1
- import type { TranspileOptions } from 'typescript';
2
- import type { FilterPattern } from '@rollup/pluginutils';
1
+ import type { TranspileOptions } from "typescript";
2
+ import type { FilterPattern } from "@rollup/pluginutils";
3
3
  export type Options = {
4
4
  include?: FilterPattern;
5
5
  exclude?: FilterPattern;
6
- enforce?: 'pre' | 'post' | undefined;
7
- } & ({transformer?: 'oxc' | 'swc'} | {
8
- transformer: 'typescript';
6
+ enforce?: "pre" | "post" | undefined;
7
+ ignoreErrors?: boolean;
8
+ } & ({transformer?: "oxc" | "swc"} | {
9
+ transformer: "typescript";
9
10
  transformOptions?: TranspileOptions;
10
11
  });
11
12
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
12
- export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
13
+ export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
13
14
  export declare function resolveOptions(options: Options): OptionsResolved;
14
15
  export {};
@@ -1,14 +1,15 @@
1
- import type { TranspileOptions } from 'typescript';
2
- import type { FilterPattern } from '@rollup/pluginutils';
1
+ import type { TranspileOptions } from "typescript";
2
+ import type { FilterPattern } from "@rollup/pluginutils";
3
3
  export type Options = {
4
4
  include?: FilterPattern;
5
5
  exclude?: FilterPattern;
6
- enforce?: 'pre' | 'post' | undefined;
7
- } & ({transformer?: 'oxc' | 'swc'} | {
8
- transformer: 'typescript';
6
+ enforce?: "pre" | "post" | undefined;
7
+ ignoreErrors?: boolean;
8
+ } & ({transformer?: "oxc" | "swc"} | {
9
+ transformer: "typescript";
9
10
  transformOptions?: TranspileOptions;
10
11
  });
11
12
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
12
- export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
13
+ export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
13
14
  export declare function resolveOptions(options: Options): OptionsResolved;
14
15
  export {};
@@ -1,4 +1,4 @@
1
- import type { TranspileOptions } from 'typescript';
1
+ import type { TranspileOptions } from "typescript";
2
2
  export interface TransformResult {
3
3
  sourceText: string;
4
4
  errors: Array<string>;
@@ -1,4 +1,4 @@
1
- import type { TranspileOptions } from 'typescript';
1
+ import type { TranspileOptions } from "typescript";
2
2
  export interface TransformResult {
3
3
  sourceText: string;
4
4
  errors: Array<string>;
package/dist/esbuild.cjs CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
-
3
- const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
- const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const require_src_index = require('./src_index-jgSmcGXY.cjs');
5
4
 
6
5
  //#region src/esbuild.ts
7
- var esbuild_ns = {};
8
- __export(esbuild_ns, {default: () => esbuild_default});
9
- var esbuild_default = IsolatedDecl.esbuild;
6
+ var esbuild_default = require_src_index.IsolatedDecl.esbuild;
10
7
 
11
8
  //#endregion
12
- module.exports = __toCommonJS(esbuild_ns)
9
+ module.exports = esbuild_default;
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.esbuild;
3
3
  export default _default;
package/dist/esbuild.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.esbuild;
3
3
  export default _default;
package/dist/esbuild.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-m4c_uotZ.js";
2
- import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
1
+ import "./transformer-ScZEjI0h.js";
2
+ import { IsolatedDecl } from "./src_index-lTUNmGu_.js";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  var esbuild_default = IsolatedDecl.esbuild;
package/dist/index.cjs CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const require_src_index = require('./src_index-jgSmcGXY.cjs');
2
4
 
3
- const { __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
- const { IsolatedDecl, src_index_ns } = require("./src_index-JrSKjSmw.cjs");
5
-
6
- module.exports = __toCommonJS(src_index_ns)
5
+ Object.defineProperty(exports, 'IsolatedDecl', {
6
+ enumerable: true,
7
+ get: function () {
8
+ return require_src_index.IsolatedDecl;
9
+ }
10
+ });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { type UnpluginInstance } from 'unplugin';
2
- import { type Options } from './core/options';
1
+ import { type UnpluginInstance } from "unplugin";
2
+ import { type Options } from "./core/options";
3
3
  export type { Options };
4
4
  export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type UnpluginInstance } from 'unplugin';
2
- import { type Options } from './core/options';
1
+ import { type UnpluginInstance } from "unplugin";
2
+ import { type Options } from "./core/options";
3
3
  export type { Options };
4
4
  export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./transformer-m4c_uotZ.js";
2
- import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
1
+ import "./transformer-ScZEjI0h.js";
2
+ import { IsolatedDecl } from "./src_index-lTUNmGu_.js";
3
3
 
4
4
  export { IsolatedDecl };
package/dist/rolldown.cjs CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
-
3
- const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
- const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const require_src_index = require('./src_index-jgSmcGXY.cjs');
5
4
 
6
5
  //#region src/rolldown.ts
7
- var rolldown_ns = {};
8
- __export(rolldown_ns, {default: () => rolldown_default});
9
- var rolldown_default = IsolatedDecl.rolldown;
6
+ var rolldown_default = require_src_index.IsolatedDecl.rolldown;
10
7
 
11
8
  //#endregion
12
- module.exports = __toCommonJS(rolldown_ns)
9
+ module.exports = rolldown_default;
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.rolldown;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.rolldown;
3
3
  export default _default;
package/dist/rolldown.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-m4c_uotZ.js";
2
- import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
1
+ import "./transformer-ScZEjI0h.js";
2
+ import { IsolatedDecl } from "./src_index-lTUNmGu_.js";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  var rolldown_default = IsolatedDecl.rolldown;
package/dist/rollup.cjs CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
-
3
- const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
- const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const require_src_index = require('./src_index-jgSmcGXY.cjs');
5
4
 
6
5
  //#region src/rollup.ts
7
- var rollup_ns = {};
8
- __export(rollup_ns, {default: () => rollup_default});
9
- var rollup_default = IsolatedDecl.rollup;
6
+ var rollup_default = require_src_index.IsolatedDecl.rollup;
10
7
 
11
8
  //#endregion
12
- module.exports = __toCommonJS(rollup_ns)
9
+ module.exports = rollup_default;
package/dist/rollup.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.rollup;
3
3
  export default _default;
package/dist/rollup.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.rollup;
3
3
  export default _default;
package/dist/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-m4c_uotZ.js";
2
- import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
1
+ import "./transformer-ScZEjI0h.js";
2
+ import { IsolatedDecl } from "./src_index-lTUNmGu_.js";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  var rollup_default = IsolatedDecl.rollup;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const { default: path } = __toESM(require("node:path"));
4
+ const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
5
+ const { createUnplugin } = __toESM(require("unplugin"));
6
+ const { createFilter } = __toESM(require("@rollup/pluginutils"));
7
+
8
+ //#region src/core/options.ts
9
+ function resolveOptions(options) {
10
+ return {
11
+ include: options.include || [/\.[cm]?ts$/],
12
+ exclude: options.exclude || [/node_modules/],
13
+ enforce: "enforce" in options ? options.enforce : "pre",
14
+ transformer: options.transformer || "oxc",
15
+ ignoreErrors: options.ignoreErrors || false
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/index.ts
21
+ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
22
+ const options = resolveOptions(rawOptions);
23
+ const filter = createFilter(options.include, options.exclude);
24
+ const outputFiles = {};
25
+ function addOutput(filename, source) {
26
+ outputFiles[filename.replace(/\.(.?)[jt]s$/, "")] = source;
27
+ }
28
+ const rollup = { renderStart(outputOptions, inputOptions) {
29
+ let outBase = "";
30
+ let input = inputOptions.input;
31
+ input = typeof input === "string" ? [input] : input;
32
+ if (Array.isArray(input)) {
33
+ outBase = lowestCommonAncestor(...input);
34
+ }
35
+ if (typeof outputOptions.entryFileNames !== "string") {
36
+ return this.error("entryFileNames must be a string");
37
+ }
38
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
39
+ for (const [filename, source] of Object.entries(outputFiles)) {
40
+ this.emitFile({
41
+ type: "asset",
42
+ fileName: entryFileNames.replace("[name]", path.relative(outBase, filename)),
43
+ source
44
+ });
45
+ }
46
+ } };
47
+ return {
48
+ name: "unplugin-isolated-decl",
49
+ transformInclude(id) {
50
+ return filter(id);
51
+ },
52
+ async transform(code, id) {
53
+ let result;
54
+ switch (options.transformer) {
55
+ case "oxc":
56
+ result = require_transformer.oxcTransform(id, code);
57
+ break;
58
+ case "swc":
59
+ result = await require_transformer.swcTransform(id, code);
60
+ break;
61
+ case "typescript": result = await require_transformer.tsTransform(id, code, options.transformOptions);
62
+ }
63
+ const { sourceText, errors } = result;
64
+ if (errors.length) {
65
+ if (options.ignoreErrors) {
66
+ this.warn(errors[0]);
67
+ } else {
68
+ this.error(errors[0]);
69
+ return;
70
+ }
71
+ }
72
+ addOutput(id, sourceText);
73
+ },
74
+ esbuild: { setup(build) {
75
+ build.onEnd(async (result) => {
76
+ const esbuildOptions = build.initialOptions;
77
+ const entries = esbuildOptions.entryPoints;
78
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
79
+ const outBase = lowestCommonAncestor(...entries);
80
+ const jsExt = esbuildOptions.outExtension?.[".js"];
81
+ let outExt;
82
+ switch (jsExt) {
83
+ case ".cjs":
84
+ outExt = "cts";
85
+ break;
86
+ case ".mjs":
87
+ outExt = "mts";
88
+ break;
89
+ default:
90
+ outExt = "ts";
91
+ break;
92
+ }
93
+ if (build.initialOptions.write ?? true) {
94
+ if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
95
+ for (const [filename, source] of Object.entries(outputFiles)) {
96
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
97
+ const filePath = path.resolve(build.initialOptions.outdir, outFile);
98
+ await mkdir(path.dirname(filePath), { recursive: true });
99
+ await writeFile(filePath, source);
100
+ }
101
+ } else {
102
+ result.outputFiles ||= [];
103
+ const textEncoder = new TextEncoder();
104
+ for (const [filename, source] of Object.entries(outputFiles)) {
105
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
106
+ result.outputFiles.push({
107
+ path: outFile,
108
+ contents: textEncoder.encode(source),
109
+ hash: "",
110
+ text: source
111
+ });
112
+ }
113
+ }
114
+ });
115
+ } },
116
+ rollup,
117
+ rolldown: rollup,
118
+ vite: {
119
+ apply: "build",
120
+ enforce: "pre",
121
+ ...rollup
122
+ }
123
+ };
124
+ });
125
+ function lowestCommonAncestor(...filepaths) {
126
+ if (filepaths.length === 0) return "";
127
+ if (filepaths.length === 1) return path.dirname(filepaths[0]);
128
+ const [first, ...rest] = filepaths;
129
+ let ancestor = first.split(path.sep);
130
+ for (const filepath of rest) {
131
+ const directories = filepath.split(path.sep, ancestor.length);
132
+ let index = 0;
133
+ for (const directory of directories) {
134
+ if (directory === ancestor[index]) {
135
+ index += 1;
136
+ } else {
137
+ ancestor = ancestor.slice(0, index);
138
+ break;
139
+ }
140
+ }
141
+ ancestor = ancestor.slice(0, index);
142
+ }
143
+ return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
144
+ }
145
+
146
+ //#endregion
147
+ Object.defineProperty(exports, 'IsolatedDecl', {
148
+ enumerable: true,
149
+ get: function () {
150
+ return IsolatedDecl;
151
+ }
152
+ });
@@ -1,4 +1,4 @@
1
- import { oxcTransform, swcTransform, tsTransform } from "./transformer-m4c_uotZ.js";
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-ScZEjI0h.js";
2
2
  import { default as path } from "node:path";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { createUnplugin } from "unplugin";
@@ -9,8 +9,9 @@ function resolveOptions(options) {
9
9
  return {
10
10
  include: options.include || [/\.[cm]?ts$/],
11
11
  exclude: options.exclude || [/node_modules/],
12
- enforce: 'enforce'in options ? options.enforce : 'pre',
13
- transformer: options.transformer || 'oxc'
12
+ enforce: "enforce" in options ? options.enforce : "pre",
13
+ transformer: options.transformer || "oxc",
14
+ ignoreErrors: options.ignoreErrors || false
14
15
  };
15
16
  }
16
17
 
@@ -21,89 +22,107 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
21
22
  const filter = createFilter(options.include, options.exclude);
22
23
  const outputFiles = {};
23
24
  function addOutput(filename, source) {
24
- outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
25
+ outputFiles[filename.replace(/\.(.?)[jt]s$/, "")] = source;
25
26
  }
26
- const rollup = {renderStart(outputOptions, inputOptions) {
27
- let outBase = '';
27
+ const rollup = { renderStart(outputOptions, inputOptions) {
28
+ let outBase = "";
28
29
  let input = inputOptions.input;
29
- input = typeof input === 'string' ? [input] : input;
30
+ input = typeof input === "string" ? [input] : input;
30
31
  if (Array.isArray(input)) {
31
32
  outBase = lowestCommonAncestor(...input);
32
33
  }
33
- if (typeof outputOptions.entryFileNames !== 'string') {
34
- return this.error('entryFileNames must be a string');
34
+ if (typeof outputOptions.entryFileNames !== "string") {
35
+ return this.error("entryFileNames must be a string");
35
36
  }
36
- const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
37
+ const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
37
38
  for (const [filename, source] of Object.entries(outputFiles)) {
38
39
  this.emitFile({
39
- type: 'asset',
40
- fileName: entryFileNames.replace('[name]', path.relative(outBase, filename)),
40
+ type: "asset",
41
+ fileName: entryFileNames.replace("[name]", path.relative(outBase, filename)),
41
42
  source
42
43
  });
43
44
  }
44
- }};
45
+ } };
45
46
  return {
46
- name: 'unplugin-isolated-decl',
47
+ name: "unplugin-isolated-decl",
47
48
  transformInclude(id) {
48
49
  return filter(id);
49
50
  },
50
51
  async transform(code, id) {
51
52
  let result;
52
53
  switch (options.transformer) {
53
- case 'oxc':
54
+ case "oxc":
54
55
  result = oxcTransform(id, code);
55
56
  break;
56
- case 'swc':
57
+ case "swc":
57
58
  result = await swcTransform(id, code);
58
59
  break;
59
- case 'typescript': result = await tsTransform(id, code, options.transformOptions);
60
+ case "typescript": result = await tsTransform(id, code, options.transformOptions);
60
61
  }
61
62
  const { sourceText, errors } = result;
62
63
  if (errors.length) {
63
- this.error(errors[0]);
64
- return;
64
+ if (options.ignoreErrors) {
65
+ this.warn(errors[0]);
66
+ } else {
67
+ this.error(errors[0]);
68
+ return;
69
+ }
65
70
  }
66
71
  addOutput(id, sourceText);
67
72
  },
68
- async buildEnd() {
69
- if (meta.framework === 'esbuild') {
70
- const esbuildOptions = meta.build.initialOptions;
73
+ esbuild: { setup(build) {
74
+ build.onEnd(async (result) => {
75
+ const esbuildOptions = build.initialOptions;
71
76
  const entries = esbuildOptions.entryPoints;
72
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
77
+ if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
73
78
  const outBase = lowestCommonAncestor(...entries);
74
- const jsExt = esbuildOptions.outExtension?.['.js'];
79
+ const jsExt = esbuildOptions.outExtension?.[".js"];
75
80
  let outExt;
76
81
  switch (jsExt) {
77
- case '.cjs':
78
- outExt = 'cts';
82
+ case ".cjs":
83
+ outExt = "cts";
79
84
  break;
80
- case '.mjs':
81
- outExt = 'mts';
85
+ case ".mjs":
86
+ outExt = "mts";
82
87
  break;
83
88
  default:
84
- outExt = 'ts';
89
+ outExt = "ts";
85
90
  break;
86
91
  }
87
- const build = meta.build;
88
- if (build.initialOptions.outdir && (build.initialOptions.write ?? true)) for (const [filename, source] of Object.entries(outputFiles)) {
89
- const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
90
- const filePath = path.resolve(build.initialOptions.outdir, outFile);
91
- await mkdir(path.dirname(filePath), {recursive: true});
92
- await writeFile(filePath, source);
92
+ if (build.initialOptions.write ?? true) {
93
+ if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
94
+ for (const [filename, source] of Object.entries(outputFiles)) {
95
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
96
+ const filePath = path.resolve(build.initialOptions.outdir, outFile);
97
+ await mkdir(path.dirname(filePath), { recursive: true });
98
+ await writeFile(filePath, source);
99
+ }
100
+ } else {
101
+ result.outputFiles ||= [];
102
+ const textEncoder = new TextEncoder();
103
+ for (const [filename, source] of Object.entries(outputFiles)) {
104
+ const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
105
+ result.outputFiles.push({
106
+ path: outFile,
107
+ contents: textEncoder.encode(source),
108
+ hash: "",
109
+ text: source
110
+ });
111
+ }
93
112
  }
94
- }
95
- },
113
+ });
114
+ } },
96
115
  rollup,
97
116
  rolldown: rollup,
98
117
  vite: {
99
- apply: 'build',
100
- enforce: 'pre',
118
+ apply: "build",
119
+ enforce: "pre",
101
120
  ...rollup
102
121
  }
103
122
  };
104
123
  });
105
124
  function lowestCommonAncestor(...filepaths) {
106
- if (filepaths.length === 0) return '';
125
+ if (filepaths.length === 0) return "";
107
126
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
108
127
  const [first, ...rest] = filepaths;
109
128
  let ancestor = first.split(path.sep);
@@ -120,7 +139,7 @@ function lowestCommonAncestor(...filepaths) {
120
139
  }
121
140
  ancestor = ancestor.slice(0, index);
122
141
  }
123
- return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
142
+ return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
124
143
  }
125
144
 
126
145
  //#endregion
@@ -7,11 +7,11 @@ function oxcTransform(id, code) {
7
7
  async function swcTransform(id, code) {
8
8
  let swc;
9
9
  try {
10
- swc = await import('@swc/core');
10
+ swc = await import("@swc/core");
11
11
  } catch {
12
12
  return {
13
- sourceText: '',
14
- errors: ['SWC is required for transforming TypeScript, please install `@swc/core`.',]
13
+ sourceText: "",
14
+ errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
15
15
  };
16
16
  }
17
17
  try {
@@ -19,10 +19,10 @@ async function swcTransform(id, code) {
19
19
  filename: id,
20
20
  jsc: {
21
21
  parser: {
22
- syntax: 'typescript',
22
+ syntax: "typescript",
23
23
  tsx: false
24
24
  },
25
- experimental: {emitIsolatedDts: true}
25
+ experimental: { emitIsolatedDts: true }
26
26
  }
27
27
  });
28
28
  const output = JSON.parse(result.output);
@@ -32,7 +32,7 @@ async function swcTransform(id, code) {
32
32
  };
33
33
  } catch (error) {
34
34
  return {
35
- sourceText: '',
35
+ sourceText: "",
36
36
  errors: [error.toString()]
37
37
  };
38
38
  }
@@ -40,17 +40,17 @@ async function swcTransform(id, code) {
40
40
  async function tsTransform(id, code, transformOptions) {
41
41
  let ts;
42
42
  try {
43
- ts = await import('typescript');
43
+ ts = await import("typescript");
44
44
  } catch {
45
45
  return {
46
- sourceText: '',
47
- errors: ['TypeScript is required for transforming TypeScript, please install `typescript`.',]
46
+ sourceText: "",
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: '',
53
- errors: ['TypeScript version is too low, please upgrade to TypeScript 5.5.2+.',]
52
+ sourceText: "",
53
+ errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
54
54
  };
55
55
  }
56
56
  const { outputText, diagnostics } = ts.transpileDeclaration(code, {
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
-
3
2
  //#region rolldown:runtime
4
3
  var __create = Object.create;
5
4
  var __defProp = Object.defineProperty;
@@ -7,14 +6,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
7
  var __getProtoOf = Object.getPrototypeOf;
9
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __export = (target, all) => {
11
- for (var name in all) __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- };
16
9
  var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === 'object' || typeof from === 'function') for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
11
  key = keys[i];
19
12
  if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
13
  get: ((k) => from[k]).bind(null, key),
@@ -23,11 +16,10 @@ var __copyProps = (to, from, except, desc) => {
23
16
  }
24
17
  return to;
25
18
  };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, 'default', {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
20
  value: mod,
28
21
  enumerable: true
29
22
  }) : target, mod));
30
- var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', {value: true}), mod);
31
23
 
32
24
  //#endregion
33
25
  const { isolatedDeclaration } = __toESM(require("oxc-transform"));
@@ -39,11 +31,11 @@ function oxcTransform(id, code) {
39
31
  async function swcTransform(id, code) {
40
32
  let swc;
41
33
  try {
42
- swc = await import('@swc/core');
34
+ swc = await import("@swc/core");
43
35
  } catch {
44
36
  return {
45
- sourceText: '',
46
- errors: ['SWC is required for transforming TypeScript, please install `@swc/core`.',]
37
+ sourceText: "",
38
+ errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
47
39
  };
48
40
  }
49
41
  try {
@@ -51,10 +43,10 @@ async function swcTransform(id, code) {
51
43
  filename: id,
52
44
  jsc: {
53
45
  parser: {
54
- syntax: 'typescript',
46
+ syntax: "typescript",
55
47
  tsx: false
56
48
  },
57
- experimental: {emitIsolatedDts: true}
49
+ experimental: { emitIsolatedDts: true }
58
50
  }
59
51
  });
60
52
  const output = JSON.parse(result.output);
@@ -64,7 +56,7 @@ async function swcTransform(id, code) {
64
56
  };
65
57
  } catch (error) {
66
58
  return {
67
- sourceText: '',
59
+ sourceText: "",
68
60
  errors: [error.toString()]
69
61
  };
70
62
  }
@@ -72,17 +64,17 @@ async function swcTransform(id, code) {
72
64
  async function tsTransform(id, code, transformOptions) {
73
65
  let ts;
74
66
  try {
75
- ts = await import('typescript');
67
+ ts = await import("typescript");
76
68
  } catch {
77
69
  return {
78
- sourceText: '',
79
- errors: ['TypeScript is required for transforming TypeScript, please install `typescript`.',]
70
+ sourceText: "",
71
+ errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
80
72
  };
81
73
  }
82
74
  if (!ts.transpileDeclaration) {
83
75
  return {
84
- sourceText: '',
85
- errors: ['TypeScript version is too low, please upgrade to TypeScript 5.5.2+.',]
76
+ sourceText: "",
77
+ errors: ["TypeScript version is too low, please upgrade to TypeScript 5.5.2+.",]
86
78
  };
87
79
  }
88
80
  const { outputText, diagnostics } = ts.transpileDeclaration(code, {
@@ -102,9 +94,24 @@ async function tsTransform(id, code, transformOptions) {
102
94
  }
103
95
 
104
96
  //#endregion
105
- exports.__export = __export;
106
- exports.__toCommonJS = __toCommonJS;
107
- exports.__toESM = __toESM;
108
- exports.oxcTransform = oxcTransform;
109
- exports.swcTransform = swcTransform;
110
- exports.tsTransform = tsTransform;
97
+ Object.defineProperty(exports, '__toESM', {
98
+ enumerable: true,
99
+ get: function () {
100
+ return __toESM;
101
+ }
102
+ });Object.defineProperty(exports, 'oxcTransform', {
103
+ enumerable: true,
104
+ get: function () {
105
+ return oxcTransform;
106
+ }
107
+ });Object.defineProperty(exports, 'swcTransform', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return swcTransform;
111
+ }
112
+ });Object.defineProperty(exports, 'tsTransform', {
113
+ enumerable: true,
114
+ get: function () {
115
+ return tsTransform;
116
+ }
117
+ });
package/dist/vite.cjs CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
-
3
- const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
- const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
2
+ const require_transformer = require('./transformer-oh0-JTHH.cjs');
3
+ const require_src_index = require('./src_index-jgSmcGXY.cjs');
5
4
 
6
5
  //#region src/vite.ts
7
- var vite_ns = {};
8
- __export(vite_ns, {default: () => vite_default});
9
- var vite_default = IsolatedDecl.vite;
6
+ var vite_default = require_src_index.IsolatedDecl.vite;
10
7
 
11
8
  //#endregion
12
- module.exports = __toCommonJS(vite_ns)
9
+ module.exports = vite_default;
package/dist/vite.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.vite;
3
3
  export default _default;
package/dist/vite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { IsolatedDecl } from './index';
1
+ import { IsolatedDecl } from "./index";
2
2
  declare const _default: typeof IsolatedDecl.vite;
3
3
  export default _default;
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./transformer-m4c_uotZ.js";
2
- import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
1
+ import "./transformer-ScZEjI0h.js";
2
+ import { IsolatedDecl } from "./src_index-lTUNmGu_.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.1",
3
+ "version": "0.4.2",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -81,25 +81,25 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@rollup/pluginutils": "^5.1.0",
84
- "oxc-transform": "^0.16.3",
85
- "unplugin": "^1.11.0"
84
+ "oxc-transform": "^0.21.0",
85
+ "unplugin": "^1.11.1"
86
86
  },
87
87
  "devDependencies": {
88
- "@swc/core": "^1.6.6",
89
- "@sxzz/eslint-config": "^3.13.0",
88
+ "@swc/core": "^1.7.0",
89
+ "@sxzz/eslint-config": "^3.14.0",
90
90
  "@sxzz/prettier-config": "^2.0.2",
91
- "@types/node": "^20.14.9",
91
+ "@types/node": "^20.14.11",
92
92
  "bumpp": "^9.4.1",
93
93
  "esbuild": "^0.23.0",
94
- "eslint": "^9.6.0",
94
+ "eslint": "^9.7.0",
95
95
  "fast-glob": "^3.3.2",
96
- "prettier": "^3.3.2",
97
- "rollup": "^4.18.0",
96
+ "prettier": "^3.3.3",
97
+ "rollup": "^4.19.0",
98
98
  "tsdown": "^0.2.3",
99
- "tsx": "^4.16.0",
99
+ "tsx": "^4.16.2",
100
100
  "typescript": "^5.5.3",
101
- "vite": "^5.3.2",
102
- "vitest": "^1.6.0"
101
+ "vite": "^5.3.4",
102
+ "vitest": "^2.0.3"
103
103
  },
104
104
  "engines": {
105
105
  "node": ">=18.12.0"
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- const { __export, __toESM, oxcTransform, swcTransform, tsTransform } = require("./transformer-ZIY9xt38.cjs");
4
- const { default: path } = __toESM(require("node:path"));
5
- const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
6
- const { createUnplugin } = __toESM(require("unplugin"));
7
- const { createFilter } = __toESM(require("@rollup/pluginutils"));
8
-
9
- //#region src/core/options.ts
10
- function resolveOptions(options) {
11
- return {
12
- include: options.include || [/\.[cm]?ts$/],
13
- exclude: options.exclude || [/node_modules/],
14
- enforce: 'enforce'in options ? options.enforce : 'pre',
15
- transformer: options.transformer || 'oxc'
16
- };
17
- }
18
-
19
- //#endregion
20
- //#region src/index.ts
21
- var src_index_ns = {};
22
- __export(src_index_ns, {IsolatedDecl: () => IsolatedDecl});
23
- const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
24
- const options = resolveOptions(rawOptions);
25
- const filter = createFilter(options.include, options.exclude);
26
- const outputFiles = {};
27
- function addOutput(filename, source) {
28
- outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source;
29
- }
30
- const rollup = {renderStart(outputOptions, inputOptions) {
31
- let outBase = '';
32
- let input = inputOptions.input;
33
- input = typeof input === 'string' ? [input] : input;
34
- if (Array.isArray(input)) {
35
- outBase = lowestCommonAncestor(...input);
36
- }
37
- if (typeof outputOptions.entryFileNames !== 'string') {
38
- return this.error('entryFileNames must be a string');
39
- }
40
- const entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ''}ts`);
41
- for (const [filename, source] of Object.entries(outputFiles)) {
42
- this.emitFile({
43
- type: 'asset',
44
- fileName: entryFileNames.replace('[name]', path.relative(outBase, filename)),
45
- source
46
- });
47
- }
48
- }};
49
- return {
50
- name: 'unplugin-isolated-decl',
51
- transformInclude(id) {
52
- return filter(id);
53
- },
54
- async transform(code, id) {
55
- let result;
56
- switch (options.transformer) {
57
- case 'oxc':
58
- result = oxcTransform(id, code);
59
- break;
60
- case 'swc':
61
- result = await swcTransform(id, code);
62
- break;
63
- case 'typescript': result = await tsTransform(id, code, options.transformOptions);
64
- }
65
- const { sourceText, errors } = result;
66
- if (errors.length) {
67
- this.error(errors[0]);
68
- return;
69
- }
70
- addOutput(id, sourceText);
71
- },
72
- async buildEnd() {
73
- if (meta.framework === 'esbuild') {
74
- const esbuildOptions = meta.build.initialOptions;
75
- const entries = esbuildOptions.entryPoints;
76
- if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === 'string'))) throw new Error('unsupported entryPoints, must be an string[]');
77
- const outBase = lowestCommonAncestor(...entries);
78
- const jsExt = esbuildOptions.outExtension?.['.js'];
79
- let outExt;
80
- switch (jsExt) {
81
- case '.cjs':
82
- outExt = 'cts';
83
- break;
84
- case '.mjs':
85
- outExt = 'mts';
86
- break;
87
- default:
88
- outExt = 'ts';
89
- break;
90
- }
91
- const build = meta.build;
92
- if (build.initialOptions.outdir && (build.initialOptions.write ?? true)) for (const [filename, source] of Object.entries(outputFiles)) {
93
- const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
94
- const filePath = path.resolve(build.initialOptions.outdir, outFile);
95
- await mkdir(path.dirname(filePath), {recursive: true});
96
- await writeFile(filePath, source);
97
- }
98
- }
99
- },
100
- rollup,
101
- rolldown: rollup,
102
- vite: {
103
- apply: 'build',
104
- enforce: 'pre',
105
- ...rollup
106
- }
107
- };
108
- });
109
- function lowestCommonAncestor(...filepaths) {
110
- if (filepaths.length === 0) return '';
111
- if (filepaths.length === 1) return path.dirname(filepaths[0]);
112
- const [first, ...rest] = filepaths;
113
- let ancestor = first.split(path.sep);
114
- for (const filepath of rest) {
115
- const directories = filepath.split(path.sep, ancestor.length);
116
- let index = 0;
117
- for (const directory of directories) {
118
- if (directory === ancestor[index]) {
119
- index += 1;
120
- } else {
121
- ancestor = ancestor.slice(0, index);
122
- break;
123
- }
124
- }
125
- ancestor = ancestor.slice(0, index);
126
- }
127
- return ancestor.length <= 1 && ancestor[0] === '' ? path.sep + ancestor[0] : ancestor.join(path.sep);
128
- }
129
-
130
- //#endregion
131
- exports.IsolatedDecl = IsolatedDecl;
132
- exports.src_index_ns = src_index_ns;