unplugin-isolated-decl 0.11.0 → 0.12.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/dist/api.js +1 -1
- package/dist/core/options.d.ts +12 -4
- package/dist/core/transformer.d.ts +2 -1
- package/dist/esbuild.js +2 -2
- package/dist/farm.js +2 -2
- package/dist/index.js +2 -2
- package/dist/rolldown.js +2 -2
- package/dist/rollup.js +2 -2
- package/dist/{src-BKZ7wewR.js → src-D9EUDQkW.js} +44 -38
- package/dist/{transformer-CBYRFUWY.js → transformer-Bp3NCHCk.js} +2 -2
- package/dist/vite.js +2 -2
- package/package.json +26 -22
package/dist/api.js
CHANGED
package/dist/core/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IsolatedDeclarationsOptions } from "oxc-transform";
|
|
1
2
|
import type { TranspileOptions } from "typescript";
|
|
2
3
|
import type { FilterPattern } from "unplugin-utils";
|
|
3
4
|
/**
|
|
@@ -25,10 +26,15 @@ export type Options = {
|
|
|
25
26
|
rewriteImports?: (id: string, importer: string) => string | void | null | undefined
|
|
26
27
|
} & ({
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
* if you want to use `oxc` or `swc` transformer.
|
|
29
|
+
* `@swc/core` should be installed yourself.
|
|
30
30
|
*/
|
|
31
|
-
transformer?: "
|
|
31
|
+
transformer?: "swc"
|
|
32
|
+
} | {
|
|
33
|
+
/**
|
|
34
|
+
* `oxc-transform` should be installed yourself.
|
|
35
|
+
*/
|
|
36
|
+
transformer?: "oxc"
|
|
37
|
+
transformOptions?: Omit<IsolatedDeclarationsOptions, "sourceMap">
|
|
32
38
|
} | {
|
|
33
39
|
/**
|
|
34
40
|
* `typescript` should be installed yourself.
|
|
@@ -42,6 +48,8 @@ type Overwrite<
|
|
|
42
48
|
T,
|
|
43
49
|
U
|
|
44
50
|
> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
45
|
-
export type OptionsResolved = Overwrite<Required<Options
|
|
51
|
+
export type OptionsResolved = Overwrite<Required<Options> & {
|
|
52
|
+
transformOptions?: any
|
|
53
|
+
}, Pick<Options, "enforce" | "extraOutdir" | "rewriteImports" | "inputBase">>;
|
|
46
54
|
export declare function resolveOptions(options: Options): OptionsResolved;
|
|
47
55
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IsolatedDeclarationsOptions } from "oxc-transform";
|
|
1
2
|
import type { TranspileOptions } from "typescript";
|
|
2
3
|
export interface TransformResult {
|
|
3
4
|
code: string;
|
|
@@ -7,7 +8,7 @@ export interface TransformResult {
|
|
|
7
8
|
/**
|
|
8
9
|
* Transform isolated declarations with `oxc-transform`.
|
|
9
10
|
*/
|
|
10
|
-
export declare function oxcTransform(id: string, code: string,
|
|
11
|
+
export declare function oxcTransform(id: string, code: string, transformOptions?: IsolatedDeclarationsOptions): Promise<TransformResult>;
|
|
11
12
|
/**
|
|
12
13
|
* Transform isolated declarations with `@swc/core`.
|
|
13
14
|
*/
|
package/dist/esbuild.js
CHANGED
package/dist/farm.js
CHANGED
package/dist/index.js
CHANGED
package/dist/rolldown.js
CHANGED
package/dist/rollup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { appendMapUrl, generateDtsMap, oxcTransform, swcTransform, tsTransform } from "./transformer-
|
|
1
|
+
import { appendMapUrl, generateDtsMap, oxcTransform, swcTransform, tsTransform } from "./transformer-Bp3NCHCk.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import MagicString from "magic-string";
|
|
@@ -103,7 +103,8 @@ function resolveOptions(options) {
|
|
|
103
103
|
extraOutdir: options.extraOutdir,
|
|
104
104
|
patchCjsDefaultExport: options.patchCjsDefaultExport || false,
|
|
105
105
|
rewriteImports: options.rewriteImports,
|
|
106
|
-
inputBase: options.inputBase
|
|
106
|
+
inputBase: options.inputBase,
|
|
107
|
+
transformOptions: options.transformOptions
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -151,7 +152,10 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
151
152
|
let result;
|
|
152
153
|
switch (options.transformer) {
|
|
153
154
|
case "oxc":
|
|
154
|
-
result = await oxcTransform(id, code,
|
|
155
|
+
result = await oxcTransform(id, code, {
|
|
156
|
+
...options.transformOptions,
|
|
157
|
+
sourcemap: options.sourceMap
|
|
158
|
+
});
|
|
155
159
|
break;
|
|
156
160
|
case "swc":
|
|
157
161
|
result = await swcTransform(id, code);
|
|
@@ -281,7 +285,7 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
281
285
|
build.onEnd(async (result) => {
|
|
282
286
|
const esbuildOptions = build.initialOptions;
|
|
283
287
|
const entries = esbuildOptions.entryPoints;
|
|
284
|
-
if (!
|
|
288
|
+
if (!entries || !Array.isArray(entries) || !entries.every((entry) => typeof entry === "string")) throw new Error("unsupported entryPoints, must be an string[]");
|
|
285
289
|
const inputBase = options.inputBase || lowestCommonAncestor(...entries);
|
|
286
290
|
debug("[esbuild] input base:", inputBase);
|
|
287
291
|
const jsExt = esbuildOptions.outExtension?.[".js"];
|
|
@@ -332,41 +336,43 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
332
336
|
});
|
|
333
337
|
async function resolve(context, id, importer) {
|
|
334
338
|
const nativeContext = context.getNativeBuildContext?.();
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
339
|
+
try {
|
|
340
|
+
switch (nativeContext?.framework) {
|
|
341
|
+
case "esbuild": {
|
|
342
|
+
const resolved = await nativeContext?.build.resolve(id, {
|
|
343
|
+
importer,
|
|
344
|
+
resolveDir: path.dirname(importer),
|
|
345
|
+
kind: "import-statement"
|
|
346
|
+
});
|
|
347
|
+
return {
|
|
348
|
+
id: resolved?.path,
|
|
349
|
+
external: resolved?.external
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
case "farm": {
|
|
353
|
+
const resolved = await nativeContext?.context.resolve({
|
|
354
|
+
source: id,
|
|
355
|
+
importer,
|
|
356
|
+
kind: "import"
|
|
357
|
+
}, {
|
|
358
|
+
meta: {},
|
|
359
|
+
caller: "unplugin-isolated-decl"
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
id: resolved.resolvedPath,
|
|
363
|
+
external: !!resolved.external
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
default: {
|
|
367
|
+
const resolved = await context.resolve(id, importer);
|
|
368
|
+
if (!resolved) return;
|
|
369
|
+
return {
|
|
370
|
+
id: resolved.id,
|
|
371
|
+
external: !!resolved.external
|
|
372
|
+
};
|
|
373
|
+
}
|
|
368
374
|
}
|
|
369
|
-
}
|
|
375
|
+
} catch {}
|
|
370
376
|
}
|
|
371
377
|
function patchCjsDefaultExport(source) {
|
|
372
378
|
return source.replace(/(?<=(?:[;}]|^)\s*export\s*)(?:\{\s*([\w$]+)\s*as\s+default\s*\}|default\s+([\w$]+))/, (_, s1, s2) => `= ${s1 || s2}`);
|
|
@@ -4,13 +4,13 @@ import path from "node:path";
|
|
|
4
4
|
function tryImport(pkg) {
|
|
5
5
|
return import(pkg).catch(() => null);
|
|
6
6
|
}
|
|
7
|
-
async function oxcTransform(id, code,
|
|
7
|
+
async function oxcTransform(id, code, transformOptions) {
|
|
8
8
|
const oxc = await tryImport("oxc-transform");
|
|
9
9
|
if (!oxc) return {
|
|
10
10
|
code: "",
|
|
11
11
|
errors: ["oxc-transform is required for transforming TypeScript, please install `oxc-transform`."]
|
|
12
12
|
};
|
|
13
|
-
const result = oxc.isolatedDeclaration(id, code,
|
|
13
|
+
const result = oxc.isolatedDeclaration(id, code, transformOptions);
|
|
14
14
|
return {
|
|
15
15
|
...result,
|
|
16
16
|
map: result.map?.mappings,
|
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.12.0",
|
|
4
4
|
"description": "A blazing-fast tool for generating isolated declarations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -66,40 +66,44 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"debug": "^4.4.0",
|
|
68
68
|
"magic-string": "^0.30.17",
|
|
69
|
-
"oxc-parser": "^0.
|
|
70
|
-
"unplugin": "^2.
|
|
71
|
-
"unplugin-utils": "^0.2.
|
|
69
|
+
"oxc-parser": "^0.53.0",
|
|
70
|
+
"unplugin": "^2.2.0",
|
|
71
|
+
"unplugin-utils": "^0.2.4"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@farmfe/core": "^1.6.6",
|
|
75
|
-
"@oxc-project/types": "^0.
|
|
75
|
+
"@oxc-project/types": "^0.53.0",
|
|
76
76
|
"@rollup/plugin-alias": "^5.1.1",
|
|
77
|
-
"@swc/core": "^1.
|
|
78
|
-
"@sxzz/eslint-config": "^5.0
|
|
79
|
-
"@sxzz/prettier-config": "^2.
|
|
77
|
+
"@swc/core": "^1.11.5",
|
|
78
|
+
"@sxzz/eslint-config": "^5.2.0",
|
|
79
|
+
"@sxzz/prettier-config": "^2.2.0",
|
|
80
80
|
"@sxzz/test-utils": "^0.5.1",
|
|
81
81
|
"@types/debug": "^4.1.12",
|
|
82
|
-
"@types/node": "^22.13.
|
|
83
|
-
"bumpp": "^10.0.
|
|
84
|
-
"esbuild": "^0.
|
|
85
|
-
"eslint": "^9.
|
|
82
|
+
"@types/node": "^22.13.8",
|
|
83
|
+
"bumpp": "^10.0.3",
|
|
84
|
+
"esbuild": "^0.25.0",
|
|
85
|
+
"eslint": "^9.21.0",
|
|
86
86
|
"fast-glob": "^3.3.3",
|
|
87
|
-
"oxc-transform": "^0.
|
|
88
|
-
"prettier": "^3.
|
|
87
|
+
"oxc-transform": "^0.53.0",
|
|
88
|
+
"prettier": "^3.5.3",
|
|
89
89
|
"rolldown": "^1.0.0-beta.3",
|
|
90
|
-
"rollup": "^4.34.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"vite": "^6.
|
|
97
|
-
"vitest": "^3.0.
|
|
90
|
+
"rollup": "^4.34.9",
|
|
91
|
+
"tinyglobby": "^0.2.12",
|
|
92
|
+
"tsdown": "^0.6.0",
|
|
93
|
+
"tsx": "^4.19.3",
|
|
94
|
+
"typescript": "^5.8.2",
|
|
95
|
+
"unplugin-oxc": "^0.2.5",
|
|
96
|
+
"vite": "^6.2.0",
|
|
97
|
+
"vitest": "^3.0.7"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=18.12.0"
|
|
101
101
|
},
|
|
102
102
|
"prettier": "@sxzz/prettier-config",
|
|
103
|
+
"resolutions": {
|
|
104
|
+
"@changesets/cli": "-",
|
|
105
|
+
"unplugin-isolated-decl": "-"
|
|
106
|
+
},
|
|
103
107
|
"scripts": {
|
|
104
108
|
"lint": "eslint --cache .",
|
|
105
109
|
"lint:fix": "pnpm run lint --fix",
|