@vxrn/compiler 1.1.546 → 1.1.547
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/cjs/index.cjs +126 -72
- package/dist/cjs/index.js +126 -60
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/transformBabel.cjs +26 -28
- package/dist/cjs/transformBabel.js +28 -33
- package/dist/cjs/transformBabel.js.map +1 -1
- package/dist/esm/index.js +124 -60
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +126 -71
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transformBabel.js +28 -33
- package/dist/esm/transformBabel.js.map +1 -1
- package/dist/esm/transformBabel.mjs +26 -28
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +218 -130
- package/src/transformBabel.ts +34 -39
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts.map +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,12 +21,10 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
21
21
|
}), mod);
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
-
clearCompilerCache: () => clearCompilerCache,
|
|
25
24
|
createVXRNCompilerPlugin: () => createVXRNCompilerPlugin
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(index_exports);
|
|
28
27
|
var import_utils = require("@vxrn/utils"),
|
|
29
|
-
import_node_crypto = require("node:crypto"),
|
|
30
28
|
import_node_fs = require("node:fs"),
|
|
31
29
|
import_promises = require("node:fs/promises"),
|
|
32
30
|
import_node_path = require("node:path"),
|
|
@@ -38,14 +36,86 @@ var import_utils = require("@vxrn/utils"),
|
|
|
38
36
|
__reExport(index_exports, require("./configure.cjs"), module.exports);
|
|
39
37
|
__reExport(index_exports, require("./transformBabel.cjs"), module.exports);
|
|
40
38
|
__reExport(index_exports, require("./transformSWC.cjs"), module.exports);
|
|
41
|
-
const import_meta = {}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
const import_meta = {};
|
|
40
|
+
async function performBabelTransform({
|
|
41
|
+
id,
|
|
42
|
+
code,
|
|
43
|
+
environment,
|
|
44
|
+
production,
|
|
45
|
+
reactForRNVersion,
|
|
46
|
+
optionsIn
|
|
47
|
+
}) {
|
|
48
|
+
const transformProps = {
|
|
49
|
+
id,
|
|
50
|
+
code,
|
|
51
|
+
development: !production,
|
|
52
|
+
environment,
|
|
53
|
+
reactForRNVersion
|
|
54
|
+
},
|
|
55
|
+
userTransform = optionsIn?.transform?.(transformProps);
|
|
56
|
+
if (userTransform === !1) return null;
|
|
57
|
+
if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
|
|
58
|
+
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
59
|
+
...transformProps,
|
|
60
|
+
userSetting: userTransform
|
|
61
|
+
});
|
|
62
|
+
if (babelOptions) {
|
|
63
|
+
const babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
|
|
64
|
+
if (babelOut?.code) return (0, import_constants.debug)?.(`[babel] ${id}`), {
|
|
65
|
+
code: babelOut.code,
|
|
66
|
+
map: babelOut.map
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
async function performFullTransform({
|
|
73
|
+
codeIn,
|
|
74
|
+
_id,
|
|
75
|
+
environment,
|
|
76
|
+
production,
|
|
77
|
+
reactForRNVersion,
|
|
78
|
+
optionsIn,
|
|
79
|
+
mode
|
|
80
|
+
}) {
|
|
81
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
82
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
83
|
+
let id = _id.split("?")[0];
|
|
84
|
+
const extension = (0, import_node_path.extname)(id);
|
|
85
|
+
if (extension === ".css" || !import_constants.validParsers.has(extension)) return;
|
|
86
|
+
if (id.includes("node_modules")) {
|
|
87
|
+
(0, import_constants.debug)?.(`[skip node_modules] ${id}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
91
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
|
|
92
|
+
let code = codeIn,
|
|
93
|
+
out = null;
|
|
94
|
+
const babelResult = await performBabelTransform({
|
|
95
|
+
id,
|
|
96
|
+
code,
|
|
97
|
+
environment,
|
|
98
|
+
production,
|
|
99
|
+
reactForRNVersion,
|
|
100
|
+
optionsIn
|
|
101
|
+
});
|
|
102
|
+
babelResult && (out = babelResult, code = babelResult.code);
|
|
103
|
+
const swcOptions = {
|
|
104
|
+
environment,
|
|
105
|
+
mode: optionsIn?.mode || mode,
|
|
106
|
+
production,
|
|
107
|
+
...optionsIn
|
|
108
|
+
},
|
|
109
|
+
swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
|
|
110
|
+
es5: !0,
|
|
111
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
112
|
+
...swcOptions
|
|
113
|
+
});
|
|
114
|
+
return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
|
|
115
|
+
code: swcOut.code,
|
|
116
|
+
map: swcOut.map
|
|
117
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
118
|
+
}
|
|
49
119
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
50
120
|
const reactVersion = await (async () => {
|
|
51
121
|
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
@@ -114,19 +184,48 @@ ${rootJS.code}
|
|
|
114
184
|
name: "one:compiler",
|
|
115
185
|
enforce: "pre",
|
|
116
186
|
config: () => {
|
|
117
|
-
const
|
|
118
|
-
esbuild: !1,
|
|
187
|
+
const createEnvironmentConfig = environment => ({
|
|
119
188
|
optimizeDeps: {
|
|
120
|
-
|
|
189
|
+
esbuildOptions: {
|
|
190
|
+
plugins: [{
|
|
191
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
192
|
+
setup(build) {
|
|
193
|
+
build.onLoad({
|
|
194
|
+
filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/
|
|
195
|
+
}, async args => {
|
|
196
|
+
const production = process.env.NODE_ENV === "production",
|
|
197
|
+
code = await (0, import_promises.readFile)(args.path, "utf-8");
|
|
198
|
+
(0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
199
|
+
const result = await performBabelTransform({
|
|
200
|
+
id: args.path,
|
|
201
|
+
code,
|
|
202
|
+
environment,
|
|
203
|
+
production,
|
|
204
|
+
reactForRNVersion,
|
|
205
|
+
optionsIn
|
|
206
|
+
});
|
|
207
|
+
if (!result) return null;
|
|
208
|
+
const ext = (0, import_node_path.extname)(args.path),
|
|
209
|
+
loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
210
|
+
return {
|
|
211
|
+
contents: result.code,
|
|
212
|
+
loader
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}]
|
|
217
|
+
}
|
|
121
218
|
},
|
|
122
219
|
define: {
|
|
123
|
-
"process.env.NATIVEWIND_OS": "native"
|
|
220
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
|
|
124
221
|
}
|
|
125
|
-
};
|
|
222
|
+
});
|
|
126
223
|
return {
|
|
127
224
|
environments: {
|
|
128
|
-
ios:
|
|
129
|
-
android:
|
|
225
|
+
ios: createEnvironmentConfig("ios"),
|
|
226
|
+
android: createEnvironmentConfig("android"),
|
|
227
|
+
client: createEnvironmentConfig("client"),
|
|
228
|
+
ssr: createEnvironmentConfig("ssr")
|
|
130
229
|
}
|
|
131
230
|
};
|
|
132
231
|
},
|
|
@@ -138,62 +237,17 @@ ${rootJS.code}
|
|
|
138
237
|
const environment = getEnvName(this.environment.name),
|
|
139
238
|
isNative = environment === "ios" || environment === "android",
|
|
140
239
|
production = process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
141
|
-
|
|
240
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
142
241
|
${code}`), isNative && import_configure.configuration.enableNativewind && (code = `import * as x from 'nativewind'
|
|
143
|
-
${code}`), code
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (extension === ".css" || !import_constants.validParsers.has(extension)) return;
|
|
153
|
-
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
154
|
-
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
|
|
155
|
-
const transformProps = {
|
|
156
|
-
id,
|
|
157
|
-
code,
|
|
158
|
-
development: !production,
|
|
159
|
-
environment,
|
|
160
|
-
reactForRNVersion
|
|
161
|
-
},
|
|
162
|
-
userTransform = optionsIn?.transform?.(transformProps);
|
|
163
|
-
if (userTransform === !1) return;
|
|
164
|
-
let out = null;
|
|
165
|
-
if (!isPreProcess && userTransform !== "swc") {
|
|
166
|
-
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
167
|
-
...transformProps,
|
|
168
|
-
userSetting: userTransform
|
|
169
|
-
});
|
|
170
|
-
if (babelOptions) {
|
|
171
|
-
const babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
|
|
172
|
-
babelOut?.code && ((0, import_constants.debug)?.(`[${id}] transformed with babel options: ${JSON.stringify(babelOptions)}`), out = {
|
|
173
|
-
code: babelOut.code,
|
|
174
|
-
map: babelOut.map
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const swcOptions = {
|
|
179
|
-
environment,
|
|
180
|
-
mode: optionsIn?.mode || config.command,
|
|
181
|
-
production,
|
|
182
|
-
...optionsIn
|
|
183
|
-
},
|
|
184
|
-
swcOut = await (0, import_transformSWC.transformSWC)(id, out?.code || code, {
|
|
185
|
-
es5: !0,
|
|
186
|
-
// dont need refresh for ssr, but do for client
|
|
187
|
-
noHMR: isPreProcess || environment === "ssr",
|
|
188
|
-
...swcOptions
|
|
189
|
-
});
|
|
190
|
-
return swcOut && (out = {
|
|
191
|
-
code: swcOut?.code,
|
|
192
|
-
map: swcOut?.map
|
|
193
|
-
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out && (cacheSize += out?.code.length, cacheSize > 52428800 && clearCompilerCache(), memoryCache[cacheId] = {
|
|
194
|
-
out,
|
|
195
|
-
hash: cacheHash
|
|
196
|
-
}), out;
|
|
242
|
+
${code}`), code) : performFullTransform({
|
|
243
|
+
codeIn,
|
|
244
|
+
_id,
|
|
245
|
+
environment,
|
|
246
|
+
production,
|
|
247
|
+
reactForRNVersion,
|
|
248
|
+
optionsIn,
|
|
249
|
+
mode: config.command
|
|
250
|
+
});
|
|
197
251
|
}
|
|
198
252
|
}];
|
|
199
253
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,18 +14,91 @@ var __export = (target, all) => {
|
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
15
|
var index_exports = {};
|
|
16
16
|
__export(index_exports, {
|
|
17
|
-
clearCompilerCache: () => clearCompilerCache,
|
|
18
17
|
createVXRNCompilerPlugin: () => createVXRNCompilerPlugin
|
|
19
18
|
});
|
|
20
19
|
module.exports = __toCommonJS(index_exports);
|
|
21
|
-
var import_utils = require("@vxrn/utils"),
|
|
20
|
+
var import_utils = require("@vxrn/utils"), import_node_fs = require("node:fs"), import_promises = require("node:fs/promises"), import_node_path = require("node:path"), import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js"), import_configure = require("./configure"), import_constants = require("./constants"), import_transformBabel = require("./transformBabel"), import_transformSWC = require("./transformSWC");
|
|
22
21
|
__reExport(index_exports, require("./configure"), module.exports);
|
|
23
22
|
__reExport(index_exports, require("./transformBabel"), module.exports);
|
|
24
23
|
__reExport(index_exports, require("./transformSWC"), module.exports);
|
|
25
|
-
const import_meta = {}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const import_meta = {};
|
|
25
|
+
async function performBabelTransform({
|
|
26
|
+
id,
|
|
27
|
+
code,
|
|
28
|
+
environment,
|
|
29
|
+
production,
|
|
30
|
+
reactForRNVersion,
|
|
31
|
+
optionsIn
|
|
32
|
+
}) {
|
|
33
|
+
const transformProps = {
|
|
34
|
+
id,
|
|
35
|
+
code,
|
|
36
|
+
development: !production,
|
|
37
|
+
environment,
|
|
38
|
+
reactForRNVersion
|
|
39
|
+
}, userTransform = optionsIn?.transform?.(transformProps);
|
|
40
|
+
if (userTransform === !1)
|
|
41
|
+
return null;
|
|
42
|
+
if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
|
|
43
|
+
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
44
|
+
...transformProps,
|
|
45
|
+
userSetting: userTransform
|
|
46
|
+
});
|
|
47
|
+
if (babelOptions) {
|
|
48
|
+
const babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
|
|
49
|
+
if (babelOut?.code)
|
|
50
|
+
return (0, import_constants.debug)?.(`[babel] ${id}`), { code: babelOut.code, map: babelOut.map };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
async function performFullTransform({
|
|
56
|
+
codeIn,
|
|
57
|
+
_id,
|
|
58
|
+
environment,
|
|
59
|
+
production,
|
|
60
|
+
reactForRNVersion,
|
|
61
|
+
optionsIn,
|
|
62
|
+
mode
|
|
63
|
+
}) {
|
|
64
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
65
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
66
|
+
let id = _id.split("?")[0];
|
|
67
|
+
const extension = (0, import_node_path.extname)(id);
|
|
68
|
+
if (extension === ".css" || !import_constants.validParsers.has(extension))
|
|
69
|
+
return;
|
|
70
|
+
if (id.includes("node_modules")) {
|
|
71
|
+
(0, import_constants.debug)?.(`[skip node_modules] ${id}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
75
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
|
|
76
|
+
return;
|
|
77
|
+
let code = codeIn, out = null;
|
|
78
|
+
const babelResult = await performBabelTransform({
|
|
79
|
+
id,
|
|
80
|
+
code,
|
|
81
|
+
environment,
|
|
82
|
+
production,
|
|
83
|
+
reactForRNVersion,
|
|
84
|
+
optionsIn
|
|
85
|
+
});
|
|
86
|
+
babelResult && (out = babelResult, code = babelResult.code);
|
|
87
|
+
const swcOptions = {
|
|
88
|
+
environment,
|
|
89
|
+
mode: optionsIn?.mode || mode,
|
|
90
|
+
production,
|
|
91
|
+
...optionsIn
|
|
92
|
+
}, swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
|
|
93
|
+
es5: !0,
|
|
94
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
95
|
+
...swcOptions
|
|
96
|
+
});
|
|
97
|
+
return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
|
|
98
|
+
code: swcOut.code,
|
|
99
|
+
map: swcOut.map
|
|
100
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
101
|
+
}
|
|
29
102
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
30
103
|
const reactVersion = await (async () => {
|
|
31
104
|
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
@@ -91,19 +164,52 @@ ${rootJS.code}
|
|
|
91
164
|
name: "one:compiler",
|
|
92
165
|
enforce: "pre",
|
|
93
166
|
config: () => {
|
|
94
|
-
const
|
|
95
|
-
esbuild: !1,
|
|
167
|
+
const createEnvironmentConfig = (environment) => ({
|
|
96
168
|
optimizeDeps: {
|
|
97
|
-
|
|
169
|
+
esbuildOptions: {
|
|
170
|
+
plugins: [
|
|
171
|
+
{
|
|
172
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
173
|
+
setup(build) {
|
|
174
|
+
build.onLoad(
|
|
175
|
+
{ filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/ },
|
|
176
|
+
async (args) => {
|
|
177
|
+
const production = process.env.NODE_ENV === "production", code = await (0, import_promises.readFile)(args.path, "utf-8");
|
|
178
|
+
(0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
179
|
+
const result = await performBabelTransform({
|
|
180
|
+
id: args.path,
|
|
181
|
+
code,
|
|
182
|
+
environment,
|
|
183
|
+
production,
|
|
184
|
+
reactForRNVersion,
|
|
185
|
+
optionsIn
|
|
186
|
+
});
|
|
187
|
+
if (!result)
|
|
188
|
+
return null;
|
|
189
|
+
const ext = (0, import_node_path.extname)(args.path), loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
190
|
+
return {
|
|
191
|
+
contents: result.code,
|
|
192
|
+
loader
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
98
200
|
},
|
|
99
201
|
define: {
|
|
100
|
-
"process.env.NATIVEWIND_OS":
|
|
202
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(
|
|
203
|
+
environment === "ios" || environment === "android" ? "native" : "web"
|
|
204
|
+
)
|
|
101
205
|
}
|
|
102
|
-
};
|
|
206
|
+
});
|
|
103
207
|
return {
|
|
104
208
|
environments: {
|
|
105
|
-
ios:
|
|
106
|
-
android:
|
|
209
|
+
ios: createEnvironmentConfig("ios"),
|
|
210
|
+
android: createEnvironmentConfig("android"),
|
|
211
|
+
client: createEnvironmentConfig("client"),
|
|
212
|
+
ssr: createEnvironmentConfig("ssr")
|
|
107
213
|
}
|
|
108
214
|
};
|
|
109
215
|
},
|
|
@@ -113,57 +219,17 @@ ${rootJS.code}
|
|
|
113
219
|
async transform(codeIn, _id) {
|
|
114
220
|
let code = codeIn;
|
|
115
221
|
const environment = getEnvName(this.environment.name), isNative = environment === "ios" || environment === "android", production = process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
116
|
-
|
|
117
|
-
return isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
222
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
118
223
|
${code}`), isNative && import_configure.configuration.enableNativewind && (code = `import * as x from 'nativewind'
|
|
119
|
-
${code}`), code
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const cacheId = getCacheId(environment, _id), cacheHash = getCacheHash(code), cached = memoryCache[cacheId];
|
|
123
|
-
if (cached?.hash === cacheHash)
|
|
124
|
-
return (0, import_constants.debug)?.(`Using cache ${_id} ${cacheId}`), cached.out;
|
|
125
|
-
let id = _id.split("?")[0];
|
|
126
|
-
const extension = (0, import_node_path.extname)(id);
|
|
127
|
-
if (extension === ".css" || !import_constants.validParsers.has(extension))
|
|
128
|
-
return;
|
|
129
|
-
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
130
|
-
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
|
|
131
|
-
return;
|
|
132
|
-
const transformProps = {
|
|
133
|
-
id,
|
|
134
|
-
code,
|
|
135
|
-
development: !production,
|
|
136
|
-
environment,
|
|
137
|
-
reactForRNVersion
|
|
138
|
-
}, userTransform = optionsIn?.transform?.(transformProps);
|
|
139
|
-
if (userTransform === !1)
|
|
140
|
-
return;
|
|
141
|
-
let out = null;
|
|
142
|
-
if (!isPreProcess && userTransform !== "swc") {
|
|
143
|
-
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
144
|
-
...transformProps,
|
|
145
|
-
userSetting: userTransform
|
|
146
|
-
});
|
|
147
|
-
if (babelOptions) {
|
|
148
|
-
const babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
|
|
149
|
-
babelOut?.code && ((0, import_constants.debug)?.(`[${id}] transformed with babel options: ${JSON.stringify(babelOptions)}`), out = { code: babelOut.code, map: babelOut.map });
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const swcOptions = {
|
|
224
|
+
${code}`), code) : performFullTransform({
|
|
225
|
+
codeIn,
|
|
226
|
+
_id,
|
|
153
227
|
environment,
|
|
154
|
-
mode: optionsIn?.mode || config.command,
|
|
155
228
|
production,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// dont need refresh for ssr, but do for client
|
|
160
|
-
noHMR: isPreProcess || environment === "ssr",
|
|
161
|
-
...swcOptions
|
|
229
|
+
reactForRNVersion,
|
|
230
|
+
optionsIn,
|
|
231
|
+
mode: config.command
|
|
162
232
|
});
|
|
163
|
-
return swcOut && (out = {
|
|
164
|
-
code: swcOut?.code,
|
|
165
|
-
map: swcOut?.map
|
|
166
|
-
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out && (cacheSize += out?.code.length, cacheSize > 52428800 && clearCompilerCache(), memoryCache[cacheId] = { out, hash: cacheHash }), out;
|
|
167
233
|
}
|
|
168
234
|
}
|
|
169
235
|
];
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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cACF;AAAA,YACF;AAAA,UACF;AAAA,UAEA,QAAQ;AAAA,YACN,6BAA6B,KAAK;AAAA,cAChC,gBAAgB,SAAS,gBAAgB,YAAY,WAAW;AAAA,YAClE;AAAA,UACF;AAAA,QACF;AAGF,eAAO;AAAA,UACL,cAAc;AAAA,YACZ,KAAK,wBAAwB,KAAK;AAAA,YAClC,SAAS,wBAAwB,SAAS;AAAA,YAC1C,QAAQ,wBAAwB,QAAQ;AAAA,YACxC,KAAK,wBAAwB,KAAK;AAAA,UACpC;AAAA,QACF;AAAA,MACF;AAAA,MAEA,eAAe,gBAAgB;AAC7B,iBAAS;AAAA,MACX;AAAA,MAEA,MAAM,UAAU,QAAQ,KAAK;AAC3B,YAAI,OAAO;AACX,cAAM,cAAc,WAAW,KAAK,YAAY,IAAI,GAC9C,WAAW,gBAAgB,SAAS,gBAAgB,WACpD,aACJ,QAAQ,IAAI,aAAa,gBACzB,KAAK,MAAM,KAAK,YAAY,QAAQ,SAAS,sBAAsB,KAAK,IAAI,MAC1E;AAMJ,eAFgB,IAAI,SAAS,kBAAkB,KAGzC,YAAY,CAAC,eACf,OAAO;AAAA,EAAsC,IAAI,KAE/C,YAAY,+BAAc,qBAE5B,OAAO;AAAA,EAAoC,IAAI,KAI1C,QAGF,qBAAqB;AAAA,UAC1B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,MAAM,OAAO;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -44,7 +44,6 @@ function getBabelOptions(props) {
|
|
|
44
44
|
return props.userSetting === "babel" ? getOptions(props, !0) : typeof props.userSetting > "u" || typeof props.userSetting == "object" && props.userSetting.transform === "babel" ? props.userSetting?.excludeDefaultPlugins ? props.userSetting : getOptions(props) : null;
|
|
45
45
|
}
|
|
46
46
|
const getOptions = (props, force = !1) => {
|
|
47
|
-
const presets = [];
|
|
48
47
|
let plugins = [];
|
|
49
48
|
(force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(props));
|
|
50
49
|
const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
|
|
@@ -52,42 +51,41 @@ const getOptions = (props, force = !1) => {
|
|
|
52
51
|
!/node_modules/.test(props.id) &&
|
|
53
52
|
// only needed for createElement calls, so be a bit conservative
|
|
54
53
|
props.code.includes("createElement");
|
|
55
|
-
return enableNativewind && (props.id.includes("node_modules") || plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"))), (enableNativewind || shouldBabelReanimated(props)) && ((0, import_constants.debug)?.(
|
|
54
|
+
return enableNativewind && (props.id.includes("node_modules") || plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"))), (enableNativewind || shouldBabelReanimated(props)) && ((0, import_constants.debug)?.(`Using babel reanimated on file ${props.id}`), plugins.push(
|
|
56
55
|
// TODO make this configurable
|
|
57
|
-
process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && ((0, import_constants.debug)?.("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && ((0, import_constants.debug)?.("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins.length
|
|
58
|
-
plugins
|
|
59
|
-
presets
|
|
56
|
+
process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && ((0, import_constants.debug)?.("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && ((0, import_constants.debug)?.("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins.length ? {
|
|
57
|
+
plugins
|
|
60
58
|
} : null;
|
|
61
59
|
};
|
|
62
60
|
async function transformBabel(id, code, options) {
|
|
63
|
-
const compilerPlugin = options.plugins?.find(x => x && x[0] === "babel-plugin-react-compiler")
|
|
61
|
+
const compilerPlugin = options.plugins?.find(x => x && x[0] === "babel-plugin-react-compiler"),
|
|
62
|
+
extension = (0, import_node_path.extname)(id),
|
|
63
|
+
isTSX = extension === ".tsx",
|
|
64
|
+
babelOptions = {
|
|
65
|
+
filename: id,
|
|
66
|
+
compact: !1,
|
|
67
|
+
babelrc: !1,
|
|
68
|
+
configFile: !1,
|
|
69
|
+
sourceMaps: !1,
|
|
70
|
+
minified: !1,
|
|
71
|
+
...options,
|
|
72
|
+
presets: [isTSX || extension === ".ts" ? ["@babel/preset-typescript", {
|
|
73
|
+
isTSX,
|
|
74
|
+
allExtensions: isTSX
|
|
75
|
+
}] : "", ...(options.presets || [])].filter(Boolean)
|
|
76
|
+
};
|
|
64
77
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
import_core.default.transform(code, {
|
|
70
|
-
filename: id,
|
|
71
|
-
compact: !1,
|
|
72
|
-
babelrc: !1,
|
|
73
|
-
configFile: !1,
|
|
74
|
-
sourceMaps: !1,
|
|
75
|
-
minified: !1,
|
|
76
|
-
...options,
|
|
77
|
-
presets: [isTS ? ["@babel/preset-typescript", {
|
|
78
|
-
isTSX,
|
|
79
|
-
allExtensions: isTSX
|
|
80
|
-
}] : "", ...(options.presets || [])].filter(Boolean)
|
|
81
|
-
}, (err, result) => {
|
|
82
|
-
if (!result || err) return rej(err || "no res");
|
|
83
|
-
res(result);
|
|
84
|
-
});
|
|
78
|
+
const out = await new Promise((res, rej) => {
|
|
79
|
+
import_core.default.transform(code, babelOptions, (err, result) => {
|
|
80
|
+
if (!result || err) return rej(err || "no res");
|
|
81
|
+
res(result);
|
|
85
82
|
});
|
|
83
|
+
});
|
|
86
84
|
return compilerPlugin &&
|
|
87
85
|
// TODO this detection could be a lot faster
|
|
88
86
|
out.code?.includes(compilerPlugin[1] === "18" ? "react-compiler-runtime" : "react/compiler-runtime") && console.info(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)}`), out;
|
|
89
87
|
} catch (err) {
|
|
90
|
-
console.error("[vxrn:compiler] babel transform error", err), console.error("code", code), console.error("id", id);
|
|
88
|
+
console.error("[vxrn:compiler] babel transform error", err, "with options", babelOptions), console.error("code", code), console.error("id", id);
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
const getBasePlugins = ({
|
|
@@ -105,7 +103,7 @@ const getBasePlugins = ({
|
|
|
105
103
|
id,
|
|
106
104
|
environment
|
|
107
105
|
}) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)),
|
|
108
|
-
shouldBabelReactCompiler = props => !(props.environment === "ssr" || !import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) ||
|
|
106
|
+
shouldBabelReactCompiler = props => !(props.environment === "ssr" || !import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) || !/(\.tsx?)$/.test(props.id) || props.id.includes("node_modules") || props.id.includes("+api.") || props.code.startsWith("// disable-compiler")),
|
|
109
107
|
getBabelReactCompilerPlugin = props => ["babel-plugin-react-compiler", {
|
|
110
108
|
target: props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19"
|
|
111
109
|
}];
|