unplugin-isolated-decl 0.4.4 → 0.4.6
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.cjs +1 -1
- package/dist/api.js +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-QT5bMpQf.js → src_index-CysF8PH2.js} +65 -25
- package/dist/{src_index-5Xl2iCUQ.cjs → src_index-yIG2muej.cjs} +65 -25
- package/dist/vite.cjs +2 -2
- package/dist/vite.js +2 -2
- package/package.json +16 -13
- /package/dist/{transformer-ScZEjI0h.js → transformer-69vts78l.js} +0 -0
- /package/dist/{transformer-oh0-JTHH.cjs → transformer-wFl7-Qrk.cjs} +0 -0
package/dist/api.cjs
CHANGED
package/dist/api.js
CHANGED
package/dist/esbuild.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const require_src_index = require('./src_index-
|
|
2
|
+
require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const require_src_index = require('./src_index-yIG2muej.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
|
-
|
|
3
|
-
const require_src_index = require('./src_index-
|
|
2
|
+
require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const require_src_index = require('./src_index-yIG2muej.cjs');
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, 'IsolatedDecl', {
|
|
6
6
|
enumerable: true,
|
package/dist/index.js
CHANGED
package/dist/rolldown.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const require_src_index = require('./src_index-
|
|
2
|
+
require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const require_src_index = require('./src_index-yIG2muej.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
|
-
|
|
3
|
-
const require_src_index = require('./src_index-
|
|
2
|
+
require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const require_src_index = require('./src_index-yIG2muej.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,7 +1,8 @@
|
|
|
1
|
-
import { oxcTransform, swcTransform, tsTransform } from "./transformer-
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
1
|
+
import { oxcTransform, swcTransform, tsTransform } from "./transformer-69vts78l.js";
|
|
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 { parseAsync } from "oxc-parser";
|
|
5
6
|
import { createUnplugin } from "unplugin";
|
|
6
7
|
|
|
7
8
|
//#region src/core/options.ts
|
|
@@ -17,12 +18,15 @@ function resolveOptions(options) {
|
|
|
17
18
|
|
|
18
19
|
//#endregion
|
|
19
20
|
//#region src/index.ts
|
|
20
|
-
const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
21
|
+
const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
21
22
|
const options = resolveOptions(rawOptions);
|
|
22
23
|
const filter = createFilter(options.include, options.exclude);
|
|
23
24
|
const outputFiles = {};
|
|
25
|
+
function stripExt(filename) {
|
|
26
|
+
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
27
|
+
}
|
|
24
28
|
function addOutput(filename, source) {
|
|
25
|
-
outputFiles[filename
|
|
29
|
+
outputFiles[stripExt(filename)] = source;
|
|
26
30
|
}
|
|
27
31
|
const rollup = { renderStart(outputOptions, inputOptions) {
|
|
28
32
|
let outBase = "";
|
|
@@ -48,27 +52,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
48
52
|
transformInclude(id) {
|
|
49
53
|
return filter(id);
|
|
50
54
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
switch (options.transformer) {
|
|
54
|
-
case "oxc":
|
|
55
|
-
result = oxcTransform(id, code);
|
|
56
|
-
break;
|
|
57
|
-
case "swc":
|
|
58
|
-
result = await swcTransform(id, code);
|
|
59
|
-
break;
|
|
60
|
-
case "typescript": result = await tsTransform(id, code, options.transformOptions);
|
|
61
|
-
}
|
|
62
|
-
const { sourceText, errors } = result;
|
|
63
|
-
if (errors.length) {
|
|
64
|
-
if (options.ignoreErrors) {
|
|
65
|
-
this.warn(errors[0]);
|
|
66
|
-
} else {
|
|
67
|
-
this.error(errors[0]);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
addOutput(id, sourceText);
|
|
55
|
+
transform(code, id) {
|
|
56
|
+
return transform.call(this, code, id);
|
|
72
57
|
},
|
|
73
58
|
esbuild: { setup(build) {
|
|
74
59
|
build.onEnd(async (result) => {
|
|
@@ -122,6 +107,61 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
122
107
|
...rollup
|
|
123
108
|
}
|
|
124
109
|
};
|
|
110
|
+
async function transform(code, id) {
|
|
111
|
+
let result;
|
|
112
|
+
switch (options.transformer) {
|
|
113
|
+
case "oxc":
|
|
114
|
+
result = oxcTransform(id, code);
|
|
115
|
+
break;
|
|
116
|
+
case "swc":
|
|
117
|
+
result = await swcTransform(id, code);
|
|
118
|
+
break;
|
|
119
|
+
case "typescript": result = await tsTransform(id, code, options.transformOptions);
|
|
120
|
+
}
|
|
121
|
+
const { sourceText, errors } = result;
|
|
122
|
+
if (errors.length) {
|
|
123
|
+
if (options.ignoreErrors) {
|
|
124
|
+
this.warn(errors[0]);
|
|
125
|
+
} else {
|
|
126
|
+
this.error(errors[0]);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
addOutput(id, sourceText);
|
|
131
|
+
let program;
|
|
132
|
+
try {
|
|
133
|
+
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const typeImports = program.body.filter((node) => {
|
|
138
|
+
if (node.type !== "ImportDeclaration") return false;
|
|
139
|
+
if (node.importKind === "type") return true;
|
|
140
|
+
return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
141
|
+
});
|
|
142
|
+
const resolve = async (id$1, importer) => {
|
|
143
|
+
if (meta.framework === "esbuild") {
|
|
144
|
+
return (await meta.build.resolve(id$1, {
|
|
145
|
+
importer,
|
|
146
|
+
resolveDir: path.dirname(importer),
|
|
147
|
+
kind: "import-statement"
|
|
148
|
+
})).path;
|
|
149
|
+
}
|
|
150
|
+
return (await this.resolve(id$1, importer))?.id;
|
|
151
|
+
};
|
|
152
|
+
for (const i of typeImports) {
|
|
153
|
+
const resolved = await resolve(i.source.value, id);
|
|
154
|
+
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
155
|
+
let source;
|
|
156
|
+
try {
|
|
157
|
+
source = await readFile(resolved, "utf8");
|
|
158
|
+
} catch {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
await transform.call(this, source, resolved);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
125
165
|
});
|
|
126
166
|
function lowestCommonAncestor(...filepaths) {
|
|
127
167
|
if (filepaths.length === 0) return "";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const require_transformer = require('./transformer-
|
|
3
|
-
const { mkdir, writeFile } = __toESM(require("node:fs/promises"));
|
|
2
|
+
const require_transformer = require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const { mkdir, readFile, writeFile } = __toESM(require("node:fs/promises"));
|
|
4
4
|
const { default: path } = __toESM(require("node:path"));
|
|
5
5
|
const { createFilter } = __toESM(require("@rollup/pluginutils"));
|
|
6
|
+
const { parseAsync } = __toESM(require("oxc-parser"));
|
|
6
7
|
const { createUnplugin } = __toESM(require("unplugin"));
|
|
7
8
|
|
|
8
9
|
//#region src/core/options.ts
|
|
@@ -18,12 +19,15 @@ function resolveOptions(options) {
|
|
|
18
19
|
|
|
19
20
|
//#endregion
|
|
20
21
|
//#region src/index.ts
|
|
21
|
-
const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
22
|
+
const IsolatedDecl = createUnplugin((rawOptions = {}, meta) => {
|
|
22
23
|
const options = resolveOptions(rawOptions);
|
|
23
24
|
const filter = createFilter(options.include, options.exclude);
|
|
24
25
|
const outputFiles = {};
|
|
26
|
+
function stripExt(filename) {
|
|
27
|
+
return filename.replace(/\.(.?)[jt]s$/, "");
|
|
28
|
+
}
|
|
25
29
|
function addOutput(filename, source) {
|
|
26
|
-
outputFiles[filename
|
|
30
|
+
outputFiles[stripExt(filename)] = source;
|
|
27
31
|
}
|
|
28
32
|
const rollup = { renderStart(outputOptions, inputOptions) {
|
|
29
33
|
let outBase = "";
|
|
@@ -49,27 +53,8 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
49
53
|
transformInclude(id) {
|
|
50
54
|
return filter(id);
|
|
51
55
|
},
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
56
|
+
transform(code, id) {
|
|
57
|
+
return transform.call(this, code, id);
|
|
73
58
|
},
|
|
74
59
|
esbuild: { setup(build) {
|
|
75
60
|
build.onEnd(async (result) => {
|
|
@@ -123,6 +108,61 @@ const IsolatedDecl = createUnplugin((rawOptions = {}) => {
|
|
|
123
108
|
...rollup
|
|
124
109
|
}
|
|
125
110
|
};
|
|
111
|
+
async function transform(code, id) {
|
|
112
|
+
let result;
|
|
113
|
+
switch (options.transformer) {
|
|
114
|
+
case "oxc":
|
|
115
|
+
result = require_transformer.oxcTransform(id, code);
|
|
116
|
+
break;
|
|
117
|
+
case "swc":
|
|
118
|
+
result = await require_transformer.swcTransform(id, code);
|
|
119
|
+
break;
|
|
120
|
+
case "typescript": result = await require_transformer.tsTransform(id, code, options.transformOptions);
|
|
121
|
+
}
|
|
122
|
+
const { sourceText, errors } = result;
|
|
123
|
+
if (errors.length) {
|
|
124
|
+
if (options.ignoreErrors) {
|
|
125
|
+
this.warn(errors[0]);
|
|
126
|
+
} else {
|
|
127
|
+
this.error(errors[0]);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
addOutput(id, sourceText);
|
|
132
|
+
let program;
|
|
133
|
+
try {
|
|
134
|
+
program = JSON.parse((await parseAsync(code, { sourceFilename: id })).program);
|
|
135
|
+
} catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const typeImports = program.body.filter((node) => {
|
|
139
|
+
if (node.type !== "ImportDeclaration") return false;
|
|
140
|
+
if (node.importKind === "type") return true;
|
|
141
|
+
return (node.specifiers || []).every((spec) => spec.type === "ImportSpecifier" && spec.importKind === "type");
|
|
142
|
+
});
|
|
143
|
+
const resolve = async (id$1, importer) => {
|
|
144
|
+
if (meta.framework === "esbuild") {
|
|
145
|
+
return (await meta.build.resolve(id$1, {
|
|
146
|
+
importer,
|
|
147
|
+
resolveDir: path.dirname(importer),
|
|
148
|
+
kind: "import-statement"
|
|
149
|
+
})).path;
|
|
150
|
+
}
|
|
151
|
+
return (await this.resolve(id$1, importer))?.id;
|
|
152
|
+
};
|
|
153
|
+
for (const i of typeImports) {
|
|
154
|
+
const resolved = await resolve(i.source.value, id);
|
|
155
|
+
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
|
|
156
|
+
let source;
|
|
157
|
+
try {
|
|
158
|
+
source = await readFile(resolved, "utf8");
|
|
159
|
+
} catch {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
await transform.call(this, source, resolved);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
126
166
|
});
|
|
127
167
|
function lowestCommonAncestor(...filepaths) {
|
|
128
168
|
if (filepaths.length === 0) return "";
|
package/dist/vite.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const require_src_index = require('./src_index-
|
|
2
|
+
require('./transformer-wFl7-Qrk.cjs');
|
|
3
|
+
const require_src_index = require('./src_index-yIG2muej.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/vite.ts
|
|
6
6
|
var vite_default = require_src_index.IsolatedDecl.vite;
|
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-isolated-decl",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "A blazing-fast tool for generating isolated declarations, powered by Oxc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -81,24 +81,27 @@
|
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@rollup/pluginutils": "^5.1.0",
|
|
84
|
-
"oxc-
|
|
85
|
-
"
|
|
84
|
+
"oxc-parser": "^0.25.0",
|
|
85
|
+
"oxc-transform": "^0.24.3",
|
|
86
|
+
"unplugin": "^1.12.2"
|
|
86
87
|
},
|
|
87
88
|
"devDependencies": {
|
|
88
|
-
"@swc/core": "^1.7.
|
|
89
|
-
"@sxzz/eslint-config": "^3.17.
|
|
89
|
+
"@swc/core": "^1.7.11",
|
|
90
|
+
"@sxzz/eslint-config": "^3.17.2",
|
|
90
91
|
"@sxzz/prettier-config": "^2.0.2",
|
|
91
|
-
"@types/node": "^20.
|
|
92
|
-
"bumpp": "^9.
|
|
93
|
-
"esbuild": "^0.23.
|
|
94
|
-
"eslint": "^9.
|
|
92
|
+
"@types/node": "^20.16.0",
|
|
93
|
+
"bumpp": "^9.5.1",
|
|
94
|
+
"esbuild": "^0.23.1",
|
|
95
|
+
"eslint": "^9.9.0",
|
|
95
96
|
"fast-glob": "^3.3.2",
|
|
96
97
|
"prettier": "^3.3.3",
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
98
|
+
"rolldown": "nightly",
|
|
99
|
+
"rollup": "^4.21.0",
|
|
100
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
101
|
+
"tsdown": "^0.2.6",
|
|
102
|
+
"tsx": "^4.17.0",
|
|
100
103
|
"typescript": "^5.5.4",
|
|
101
|
-
"vite": "^5.4.
|
|
104
|
+
"vite": "^5.4.1",
|
|
102
105
|
"vitest": "^2.0.5"
|
|
103
106
|
},
|
|
104
107
|
"engines": {
|
|
File without changes
|
|
File without changes
|