@o.z/vite-plugin-swc 0.6.0 → 0.7.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 +1 -1
- package/dist/index.cjs +1 -293
- package/dist/index.js +181 -280
- package/package.json +14 -14
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,293 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const pluginutils = require('@rollup/pluginutils');
|
|
6
|
-
const core = require('@swc/core');
|
|
7
|
-
|
|
8
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
9
|
-
try {
|
|
10
|
-
var info = gen[key](arg);
|
|
11
|
-
var value = info.value;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
reject(error);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (info.done) {
|
|
17
|
-
resolve(value);
|
|
18
|
-
} else {
|
|
19
|
-
Promise.resolve(value).then(_next, _throw);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function _async_to_generator(fn) {
|
|
23
|
-
return function() {
|
|
24
|
-
var self = this, args = arguments;
|
|
25
|
-
return new Promise(function(resolve, reject) {
|
|
26
|
-
var gen = fn.apply(self, args);
|
|
27
|
-
function _next(value) {
|
|
28
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
29
|
-
}
|
|
30
|
-
function _throw(err) {
|
|
31
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
32
|
-
}
|
|
33
|
-
_next(undefined);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function _define_property(obj, key, value) {
|
|
38
|
-
if (key in obj) {
|
|
39
|
-
Object.defineProperty(obj, key, {
|
|
40
|
-
value: value,
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
obj[key] = value;
|
|
47
|
-
}
|
|
48
|
-
return obj;
|
|
49
|
-
}
|
|
50
|
-
function _object_spread(target) {
|
|
51
|
-
for(var i = 1; i < arguments.length; i++){
|
|
52
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
53
|
-
var ownKeys = Object.keys(source);
|
|
54
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
55
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
56
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
ownKeys.forEach(function(key) {
|
|
60
|
-
_define_property(target, key, source[key]);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
function _object_without_properties(source, excluded) {
|
|
66
|
-
if (source == null) return {};
|
|
67
|
-
var target = {}, sourceKeys, key, i;
|
|
68
|
-
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
69
|
-
sourceKeys = Reflect.ownKeys(source);
|
|
70
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
71
|
-
key = sourceKeys[i];
|
|
72
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
73
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
74
|
-
target[key] = source[key];
|
|
75
|
-
}
|
|
76
|
-
return target;
|
|
77
|
-
}
|
|
78
|
-
target = _object_without_properties_loose(source, excluded);
|
|
79
|
-
if (Object.getOwnPropertySymbols) {
|
|
80
|
-
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
81
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
82
|
-
key = sourceKeys[i];
|
|
83
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
84
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
85
|
-
target[key] = source[key];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return target;
|
|
89
|
-
}
|
|
90
|
-
function _object_without_properties_loose(source, excluded) {
|
|
91
|
-
if (source == null) return {};
|
|
92
|
-
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
93
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
94
|
-
key = sourceKeys[i];
|
|
95
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
96
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
97
|
-
target[key] = source[key];
|
|
98
|
-
}
|
|
99
|
-
return target;
|
|
100
|
-
}
|
|
101
|
-
function _ts_generator(thisArg, body) {
|
|
102
|
-
var f, y, t, _ = {
|
|
103
|
-
label: 0,
|
|
104
|
-
sent: function() {
|
|
105
|
-
if (t[0] & 1) throw t[1];
|
|
106
|
-
return t[1];
|
|
107
|
-
},
|
|
108
|
-
trys: [],
|
|
109
|
-
ops: []
|
|
110
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
111
|
-
return d(g, "next", {
|
|
112
|
-
value: verb(0)
|
|
113
|
-
}), d(g, "throw", {
|
|
114
|
-
value: verb(1)
|
|
115
|
-
}), d(g, "return", {
|
|
116
|
-
value: verb(2)
|
|
117
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
118
|
-
value: function() {
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
}), g;
|
|
122
|
-
function verb(n) {
|
|
123
|
-
return function(v) {
|
|
124
|
-
return step([
|
|
125
|
-
n,
|
|
126
|
-
v
|
|
127
|
-
]);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function step(op) {
|
|
131
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
132
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
133
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
134
|
-
if (y = 0, t) op = [
|
|
135
|
-
op[0] & 2,
|
|
136
|
-
t.value
|
|
137
|
-
];
|
|
138
|
-
switch(op[0]){
|
|
139
|
-
case 0:
|
|
140
|
-
case 1:
|
|
141
|
-
t = op;
|
|
142
|
-
break;
|
|
143
|
-
case 4:
|
|
144
|
-
_.label++;
|
|
145
|
-
return {
|
|
146
|
-
value: op[1],
|
|
147
|
-
done: false
|
|
148
|
-
};
|
|
149
|
-
case 5:
|
|
150
|
-
_.label++;
|
|
151
|
-
y = op[1];
|
|
152
|
-
op = [
|
|
153
|
-
0
|
|
154
|
-
];
|
|
155
|
-
continue;
|
|
156
|
-
case 7:
|
|
157
|
-
op = _.ops.pop();
|
|
158
|
-
_.trys.pop();
|
|
159
|
-
continue;
|
|
160
|
-
default:
|
|
161
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
162
|
-
_ = 0;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
166
|
-
_.label = op[1];
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
170
|
-
_.label = t[1];
|
|
171
|
-
t = op;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (t && _.label < t[2]) {
|
|
175
|
-
_.label = t[2];
|
|
176
|
-
_.ops.push(op);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
if (t[2]) _.ops.pop();
|
|
180
|
-
_.trys.pop();
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
op = body.call(thisArg, _);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
op = [
|
|
186
|
-
6,
|
|
187
|
-
e
|
|
188
|
-
];
|
|
189
|
-
y = 0;
|
|
190
|
-
} finally{
|
|
191
|
-
f = t = 0;
|
|
192
|
-
}
|
|
193
|
-
if (op[0] & 5) throw op[1];
|
|
194
|
-
return {
|
|
195
|
-
value: op[0] ? op[1] : void 0,
|
|
196
|
-
done: true
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Vite plugin that transforms TypeScript and JavaScript files using SWC.
|
|
202
|
-
* It disables Vite's default esbuild transform to let SWC handle the compilation,
|
|
203
|
-
* resulting in significantly faster builds, especially for large codebases.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* // vite.config.ts
|
|
208
|
-
* import { defineConfig } from 'vite'
|
|
209
|
-
* import swc from '@o.z/vite-plugin-swc'
|
|
210
|
-
*
|
|
211
|
-
* export default defineConfig({
|
|
212
|
-
* plugins: [swc()]
|
|
213
|
-
* })
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @param options - Configuration options for the plugin and SWC.
|
|
217
|
-
* @returns A Vite plugin instance.
|
|
218
|
-
*/ var swc = function swc() {
|
|
219
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
220
|
-
// Default include/exclude patterns – now covering .ts, .tsx, .js, .jsx
|
|
221
|
-
var _options_include = options.include, include = _options_include === void 0 ? /\.(ts|tsx|js|jsx)$/ : _options_include, _options_exclude = options.exclude, exclude = _options_exclude === void 0 ? "node_modules" : _options_exclude, swcOptions = _object_without_properties(options, [
|
|
222
|
-
"include",
|
|
223
|
-
"exclude"
|
|
224
|
-
]);
|
|
225
|
-
var filter = pluginutils.createFilter(include, exclude);
|
|
226
|
-
return {
|
|
227
|
-
name: "vite-plugin-swc",
|
|
228
|
-
enforce: "pre",
|
|
229
|
-
config: function config() {
|
|
230
|
-
return {
|
|
231
|
-
esbuild: false
|
|
232
|
-
};
|
|
233
|
-
},
|
|
234
|
-
transform: function transform(code, id) {
|
|
235
|
-
return _async_to_generator(function() {
|
|
236
|
-
var _this_environment_config_css, sourceMaps, result, error;
|
|
237
|
-
return _ts_generator(this, function(_state) {
|
|
238
|
-
switch(_state.label){
|
|
239
|
-
case 0:
|
|
240
|
-
if (!filter(id)) return [
|
|
241
|
-
2,
|
|
242
|
-
null
|
|
243
|
-
];
|
|
244
|
-
_state.label = 1;
|
|
245
|
-
case 1:
|
|
246
|
-
_state.trys.push([
|
|
247
|
-
1,
|
|
248
|
-
3,
|
|
249
|
-
,
|
|
250
|
-
4
|
|
251
|
-
]);
|
|
252
|
-
// Determine if source maps should be generated based on Vite's config
|
|
253
|
-
// `this.environment.config` is available inside the transform hook
|
|
254
|
-
sourceMaps = this.environment.config.command === "build" ? !!this.environment.config.build.sourcemap : !!((_this_environment_config_css = this.environment.config.css) === null || _this_environment_config_css === void 0 ? void 0 : _this_environment_config_css.devSourcemap); // For dev, you might want to align with css sourcemaps or a dedicated flag
|
|
255
|
-
return [
|
|
256
|
-
4,
|
|
257
|
-
core.transform(code, _object_spread({
|
|
258
|
-
filename: id,
|
|
259
|
-
sourceFileName: id.split("?", 1)[0],
|
|
260
|
-
sourceMaps: sourceMaps
|
|
261
|
-
}, swcOptions))
|
|
262
|
-
];
|
|
263
|
-
case 2:
|
|
264
|
-
result = _state.sent();
|
|
265
|
-
// SWC returns { code, map } when sourceMaps are enabled, otherwise just { code }
|
|
266
|
-
return [
|
|
267
|
-
2,
|
|
268
|
-
{
|
|
269
|
-
code: result.code,
|
|
270
|
-
map: result.map
|
|
271
|
-
}
|
|
272
|
-
];
|
|
273
|
-
case 3:
|
|
274
|
-
error = _state.sent();
|
|
275
|
-
// Enhance error message with file information and re-throw as a plugin error
|
|
276
|
-
this.error("SWC transform failed in ".concat(id, ": ").concat((error === null || error === void 0 ? void 0 : error.message) || error));
|
|
277
|
-
return [
|
|
278
|
-
3,
|
|
279
|
-
4
|
|
280
|
-
];
|
|
281
|
-
case 4:
|
|
282
|
-
return [
|
|
283
|
-
2
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}).call(this);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
exports.default = swc;
|
|
293
|
-
exports.swc = swc;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@rollup/pluginutils`),t=require(`@swc/core`);function n(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function r(e){return function(){var t=this,r=arguments;return new Promise(function(i,a){var o=e.apply(t,r);function s(e){n(o,i,a,s,c,`next`,e)}function c(e){n(o,i,a,s,c,`throw`,e)}s(void 0)})}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){i(e,t,n[t])})}return e}function o(e,t){if(e==null)return{};var n={},r,i,a;if(typeof Reflect<`u`&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i]);return n}if(n=s(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i]);return n}function s(e,t){if(e==null)return{};var n={},r=Object.getOwnPropertyNames(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i]);return n}function c(e,t){var n,r,i,a={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype),s=Object.defineProperty;return s(o,`next`,{value:c(0)}),s(o,`throw`,{value:c(1)}),s(o,`return`,{value:c(2)}),typeof Symbol==`function`&&s(o,Symbol.iterator,{value:function(){return this}}),o;function c(e){return function(t){return l([e,t])}}function l(s){if(n)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=s[0]&2?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[s[0]&2,i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if((i=a.trys,!(i=i.length>0&&i[i.length-1]))&&(s[0]===6||s[0]===2)){a=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(s[0]===6&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var l=function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{swcrc:!1,configFile:!1,minify:!0,jsc:{parser:{syntax:`typescript`,decorators:!0},transform:{decoratorMetadata:!0,decoratorVersion:`2022-03`}}},i=n.include,s=i===void 0?/\.(ts|tsx|js|jsx)$/:i,l=n.exclude,u=l===void 0?`node_modules`:l,d=o(n,[`include`,`exclude`]),f=(0,e.createFilter)(s,u);return{name:`vite-plugin-swc`,enforce:`pre`,config:function(){return{oxc:!1,esbuild:!1}},transform:function(e,n){return r(function(){var r,i,o;return c(this,function(s){switch(s.label){case 0:if(!f(n))return[2,null];s.label=1;case 1:return s.trys.push([1,3,,4]),r=this.environment.config.command===`build`?!!this.environment.config.build.sourcemap:!!this.environment.config.css?.devSourcemap,[4,(0,t.transform)(e,a({filename:n,sourceFileName:n.split(`?`,1)[0],sourceMaps:r},d))];case 2:return i=s.sent(),[2,{code:i.code,map:i.map}];case 3:return o=s.sent(),this.error(`SWC transform failed in ${n}: ${o?.message||o}`),[3,4];case 4:return[2]}})}).call(this)}}};exports.default=l,exports.swc=l;
|
package/dist/index.js
CHANGED
|
@@ -1,288 +1,189 @@
|
|
|
1
|
-
import { createFilter } from
|
|
2
|
-
import { transform } from
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (info.done) {
|
|
13
|
-
resolve(value);
|
|
14
|
-
} else {
|
|
15
|
-
Promise.resolve(value).then(_next, _throw);
|
|
16
|
-
}
|
|
1
|
+
import { createFilter as e } from "@rollup/pluginutils";
|
|
2
|
+
import { transform as t } from "@swc/core";
|
|
3
|
+
//#region src/lib/index.ts
|
|
4
|
+
function n(e, t, n, r, i, a, o) {
|
|
5
|
+
try {
|
|
6
|
+
var s = e[a](o), c = s.value;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
n(e);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
s.done ? t(c) : Promise.resolve(c).then(r, i);
|
|
17
12
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
function r(e) {
|
|
14
|
+
return function() {
|
|
15
|
+
var t = this, r = arguments;
|
|
16
|
+
return new Promise(function(i, a) {
|
|
17
|
+
var o = e.apply(t, r);
|
|
18
|
+
function s(e) {
|
|
19
|
+
n(o, i, a, s, c, "next", e);
|
|
20
|
+
}
|
|
21
|
+
function c(e) {
|
|
22
|
+
n(o, i, a, s, c, "throw", e);
|
|
23
|
+
}
|
|
24
|
+
s(void 0);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
32
27
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
obj[key] = value;
|
|
43
|
-
}
|
|
44
|
-
return obj;
|
|
28
|
+
function i(e, t, n) {
|
|
29
|
+
return t in e ? Object.defineProperty(e, t, {
|
|
30
|
+
value: n,
|
|
31
|
+
enumerable: !0,
|
|
32
|
+
configurable: !0,
|
|
33
|
+
writable: !0
|
|
34
|
+
}) : e[t] = n, e;
|
|
45
35
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_define_property(target, key, source[key]);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return target;
|
|
36
|
+
function a(e) {
|
|
37
|
+
for (var t = 1; t < arguments.length; t++) {
|
|
38
|
+
var n = arguments[t] == null ? {} : arguments[t], r = Object.keys(n);
|
|
39
|
+
typeof Object.getOwnPropertySymbols == "function" && (r = r.concat(Object.getOwnPropertySymbols(n).filter(function(e) {
|
|
40
|
+
return Object.getOwnPropertyDescriptor(n, e).enumerable;
|
|
41
|
+
}))), r.forEach(function(t) {
|
|
42
|
+
i(e, t, n[t]);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return e;
|
|
60
46
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
target[key] = source[key];
|
|
71
|
-
}
|
|
72
|
-
return target;
|
|
73
|
-
}
|
|
74
|
-
target = _object_without_properties_loose(source, excluded);
|
|
75
|
-
if (Object.getOwnPropertySymbols) {
|
|
76
|
-
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
77
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
78
|
-
key = sourceKeys[i];
|
|
79
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
80
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
81
|
-
target[key] = source[key];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return target;
|
|
47
|
+
function o(e, t) {
|
|
48
|
+
if (e == null) return {};
|
|
49
|
+
var n = {}, r, i, a;
|
|
50
|
+
if (typeof Reflect < "u" && Reflect.ownKeys) {
|
|
51
|
+
for (r = Reflect.ownKeys(Object(e)), a = 0; a < r.length; a++) i = r[a], !(t.indexOf(i) >= 0) && Object.prototype.propertyIsEnumerable.call(e, i) && (n[i] = e[i]);
|
|
52
|
+
return n;
|
|
53
|
+
}
|
|
54
|
+
if (n = s(e, t), Object.getOwnPropertySymbols) for (r = Object.getOwnPropertySymbols(e), a = 0; a < r.length; a++) i = r[a], !(t.indexOf(i) >= 0) && Object.prototype.propertyIsEnumerable.call(e, i) && (n[i] = e[i]);
|
|
55
|
+
return n;
|
|
85
56
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
92
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
93
|
-
target[key] = source[key];
|
|
94
|
-
}
|
|
95
|
-
return target;
|
|
57
|
+
function s(e, t) {
|
|
58
|
+
if (e == null) return {};
|
|
59
|
+
var n = {}, r = Object.getOwnPropertyNames(e), i, a;
|
|
60
|
+
for (a = 0; a < r.length; a++) i = r[a], !(t.indexOf(i) >= 0) && Object.prototype.propertyIsEnumerable.call(e, i) && (n[i] = e[i]);
|
|
61
|
+
return n;
|
|
96
62
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
_.label = t[1];
|
|
167
|
-
t = op;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
if (t && _.label < t[2]) {
|
|
171
|
-
_.label = t[2];
|
|
172
|
-
_.ops.push(op);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
if (t[2]) _.ops.pop();
|
|
176
|
-
_.trys.pop();
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
op = body.call(thisArg, _);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
op = [
|
|
182
|
-
6,
|
|
183
|
-
e
|
|
184
|
-
];
|
|
185
|
-
y = 0;
|
|
186
|
-
} finally{
|
|
187
|
-
f = t = 0;
|
|
188
|
-
}
|
|
189
|
-
if (op[0] & 5) throw op[1];
|
|
190
|
-
return {
|
|
191
|
-
value: op[0] ? op[1] : void 0,
|
|
192
|
-
done: true
|
|
193
|
-
};
|
|
194
|
-
}
|
|
63
|
+
function c(e, t) {
|
|
64
|
+
var n, r, i, a = {
|
|
65
|
+
label: 0,
|
|
66
|
+
sent: function() {
|
|
67
|
+
if (i[0] & 1) throw i[1];
|
|
68
|
+
return i[1];
|
|
69
|
+
},
|
|
70
|
+
trys: [],
|
|
71
|
+
ops: []
|
|
72
|
+
}, o = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype), s = Object.defineProperty;
|
|
73
|
+
return s(o, "next", { value: c(0) }), s(o, "throw", { value: c(1) }), s(o, "return", { value: c(2) }), typeof Symbol == "function" && s(o, Symbol.iterator, { value: function() {
|
|
74
|
+
return this;
|
|
75
|
+
} }), o;
|
|
76
|
+
function c(e) {
|
|
77
|
+
return function(t) {
|
|
78
|
+
return l([e, t]);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function l(s) {
|
|
82
|
+
if (n) throw TypeError("Generator is already executing.");
|
|
83
|
+
for (; o && (o = 0, s[0] && (a = 0)), a;) try {
|
|
84
|
+
if (n = 1, r && (i = s[0] & 2 ? r.return : s[0] ? r.throw || ((i = r.return) && i.call(r), 0) : r.next) && !(i = i.call(r, s[1])).done) return i;
|
|
85
|
+
switch (r = 0, i && (s = [s[0] & 2, i.value]), s[0]) {
|
|
86
|
+
case 0:
|
|
87
|
+
case 1:
|
|
88
|
+
i = s;
|
|
89
|
+
break;
|
|
90
|
+
case 4: return a.label++, {
|
|
91
|
+
value: s[1],
|
|
92
|
+
done: !1
|
|
93
|
+
};
|
|
94
|
+
case 5:
|
|
95
|
+
a.label++, r = s[1], s = [0];
|
|
96
|
+
continue;
|
|
97
|
+
case 7:
|
|
98
|
+
s = a.ops.pop(), a.trys.pop();
|
|
99
|
+
continue;
|
|
100
|
+
default:
|
|
101
|
+
if ((i = a.trys, !(i = i.length > 0 && i[i.length - 1])) && (s[0] === 6 || s[0] === 2)) {
|
|
102
|
+
a = 0;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (s[0] === 3 && (!i || s[1] > i[0] && s[1] < i[3])) {
|
|
106
|
+
a.label = s[1];
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (s[0] === 6 && a.label < i[1]) {
|
|
110
|
+
a.label = i[1], i = s;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (i && a.label < i[2]) {
|
|
114
|
+
a.label = i[2], a.ops.push(s);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
i[2] && a.ops.pop(), a.trys.pop();
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
s = t.call(e, a);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
s = [6, e], r = 0;
|
|
123
|
+
} finally {
|
|
124
|
+
n = i = 0;
|
|
125
|
+
}
|
|
126
|
+
if (s[0] & 5) throw s[1];
|
|
127
|
+
return {
|
|
128
|
+
value: s[0] ? s[1] : void 0,
|
|
129
|
+
done: !0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
195
132
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
sourceMaps = this.environment.config.command === "build" ? !!this.environment.config.build.sourcemap : !!((_this_environment_config_css = this.environment.config.css) === null || _this_environment_config_css === void 0 ? void 0 : _this_environment_config_css.devSourcemap); // For dev, you might want to align with css sourcemaps or a dedicated flag
|
|
251
|
-
return [
|
|
252
|
-
4,
|
|
253
|
-
transform(code, _object_spread({
|
|
254
|
-
filename: id,
|
|
255
|
-
sourceFileName: id.split("?", 1)[0],
|
|
256
|
-
sourceMaps: sourceMaps
|
|
257
|
-
}, swcOptions))
|
|
258
|
-
];
|
|
259
|
-
case 2:
|
|
260
|
-
result = _state.sent();
|
|
261
|
-
// SWC returns { code, map } when sourceMaps are enabled, otherwise just { code }
|
|
262
|
-
return [
|
|
263
|
-
2,
|
|
264
|
-
{
|
|
265
|
-
code: result.code,
|
|
266
|
-
map: result.map
|
|
267
|
-
}
|
|
268
|
-
];
|
|
269
|
-
case 3:
|
|
270
|
-
error = _state.sent();
|
|
271
|
-
// Enhance error message with file information and re-throw as a plugin error
|
|
272
|
-
this.error("SWC transform failed in ".concat(id, ": ").concat((error === null || error === void 0 ? void 0 : error.message) || error));
|
|
273
|
-
return [
|
|
274
|
-
3,
|
|
275
|
-
4
|
|
276
|
-
];
|
|
277
|
-
case 4:
|
|
278
|
-
return [
|
|
279
|
-
2
|
|
280
|
-
];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}).call(this);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
133
|
+
var l = function() {
|
|
134
|
+
var n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
135
|
+
swcrc: !1,
|
|
136
|
+
configFile: !1,
|
|
137
|
+
minify: !0,
|
|
138
|
+
jsc: {
|
|
139
|
+
parser: {
|
|
140
|
+
syntax: "typescript",
|
|
141
|
+
decorators: !0
|
|
142
|
+
},
|
|
143
|
+
transform: {
|
|
144
|
+
decoratorMetadata: !0,
|
|
145
|
+
decoratorVersion: "2022-03"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, i = n.include, s = i === void 0 ? /\.(ts|tsx|js|jsx)$/ : i, l = n.exclude, u = l === void 0 ? "node_modules" : l, d = o(n, ["include", "exclude"]), f = e(s, u);
|
|
149
|
+
return {
|
|
150
|
+
name: "vite-plugin-swc",
|
|
151
|
+
enforce: "pre",
|
|
152
|
+
config: function() {
|
|
153
|
+
return {
|
|
154
|
+
oxc: !1,
|
|
155
|
+
esbuild: !1
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
transform: function(e, n) {
|
|
159
|
+
return r(function() {
|
|
160
|
+
var r, i, o;
|
|
161
|
+
return c(this, function(s) {
|
|
162
|
+
switch (s.label) {
|
|
163
|
+
case 0:
|
|
164
|
+
if (!f(n)) return [2, null];
|
|
165
|
+
s.label = 1;
|
|
166
|
+
case 1: return s.trys.push([
|
|
167
|
+
1,
|
|
168
|
+
3,
|
|
169
|
+
,
|
|
170
|
+
4
|
|
171
|
+
]), r = this.environment.config.command === "build" ? !!this.environment.config.build.sourcemap : !!this.environment.config.css?.devSourcemap, [4, t(e, a({
|
|
172
|
+
filename: n,
|
|
173
|
+
sourceFileName: n.split("?", 1)[0],
|
|
174
|
+
sourceMaps: r
|
|
175
|
+
}, d))];
|
|
176
|
+
case 2: return i = s.sent(), [2, {
|
|
177
|
+
code: i.code,
|
|
178
|
+
map: i.map
|
|
179
|
+
}];
|
|
180
|
+
case 3: return o = s.sent(), this.error(`SWC transform failed in ${n}: ${o?.message || o}`), [3, 4];
|
|
181
|
+
case 4: return [2];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}).call(this);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
286
187
|
};
|
|
287
|
-
|
|
288
|
-
export {
|
|
188
|
+
//#endregion
|
|
189
|
+
export { l as default, l as swc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o.z/vite-plugin-swc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A high-performance Vite plugin that transforms TypeScript and JavaScript files using SWC for lightning-fast builds",
|
|
5
5
|
"homepage": "https://github.com/z-npm/vite-plugin-swc#readme",
|
|
6
6
|
"docs": "https://github.com/z-npm/vite-plugin-swc#readme",
|
|
@@ -92,27 +92,27 @@
|
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@testing-library/dom": "^10.4.1",
|
|
94
94
|
"@testing-library/user-event": "^14.6.1",
|
|
95
|
-
"@types/jsdom": "^
|
|
96
|
-
"@types/node": "^25.
|
|
97
|
-
"@vitest/coverage-v8": "^4.0
|
|
98
|
-
"@vitest/ui": "^4.0
|
|
99
|
-
"glob": "^13.0.
|
|
100
|
-
"jsdom": "^
|
|
95
|
+
"@types/jsdom": "^28.0.1",
|
|
96
|
+
"@types/node": "^25.5.0",
|
|
97
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
98
|
+
"@vitest/ui": "^4.1.0",
|
|
99
|
+
"glob": "^13.0.6",
|
|
100
|
+
"jsdom": "^29.0.1",
|
|
101
101
|
"rollup-plugin-node-externals": "^8.1.2",
|
|
102
|
-
"sass": "^1.
|
|
103
|
-
"typedoc": "^0.28.
|
|
104
|
-
"typedoc-plugin-markdown": "^4.
|
|
102
|
+
"sass": "^1.98.0",
|
|
103
|
+
"typedoc": "^0.28.18",
|
|
104
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
105
105
|
"typescript": "^5.9.3",
|
|
106
|
-
"vite": "^
|
|
106
|
+
"vite": "^8.0.1",
|
|
107
107
|
"vite-plugin-dts": "^4.5.4",
|
|
108
108
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
109
|
-
"vitest": "^4.0
|
|
109
|
+
"vitest": "^4.1.0"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
112
|
"@rollup/pluginutils": "^5.3.0",
|
|
113
|
-
"@swc/core": "^1.15.
|
|
113
|
+
"@swc/core": "^1.15.21"
|
|
114
114
|
},
|
|
115
|
-
"packageManager": "yarn@4.
|
|
115
|
+
"packageManager": "yarn@4.13.0",
|
|
116
116
|
"types": "./dist/index.d.ts",
|
|
117
117
|
"module": "./dist/index.js",
|
|
118
118
|
"main": "./dist/index.cjs",
|