@vxrn/compiler 1.1.546 → 1.1.547-1762235181981
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 +127 -74
- package/dist/cjs/index.js +127 -60
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/transformBabel.cjs +29 -31
- package/dist/cjs/transformBabel.js +29 -34
- package/dist/cjs/transformBabel.js.map +1 -1
- package/dist/cjs/transformSWC.cjs +3 -3
- package/dist/cjs/transformSWC.js +2 -2
- package/dist/cjs/transformSWC.js.map +1 -1
- package/dist/esm/index.js +126 -61
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +126 -72
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transformBabel.js +29 -34
- package/dist/esm/transformBabel.js.map +1 -1
- package/dist/esm/transformBabel.mjs +28 -30
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformSWC.js +2 -2
- package/dist/esm/transformSWC.js.map +1 -1
- package/dist/esm/transformSWC.mjs +2 -2
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/package.json +7 -11
- package/src/index.ts +218 -131
- package/src/transformBabel.ts +36 -41
- package/src/transformSWC.ts +3 -3
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts.map +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,15 +21,13 @@ 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
|
-
var
|
|
29
|
-
import_node_crypto = require("node:crypto"),
|
|
30
|
-
import_node_fs = require("node:fs"),
|
|
27
|
+
var import_node_fs = require("node:fs"),
|
|
31
28
|
import_promises = require("node:fs/promises"),
|
|
32
29
|
import_node_path = require("node:path"),
|
|
30
|
+
import_utils = require("@vxrn/utils"),
|
|
33
31
|
import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js"),
|
|
34
32
|
import_configure = require("./configure.cjs"),
|
|
35
33
|
import_constants = require("./constants.cjs"),
|
|
@@ -38,14 +36,85 @@ 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
|
+
// vxrn-did-babel`,
|
|
67
|
+
map: babelOut.map
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
async function performFullTransform({
|
|
74
|
+
codeIn,
|
|
75
|
+
_id,
|
|
76
|
+
environment,
|
|
77
|
+
production,
|
|
78
|
+
reactForRNVersion,
|
|
79
|
+
optionsIn,
|
|
80
|
+
mode
|
|
81
|
+
}) {
|
|
82
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
83
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
84
|
+
let id = _id.split("?")[0];
|
|
85
|
+
const extension = (0, import_node_path.extname)(id);
|
|
86
|
+
if (extension === ".css" || !import_constants.validParsers.has(extension)) return;
|
|
87
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
88
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
|
|
89
|
+
let code = codeIn,
|
|
90
|
+
out = null;
|
|
91
|
+
if (codeIn.endsWith("// vxrn-did-babel")) (0, import_constants.debug)?.(`[skip babel] ${id}`);else {
|
|
92
|
+
const babelResult = await performBabelTransform({
|
|
93
|
+
id,
|
|
94
|
+
code,
|
|
95
|
+
environment,
|
|
96
|
+
production,
|
|
97
|
+
reactForRNVersion,
|
|
98
|
+
optionsIn
|
|
99
|
+
});
|
|
100
|
+
babelResult && (out = babelResult, code = babelResult.code);
|
|
101
|
+
}
|
|
102
|
+
const swcOptions = {
|
|
103
|
+
environment,
|
|
104
|
+
mode: optionsIn?.mode || mode,
|
|
105
|
+
production,
|
|
106
|
+
...optionsIn
|
|
107
|
+
},
|
|
108
|
+
swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
|
|
109
|
+
es5: !0,
|
|
110
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
111
|
+
...swcOptions
|
|
112
|
+
});
|
|
113
|
+
return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
|
|
114
|
+
code: swcOut.code,
|
|
115
|
+
map: swcOut.map
|
|
116
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
117
|
+
}
|
|
49
118
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
50
119
|
const reactVersion = await (async () => {
|
|
51
120
|
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
@@ -114,19 +183,48 @@ ${rootJS.code}
|
|
|
114
183
|
name: "one:compiler",
|
|
115
184
|
enforce: "pre",
|
|
116
185
|
config: () => {
|
|
117
|
-
const
|
|
118
|
-
esbuild: !1,
|
|
186
|
+
const createEnvironmentConfig = environment => ({
|
|
119
187
|
optimizeDeps: {
|
|
120
|
-
|
|
188
|
+
esbuildOptions: {
|
|
189
|
+
plugins: [{
|
|
190
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
191
|
+
setup(build) {
|
|
192
|
+
build.onLoad({
|
|
193
|
+
filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/
|
|
194
|
+
}, async args => {
|
|
195
|
+
const production = process.env.NODE_ENV === "production",
|
|
196
|
+
code = await (0, import_promises.readFile)(args.path, "utf-8");
|
|
197
|
+
(0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
198
|
+
const result = await performBabelTransform({
|
|
199
|
+
id: args.path,
|
|
200
|
+
code,
|
|
201
|
+
environment,
|
|
202
|
+
production,
|
|
203
|
+
reactForRNVersion,
|
|
204
|
+
optionsIn
|
|
205
|
+
});
|
|
206
|
+
if (!result) return null;
|
|
207
|
+
const ext = (0, import_node_path.extname)(args.path),
|
|
208
|
+
loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
209
|
+
return {
|
|
210
|
+
contents: result.code,
|
|
211
|
+
loader
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}]
|
|
216
|
+
}
|
|
121
217
|
},
|
|
122
218
|
define: {
|
|
123
|
-
"process.env.NATIVEWIND_OS": "native"
|
|
219
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
|
|
124
220
|
}
|
|
125
|
-
};
|
|
221
|
+
});
|
|
126
222
|
return {
|
|
127
223
|
environments: {
|
|
128
|
-
ios:
|
|
129
|
-
android:
|
|
224
|
+
ios: createEnvironmentConfig("ios"),
|
|
225
|
+
android: createEnvironmentConfig("android"),
|
|
226
|
+
client: createEnvironmentConfig("client"),
|
|
227
|
+
ssr: createEnvironmentConfig("ssr")
|
|
130
228
|
}
|
|
131
229
|
};
|
|
132
230
|
},
|
|
@@ -138,62 +236,17 @@ ${rootJS.code}
|
|
|
138
236
|
const environment = getEnvName(this.environment.name),
|
|
139
237
|
isNative = environment === "ios" || environment === "android",
|
|
140
238
|
production = process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
141
|
-
|
|
239
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
142
240
|
${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;
|
|
241
|
+
${code}`), code) : performFullTransform({
|
|
242
|
+
codeIn,
|
|
243
|
+
_id,
|
|
244
|
+
environment,
|
|
245
|
+
production,
|
|
246
|
+
reactForRNVersion,
|
|
247
|
+
optionsIn,
|
|
248
|
+
mode: config.command
|
|
249
|
+
});
|
|
197
250
|
}
|
|
198
251
|
}];
|
|
199
252
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,18 +14,92 @@ 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
|
|
20
|
+
var import_node_fs = require("node:fs"), import_promises = require("node:fs/promises"), import_node_path = require("node:path"), import_utils = require("@vxrn/utils"), 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}
|
|
51
|
+
// vxrn-did-babel`, map: babelOut.map };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
async function performFullTransform({
|
|
57
|
+
codeIn,
|
|
58
|
+
_id,
|
|
59
|
+
environment,
|
|
60
|
+
production,
|
|
61
|
+
reactForRNVersion,
|
|
62
|
+
optionsIn,
|
|
63
|
+
mode
|
|
64
|
+
}) {
|
|
65
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
66
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
67
|
+
let id = _id.split("?")[0];
|
|
68
|
+
const extension = (0, import_node_path.extname)(id);
|
|
69
|
+
if (extension === ".css" || !import_constants.validParsers.has(extension))
|
|
70
|
+
return;
|
|
71
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
72
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
|
|
73
|
+
return;
|
|
74
|
+
let code = codeIn, out = null;
|
|
75
|
+
if (codeIn.endsWith("// vxrn-did-babel"))
|
|
76
|
+
(0, import_constants.debug)?.(`[skip babel] ${id}`);
|
|
77
|
+
else {
|
|
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
|
+
}
|
|
88
|
+
const swcOptions = {
|
|
89
|
+
environment,
|
|
90
|
+
mode: optionsIn?.mode || mode,
|
|
91
|
+
production,
|
|
92
|
+
...optionsIn
|
|
93
|
+
}, swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
|
|
94
|
+
es5: !0,
|
|
95
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
96
|
+
...swcOptions
|
|
97
|
+
});
|
|
98
|
+
return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
|
|
99
|
+
code: swcOut.code,
|
|
100
|
+
map: swcOut.map
|
|
101
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
102
|
+
}
|
|
29
103
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
30
104
|
const reactVersion = await (async () => {
|
|
31
105
|
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
@@ -91,19 +165,52 @@ ${rootJS.code}
|
|
|
91
165
|
name: "one:compiler",
|
|
92
166
|
enforce: "pre",
|
|
93
167
|
config: () => {
|
|
94
|
-
const
|
|
95
|
-
esbuild: !1,
|
|
168
|
+
const createEnvironmentConfig = (environment) => ({
|
|
96
169
|
optimizeDeps: {
|
|
97
|
-
|
|
170
|
+
esbuildOptions: {
|
|
171
|
+
plugins: [
|
|
172
|
+
{
|
|
173
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
174
|
+
setup(build) {
|
|
175
|
+
build.onLoad(
|
|
176
|
+
{ filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/ },
|
|
177
|
+
async (args) => {
|
|
178
|
+
const production = process.env.NODE_ENV === "production", code = await (0, import_promises.readFile)(args.path, "utf-8");
|
|
179
|
+
(0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
180
|
+
const result = await performBabelTransform({
|
|
181
|
+
id: args.path,
|
|
182
|
+
code,
|
|
183
|
+
environment,
|
|
184
|
+
production,
|
|
185
|
+
reactForRNVersion,
|
|
186
|
+
optionsIn
|
|
187
|
+
});
|
|
188
|
+
if (!result)
|
|
189
|
+
return null;
|
|
190
|
+
const ext = (0, import_node_path.extname)(args.path), loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
191
|
+
return {
|
|
192
|
+
contents: result.code,
|
|
193
|
+
loader
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
98
201
|
},
|
|
99
202
|
define: {
|
|
100
|
-
"process.env.NATIVEWIND_OS":
|
|
203
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(
|
|
204
|
+
environment === "ios" || environment === "android" ? "native" : "web"
|
|
205
|
+
)
|
|
101
206
|
}
|
|
102
|
-
};
|
|
207
|
+
});
|
|
103
208
|
return {
|
|
104
209
|
environments: {
|
|
105
|
-
ios:
|
|
106
|
-
android:
|
|
210
|
+
ios: createEnvironmentConfig("ios"),
|
|
211
|
+
android: createEnvironmentConfig("android"),
|
|
212
|
+
client: createEnvironmentConfig("client"),
|
|
213
|
+
ssr: createEnvironmentConfig("ssr")
|
|
107
214
|
}
|
|
108
215
|
};
|
|
109
216
|
},
|
|
@@ -113,57 +220,17 @@ ${rootJS.code}
|
|
|
113
220
|
async transform(codeIn, _id) {
|
|
114
221
|
let code = codeIn;
|
|
115
222
|
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'
|
|
223
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
118
224
|
${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 = {
|
|
225
|
+
${code}`), code) : performFullTransform({
|
|
226
|
+
codeIn,
|
|
227
|
+
_id,
|
|
153
228
|
environment,
|
|
154
|
-
mode: optionsIn?.mode || config.command,
|
|
155
229
|
production,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// dont need refresh for ssr, but do for client
|
|
160
|
-
noHMR: isPreProcess || environment === "ssr",
|
|
161
|
-
...swcOptions
|
|
230
|
+
reactForRNVersion,
|
|
231
|
+
optionsIn,
|
|
232
|
+
mode: config.command
|
|
162
233
|
});
|
|
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
234
|
}
|
|
168
235
|
}
|
|
169
236
|
];
|
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;AAAA;
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,qBAA6B,oBAC7B,kBAAyB,6BACzB,mBAAmC,sBACnC,eAA4B,wBAC5B,mBAAwC,wDAGxC,mBAA8B,wBAC9B,mBAAuD,wBACvD,wBAAgD,6BAChD,sBAA6B;AAG7B,0BAAc,wBAlBd;AAmBA,0BAAc,6BAnBd;AAoBA,0BAAc,2BApBd;AAAA;AAwBA,eAAe,sBAAsB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOG;AACD,QAAM,iBAAoC;AAAA,IACxC;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd;AAAA,IACA;AAAA,EACF,GAEM,gBAAgB,WAAW,YAAY,cAAc;AAE3D,MAAI,kBAAkB;AACpB,WAAO;AAKT,MAAI,CAFiB,GAAG,WAAW,sBAAsB,KAEpC,kBAAkB,OAAO;AAC5C,UAAM,mBAAe,uCAAgB;AAAA,MACnC,GAAG;AAAA,MACH,aAAa;AAAA,IACf,CAAC;AAED,QAAI,cAAc;AAChB,YAAM,WAAW,UAAM,sCAAe,IAAI,MAAM,YAAY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AA,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
|
}
|
|
@@ -35,16 +35,15 @@ __export(transformBabel_exports, {
|
|
|
35
35
|
transformBabel: () => transformBabel
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(transformBabel_exports);
|
|
38
|
-
var
|
|
38
|
+
var import_node_path = require("node:path"),
|
|
39
|
+
import_core = __toESM(require("@babel/core"), 1),
|
|
39
40
|
import_utils = require("@vxrn/utils"),
|
|
40
|
-
import_node_path = require("node:path"),
|
|
41
41
|
import_configure = require("./configure.cjs"),
|
|
42
42
|
import_constants = require("./constants.cjs");
|
|
43
43
|
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 = ({
|
|
@@ -100,12 +98,12 @@ const getBasePlugins = ({
|
|
|
100
98
|
regenerator: !1
|
|
101
99
|
}]],
|
|
102
100
|
NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/,
|
|
103
|
-
SPEC_FILE_RE = /[
|
|
101
|
+
SPEC_FILE_RE = /[/\\]specs?[/\\]/,
|
|
104
102
|
shouldBabelReactNativeCodegen = ({
|
|
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
|
}];
|