unplugin-isolated-decl 0.5.2 → 0.6.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 +22 -0
- package/dist/api.cjs +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/core/options.d.cts +25 -11
- package/dist/core/options.d.ts +25 -11
- package/dist/core/transformer.d.cts +3 -3
- package/dist/core/transformer.d.ts +3 -3
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rolldown.cjs +2 -2
- package/dist/rolldown.d.cts +1 -1
- package/dist/rolldown.d.ts +1 -1
- package/dist/rolldown.js +2 -2
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/{src_index-ytEwnjsz.cjs → src_index-Q6qrrUBW.cjs} +50 -18
- package/dist/{src_index-ZsbwyfTU.js → src_index-g0Uyr2cn.js} +50 -18
- package/dist/{transformer-5sKdcRP0.js → transformer-YxBC7dLI.js} +19 -10
- package/dist/{transformer-AnxdogMH.cjs → transformer-ZHFQTLaY.cjs} +19 -10
- package/dist/vite.cjs +2 -2
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -93,9 +93,27 @@ export interface Options {
|
|
|
93
93
|
|
|
94
94
|
/** An extra directory layer for output files. */
|
|
95
95
|
extraOutdir?: string
|
|
96
|
+
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
97
|
+
autoAddExts?: boolean
|
|
96
98
|
}
|
|
97
99
|
```
|
|
98
100
|
|
|
101
|
+
### `autoAddExts`
|
|
102
|
+
|
|
103
|
+
Automatically add `.js` extension to resolve in Node 16+ ESM mode.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// index.d.ts
|
|
107
|
+
import {} from './foo'
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
With `autoAddExts`, it will be transformed to:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// index.d.ts
|
|
114
|
+
import {} from './foo.js'
|
|
115
|
+
```
|
|
116
|
+
|
|
99
117
|
## Sponsors
|
|
100
118
|
|
|
101
119
|
<p align="center">
|
|
@@ -107,3 +125,7 @@ export interface Options {
|
|
|
107
125
|
## License
|
|
108
126
|
|
|
109
127
|
[MIT](./LICENSE) License © 2024-PRESENT [三咲智子](https://github.com/sxzz)
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```
|
package/dist/api.cjs
CHANGED
package/dist/api.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { oxcTransform, swcTransform, tsTransform } from "./core/transformer";
|
|
1
|
+
export { oxcTransform, swcTransform, tsTransform } from "./core/transformer.js";
|
package/dist/api.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { oxcTransform, swcTransform, tsTransform } from "./core/transformer";
|
|
1
|
+
export { oxcTransform, swcTransform, tsTransform } from "./core/transformer.js";
|
package/dist/api.js
CHANGED
package/dist/core/options.d.cts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import type { FilterPattern } from
|
|
2
|
-
import type { TranspileOptions } from
|
|
1
|
+
import type { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
+
import type { TranspileOptions } from 'typescript';
|
|
3
3
|
export type Options = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
include?: FilterPattern;
|
|
5
|
+
exclude?: FilterPattern;
|
|
6
|
+
enforce?: 'pre' | 'post' | undefined;
|
|
7
|
+
ignoreErrors?: boolean;
|
|
8
|
+
/** An extra directory layer for output files. */
|
|
9
|
+
extraOutdir?: string;
|
|
10
|
+
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
11
|
+
autoAddExts?: boolean;
|
|
12
|
+
} & ({
|
|
13
|
+
/**
|
|
14
|
+
* `oxc-transform` or `@swc/core` should be installed yourself
|
|
15
|
+
* if you want to use `oxc` or `swc` transformer.
|
|
16
|
+
*/
|
|
17
|
+
transformer?: 'oxc' | 'swc';
|
|
18
|
+
} | {
|
|
19
|
+
/**
|
|
20
|
+
* `typescript` should be installed yourself.
|
|
21
|
+
* @default 'typescript'
|
|
22
|
+
*/
|
|
23
|
+
transformer: 'typescript';
|
|
24
|
+
/** Only for typescript transformer */
|
|
25
|
+
transformOptions?: TranspileOptions;
|
|
12
26
|
});
|
|
13
27
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
14
|
-
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options,
|
|
28
|
+
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce' | 'extraOutdir'>>;
|
|
15
29
|
export declare function resolveOptions(options: Options): OptionsResolved;
|
|
16
30
|
export {};
|
package/dist/core/options.d.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import type { FilterPattern } from
|
|
2
|
-
import type { TranspileOptions } from
|
|
1
|
+
import type { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
+
import type { TranspileOptions } from 'typescript';
|
|
3
3
|
export type Options = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
include?: FilterPattern;
|
|
5
|
+
exclude?: FilterPattern;
|
|
6
|
+
enforce?: 'pre' | 'post' | undefined;
|
|
7
|
+
ignoreErrors?: boolean;
|
|
8
|
+
/** An extra directory layer for output files. */
|
|
9
|
+
extraOutdir?: string;
|
|
10
|
+
/** Automatically add `.js` extension to resolve in `Node16` + ESM mode. */
|
|
11
|
+
autoAddExts?: boolean;
|
|
12
|
+
} & ({
|
|
13
|
+
/**
|
|
14
|
+
* `oxc-transform` or `@swc/core` should be installed yourself
|
|
15
|
+
* if you want to use `oxc` or `swc` transformer.
|
|
16
|
+
*/
|
|
17
|
+
transformer?: 'oxc' | 'swc';
|
|
18
|
+
} | {
|
|
19
|
+
/**
|
|
20
|
+
* `typescript` should be installed yourself.
|
|
21
|
+
* @default 'typescript'
|
|
22
|
+
*/
|
|
23
|
+
transformer: 'typescript';
|
|
24
|
+
/** Only for typescript transformer */
|
|
25
|
+
transformOptions?: TranspileOptions;
|
|
12
26
|
});
|
|
13
27
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
14
|
-
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options,
|
|
28
|
+
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, 'enforce' | 'extraOutdir'>>;
|
|
15
29
|
export declare function resolveOptions(options: Options): OptionsResolved;
|
|
16
30
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TranspileOptions } from
|
|
1
|
+
import type { TranspileOptions } from 'typescript';
|
|
2
2
|
export interface TransformResult {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
code: string;
|
|
4
|
+
errors: Array<string>;
|
|
5
5
|
}
|
|
6
6
|
export declare function oxcTransform(id: string, code: string): Promise<TransformResult>;
|
|
7
7
|
export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TranspileOptions } from
|
|
1
|
+
import type { TranspileOptions } from 'typescript';
|
|
2
2
|
export interface TransformResult {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
code: string;
|
|
4
|
+
errors: Array<string>;
|
|
5
5
|
}
|
|
6
6
|
export declare function oxcTransform(id: string, code: string): Promise<TransformResult>;
|
|
7
7
|
export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_src_index = require('./src_index-
|
|
3
|
-
require('./transformer-
|
|
2
|
+
const require_src_index = require('./src_index-Q6qrrUBW.cjs');
|
|
3
|
+
require('./transformer-ZHFQTLaY.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/esbuild.ts
|
|
6
6
|
var esbuild_default = require_src_index.IsolatedDecl.esbuild;
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_src_index = require('./src_index-
|
|
3
|
-
require('./transformer-
|
|
2
|
+
const require_src_index = require('./src_index-Q6qrrUBW.cjs');
|
|
3
|
+
require('./transformer-ZHFQTLaY.cjs');
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, 'IsolatedDecl', {
|
|
6
6
|
enumerable: true,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type UnpluginInstance } from
|
|
2
|
-
import { type Options } from "./core/options";
|
|
1
|
+
import { type UnpluginInstance } from 'unplugin';
|
|
2
|
+
import { type Options } from "./core/options.js";
|
|
3
3
|
export type { Options };
|
|
4
4
|
export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
|
|
5
5
|
export declare function lowestCommonAncestor(...filepaths: string[]): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type UnpluginInstance } from
|
|
2
|
-
import { type Options } from "./core/options";
|
|
1
|
+
import { type UnpluginInstance } from 'unplugin';
|
|
2
|
+
import { type Options } from "./core/options.js";
|
|
3
3
|
export type { Options };
|
|
4
4
|
export declare const IsolatedDecl: UnpluginInstance<Options | undefined, false>;
|
|
5
5
|
export declare function lowestCommonAncestor(...filepaths: string[]): string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./transformer-
|
|
2
|
-
import { IsolatedDecl, lowestCommonAncestor } from "./src_index-
|
|
1
|
+
import "./transformer-YxBC7dLI.js";
|
|
2
|
+
import { IsolatedDecl, lowestCommonAncestor } from "./src_index-g0Uyr2cn.js";
|
|
3
3
|
|
|
4
4
|
export { IsolatedDecl, lowestCommonAncestor };
|
package/dist/rolldown.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_src_index = require('./src_index-
|
|
3
|
-
require('./transformer-
|
|
2
|
+
const require_src_index = require('./src_index-Q6qrrUBW.cjs');
|
|
3
|
+
require('./transformer-ZHFQTLaY.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/rolldown.ts
|
|
6
6
|
var rolldown_default = require_src_index.IsolatedDecl.rolldown;
|
package/dist/rolldown.d.cts
CHANGED
package/dist/rolldown.d.ts
CHANGED
package/dist/rolldown.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_src_index = require('./src_index-
|
|
3
|
-
require('./transformer-
|
|
2
|
+
const require_src_index = require('./src_index-Q6qrrUBW.cjs');
|
|
3
|
+
require('./transformer-ZHFQTLaY.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/rollup.ts
|
|
6
6
|
var rollup_default = require_src_index.IsolatedDecl.rollup;
|
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
|
@@ -22,10 +22,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
|
-
const require_transformer = require('./transformer-
|
|
25
|
+
const require_transformer = require('./transformer-ZHFQTLaY.cjs');
|
|
26
26
|
const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
|
|
27
27
|
const { default: path } = __toESM(require("node:path"));
|
|
28
28
|
const { createFilter } = __toESM(require("@rollup/pluginutils"));
|
|
29
|
+
const { default: MagicString } = __toESM(require("magic-string"));
|
|
29
30
|
const { parseAsync } = __toESM(require("oxc-parser"));
|
|
30
31
|
const { createUnplugin } = __toESM(require("unplugin"));
|
|
31
32
|
|
|
@@ -35,9 +36,10 @@ function resolveOptions(options) {
|
|
|
35
36
|
include: options.include || [/\.[cm]?ts$/],
|
|
36
37
|
exclude: options.exclude || [/node_modules/],
|
|
37
38
|
enforce: "enforce" in options ? options.enforce : "pre",
|
|
38
|
-
transformer: options.transformer || "
|
|
39
|
+
transformer: options.transformer || "typescript",
|
|
39
40
|
ignoreErrors: options.ignoreErrors || false,
|
|
40
|
-
extraOutdir: options.extraOutdir
|
|
41
|
+
extraOutdir: options.extraOutdir,
|
|
42
|
+
autoAddExts: options.autoAddExts || false
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -90,6 +92,25 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
async function transform(context, code, id) {
|
|
95
|
+
let program;
|
|
96
|
+
try {
|
|
97
|
+
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
98
|
+
} catch {}
|
|
99
|
+
if (options.autoAddExts && program) {
|
|
100
|
+
const imports = program.body.filter((node) => node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration");
|
|
101
|
+
const s = new MagicString(code);
|
|
102
|
+
for (const i of imports) {
|
|
103
|
+
if (!i.source || path.basename(i.source.value).includes(".")) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const resolved = await resolve(context, i.source.value, id);
|
|
107
|
+
if (!resolved || resolved.external) continue;
|
|
108
|
+
if (resolved.id.endsWith(".ts")) {
|
|
109
|
+
s.overwrite(i.source.start, i.source.end, JSON.stringify(`${i.source.value}.js`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
code = s.toString();
|
|
113
|
+
}
|
|
93
114
|
let result;
|
|
94
115
|
switch (options.transformer) {
|
|
95
116
|
case "oxc":
|
|
@@ -110,19 +131,21 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
110
131
|
}
|
|
111
132
|
}
|
|
112
133
|
addOutput(id, sourceText);
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
116
|
-
} catch {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
134
|
+
if (!program) return;
|
|
119
135
|
const typeImports = program.body.filter((node) => {
|
|
120
|
-
if (node.type
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
if (node.type === "ImportDeclaration") {
|
|
137
|
+
if (node.importKind === "type") return true;
|
|
138
|
+
return node.specifiers && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
139
|
+
}
|
|
140
|
+
if (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
|
|
141
|
+
if (node.exportKind === "type") return true;
|
|
142
|
+
return node.type === "ExportNamedDeclaration" && node.specifiers && node.specifiers.every((spec) => spec.type === "ExportSpecifier" && spec.exportKind === "type");
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
123
145
|
});
|
|
124
146
|
for (const i of typeImports) {
|
|
125
|
-
|
|
147
|
+
if (!i.source) continue;
|
|
148
|
+
const resolved = (await resolve(context, i.source.value, id))?.id;
|
|
126
149
|
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
127
150
|
let source;
|
|
128
151
|
try {
|
|
@@ -182,17 +205,26 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
182
205
|
});
|
|
183
206
|
}
|
|
184
207
|
});
|
|
185
|
-
|
|
208
|
+
async function resolve(context, id, importer) {
|
|
186
209
|
const nativeContext = context.getNativeBuildContext?.();
|
|
187
210
|
if (nativeContext?.framework === "esbuild") {
|
|
188
|
-
|
|
211
|
+
const resolved$1 = await nativeContext.build.resolve(id, {
|
|
189
212
|
importer,
|
|
190
213
|
resolveDir: path.dirname(importer),
|
|
191
214
|
kind: "import-statement"
|
|
192
|
-
})
|
|
215
|
+
});
|
|
216
|
+
return {
|
|
217
|
+
id: resolved$1.path,
|
|
218
|
+
external: resolved$1.external
|
|
219
|
+
};
|
|
193
220
|
}
|
|
194
|
-
|
|
195
|
-
|
|
221
|
+
const resolved = await context.resolve(id, importer);
|
|
222
|
+
if (!resolved) return;
|
|
223
|
+
return {
|
|
224
|
+
id: resolved.id,
|
|
225
|
+
external: !!resolved.external
|
|
226
|
+
};
|
|
227
|
+
}
|
|
196
228
|
function stripExt(filename) {
|
|
197
229
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
198
230
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { oxcTransform, swcTransform, tsTransform } from "./transformer-
|
|
1
|
+
import { oxcTransform, swcTransform, tsTransform } from "./transformer-YxBC7dLI.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";
|
|
5
|
+
import { default as MagicString } from "magic-string";
|
|
5
6
|
import { parseAsync } from "oxc-parser";
|
|
6
7
|
import { createUnplugin } from "unplugin";
|
|
7
8
|
|
|
@@ -11,9 +12,10 @@ function resolveOptions(options) {
|
|
|
11
12
|
include: options.include || [/\.[cm]?ts$/],
|
|
12
13
|
exclude: options.exclude || [/node_modules/],
|
|
13
14
|
enforce: "enforce" in options ? options.enforce : "pre",
|
|
14
|
-
transformer: options.transformer || "
|
|
15
|
+
transformer: options.transformer || "typescript",
|
|
15
16
|
ignoreErrors: options.ignoreErrors || false,
|
|
16
|
-
extraOutdir: options.extraOutdir
|
|
17
|
+
extraOutdir: options.extraOutdir,
|
|
18
|
+
autoAddExts: options.autoAddExts || false
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -66,6 +68,25 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
66
68
|
}
|
|
67
69
|
};
|
|
68
70
|
async function transform(context, code, id) {
|
|
71
|
+
let program;
|
|
72
|
+
try {
|
|
73
|
+
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
74
|
+
} catch {}
|
|
75
|
+
if (options.autoAddExts && program) {
|
|
76
|
+
const imports = program.body.filter((node) => node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration");
|
|
77
|
+
const s = new MagicString(code);
|
|
78
|
+
for (const i of imports) {
|
|
79
|
+
if (!i.source || path.basename(i.source.value).includes(".")) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const resolved = await resolve(context, i.source.value, id);
|
|
83
|
+
if (!resolved || resolved.external) continue;
|
|
84
|
+
if (resolved.id.endsWith(".ts")) {
|
|
85
|
+
s.overwrite(i.source.start, i.source.end, JSON.stringify(`${i.source.value}.js`));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
code = s.toString();
|
|
89
|
+
}
|
|
69
90
|
let result;
|
|
70
91
|
switch (options.transformer) {
|
|
71
92
|
case "oxc":
|
|
@@ -86,19 +107,21 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
86
107
|
}
|
|
87
108
|
}
|
|
88
109
|
addOutput(id, sourceText);
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
92
|
-
} catch {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
110
|
+
if (!program) return;
|
|
95
111
|
const typeImports = program.body.filter((node) => {
|
|
96
|
-
if (node.type
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
if (node.type === "ImportDeclaration") {
|
|
113
|
+
if (node.importKind === "type") return true;
|
|
114
|
+
return node.specifiers && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
115
|
+
}
|
|
116
|
+
if (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
|
|
117
|
+
if (node.exportKind === "type") return true;
|
|
118
|
+
return node.type === "ExportNamedDeclaration" && node.specifiers && node.specifiers.every((spec) => spec.type === "ExportSpecifier" && spec.exportKind === "type");
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
99
121
|
});
|
|
100
122
|
for (const i of typeImports) {
|
|
101
|
-
|
|
123
|
+
if (!i.source) continue;
|
|
124
|
+
const resolved = (await resolve(context, i.source.value, id))?.id;
|
|
102
125
|
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
103
126
|
let source;
|
|
104
127
|
try {
|
|
@@ -158,17 +181,26 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
158
181
|
});
|
|
159
182
|
}
|
|
160
183
|
});
|
|
161
|
-
|
|
184
|
+
async function resolve(context, id, importer) {
|
|
162
185
|
const nativeContext = context.getNativeBuildContext?.();
|
|
163
186
|
if (nativeContext?.framework === "esbuild") {
|
|
164
|
-
|
|
187
|
+
const resolved$1 = await nativeContext.build.resolve(id, {
|
|
165
188
|
importer,
|
|
166
189
|
resolveDir: path.dirname(importer),
|
|
167
190
|
kind: "import-statement"
|
|
168
|
-
})
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
id: resolved$1.path,
|
|
194
|
+
external: resolved$1.external
|
|
195
|
+
};
|
|
169
196
|
}
|
|
170
|
-
|
|
171
|
-
|
|
197
|
+
const resolved = await context.resolve(id, importer);
|
|
198
|
+
if (!resolved) return;
|
|
199
|
+
return {
|
|
200
|
+
id: resolved.id,
|
|
201
|
+
external: !!resolved.external
|
|
202
|
+
};
|
|
203
|
+
}
|
|
172
204
|
function stripExt(filename) {
|
|
173
205
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
174
206
|
}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/core/transformer.ts
|
|
3
|
+
function tryImport(pkg) {
|
|
4
|
+
try {
|
|
5
|
+
return import(pkg);
|
|
6
|
+
} catch {
|
|
7
|
+
return Promise.resolve(null);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
async function oxcTransform(id, code) {
|
|
4
|
-
const
|
|
5
|
-
|
|
11
|
+
const oxc = await tryImport("oxc-transform");
|
|
12
|
+
if (!oxc) {
|
|
13
|
+
return {
|
|
14
|
+
code: "",
|
|
15
|
+
errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`.",]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return oxc.isolatedDeclaration(id, code, { sourcemap: false });
|
|
6
19
|
}
|
|
7
20
|
async function swcTransform(id, code) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
swc = await import("@swc/core");
|
|
11
|
-
} catch {
|
|
21
|
+
const swc = await tryImport("@swc/core");
|
|
22
|
+
if (!swc) {
|
|
12
23
|
return {
|
|
13
24
|
code: "",
|
|
14
25
|
errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
|
|
@@ -38,10 +49,8 @@ async function swcTransform(id, code) {
|
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
async function tsTransform(id, code, transformOptions) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ts = await import("typescript");
|
|
44
|
-
} catch {
|
|
52
|
+
const ts = await tryImport("typescript");
|
|
53
|
+
if (!ts) {
|
|
45
54
|
return {
|
|
46
55
|
code: "",
|
|
47
56
|
errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
//#region src/core/transformer.ts
|
|
4
|
+
function tryImport(pkg) {
|
|
5
|
+
try {
|
|
6
|
+
return import(pkg);
|
|
7
|
+
} catch {
|
|
8
|
+
return Promise.resolve(null);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
async function oxcTransform(id, code) {
|
|
5
|
-
const
|
|
6
|
-
|
|
12
|
+
const oxc = await tryImport("oxc-transform");
|
|
13
|
+
if (!oxc) {
|
|
14
|
+
return {
|
|
15
|
+
code: "",
|
|
16
|
+
errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`.",]
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return oxc.isolatedDeclaration(id, code, { sourcemap: false });
|
|
7
20
|
}
|
|
8
21
|
async function swcTransform(id, code) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
swc = await import("@swc/core");
|
|
12
|
-
} catch {
|
|
22
|
+
const swc = await tryImport("@swc/core");
|
|
23
|
+
if (!swc) {
|
|
13
24
|
return {
|
|
14
25
|
code: "",
|
|
15
26
|
errors: ["SWC is required for transforming TypeScript, please install `@swc/core`.",]
|
|
@@ -39,10 +50,8 @@ async function swcTransform(id, code) {
|
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
async function tsTransform(id, code, transformOptions) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ts = await import("typescript");
|
|
45
|
-
} catch {
|
|
53
|
+
const ts = await tryImport("typescript");
|
|
54
|
+
if (!ts) {
|
|
46
55
|
return {
|
|
47
56
|
code: "",
|
|
48
57
|
errors: ["TypeScript is required for transforming TypeScript, please install `typescript`.",]
|
package/dist/vite.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_src_index = require('./src_index-
|
|
3
|
-
require('./transformer-
|
|
2
|
+
const require_src_index = require('./src_index-Q6qrrUBW.cjs');
|
|
3
|
+
require('./transformer-ZHFQTLaY.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/vite.ts
|
|
6
6
|
var vite_default = require_src_index.IsolatedDecl.vite;
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-isolated-decl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -69,20 +69,24 @@
|
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@swc/core": "^1.6.6",
|
|
72
|
+
"oxc-transform": "^0.28.0",
|
|
72
73
|
"typescript": "^5.5.2"
|
|
73
74
|
},
|
|
74
75
|
"peerDependenciesMeta": {
|
|
75
76
|
"@swc/core": {
|
|
76
77
|
"optional": true
|
|
77
78
|
},
|
|
79
|
+
"oxc-transform": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
78
82
|
"typescript": {
|
|
79
83
|
"optional": true
|
|
80
84
|
}
|
|
81
85
|
},
|
|
82
86
|
"dependencies": {
|
|
83
87
|
"@rollup/pluginutils": "^5.1.0",
|
|
88
|
+
"magic-string": "^0.30.11",
|
|
84
89
|
"oxc-parser": "^0.27.0",
|
|
85
|
-
"oxc-transform": "^0.27.0",
|
|
86
90
|
"unplugin": "^1.14.0"
|
|
87
91
|
},
|
|
88
92
|
"devDependencies": {
|
|
@@ -90,10 +94,12 @@
|
|
|
90
94
|
"@sxzz/eslint-config": "^4.2.0",
|
|
91
95
|
"@sxzz/prettier-config": "^2.0.2",
|
|
92
96
|
"@types/node": "^22.5.4",
|
|
97
|
+
"@typescript-eslint/typescript-estree": "^8.5.0",
|
|
93
98
|
"bumpp": "^9.5.2",
|
|
94
99
|
"esbuild": "^0.23.1",
|
|
95
100
|
"eslint": "^9.10.0",
|
|
96
101
|
"fast-glob": "^3.3.2",
|
|
102
|
+
"oxc-transform": "^0.27.0",
|
|
97
103
|
"prettier": "^3.3.3",
|
|
98
104
|
"rolldown": "nightly",
|
|
99
105
|
"rollup": "^4.21.2",
|