@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 CHANGED
@@ -53,7 +53,7 @@ When no options are provided, the plugin uses the following defaults:
53
53
 
54
54
  ```ts
55
55
  {
56
- include: /\.ts?$/,
56
+ include: /\.(ts|tsx|js|jsx)$/,
57
57
  exclude: "node_modules",
58
58
  swcrc: false,
59
59
  configFile: false,
package/dist/index.cjs CHANGED
@@ -1,293 +1 @@
1
- 'use strict';
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 '@rollup/pluginutils';
2
- import { transform } from '@swc/core';
3
-
4
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
5
- try {
6
- var info = gen[key](arg);
7
- var value = info.value;
8
- } catch (error) {
9
- reject(error);
10
- return;
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 _async_to_generator(fn) {
19
- return function() {
20
- var self = this, args = arguments;
21
- return new Promise(function(resolve, reject) {
22
- var gen = fn.apply(self, args);
23
- function _next(value) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
25
- }
26
- function _throw(err) {
27
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
28
- }
29
- _next(undefined);
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 _define_property(obj, key, value) {
34
- if (key in obj) {
35
- Object.defineProperty(obj, key, {
36
- value: value,
37
- enumerable: true,
38
- configurable: true,
39
- writable: true
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 _object_spread(target) {
47
- for(var i = 1; i < arguments.length; i++){
48
- var source = arguments[i] != null ? arguments[i] : {};
49
- var ownKeys = Object.keys(source);
50
- if (typeof Object.getOwnPropertySymbols === "function") {
51
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
52
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
53
- }));
54
- }
55
- ownKeys.forEach(function(key) {
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 _object_without_properties(source, excluded) {
62
- if (source == null) return {};
63
- var target = {}, sourceKeys, key, i;
64
- if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
65
- sourceKeys = Reflect.ownKeys(source);
66
- for(i = 0; i < sourceKeys.length; i++){
67
- key = sourceKeys[i];
68
- if (excluded.indexOf(key) >= 0) continue;
69
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
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 _object_without_properties_loose(source, excluded) {
87
- if (source == null) return {};
88
- var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
89
- for(i = 0; i < sourceKeys.length; i++){
90
- key = sourceKeys[i];
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 _ts_generator(thisArg, body) {
98
- var f, y, t, _ = {
99
- label: 0,
100
- sent: function() {
101
- if (t[0] & 1) throw t[1];
102
- return t[1];
103
- },
104
- trys: [],
105
- ops: []
106
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
107
- return d(g, "next", {
108
- value: verb(0)
109
- }), d(g, "throw", {
110
- value: verb(1)
111
- }), d(g, "return", {
112
- value: verb(2)
113
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
114
- value: function() {
115
- return this;
116
- }
117
- }), g;
118
- function verb(n) {
119
- return function(v) {
120
- return step([
121
- n,
122
- v
123
- ]);
124
- };
125
- }
126
- function step(op) {
127
- if (f) throw new TypeError("Generator is already executing.");
128
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
129
- 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;
130
- if (y = 0, t) op = [
131
- op[0] & 2,
132
- t.value
133
- ];
134
- switch(op[0]){
135
- case 0:
136
- case 1:
137
- t = op;
138
- break;
139
- case 4:
140
- _.label++;
141
- return {
142
- value: op[1],
143
- done: false
144
- };
145
- case 5:
146
- _.label++;
147
- y = op[1];
148
- op = [
149
- 0
150
- ];
151
- continue;
152
- case 7:
153
- op = _.ops.pop();
154
- _.trys.pop();
155
- continue;
156
- default:
157
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
158
- _ = 0;
159
- continue;
160
- }
161
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
162
- _.label = op[1];
163
- break;
164
- }
165
- if (op[0] === 6 && _.label < t[1]) {
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
- * Vite plugin that transforms TypeScript and JavaScript files using SWC.
198
- * It disables Vite's default esbuild transform to let SWC handle the compilation,
199
- * resulting in significantly faster builds, especially for large codebases.
200
- *
201
- * @example
202
- * ```ts
203
- * // vite.config.ts
204
- * import { defineConfig } from 'vite'
205
- * import swc from '@o.z/vite-plugin-swc'
206
- *
207
- * export default defineConfig({
208
- * plugins: [swc()]
209
- * })
210
- * ```
211
- *
212
- * @param options - Configuration options for the plugin and SWC.
213
- * @returns A Vite plugin instance.
214
- */ var swc = function swc() {
215
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
216
- // Default include/exclude patterns – now covering .ts, .tsx, .js, .jsx
217
- 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, [
218
- "include",
219
- "exclude"
220
- ]);
221
- var filter = createFilter(include, exclude);
222
- return {
223
- name: "vite-plugin-swc",
224
- enforce: "pre",
225
- config: function config() {
226
- return {
227
- esbuild: false
228
- };
229
- },
230
- transform: function transform$1(code, id) {
231
- return _async_to_generator(function() {
232
- var _this_environment_config_css, sourceMaps, result, error;
233
- return _ts_generator(this, function(_state) {
234
- switch(_state.label){
235
- case 0:
236
- if (!filter(id)) return [
237
- 2,
238
- null
239
- ];
240
- _state.label = 1;
241
- case 1:
242
- _state.trys.push([
243
- 1,
244
- 3,
245
- ,
246
- 4
247
- ]);
248
- // Determine if source maps should be generated based on Vite's config
249
- // `this.environment.config` is available inside the transform hook
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 { swc as default, swc };
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.6.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": "^27.0.0",
96
- "@types/node": "^25.2.3",
97
- "@vitest/coverage-v8": "^4.0.18",
98
- "@vitest/ui": "^4.0.18",
99
- "glob": "^13.0.3",
100
- "jsdom": "^28.0.0",
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.97.3",
103
- "typedoc": "^0.28.17",
104
- "typedoc-plugin-markdown": "^4.10.0",
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": "^7.3.1",
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.18"
109
+ "vitest": "^4.1.0"
110
110
  },
111
111
  "dependencies": {
112
112
  "@rollup/pluginutils": "^5.3.0",
113
- "@swc/core": "^1.15.11"
113
+ "@swc/core": "^1.15.21"
114
114
  },
115
- "packageManager": "yarn@4.12.0",
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",