@vxrn/compiler 1.25.4 → 1.25.5
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/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/transformBabel.test.ts +44 -2
- package/src/transformBabel.ts +2 -7
- package/src/types.ts +1 -0
- package/types/types.d.ts +1 -0
- package/dist/cjs/cache.cjs +0 -132
- package/dist/cjs/configure.cjs +0 -37
- package/dist/cjs/constants.cjs +0 -77
- package/dist/cjs/index.cjs +0 -425
- package/dist/cjs/refresh-runtime.cjs +0 -452
- package/dist/cjs/transformBabel.cjs +0 -271
- package/dist/cjs/transformBabel.test.cjs +0 -19
- package/dist/cjs/transformSWC.cjs +0 -318
- package/dist/cjs/types.cjs +0 -18
- package/dist/esm/cache.mjs +0 -104
- package/dist/esm/cache.mjs.map +0 -1
- package/dist/esm/configure.mjs +0 -11
- package/dist/esm/configure.mjs.map +0 -1
- package/dist/esm/constants.mjs +0 -48
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/index.js +0 -398
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs +0 -398
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/refresh-runtime.mjs +0 -421
- package/dist/esm/refresh-runtime.mjs.map +0 -1
- package/dist/esm/transformBabel.mjs +0 -233
- package/dist/esm/transformBabel.mjs.map +0 -1
- package/dist/esm/transformBabel.test.mjs +0 -20
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformSWC.mjs +0 -292
- package/dist/esm/transformSWC.mjs.map +0 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.mjs.map +0 -1
- package/types/cache.d.ts.map +0 -1
- package/types/configure.d.ts.map +0 -1
- package/types/constants.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/transformBabel.d.ts.map +0 -1
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformSWC.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var transformBabel_exports = {};
|
|
35
|
-
__export(transformBabel_exports, {
|
|
36
|
-
getBabelOptions: () => getBabelOptions,
|
|
37
|
-
transformBabel: () => transformBabel,
|
|
38
|
-
transformOxcReactCompiler: () => transformOxcReactCompiler
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(transformBabel_exports);
|
|
41
|
-
var import_node_path = require("node:path");
|
|
42
|
-
var import_core = __toESM(require("@babel/core"), 1);
|
|
43
|
-
var import_utils = require("@vxrn/utils");
|
|
44
|
-
var import_babel_plugin_syntax_hermes_parser = __toESM(require("babel-plugin-syntax-hermes-parser"), 1);
|
|
45
|
-
var import_vite = require("vite");
|
|
46
|
-
var import_configure = require("./configure.cjs");
|
|
47
|
-
var import_constants = require("./constants.cjs");
|
|
48
|
-
function getBabelOptions(props) {
|
|
49
|
-
props = {
|
|
50
|
-
...props,
|
|
51
|
-
id: (0, import_vite.normalizePath)(props.id.split("?")[0])
|
|
52
|
-
};
|
|
53
|
-
if (props.userSetting === "babel") {
|
|
54
|
-
return getOptions(props, true);
|
|
55
|
-
}
|
|
56
|
-
if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
|
|
57
|
-
if (props.userSetting?.excludeDefaultPlugins) {
|
|
58
|
-
return props.userSetting;
|
|
59
|
-
}
|
|
60
|
-
return getOptions(props);
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const getOptions = (props, force = false) => {
|
|
65
|
-
let plugins = [];
|
|
66
|
-
if (force || shouldBabelGenerators(props)) {
|
|
67
|
-
plugins = getBasePlugins(props);
|
|
68
|
-
}
|
|
69
|
-
const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
|
|
70
|
-
// if reanimated gets wrapped in transform it causes circular dep issues
|
|
71
|
-
!/node_modules/.test(props.id) &&
|
|
72
|
-
// only needed for createElement calls, so be a bit conservative
|
|
73
|
-
props.code.includes("createElement");
|
|
74
|
-
if (enableNativewind) {
|
|
75
|
-
if (!props.id.includes("node_modules")) {
|
|
76
|
-
plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (enableNativewind || shouldBabelReanimated(props)) {
|
|
80
|
-
(0, import_constants.debug)?.(`Using babel reanimated on file ${props.id}`);
|
|
81
|
-
plugins.push(
|
|
82
|
-
// TODO make this configurable
|
|
83
|
-
process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin");
|
|
84
|
-
}
|
|
85
|
-
if (shouldBabelReactCompiler(props)) {
|
|
86
|
-
(0, import_constants.debug)?.(`Using babel react compiler on file`);
|
|
87
|
-
plugins.push(getBabelReactCompilerPlugin(props));
|
|
88
|
-
}
|
|
89
|
-
if (shouldBabelReactNativeCodegen(props)) {
|
|
90
|
-
(0, import_constants.debug)?.(`Using babel @react-native/babel-plugin-codegen on file`);
|
|
91
|
-
plugins.push("@react-native/babel-plugin-codegen");
|
|
92
|
-
}
|
|
93
|
-
if (plugins.length) {
|
|
94
|
-
return {
|
|
95
|
-
plugins
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
};
|
|
100
|
-
async function transformOxcReactCompiler(id, code, target) {
|
|
101
|
-
const {
|
|
102
|
-
transform
|
|
103
|
-
} = await import("oxc-transform-react");
|
|
104
|
-
const result = await transform(id, code, {
|
|
105
|
-
jsx: "preserve",
|
|
106
|
-
reactCompiler: {
|
|
107
|
-
target
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
if (result.fatal) {
|
|
111
|
-
throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map(e => e.message ?? String(e)).join(", ")}`);
|
|
112
|
-
}
|
|
113
|
-
if (result.errors?.length) {
|
|
114
|
-
(0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map(e => e.message ?? String(e)).join(", ")}`);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
code: result.code,
|
|
118
|
-
map: void 0
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async function transformBabel(id, code, options) {
|
|
122
|
-
const extension = (0, import_node_path.extname)(id);
|
|
123
|
-
const isTSX = extension === ".tsx";
|
|
124
|
-
const isTS = isTSX || extension === ".ts";
|
|
125
|
-
const babelOptions = {
|
|
126
|
-
filename: id,
|
|
127
|
-
compact: false,
|
|
128
|
-
babelrc: false,
|
|
129
|
-
configFile: false,
|
|
130
|
-
sourceMaps: false,
|
|
131
|
-
minified: false,
|
|
132
|
-
...options,
|
|
133
|
-
presets: [isTS ? ["@babel/preset-typescript", {
|
|
134
|
-
isTSX,
|
|
135
|
-
allExtensions: isTSX
|
|
136
|
-
}] : "", ...(options.presets || [])].filter(Boolean),
|
|
137
|
-
// non-TS files use React Native's Flow dialect. RN's own component specs are
|
|
138
|
-
// Flow `.js` (`import type`, `codegenNativeComponent<T>(…)`, `(expr: Type)` casts).
|
|
139
|
-
// enable Hermes Flow parsing + stripping, mirroring the TypeScript preset above
|
|
140
|
-
// (`@react-native/babel-preset` uses the same parser for JS). without it babel
|
|
141
|
-
// can't parse current RN Flow syntax such as `call<T>(...) as HostComponent<T>`, so
|
|
142
|
-
// plugins like
|
|
143
|
-
// @react-native/babel-plugin-codegen silently fail on RN specs and the runtime
|
|
144
|
-
// "Codegen didn't run" warning fires. TS path is byte-identical (empty slice).
|
|
145
|
-
plugins: [...(isTS ? [] : [[import_babel_plugin_syntax_hermes_parser.default, {
|
|
146
|
-
parseLangTypes: "flow",
|
|
147
|
-
reactRuntimeTarget: "19"
|
|
148
|
-
}]]), ...(options.plugins || []), ...(isTS ? [] : ["@babel/plugin-transform-flow-strip-types"])]
|
|
149
|
-
};
|
|
150
|
-
try {
|
|
151
|
-
const out = await new Promise((res, rej) => {
|
|
152
|
-
import_core.default.transform(code, babelOptions, (err, result) => {
|
|
153
|
-
if (!result || err) {
|
|
154
|
-
return rej(err || "no res");
|
|
155
|
-
}
|
|
156
|
-
res(result);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
return out;
|
|
160
|
-
} catch (err) {
|
|
161
|
-
if (err?.message?.includes("Could not find component config")) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
console.error(`[vxrn:compiler] babel transform error`, err, `with options`, babelOptions);
|
|
165
|
-
console.error("code", code);
|
|
166
|
-
console.error("id", id);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const getBasePlugins = ({
|
|
170
|
-
development
|
|
171
|
-
}) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
|
|
172
|
-
development
|
|
173
|
-
}], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
|
|
174
|
-
helpers: true,
|
|
175
|
-
// NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
|
|
176
|
-
regenerator: false
|
|
177
|
-
}]];
|
|
178
|
-
const NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/;
|
|
179
|
-
const SPEC_FILE_RE = /[/\\]specs?[/\\]/;
|
|
180
|
-
const shouldBabelReactNativeCodegen = ({
|
|
181
|
-
id,
|
|
182
|
-
environment
|
|
183
|
-
}) => {
|
|
184
|
-
return (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id));
|
|
185
|
-
};
|
|
186
|
-
const shouldBabelReactCompiler = props => {
|
|
187
|
-
if (props.environment === "ssr") {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
if (!import_configure.configuration.enableCompiler) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
const {
|
|
194
|
-
enableCompiler
|
|
195
|
-
} = import_configure.configuration;
|
|
196
|
-
if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
|
|
197
|
-
const isNative = props.environment === "ios" || props.environment === "android";
|
|
198
|
-
const filter = isNative ? enableCompiler.native : enableCompiler.web;
|
|
199
|
-
if (!filter) return false;
|
|
200
|
-
return applyCompilerFilter(filter, props);
|
|
201
|
-
}
|
|
202
|
-
if (typeof enableCompiler === "function") {
|
|
203
|
-
return enableCompiler(props.id, props.environment);
|
|
204
|
-
}
|
|
205
|
-
if (enableCompiler instanceof RegExp) {
|
|
206
|
-
return enableCompiler.test(props.id);
|
|
207
|
-
}
|
|
208
|
-
if (Array.isArray(enableCompiler)) {
|
|
209
|
-
if (!enableCompiler.includes(props.environment)) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return applyDefaultFilters(props);
|
|
214
|
-
};
|
|
215
|
-
function applyCompilerFilter(filter, props) {
|
|
216
|
-
if (typeof filter === "function") {
|
|
217
|
-
return filter(props.id, props.environment);
|
|
218
|
-
}
|
|
219
|
-
if (filter instanceof RegExp) {
|
|
220
|
-
return filter.test(props.id);
|
|
221
|
-
}
|
|
222
|
-
if (filter === true) {
|
|
223
|
-
return applyDefaultFilters(props);
|
|
224
|
-
}
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
function applyDefaultFilters(props) {
|
|
228
|
-
if (!/(\.tsx?)$/.test(props.id)) return false;
|
|
229
|
-
if (props.id.includes("node_modules")) return false;
|
|
230
|
-
if (props.id.includes("+api.")) return false;
|
|
231
|
-
if (props.code.startsWith("// disable-compiler")) return false;
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
const getBabelReactCompilerPlugin = props => {
|
|
235
|
-
const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
|
|
236
|
-
return ["babel-plugin-react-compiler", {
|
|
237
|
-
target
|
|
238
|
-
}];
|
|
239
|
-
};
|
|
240
|
-
function shouldBabelGenerators({
|
|
241
|
-
code
|
|
242
|
-
}) {
|
|
243
|
-
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
|
|
244
|
-
return import_constants.asyncGeneratorRegex.test(code);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"];
|
|
248
|
-
const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|"));
|
|
249
|
-
const REANIMATED_IGNORED_PATHS = [
|
|
250
|
-
// Prebuilt/vendored react-native that shouldn't be transformed
|
|
251
|
-
"react-native-prebuilt", "node_modules/.vxrn/react-native",
|
|
252
|
-
// Known false positives - they mention worklet keywords in comments/strings but don't use them
|
|
253
|
-
"node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"];
|
|
254
|
-
const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.join("|"));
|
|
255
|
-
function shouldBabelReanimated({
|
|
256
|
-
code,
|
|
257
|
-
id
|
|
258
|
-
}) {
|
|
259
|
-
if (!import_configure.configuration.enableReanimated) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
if (REANIMATED_REGEX.test(code)) {
|
|
266
|
-
const location = id.includes("node_modules") ? "node_modules" : "user-code";
|
|
267
|
-
(0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
var import_vitest = require("vitest");
|
|
2
|
-
var import_transformBabel = require("./transformBabel.cjs");
|
|
3
|
-
(0, import_vitest.describe)("transformBabel Flow parsing", () => {
|
|
4
|
-
(0, import_vitest.it)("parses and strips React Native Flow as-casts", async () => {
|
|
5
|
-
const result = await (0, import_transformBabel.transformBabel)("/project/VirtualViewNativeComponent.js", `
|
|
6
|
-
// @flow strict-local
|
|
7
|
-
import type { HostComponent } from './HostComponent'
|
|
8
|
-
import codegenNativeComponent from './codegenNativeComponent'
|
|
9
|
-
|
|
10
|
-
type Props = $ReadOnly<{ enabled?: boolean }>
|
|
11
|
-
|
|
12
|
-
export default codegenNativeComponent<Props>('VirtualView') as HostComponent<Props>
|
|
13
|
-
`, {
|
|
14
|
-
plugins: []
|
|
15
|
-
});
|
|
16
|
-
(0, import_vitest.expect)(result?.code).toContain("codegenNativeComponent('VirtualView')");
|
|
17
|
-
(0, import_vitest.expect)(result?.code).not.toContain("HostComponent");
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all) __defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
23
|
-
var transformSWC_exports = {};
|
|
24
|
-
__export(transformSWC_exports, {
|
|
25
|
-
transformSWC: () => transformSWC,
|
|
26
|
-
transformSWCStripJSX: () => transformSWCStripJSX
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(transformSWC_exports);
|
|
29
|
-
var import_node_path = require("node:path");
|
|
30
|
-
var import_core = require("@swc/core");
|
|
31
|
-
var import_ts_deepmerge = require("ts-deepmerge");
|
|
32
|
-
var import_vite = require("vite");
|
|
33
|
-
var import_configure = require("./configure.cjs");
|
|
34
|
-
var import_constants = require("./constants.cjs");
|
|
35
|
-
const ignoreId = /node_modules\/(\.vite|vite)\//;
|
|
36
|
-
async function transformSWC(id, code, options, swcOptions) {
|
|
37
|
-
id = (0, import_vite.normalizePath)(id.split("?")[0]).replace((0, import_vite.normalizePath)(process.cwd()), "");
|
|
38
|
-
if (ignoreId.test(id)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (id === import_constants.runtimePublicPath) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const parser = getParser(id, options.forceJSX);
|
|
45
|
-
if (!parser) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
|
|
49
|
-
const reactConfig = {
|
|
50
|
-
refresh,
|
|
51
|
-
development: !options.forceJSX && !options.production,
|
|
52
|
-
runtime: "automatic",
|
|
53
|
-
importSource: "react",
|
|
54
|
-
...(import_configure.configuration.enableNativewind && !id.includes("node_modules") ? {
|
|
55
|
-
importSource: "nativewind"
|
|
56
|
-
// pragma: 'createInteropElement',
|
|
57
|
-
// pragmaFrag: '_InteropFragment',
|
|
58
|
-
// swc doesnt actually change the import right
|
|
59
|
-
// runtime: 'classic',
|
|
60
|
-
} : {})
|
|
61
|
-
};
|
|
62
|
-
const transformOptions = (() => {
|
|
63
|
-
if (options.environment === "client" || options.environment === "ssr") {
|
|
64
|
-
return {
|
|
65
|
-
sourceMaps: shouldSourceMap(),
|
|
66
|
-
jsc: {
|
|
67
|
-
target: "es2020",
|
|
68
|
-
parser,
|
|
69
|
-
transform: {
|
|
70
|
-
useDefineForClassFields: true,
|
|
71
|
-
react: reactConfig
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code);
|
|
77
|
-
const opts = shouldEs5Transform ? {
|
|
78
|
-
jsc: {
|
|
79
|
-
parser,
|
|
80
|
-
target: "es5",
|
|
81
|
-
transform: {
|
|
82
|
-
useDefineForClassFields: true,
|
|
83
|
-
react: reactConfig
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
} : {
|
|
87
|
-
...(!options.forceJSX && {
|
|
88
|
-
env: SWC_ENV
|
|
89
|
-
}),
|
|
90
|
-
jsc: {
|
|
91
|
-
...(options.forceJSX && {
|
|
92
|
-
target: "esnext"
|
|
93
|
-
}),
|
|
94
|
-
parser,
|
|
95
|
-
transform: {
|
|
96
|
-
useDefineForClassFields: true,
|
|
97
|
-
react: reactConfig
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
sourceMaps: shouldSourceMap(),
|
|
103
|
-
module: {
|
|
104
|
-
importInterop: "none",
|
|
105
|
-
type: "nodenext"
|
|
106
|
-
},
|
|
107
|
-
...(options.mode === "serve-cjs" && {
|
|
108
|
-
module: {
|
|
109
|
-
importInterop: "none",
|
|
110
|
-
type: "commonjs",
|
|
111
|
-
strict: true
|
|
112
|
-
}
|
|
113
|
-
}),
|
|
114
|
-
...opts
|
|
115
|
-
};
|
|
116
|
-
})();
|
|
117
|
-
const finalOptions = (0, import_ts_deepmerge.merge)({
|
|
118
|
-
filename: id,
|
|
119
|
-
swcrc: false,
|
|
120
|
-
configFile: false,
|
|
121
|
-
...transformOptions
|
|
122
|
-
}, swcOptions || {});
|
|
123
|
-
const result = await (async () => {
|
|
124
|
-
try {
|
|
125
|
-
(0, import_constants.debug)?.(`transformSWC ${id} using options:
|
|
126
|
-
${JSON.stringify(finalOptions, null, 2)}`);
|
|
127
|
-
return await (0, import_core.transform)(code, finalOptions);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
const message = e.message;
|
|
130
|
-
const fileStartIndex = message.indexOf("\u256D\u2500[");
|
|
131
|
-
if (fileStartIndex !== -1) {
|
|
132
|
-
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
|
|
133
|
-
if (match) {
|
|
134
|
-
e.line = match[1];
|
|
135
|
-
e.column = match[2];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw e;
|
|
139
|
-
}
|
|
140
|
-
})();
|
|
141
|
-
if (import_configure.configuration.enableNativeCSS) {
|
|
142
|
-
if (result.code.includes(`createInteropElement(`)) {
|
|
143
|
-
result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
|
|
144
|
-
${result.code}`;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
|
|
148
|
-
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && parser.syntax === "typescript") {
|
|
149
|
-
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
150
|
-
if (typeExportsMatch) {
|
|
151
|
-
for (const typeExport of Array.from(typeExportsMatch)) {
|
|
152
|
-
const [_export, _type, name] = typeExport.split(/\s+/);
|
|
153
|
-
if (name.startsWith("{")) continue;
|
|
154
|
-
if (name.includes("<")) continue;
|
|
155
|
-
const alreadyExported = new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code);
|
|
156
|
-
if (!alreadyExported) {
|
|
157
|
-
const fakeExport = `export let ${name} = {};`;
|
|
158
|
-
console.info(` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`);
|
|
159
|
-
result.code += `
|
|
160
|
-
${fakeExport}
|
|
161
|
-
`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (result && !options.production && !options.noHMR) {
|
|
167
|
-
return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
172
|
-
if (options.environment === "ssr") {
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
if (options.environment === "client") {
|
|
176
|
-
return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);
|
|
177
|
-
}
|
|
178
|
-
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
|
|
179
|
-
}
|
|
180
|
-
function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
|
|
181
|
-
const sourceMap = result.map ? JSON.parse(result.map) : void 0;
|
|
182
|
-
if (sourceMap) {
|
|
183
|
-
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
184
|
-
}
|
|
185
|
-
result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
186
|
-
|
|
187
|
-
${result.code}`;
|
|
188
|
-
if (hasRefreshRuntime) {
|
|
189
|
-
if (sourceMap) {
|
|
190
|
-
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
191
|
-
}
|
|
192
|
-
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
193
|
-
const prevRefreshReg = window.$RefreshReg$;
|
|
194
|
-
const prevRefreshSig = window.$RefreshSig$;
|
|
195
|
-
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
196
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
197
|
-
|
|
198
|
-
${result.code}
|
|
199
|
-
|
|
200
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
201
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
202
|
-
`;
|
|
203
|
-
}
|
|
204
|
-
result.code += `
|
|
205
|
-
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
206
|
-
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
207
|
-
import.meta.hot.accept((nextExports) => {
|
|
208
|
-
if (!nextExports) return;
|
|
209
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
|
|
210
|
-
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
`;
|
|
214
|
-
return {
|
|
215
|
-
code: result.code,
|
|
216
|
-
map: sourceMap
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {
|
|
220
|
-
const postfixCode = `if (module.hot) {
|
|
221
|
-
if (module.hot.accept) {
|
|
222
|
-
module.hot.accept((nextExports) => {
|
|
223
|
-
RefreshRuntime.performReactRefresh()
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}`;
|
|
227
|
-
if (hasRefreshRuntime) {
|
|
228
|
-
const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
|
|
229
|
-
const prevRefreshReg = globalThis.$RefreshReg$;
|
|
230
|
-
const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
231
|
-
console.info("no react refresh setup!")
|
|
232
|
-
return (x) => x
|
|
233
|
-
});
|
|
234
|
-
globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
|
|
235
|
-
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
236
|
-
module.url = '${id}'
|
|
237
|
-
module.hot = createHotContext(module.url)`;
|
|
238
|
-
const sourceMap = result.map ? JSON.parse(result.map) : void 0;
|
|
239
|
-
if (sourceMap) {
|
|
240
|
-
const prefixLen = prefixCode.split("\n").length + 1;
|
|
241
|
-
sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
|
|
242
|
-
}
|
|
243
|
-
return {
|
|
244
|
-
code: `${prefixCode}
|
|
245
|
-
${result.code}
|
|
246
|
-
|
|
247
|
-
if (module.hot) {
|
|
248
|
-
globalThis.$RefreshReg$ = prevRefreshReg;
|
|
249
|
-
globalThis.$RefreshSig$ = prevRefreshSig;
|
|
250
|
-
globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
${postfixCode}
|
|
254
|
-
`,
|
|
255
|
-
map: sourceMap
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
result.code += postfixCode;
|
|
259
|
-
return result;
|
|
260
|
-
}
|
|
261
|
-
const SWC_ENV = {
|
|
262
|
-
targets: {
|
|
263
|
-
node: "4"
|
|
264
|
-
},
|
|
265
|
-
// debug: true,
|
|
266
|
-
include: [],
|
|
267
|
-
// this breaks the uniswap app for any file with a ...spread
|
|
268
|
-
exclude: ["transform-spread", "transform-destructuring", "transform-object-rest-spread",
|
|
269
|
-
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
270
|
-
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
271
|
-
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
272
|
-
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
273
|
-
"transform-async-to-generator", "transform-regenerator"
|
|
274
|
-
// Similar to above
|
|
275
|
-
]
|
|
276
|
-
};
|
|
277
|
-
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
278
|
-
function shouldSourceMap() {
|
|
279
|
-
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
280
|
-
}
|
|
281
|
-
function getParser(id, forceJSX = false) {
|
|
282
|
-
if (id.endsWith("one-entry-native")) {
|
|
283
|
-
return import_constants.parsers[".tsx"];
|
|
284
|
-
}
|
|
285
|
-
const extension = (0, import_node_path.extname)(id);
|
|
286
|
-
let parser = !extension ? import_constants.parsers[".js"] : import_constants.parsers[extension];
|
|
287
|
-
if (extension === ".js" || extension === ".mjs") {
|
|
288
|
-
if (forceJSX) {
|
|
289
|
-
parser = import_constants.parsers[".jsx"];
|
|
290
|
-
}
|
|
291
|
-
if (id.includes("expo-modules-core")) {
|
|
292
|
-
parser = import_constants.parsers[".jsx"];
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return parser;
|
|
296
|
-
}
|
|
297
|
-
const transformSWCStripJSX = async (id, code) => {
|
|
298
|
-
const parser = getParser(id);
|
|
299
|
-
if (!parser) return;
|
|
300
|
-
return await (0, import_core.transform)(code, {
|
|
301
|
-
filename: id,
|
|
302
|
-
swcrc: false,
|
|
303
|
-
configFile: false,
|
|
304
|
-
sourceMaps: shouldSourceMap(),
|
|
305
|
-
jsc: {
|
|
306
|
-
target: "es2019",
|
|
307
|
-
parser,
|
|
308
|
-
transform: {
|
|
309
|
-
useDefineForClassFields: true,
|
|
310
|
-
react: {
|
|
311
|
-
development: true,
|
|
312
|
-
runtime: "automatic",
|
|
313
|
-
refresh: false
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
};
|
package/dist/cjs/types.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
-
get: () => from[key],
|
|
9
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
}), mod);
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|