unplugin-isolated-decl 0.2.0 → 0.4.0

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
@@ -7,7 +7,8 @@
7
7
  ## Features
8
8
 
9
9
  - 🚀 **Fast**: Blazing-fast `.d.ts` generator, powered by Oxc.
10
- - 🎯 **Isolated**: Generate isolated declarations for each file.
10
+ - 🎨 **Transformer**: Support Oxc, SWC, and TypeScript transformer.
11
+ - 📦 **Zero Config**: No configuration required, works out of the box.
11
12
  - ✨ **Bundler Support**: Works with Vite, Rollup, and esbuild.
12
13
 
13
14
  ## Installation
@@ -74,6 +75,23 @@ build({
74
75
 
75
76
  <br></details>
76
77
 
78
+ ## Options
79
+
80
+ ```ts
81
+ export interface Options {
82
+ include?: FilterPattern
83
+ exclude?: FilterPattern
84
+ enforce?: 'pre' | 'post' | undefined
85
+ /**
86
+ * If you use swc or typescript, you need to install `@swc/core` or `typescript` yourself.
87
+ * @default oxc
88
+ */
89
+ transformer?: 'oxc' | 'swc' | 'typescript'
90
+ /** Only for typescript transformer */
91
+ transformOptions?: TranspileOptions
92
+ }
93
+ ```
94
+
77
95
  ## Sponsors
78
96
 
79
97
  <p align="center">
package/dist/api.cjs CHANGED
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
 
3
- const { __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
3
+ const { __export, __toCommonJS, oxcTransform, swcTransform, tsTransform } = require("./transformer-ZIY9xt38.cjs");
4
4
 
5
5
  //#region src/api.ts
6
6
  var api_ns = {};
7
+ __export(api_ns, {
8
+ oxcTransform: () => oxcTransform,
9
+ swcTransform: () => swcTransform,
10
+ tsTransform: () => tsTransform
11
+ });
7
12
 
8
- //#endregion
13
+ //#endregion
14
+ module.exports = __toCommonJS(api_ns)
package/dist/api.d.cts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { oxcTransform, swcTransform, tsTransform } from './core/transformer';
package/dist/api.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { oxcTransform, swcTransform, tsTransform } from './core/transformer';
package/dist/api.js CHANGED
@@ -0,0 +1,3 @@
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-m4c_uotZ.js";
2
+
3
+ export { oxcTransform, swcTransform, tsTransform };
@@ -1,9 +1,13 @@
1
+ import type { TranspileOptions } from 'typescript';
1
2
  import type { FilterPattern } from '@rollup/pluginutils';
2
- export interface Options {
3
+ export type Options = (({
3
4
  include?: FilterPattern;
4
5
  exclude?: FilterPattern;
5
6
  enforce?: (('pre') | ('post') | (undefined));
6
- }
7
+ }) & ((({transformer?: (('oxc') | ('swc'))}) | ({
8
+ transformer: 'typescript';
9
+ transformOptions?: TranspileOptions;
10
+ }))));
7
11
  type Overwrite<T, U> = ((Pick<T, Exclude<keyof T, keyof U>>) & (U));
8
12
  export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
9
13
  export declare function resolveOptions(options: Options): OptionsResolved;
@@ -1,9 +1,13 @@
1
+ import type { TranspileOptions } from 'typescript';
1
2
  import type { FilterPattern } from '@rollup/pluginutils';
2
- export interface Options {
3
+ export type Options = (({
3
4
  include?: FilterPattern;
4
5
  exclude?: FilterPattern;
5
6
  enforce?: (('pre') | ('post') | (undefined));
6
- }
7
+ }) & ((({transformer?: (('oxc') | ('swc'))}) | ({
8
+ transformer: 'typescript';
9
+ transformOptions?: TranspileOptions;
10
+ }))));
7
11
  type Overwrite<T, U> = ((Pick<T, Exclude<keyof T, keyof U>>) & (U));
8
12
  export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce'>>;
9
13
  export declare function resolveOptions(options: Options): OptionsResolved;
@@ -0,0 +1,8 @@
1
+ import type { TranspileOptions } from 'typescript';
2
+ export interface TransformResult {
3
+ sourceText: string;
4
+ errors: Array<string>;
5
+ }
6
+ export declare function oxcTransform(id: string, code: string): TransformResult;
7
+ export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
8
+ export declare function tsTransform(id: string, code: string, transformOptions?: TranspileOptions): Promise<TransformResult>;
@@ -0,0 +1,8 @@
1
+ import type { TranspileOptions } from 'typescript';
2
+ export interface TransformResult {
3
+ sourceText: string;
4
+ errors: Array<string>;
5
+ }
6
+ export declare function oxcTransform(id: string, code: string): TransformResult;
7
+ export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
8
+ export declare function tsTransform(id: string, code: string, transformOptions?: TranspileOptions): Promise<TransformResult>;
package/dist/esbuild.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
 
3
- const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
- const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
3
+ const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
+ const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
5
5
 
6
6
  //#region src/esbuild.ts
7
7
  var esbuild_ns = {};
8
8
  __export(esbuild_ns, {default: () => esbuild_default});
9
- var esbuild_default = src_index_default.esbuild;
9
+ var esbuild_default = IsolatedDecl.esbuild;
10
10
 
11
11
  //#endregion
12
12
  module.exports = __toCommonJS(esbuild_ns)
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.esbuild;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.esbuild;
3
3
  export default _default;
package/dist/esbuild.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.esbuild;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.esbuild;
3
3
  export default _default;
package/dist/esbuild.js CHANGED
@@ -1,7 +1,8 @@
1
- import { src_index_default } from "./src_index--yc62mkz.js";
1
+ import "./transformer-m4c_uotZ.js";
2
+ import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
2
3
 
3
4
  //#region src/esbuild.ts
4
- var esbuild_default = src_index_default.esbuild;
5
+ var esbuild_default = IsolatedDecl.esbuild;
5
6
 
6
7
  //#endregion
7
8
  export { esbuild_default as default };
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- const { __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
- const { plugin, src_index_default, src_index_ns } = require("./src_index-ff_kRS8x.cjs");
3
+ const { __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
+ const { IsolatedDecl, src_index_ns } = require("./src_index-JrSKjSmw.cjs");
5
5
 
6
6
  module.exports = __toCommonJS(src_index_ns)
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { type UnpluginInstance } from 'unplugin';
2
2
  import { type Options } from './core/options';
3
- export declare const plugin: UnpluginInstance<((Options) | (undefined)), false>;
4
- export default plugin;
3
+ export type { Options };
4
+ export declare const IsolatedDecl: UnpluginInstance<((Options) | (undefined)), false>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { type UnpluginInstance } from 'unplugin';
2
2
  import { type Options } from './core/options';
3
- export declare const plugin: UnpluginInstance<((Options) | (undefined)), false>;
4
- export default plugin;
3
+ export type { Options };
4
+ export declare const IsolatedDecl: UnpluginInstance<((Options) | (undefined)), false>;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
- import { plugin, src_index_default } from "./src_index--yc62mkz.js";
1
+ import "./transformer-m4c_uotZ.js";
2
+ import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
2
3
 
3
- export { src_index_default as default, plugin };
4
+ export { IsolatedDecl };
package/dist/rolldown.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
 
3
- const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
- const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
3
+ const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
+ const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
5
5
 
6
6
  //#region src/rolldown.ts
7
7
  var rolldown_ns = {};
8
8
  __export(rolldown_ns, {default: () => rolldown_default});
9
- var rolldown_default = src_index_default.rolldown;
9
+ var rolldown_default = IsolatedDecl.rolldown;
10
10
 
11
11
  //#endregion
12
12
  module.exports = __toCommonJS(rolldown_ns)
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.rolldown;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.rolldown;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.rolldown;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.rolldown;
3
3
  export default _default;
package/dist/rolldown.js CHANGED
@@ -1,7 +1,8 @@
1
- import { src_index_default } from "./src_index--yc62mkz.js";
1
+ import "./transformer-m4c_uotZ.js";
2
+ import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
2
3
 
3
4
  //#region src/rolldown.ts
4
- var rolldown_default = src_index_default.rolldown;
5
+ var rolldown_default = IsolatedDecl.rolldown;
5
6
 
6
7
  //#endregion
7
8
  export { rolldown_default as default };
package/dist/rollup.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
 
3
- const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
- const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
3
+ const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
+ const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
5
5
 
6
6
  //#region src/rollup.ts
7
7
  var rollup_ns = {};
8
8
  __export(rollup_ns, {default: () => rollup_default});
9
- var rollup_default = src_index_default.rollup;
9
+ var rollup_default = IsolatedDecl.rollup;
10
10
 
11
11
  //#endregion
12
12
  module.exports = __toCommonJS(rollup_ns)
package/dist/rollup.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.rollup;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.rollup;
3
3
  export default _default;
package/dist/rollup.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.rollup;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.rollup;
3
3
  export default _default;
package/dist/rollup.js CHANGED
@@ -1,7 +1,8 @@
1
- import { src_index_default } from "./src_index--yc62mkz.js";
1
+ import "./transformer-m4c_uotZ.js";
2
+ import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
2
3
 
3
4
  //#region src/rollup.ts
4
- var rollup_default = src_index_default.rollup;
5
+ var rollup_default = IsolatedDecl.rollup;
5
6
 
6
7
  //#endregion
7
8
  export { rollup_default as default };
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
 
3
- const { __export, __toESM } = require("./chunk-J8LkbbVi.cjs");
3
+ const { __export, __toESM, oxcTransform, swcTransform, tsTransform } = require("./transformer-ZIY9xt38.cjs");
4
4
  const { default: path } = __toESM(require("node:path"));
5
5
  const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
6
6
  const { createUnplugin } = __toESM(require("unplugin"));
7
- const { isolatedDeclaration } = __toESM(require("oxc-transform"));
8
7
  const { createFilter } = __toESM(require("@rollup/pluginutils"));
9
8
 
10
9
  //#region src/core/options.ts
@@ -12,18 +11,16 @@ function resolveOptions(options) {
12
11
  return {
13
12
  include: options.include || [/\.[cm]?ts$/],
14
13
  exclude: options.exclude || [/node_modules/],
15
- enforce: 'enforce'in options ? options.enforce : 'pre'
14
+ enforce: 'enforce'in options ? options.enforce : 'pre',
15
+ transformer: options.transformer || 'oxc'
16
16
  };
17
17
  }
18
18
 
19
19
  //#endregion
20
20
  //#region src/index.ts
21
21
  var src_index_ns = {};
22
- __export(src_index_ns, {
23
- default: () => src_index_default,
24
- plugin: () => plugin
25
- });
26
- const plugin = createUnplugin((rawOptions = {}, meta) => {
22
+ __export(src_index_ns, {IsolatedDecl: () => IsolatedDecl});
23
+ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
27
24
  const options = resolveOptions(rawOptions);
28
25
  const filter = createFilter(options.include, options.exclude);
29
26
  const outputFiles = {};
@@ -54,8 +51,18 @@ const plugin = createUnplugin((rawOptions = {}, meta) => {
54
51
  transformInclude(id) {
55
52
  return filter(id);
56
53
  },
57
- transform(code, id) {
58
- const { sourceText, errors } = isolatedDeclaration(id, code);
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;
59
66
  if (errors.length) {
60
67
  this.error(errors[0]);
61
68
  return;
@@ -99,7 +106,6 @@ const plugin = createUnplugin((rawOptions = {}, meta) => {
99
106
  }
100
107
  };
101
108
  });
102
- var src_index_default = plugin;
103
109
  function lowestCommonAncestor(...filepaths) {
104
110
  if (filepaths.length === 0) return '';
105
111
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
@@ -122,6 +128,5 @@ function lowestCommonAncestor(...filepaths) {
122
128
  }
123
129
 
124
130
  //#endregion
125
- exports.plugin = plugin;
126
- exports.src_index_default = src_index_default;
131
+ exports.IsolatedDecl = IsolatedDecl;
127
132
  exports.src_index_ns = src_index_ns;
@@ -1,7 +1,7 @@
1
+ import { oxcTransform, swcTransform, tsTransform } from "./transformer-m4c_uotZ.js";
1
2
  import { default as path } from "node:path";
2
3
  import { mkdir, writeFile } from "node:fs/promises";
3
4
  import { createUnplugin } from "unplugin";
4
- import { isolatedDeclaration } from "oxc-transform";
5
5
  import { createFilter } from "@rollup/pluginutils";
6
6
 
7
7
  //#region src/core/options.ts
@@ -9,13 +9,14 @@ 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'
12
+ enforce: 'enforce'in options ? options.enforce : 'pre',
13
+ transformer: options.transformer || 'oxc'
13
14
  };
14
15
  }
15
16
 
16
17
  //#endregion
17
18
  //#region src/index.ts
18
- const plugin = createUnplugin((rawOptions = {}, meta) => {
19
+ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
19
20
  const options = resolveOptions(rawOptions);
20
21
  const filter = createFilter(options.include, options.exclude);
21
22
  const outputFiles = {};
@@ -46,8 +47,18 @@ const plugin = createUnplugin((rawOptions = {}, meta) => {
46
47
  transformInclude(id) {
47
48
  return filter(id);
48
49
  },
49
- transform(code, id) {
50
- const { sourceText, errors } = isolatedDeclaration(id, code);
50
+ async transform(code, id) {
51
+ let result;
52
+ switch (options.transformer) {
53
+ case 'oxc':
54
+ result = oxcTransform(id, code);
55
+ break;
56
+ case 'swc':
57
+ result = await swcTransform(id, code);
58
+ break;
59
+ case 'typescript': result = await tsTransform(id, code, options.transformOptions);
60
+ }
61
+ const { sourceText, errors } = result;
51
62
  if (errors.length) {
52
63
  this.error(errors[0]);
53
64
  return;
@@ -91,7 +102,6 @@ const plugin = createUnplugin((rawOptions = {}, meta) => {
91
102
  }
92
103
  };
93
104
  });
94
- var src_index_default = plugin;
95
105
  function lowestCommonAncestor(...filepaths) {
96
106
  if (filepaths.length === 0) return '';
97
107
  if (filepaths.length === 1) return path.dirname(filepaths[0]);
@@ -114,4 +124,4 @@ function lowestCommonAncestor(...filepaths) {
114
124
  }
115
125
 
116
126
  //#endregion
117
- export { plugin, src_index_default };
127
+ export { IsolatedDecl };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ 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
+ 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++) {
18
+ key = keys[i];
19
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, 'default', {
27
+ value: mod,
28
+ enumerable: true
29
+ }) : target, mod));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', {value: true}), mod);
31
+
32
+ //#endregion
33
+ const { isolatedDeclaration } = __toESM(require("oxc-transform"));
34
+
35
+ //#region src/core/transformer.ts
36
+ function oxcTransform(id, code) {
37
+ return isolatedDeclaration(id, code);
38
+ }
39
+ async function swcTransform(id, code) {
40
+ let swc;
41
+ try {
42
+ swc = await import('@swc/core');
43
+ } catch {
44
+ return {
45
+ sourceText: '',
46
+ errors: ['SWC is required for transforming TypeScript, please install `@swc/core`.',]
47
+ };
48
+ }
49
+ try {
50
+ const result = await swc.transform(code, {
51
+ filename: id,
52
+ jsc: {
53
+ parser: {
54
+ syntax: 'typescript',
55
+ tsx: false
56
+ },
57
+ experimental: {emitIsolatedDts: true}
58
+ }
59
+ });
60
+ const output = JSON.parse(result.output);
61
+ return {
62
+ sourceText: output.__swc_isolated_declarations__,
63
+ errors: []
64
+ };
65
+ } catch (error) {
66
+ return {
67
+ sourceText: '',
68
+ errors: [error.toString()]
69
+ };
70
+ }
71
+ }
72
+ async function tsTransform(id, code, transformOptions) {
73
+ let ts;
74
+ try {
75
+ ts = await import('typescript');
76
+ } catch {
77
+ return {
78
+ sourceText: '',
79
+ errors: ['TypeScript is required for transforming TypeScript, please install `typescript`.',]
80
+ };
81
+ }
82
+ if (!ts.transpileDeclaration) {
83
+ return {
84
+ sourceText: '',
85
+ errors: ['TypeScript version is too low, please upgrade to TypeScript 5.5.2+.',]
86
+ };
87
+ }
88
+ const { outputText, diagnostics } = ts.transpileDeclaration(code, {
89
+ fileName: id,
90
+ reportDiagnostics: true,
91
+ ...transformOptions
92
+ });
93
+ const errors = diagnostics?.length ? [ts.formatDiagnostics(diagnostics, {
94
+ getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
95
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
96
+ getNewLine: () => ts.sys.newLine
97
+ }),] : [];
98
+ return {
99
+ sourceText: outputText,
100
+ errors
101
+ };
102
+ }
103
+
104
+ //#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;
@@ -0,0 +1,73 @@
1
+ import { isolatedDeclaration } from "oxc-transform";
2
+
3
+ //#region src/core/transformer.ts
4
+ function oxcTransform(id, code) {
5
+ return isolatedDeclaration(id, code);
6
+ }
7
+ async function swcTransform(id, code) {
8
+ let swc;
9
+ try {
10
+ swc = await import('@swc/core');
11
+ } catch {
12
+ return {
13
+ sourceText: '',
14
+ errors: ['SWC is required for transforming TypeScript, please install `@swc/core`.',]
15
+ };
16
+ }
17
+ try {
18
+ const result = await swc.transform(code, {
19
+ filename: id,
20
+ jsc: {
21
+ parser: {
22
+ syntax: 'typescript',
23
+ tsx: false
24
+ },
25
+ experimental: {emitIsolatedDts: true}
26
+ }
27
+ });
28
+ const output = JSON.parse(result.output);
29
+ return {
30
+ sourceText: output.__swc_isolated_declarations__,
31
+ errors: []
32
+ };
33
+ } catch (error) {
34
+ return {
35
+ sourceText: '',
36
+ errors: [error.toString()]
37
+ };
38
+ }
39
+ }
40
+ async function tsTransform(id, code, transformOptions) {
41
+ let ts;
42
+ try {
43
+ ts = await import('typescript');
44
+ } catch {
45
+ return {
46
+ sourceText: '',
47
+ errors: ['TypeScript is required for transforming TypeScript, please install `typescript`.',]
48
+ };
49
+ }
50
+ if (!ts.transpileDeclaration) {
51
+ return {
52
+ sourceText: '',
53
+ errors: ['TypeScript version is too low, please upgrade to TypeScript 5.5.2+.',]
54
+ };
55
+ }
56
+ const { outputText, diagnostics } = ts.transpileDeclaration(code, {
57
+ fileName: id,
58
+ reportDiagnostics: true,
59
+ ...transformOptions
60
+ });
61
+ const errors = diagnostics?.length ? [ts.formatDiagnostics(diagnostics, {
62
+ getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
63
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
64
+ getNewLine: () => ts.sys.newLine
65
+ }),] : [];
66
+ return {
67
+ sourceText: outputText,
68
+ errors
69
+ };
70
+ }
71
+
72
+ //#endregion
73
+ export { oxcTransform, swcTransform, tsTransform };
package/dist/vite.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
 
3
- const { __export, __toCommonJS } = require("./chunk-J8LkbbVi.cjs");
4
- const { src_index_default } = require("./src_index-ff_kRS8x.cjs");
3
+ const { __export, __toCommonJS } = require("./transformer-ZIY9xt38.cjs");
4
+ const { IsolatedDecl } = require("./src_index-JrSKjSmw.cjs");
5
5
 
6
6
  //#region src/vite.ts
7
7
  var vite_ns = {};
8
8
  __export(vite_ns, {default: () => vite_default});
9
- var vite_default = src_index_default.vite;
9
+ var vite_default = IsolatedDecl.vite;
10
10
 
11
11
  //#endregion
12
12
  module.exports = __toCommonJS(vite_ns)
package/dist/vite.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.vite;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.vite;
3
3
  export default _default;
package/dist/vite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import unplugin from './index';
2
- declare const _default: typeof unplugin.vite;
1
+ import { IsolatedDecl } from './index';
2
+ declare const _default: typeof IsolatedDecl.vite;
3
3
  export default _default;
package/dist/vite.js CHANGED
@@ -1,7 +1,8 @@
1
- import { src_index_default } from "./src_index--yc62mkz.js";
1
+ import "./transformer-m4c_uotZ.js";
2
+ import { IsolatedDecl } from "./src_index-OeLmVd0z.js";
2
3
 
3
4
  //#region src/vite.ts
4
- var vite_default = src_index_default.vite;
5
+ var vite_default = IsolatedDecl.vite;
5
6
 
6
7
  //#endregion
7
8
  export { vite_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-isolated-decl",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -67,12 +67,25 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
+ "peerDependencies": {
71
+ "@swc/core": "^1.6.6",
72
+ "typescript": "^5.5.2"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "@swc/core": {
76
+ "optional": true
77
+ },
78
+ "typescript": {
79
+ "optional": true
80
+ }
81
+ },
70
82
  "dependencies": {
71
83
  "@rollup/pluginutils": "^5.1.0",
72
84
  "oxc-transform": "^0.15.1",
73
85
  "unplugin": "^1.10.1"
74
86
  },
75
87
  "devDependencies": {
88
+ "@swc/core": "^1.6.6",
76
89
  "@sxzz/eslint-config": "^3.13.0",
77
90
  "@sxzz/prettier-config": "^2.0.2",
78
91
  "@types/node": "^20.14.9",
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- //#region rolldown:runtime
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- 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
- 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++) {
18
- key = keys[i];
19
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
- get: ((k) => from[k]).bind(null, key),
21
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
- });
23
- }
24
- return to;
25
- };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, 'default', {
27
- value: mod,
28
- enumerable: true
29
- }) : target, mod));
30
- var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', {value: true}), mod);
31
-
32
- //#endregion
33
-
34
- exports.__export = __export;
35
- exports.__toCommonJS = __toCommonJS;
36
- exports.__toESM = __toESM;