unplugin-isolated-decl 0.5.0 → 0.5.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 +3 -0
- package/dist/api.cjs +1 -1
- package/dist/api.js +1 -1
- package/dist/core/options.d.cts +2 -1
- package/dist/core/options.d.ts +2 -1
- package/dist/core/transformer.d.cts +1 -1
- package/dist/core/transformer.d.ts +1 -1
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/rolldown.cjs +2 -2
- package/dist/rolldown.js +2 -2
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.js +2 -2
- package/dist/{src_index-GOBsoA4f.js → src_index-ZsbwyfTU.js} +74 -65
- package/dist/{src_index-2j2jy32a.cjs → src_index-ytEwnjsz.cjs} +97 -65
- package/dist/{transformer-2hVUBpkW.js → transformer-5sKdcRP0.js} +2 -2
- package/dist/{transformer-ZZscAG9G.cjs → transformer-AnxdogMH.cjs} +3 -31
- package/dist/vite.cjs +2 -2
- package/dist/vite.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/api.cjs
CHANGED
package/dist/api.js
CHANGED
package/dist/core/options.d.cts
CHANGED
|
@@ -5,11 +5,12 @@ export type Options = {
|
|
|
5
5
|
exclude?: FilterPattern;
|
|
6
6
|
enforce?: "pre" | "post" | undefined;
|
|
7
7
|
ignoreErrors?: boolean;
|
|
8
|
+
extraOutdir?: string;
|
|
8
9
|
} & ({transformer?: "oxc" | "swc"} | {
|
|
9
10
|
transformer: "typescript";
|
|
10
11
|
transformOptions?: TranspileOptions;
|
|
11
12
|
});
|
|
12
13
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
13
|
-
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
|
|
14
|
+
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce" | "extraOutdir">>;
|
|
14
15
|
export declare function resolveOptions(options: Options): OptionsResolved;
|
|
15
16
|
export {};
|
package/dist/core/options.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ export type Options = {
|
|
|
5
5
|
exclude?: FilterPattern;
|
|
6
6
|
enforce?: "pre" | "post" | undefined;
|
|
7
7
|
ignoreErrors?: boolean;
|
|
8
|
+
extraOutdir?: string;
|
|
8
9
|
} & ({transformer?: "oxc" | "swc"} | {
|
|
9
10
|
transformer: "typescript";
|
|
10
11
|
transformOptions?: TranspileOptions;
|
|
11
12
|
});
|
|
12
13
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
13
|
-
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce">>;
|
|
14
|
+
export type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "enforce" | "extraOutdir">>;
|
|
14
15
|
export declare function resolveOptions(options: Options): OptionsResolved;
|
|
15
16
|
export {};
|
|
@@ -3,6 +3,6 @@ export interface TransformResult {
|
|
|
3
3
|
code: string;
|
|
4
4
|
errors: Array<string>;
|
|
5
5
|
}
|
|
6
|
-
export declare function oxcTransform(id: string, code: string): TransformResult
|
|
6
|
+
export declare function oxcTransform(id: string, code: string): Promise<TransformResult>;
|
|
7
7
|
export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
|
|
8
8
|
export declare function tsTransform(id: string, code: string, transformOptions?: TranspileOptions): Promise<TransformResult>;
|
|
@@ -3,6 +3,6 @@ export interface TransformResult {
|
|
|
3
3
|
code: string;
|
|
4
4
|
errors: Array<string>;
|
|
5
5
|
}
|
|
6
|
-
export declare function oxcTransform(id: string, code: string): TransformResult
|
|
6
|
+
export declare function oxcTransform(id: string, code: string): Promise<TransformResult>;
|
|
7
7
|
export declare function swcTransform(id: string, code: string): Promise<TransformResult>;
|
|
8
8
|
export declare function tsTransform(id: string, code: string, transformOptions?: TranspileOptions): Promise<TransformResult>;
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
require('./
|
|
3
|
-
|
|
2
|
+
const require_src_index = require('./src_index-ytEwnjsz.cjs');
|
|
3
|
+
require('./transformer-AnxdogMH.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/esbuild.ts
|
|
6
6
|
var esbuild_default = require_src_index.IsolatedDecl.esbuild;
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
require('./
|
|
3
|
-
|
|
2
|
+
const require_src_index = require('./src_index-ytEwnjsz.cjs');
|
|
3
|
+
require('./transformer-AnxdogMH.cjs');
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, 'IsolatedDecl', {
|
|
6
6
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./transformer-
|
|
2
|
-
import { IsolatedDecl, lowestCommonAncestor } from "./src_index-
|
|
1
|
+
import "./transformer-5sKdcRP0.js";
|
|
2
|
+
import { IsolatedDecl, lowestCommonAncestor } from "./src_index-ZsbwyfTU.js";
|
|
3
3
|
|
|
4
4
|
export { IsolatedDecl, lowestCommonAncestor };
|
package/dist/rolldown.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
require('./
|
|
3
|
-
|
|
2
|
+
const require_src_index = require('./src_index-ytEwnjsz.cjs');
|
|
3
|
+
require('./transformer-AnxdogMH.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/rolldown.ts
|
|
6
6
|
var rolldown_default = require_src_index.IsolatedDecl.rolldown;
|
package/dist/rolldown.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
require('./
|
|
3
|
-
|
|
2
|
+
const require_src_index = require('./src_index-ytEwnjsz.cjs');
|
|
3
|
+
require('./transformer-AnxdogMH.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/rollup.ts
|
|
6
6
|
var rollup_default = require_src_index.IsolatedDecl.rollup;
|
package/dist/rollup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { oxcTransform, swcTransform, tsTransform } from "./transformer-
|
|
1
|
+
import { oxcTransform, swcTransform, tsTransform } from "./transformer-5sKdcRP0.js";
|
|
2
2
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { default as path } from "node:path";
|
|
4
4
|
import { createFilter } from "@rollup/pluginutils";
|
|
@@ -12,13 +12,14 @@ function resolveOptions(options) {
|
|
|
12
12
|
exclude: options.exclude || [/node_modules/],
|
|
13
13
|
enforce: "enforce" in options ? options.enforce : "pre",
|
|
14
14
|
transformer: options.transformer || "oxc",
|
|
15
|
-
ignoreErrors: options.ignoreErrors || false
|
|
15
|
+
ignoreErrors: options.ignoreErrors || false,
|
|
16
|
+
extraOutdir: options.extraOutdir
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
//#endregion
|
|
20
21
|
//#region src/index.ts
|
|
21
|
-
const IsolatedDecl = createUnplugin((rawOptions = {}
|
|
22
|
+
const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
22
23
|
const options = resolveOptions(rawOptions);
|
|
23
24
|
const filter = createFilter(options.include, options.exclude);
|
|
24
25
|
const outputFiles = {};
|
|
@@ -35,7 +36,10 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
35
36
|
if (typeof outputOptions.entryFileNames !== "string") {
|
|
36
37
|
return this.error("entryFileNames must be a string");
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
let entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
|
|
40
|
+
if (options.extraOutdir) {
|
|
41
|
+
entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
42
|
+
}
|
|
39
43
|
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
40
44
|
this.emitFile({
|
|
41
45
|
type: "asset",
|
|
@@ -50,52 +54,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
50
54
|
return filter(id);
|
|
51
55
|
},
|
|
52
56
|
transform(code, id) {
|
|
53
|
-
return transform
|
|
57
|
+
return transform(this, code, id);
|
|
54
58
|
},
|
|
55
|
-
esbuild: { setup
|
|
56
|
-
build.onEnd(async (result) => {
|
|
57
|
-
const esbuildOptions = build.initialOptions;
|
|
58
|
-
const entries = esbuildOptions.entryPoints;
|
|
59
|
-
if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
|
|
60
|
-
const outBase = lowestCommonAncestor(...entries);
|
|
61
|
-
const jsExt = esbuildOptions.outExtension?.[".js"];
|
|
62
|
-
let outExt;
|
|
63
|
-
switch (jsExt) {
|
|
64
|
-
case ".cjs":
|
|
65
|
-
outExt = "cts";
|
|
66
|
-
break;
|
|
67
|
-
case ".mjs":
|
|
68
|
-
outExt = "mts";
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
outExt = "ts";
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
const write = build.initialOptions.write ?? true;
|
|
75
|
-
if (write) {
|
|
76
|
-
if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
|
|
77
|
-
} else {
|
|
78
|
-
result.outputFiles ||= [];
|
|
79
|
-
}
|
|
80
|
-
const textEncoder = new TextEncoder();
|
|
81
|
-
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
82
|
-
const outDir = build.initialOptions.outdir;
|
|
83
|
-
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
84
|
-
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
85
|
-
if (write) {
|
|
86
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
87
|
-
await writeFile(filePath, source);
|
|
88
|
-
} else {
|
|
89
|
-
result.outputFiles.push({
|
|
90
|
-
path: filePath,
|
|
91
|
-
contents: textEncoder.encode(source),
|
|
92
|
-
hash: "",
|
|
93
|
-
text: source
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
} },
|
|
59
|
+
esbuild: { setup: esbuildSetup },
|
|
99
60
|
rollup,
|
|
100
61
|
rolldown: rollup,
|
|
101
62
|
vite: {
|
|
@@ -104,11 +65,11 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
104
65
|
...rollup
|
|
105
66
|
}
|
|
106
67
|
};
|
|
107
|
-
async function transform(code, id) {
|
|
68
|
+
async function transform(context, code, id) {
|
|
108
69
|
let result;
|
|
109
70
|
switch (options.transformer) {
|
|
110
71
|
case "oxc":
|
|
111
|
-
result = oxcTransform(id, code);
|
|
72
|
+
result = await oxcTransform(id, code);
|
|
112
73
|
break;
|
|
113
74
|
case "swc":
|
|
114
75
|
result = await swcTransform(id, code);
|
|
@@ -118,9 +79,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
118
79
|
const { code: sourceText, errors } = result;
|
|
119
80
|
if (errors.length) {
|
|
120
81
|
if (options.ignoreErrors) {
|
|
121
|
-
|
|
82
|
+
context.warn(errors[0]);
|
|
122
83
|
} else {
|
|
123
|
-
|
|
84
|
+
context.error(errors[0]);
|
|
124
85
|
return;
|
|
125
86
|
}
|
|
126
87
|
}
|
|
@@ -136,18 +97,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
136
97
|
if (node.importKind === "type") return true;
|
|
137
98
|
return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
138
99
|
});
|
|
139
|
-
const resolve = async (id$1, importer) => {
|
|
140
|
-
if (meta.framework === "esbuild") {
|
|
141
|
-
return (await meta.build.resolve(id$1, {
|
|
142
|
-
importer,
|
|
143
|
-
resolveDir: path.dirname(importer),
|
|
144
|
-
kind: "import-statement"
|
|
145
|
-
})).path;
|
|
146
|
-
}
|
|
147
|
-
return (await this.resolve(id$1, importer))?.id;
|
|
148
|
-
};
|
|
149
100
|
for (const i of typeImports) {
|
|
150
|
-
const resolved = await resolve(i.source.value, id);
|
|
101
|
+
const resolved = await resolve(context, i.source.value, id);
|
|
151
102
|
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
152
103
|
let source;
|
|
153
104
|
try {
|
|
@@ -155,11 +106,69 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
155
106
|
} catch {
|
|
156
107
|
continue;
|
|
157
108
|
}
|
|
158
|
-
await transform
|
|
109
|
+
await transform(context, source, resolved);
|
|
159
110
|
}
|
|
160
111
|
}
|
|
161
112
|
}
|
|
113
|
+
function esbuildSetup(build) {
|
|
114
|
+
build.onEnd(async (result) => {
|
|
115
|
+
const esbuildOptions = build.initialOptions;
|
|
116
|
+
const entries = esbuildOptions.entryPoints;
|
|
117
|
+
if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
|
|
118
|
+
const outBase = lowestCommonAncestor(...entries);
|
|
119
|
+
const jsExt = esbuildOptions.outExtension?.[".js"];
|
|
120
|
+
let outExt;
|
|
121
|
+
switch (jsExt) {
|
|
122
|
+
case ".cjs":
|
|
123
|
+
outExt = "cts";
|
|
124
|
+
break;
|
|
125
|
+
case ".mjs":
|
|
126
|
+
outExt = "mts";
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
outExt = "ts";
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const write = build.initialOptions.write ?? true;
|
|
133
|
+
if (write) {
|
|
134
|
+
if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
|
|
135
|
+
} else {
|
|
136
|
+
result.outputFiles ||= [];
|
|
137
|
+
}
|
|
138
|
+
const textEncoder = new TextEncoder();
|
|
139
|
+
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
140
|
+
const outDir = build.initialOptions.outdir;
|
|
141
|
+
let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
142
|
+
if (options.extraOutdir) {
|
|
143
|
+
outFile = path.join(options.extraOutdir, outFile);
|
|
144
|
+
}
|
|
145
|
+
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
146
|
+
if (write) {
|
|
147
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
148
|
+
await writeFile(filePath, source);
|
|
149
|
+
} else {
|
|
150
|
+
result.outputFiles.push({
|
|
151
|
+
path: filePath,
|
|
152
|
+
contents: textEncoder.encode(source),
|
|
153
|
+
hash: "",
|
|
154
|
+
text: source
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
162
160
|
});
|
|
161
|
+
const resolve = async (context, id, importer) => {
|
|
162
|
+
const nativeContext = context.getNativeBuildContext?.();
|
|
163
|
+
if (nativeContext?.framework === "esbuild") {
|
|
164
|
+
return (await nativeContext.build.resolve(id, {
|
|
165
|
+
importer,
|
|
166
|
+
resolveDir: path.dirname(importer),
|
|
167
|
+
kind: "import-statement"
|
|
168
|
+
})).path;
|
|
169
|
+
}
|
|
170
|
+
return (await context.resolve(id, importer))?.id;
|
|
171
|
+
};
|
|
163
172
|
function stripExt(filename) {
|
|
164
173
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
165
174
|
}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
const require_transformer = require('./transformer-AnxdogMH.cjs');
|
|
3
26
|
const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
|
|
4
27
|
const { default: path } = __toESM(require("node:path"));
|
|
5
28
|
const { createFilter } = __toESM(require("@rollup/pluginutils"));
|
|
@@ -13,13 +36,14 @@ function resolveOptions(options) {
|
|
|
13
36
|
exclude: options.exclude || [/node_modules/],
|
|
14
37
|
enforce: "enforce" in options ? options.enforce : "pre",
|
|
15
38
|
transformer: options.transformer || "oxc",
|
|
16
|
-
ignoreErrors: options.ignoreErrors || false
|
|
39
|
+
ignoreErrors: options.ignoreErrors || false,
|
|
40
|
+
extraOutdir: options.extraOutdir
|
|
17
41
|
};
|
|
18
42
|
}
|
|
19
43
|
|
|
20
44
|
//#endregion
|
|
21
45
|
//#region src/index.ts
|
|
22
|
-
const IsolatedDecl = createUnplugin((rawOptions = {}
|
|
46
|
+
const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
23
47
|
const options = resolveOptions(rawOptions);
|
|
24
48
|
const filter = createFilter(options.include, options.exclude);
|
|
25
49
|
const outputFiles = {};
|
|
@@ -36,7 +60,10 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
36
60
|
if (typeof outputOptions.entryFileNames !== "string") {
|
|
37
61
|
return this.error("entryFileNames must be a string");
|
|
38
62
|
}
|
|
39
|
-
|
|
63
|
+
let entryFileNames = outputOptions.entryFileNames.replace(/\.(.)?[jt]s$/, (_, s) => `.d.${s || ""}ts`);
|
|
64
|
+
if (options.extraOutdir) {
|
|
65
|
+
entryFileNames = path.join(options.extraOutdir, entryFileNames);
|
|
66
|
+
}
|
|
40
67
|
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
41
68
|
this.emitFile({
|
|
42
69
|
type: "asset",
|
|
@@ -51,52 +78,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
51
78
|
return filter(id);
|
|
52
79
|
},
|
|
53
80
|
transform(code, id) {
|
|
54
|
-
return transform
|
|
81
|
+
return transform(this, code, id);
|
|
55
82
|
},
|
|
56
|
-
esbuild: { setup
|
|
57
|
-
build.onEnd(async (result) => {
|
|
58
|
-
const esbuildOptions = build.initialOptions;
|
|
59
|
-
const entries = esbuildOptions.entryPoints;
|
|
60
|
-
if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
|
|
61
|
-
const outBase = lowestCommonAncestor(...entries);
|
|
62
|
-
const jsExt = esbuildOptions.outExtension?.[".js"];
|
|
63
|
-
let outExt;
|
|
64
|
-
switch (jsExt) {
|
|
65
|
-
case ".cjs":
|
|
66
|
-
outExt = "cts";
|
|
67
|
-
break;
|
|
68
|
-
case ".mjs":
|
|
69
|
-
outExt = "mts";
|
|
70
|
-
break;
|
|
71
|
-
default:
|
|
72
|
-
outExt = "ts";
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
const write = build.initialOptions.write ?? true;
|
|
76
|
-
if (write) {
|
|
77
|
-
if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
|
|
78
|
-
} else {
|
|
79
|
-
result.outputFiles ||= [];
|
|
80
|
-
}
|
|
81
|
-
const textEncoder = new TextEncoder();
|
|
82
|
-
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
83
|
-
const outDir = build.initialOptions.outdir;
|
|
84
|
-
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
85
|
-
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
86
|
-
if (write) {
|
|
87
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
88
|
-
await writeFile(filePath, source);
|
|
89
|
-
} else {
|
|
90
|
-
result.outputFiles.push({
|
|
91
|
-
path: filePath,
|
|
92
|
-
contents: textEncoder.encode(source),
|
|
93
|
-
hash: "",
|
|
94
|
-
text: source
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
} },
|
|
83
|
+
esbuild: { setup: esbuildSetup },
|
|
100
84
|
rollup,
|
|
101
85
|
rolldown: rollup,
|
|
102
86
|
vite: {
|
|
@@ -105,11 +89,11 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
105
89
|
...rollup
|
|
106
90
|
}
|
|
107
91
|
};
|
|
108
|
-
async function transform(code, id) {
|
|
92
|
+
async function transform(context, code, id) {
|
|
109
93
|
let result;
|
|
110
94
|
switch (options.transformer) {
|
|
111
95
|
case "oxc":
|
|
112
|
-
result = require_transformer.oxcTransform(id, code);
|
|
96
|
+
result = await require_transformer.oxcTransform(id, code);
|
|
113
97
|
break;
|
|
114
98
|
case "swc":
|
|
115
99
|
result = await require_transformer.swcTransform(id, code);
|
|
@@ -119,9 +103,9 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
119
103
|
const { code: sourceText, errors } = result;
|
|
120
104
|
if (errors.length) {
|
|
121
105
|
if (options.ignoreErrors) {
|
|
122
|
-
|
|
106
|
+
context.warn(errors[0]);
|
|
123
107
|
} else {
|
|
124
|
-
|
|
108
|
+
context.error(errors[0]);
|
|
125
109
|
return;
|
|
126
110
|
}
|
|
127
111
|
}
|
|
@@ -137,18 +121,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
137
121
|
if (node.importKind === "type") return true;
|
|
138
122
|
return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
139
123
|
});
|
|
140
|
-
const resolve = async (id$1, importer) => {
|
|
141
|
-
if (meta.framework === "esbuild") {
|
|
142
|
-
return (await meta.build.resolve(id$1, {
|
|
143
|
-
importer,
|
|
144
|
-
resolveDir: path.dirname(importer),
|
|
145
|
-
kind: "import-statement"
|
|
146
|
-
})).path;
|
|
147
|
-
}
|
|
148
|
-
return (await this.resolve(id$1, importer))?.id;
|
|
149
|
-
};
|
|
150
124
|
for (const i of typeImports) {
|
|
151
|
-
const resolved = await resolve(i.source.value, id);
|
|
125
|
+
const resolved = await resolve(context, i.source.value, id);
|
|
152
126
|
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
153
127
|
let source;
|
|
154
128
|
try {
|
|
@@ -156,11 +130,69 @@ const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
|
156
130
|
} catch {
|
|
157
131
|
continue;
|
|
158
132
|
}
|
|
159
|
-
await transform
|
|
133
|
+
await transform(context, source, resolved);
|
|
160
134
|
}
|
|
161
135
|
}
|
|
162
136
|
}
|
|
137
|
+
function esbuildSetup(build) {
|
|
138
|
+
build.onEnd(async (result) => {
|
|
139
|
+
const esbuildOptions = build.initialOptions;
|
|
140
|
+
const entries = esbuildOptions.entryPoints;
|
|
141
|
+
if (!(entries && Array.isArray(entries) && entries.every((entry) => typeof entry === "string"))) throw new Error("unsupported entryPoints, must be an string[]");
|
|
142
|
+
const outBase = lowestCommonAncestor(...entries);
|
|
143
|
+
const jsExt = esbuildOptions.outExtension?.[".js"];
|
|
144
|
+
let outExt;
|
|
145
|
+
switch (jsExt) {
|
|
146
|
+
case ".cjs":
|
|
147
|
+
outExt = "cts";
|
|
148
|
+
break;
|
|
149
|
+
case ".mjs":
|
|
150
|
+
outExt = "mts";
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
outExt = "ts";
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
const write = build.initialOptions.write ?? true;
|
|
157
|
+
if (write) {
|
|
158
|
+
if (!build.initialOptions.outdir) throw new Error("outdir is required when write is true");
|
|
159
|
+
} else {
|
|
160
|
+
result.outputFiles ||= [];
|
|
161
|
+
}
|
|
162
|
+
const textEncoder = new TextEncoder();
|
|
163
|
+
for (const [filename, source] of Object.entries(outputFiles)) {
|
|
164
|
+
const outDir = build.initialOptions.outdir;
|
|
165
|
+
let outFile = `${path.relative(outBase, filename)}.d.${outExt}`;
|
|
166
|
+
if (options.extraOutdir) {
|
|
167
|
+
outFile = path.join(options.extraOutdir, outFile);
|
|
168
|
+
}
|
|
169
|
+
const filePath = outDir ? path.resolve(outDir, outFile) : outFile;
|
|
170
|
+
if (write) {
|
|
171
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
172
|
+
await writeFile(filePath, source);
|
|
173
|
+
} else {
|
|
174
|
+
result.outputFiles.push({
|
|
175
|
+
path: filePath,
|
|
176
|
+
contents: textEncoder.encode(source),
|
|
177
|
+
hash: "",
|
|
178
|
+
text: source
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
163
184
|
});
|
|
185
|
+
const resolve = async (context, id, importer) => {
|
|
186
|
+
const nativeContext = context.getNativeBuildContext?.();
|
|
187
|
+
if (nativeContext?.framework === "esbuild") {
|
|
188
|
+
return (await nativeContext.build.resolve(id, {
|
|
189
|
+
importer,
|
|
190
|
+
resolveDir: path.dirname(importer),
|
|
191
|
+
kind: "import-statement"
|
|
192
|
+
})).path;
|
|
193
|
+
}
|
|
194
|
+
return (await context.resolve(id, importer))?.id;
|
|
195
|
+
};
|
|
164
196
|
function stripExt(filename) {
|
|
165
197
|
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
166
198
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isolatedDeclaration } from "oxc-transform";
|
|
2
1
|
|
|
3
2
|
//#region src/core/transformer.ts
|
|
4
|
-
function oxcTransform(id, code) {
|
|
3
|
+
async function oxcTransform(id, code) {
|
|
4
|
+
const { isolatedDeclaration } = await import("oxc-transform");
|
|
5
5
|
return isolatedDeclaration(id, code, { sourcemap: false });
|
|
6
6
|
}
|
|
7
7
|
async function swcTransform(id, code) {
|
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//#region rolldown:runtime
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
const { isolatedDeclaration } = __toESM(require("oxc-transform"));
|
|
26
2
|
|
|
27
3
|
//#region src/core/transformer.ts
|
|
28
|
-
function oxcTransform(id, code) {
|
|
4
|
+
async function oxcTransform(id, code) {
|
|
5
|
+
const { isolatedDeclaration } = await import("oxc-transform");
|
|
29
6
|
return isolatedDeclaration(id, code, { sourcemap: false });
|
|
30
7
|
}
|
|
31
8
|
async function swcTransform(id, code) {
|
|
@@ -94,12 +71,7 @@ async function tsTransform(id, code, transformOptions) {
|
|
|
94
71
|
}
|
|
95
72
|
|
|
96
73
|
//#endregion
|
|
97
|
-
Object.defineProperty(exports, '
|
|
98
|
-
enumerable: true,
|
|
99
|
-
get: function () {
|
|
100
|
-
return __toESM;
|
|
101
|
-
}
|
|
102
|
-
});Object.defineProperty(exports, 'oxcTransform', {
|
|
74
|
+
Object.defineProperty(exports, 'oxcTransform', {
|
|
103
75
|
enumerable: true,
|
|
104
76
|
get: function () {
|
|
105
77
|
return oxcTransform;
|
package/dist/vite.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
require('./
|
|
3
|
-
|
|
2
|
+
const require_src_index = require('./src_index-ytEwnjsz.cjs');
|
|
3
|
+
require('./transformer-AnxdogMH.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/vite.ts
|
|
6
6
|
var vite_default = require_src_index.IsolatedDecl.vite;
|
package/dist/vite.js
CHANGED