@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
|
@@ -31,55 +31,50 @@ function getBabelOptions(props) {
|
|
|
31
31
|
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;
|
|
32
32
|
}
|
|
33
33
|
const getOptions = (props, force = !1) => {
|
|
34
|
-
const presets = [];
|
|
35
34
|
let plugins = [];
|
|
36
35
|
(force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(props));
|
|
37
36
|
const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") && // if reanimated gets wrapped in transform it causes circular dep issues
|
|
38
37
|
!/node_modules/.test(props.id) && // only needed for createElement calls, so be a bit conservative
|
|
39
38
|
props.code.includes("createElement");
|
|
40
|
-
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)?.(
|
|
39
|
+
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(
|
|
41
40
|
// TODO make this configurable
|
|
42
41
|
process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin"
|
|
43
|
-
)), 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
|
|
42
|
+
)), 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 ? { plugins } : null;
|
|
44
43
|
};
|
|
45
44
|
async function transformBabel(id, code, options) {
|
|
46
|
-
const compilerPlugin = options.plugins?.find((x) => x && x[0] === "babel-plugin-react-compiler")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const compilerPlugin = options.plugins?.find((x) => x && x[0] === "babel-plugin-react-compiler"), extension = (0, import_node_path.extname)(id), isTSX = extension === ".tsx", babelOptions = {
|
|
46
|
+
filename: id,
|
|
47
|
+
compact: !1,
|
|
48
|
+
babelrc: !1,
|
|
49
|
+
configFile: !1,
|
|
50
|
+
sourceMaps: !1,
|
|
51
|
+
minified: !1,
|
|
52
|
+
...options,
|
|
53
|
+
presets: [
|
|
54
|
+
isTSX || extension === ".ts" ? [
|
|
55
|
+
"@babel/preset-typescript",
|
|
51
56
|
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
babelrc: !1,
|
|
55
|
-
configFile: !1,
|
|
56
|
-
sourceMaps: !1,
|
|
57
|
-
minified: !1,
|
|
58
|
-
...options,
|
|
59
|
-
presets: [
|
|
60
|
-
isTS ? [
|
|
61
|
-
"@babel/preset-typescript",
|
|
62
|
-
{
|
|
63
|
-
isTSX,
|
|
64
|
-
allExtensions: isTSX
|
|
65
|
-
}
|
|
66
|
-
] : "",
|
|
67
|
-
...options.presets || []
|
|
68
|
-
].filter(Boolean)
|
|
69
|
-
},
|
|
70
|
-
(err, result) => {
|
|
71
|
-
if (!result || err)
|
|
72
|
-
return rej(err || "no res");
|
|
73
|
-
res(result);
|
|
57
|
+
isTSX,
|
|
58
|
+
allExtensions: isTSX
|
|
74
59
|
}
|
|
75
|
-
|
|
60
|
+
] : "",
|
|
61
|
+
...options.presets || []
|
|
62
|
+
].filter(Boolean)
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
const out = await new Promise((res, rej) => {
|
|
66
|
+
import_core.default.transform(code, babelOptions, (err, result) => {
|
|
67
|
+
if (!result || err)
|
|
68
|
+
return rej(err || "no res");
|
|
69
|
+
res(result);
|
|
70
|
+
});
|
|
76
71
|
});
|
|
77
72
|
return compilerPlugin && // TODO this detection could be a lot faster
|
|
78
73
|
out.code?.includes(
|
|
79
74
|
compilerPlugin[1] === "18" ? "react-compiler-runtime" : "react/compiler-runtime"
|
|
80
75
|
) && console.info(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)}`), out;
|
|
81
76
|
} catch (err) {
|
|
82
|
-
console.error("[vxrn:compiler] babel transform error", err), console.error("code", code), console.error("id", id);
|
|
77
|
+
console.error("[vxrn:compiler] babel transform error", err, "with options", babelOptions), console.error("code", code), console.error("id", id);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
80
|
const getBasePlugins = ({ development }) => [
|
|
@@ -95,7 +90,7 @@ const getBasePlugins = ({ development }) => [
|
|
|
95
90
|
regenerator: !1
|
|
96
91
|
}
|
|
97
92
|
]
|
|
98
|
-
], NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/, SPEC_FILE_RE = /[\/\\]specs?[\/\\]/, shouldBabelReactNativeCodegen = ({ id, environment }) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)), shouldBabelReactCompiler = (props) => !(props.environment === "ssr" || !import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) ||
|
|
93
|
+
], NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/, SPEC_FILE_RE = /[\/\\]specs?[\/\\]/, shouldBabelReactNativeCodegen = ({ id, environment }) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)), 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")), getBabelReactCompilerPlugin = (props) => ["babel-plugin-react-compiler", { target: props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19" }];
|
|
99
94
|
function shouldBabelGenerators({ code }) {
|
|
100
95
|
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS)
|
|
101
96
|
return import_constants.asyncGeneratorRegex.test(code);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/transformBabel.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAkB,oCAClB,eAA4B,wBAC5B,mBAAkC,sBAClC,mBAA8B,wBAC9B,mBAA2C;AAOpC,SAAS,gBAAgB,OAA6C;AAC3E,SAAI,MAAM,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,KAAK,GAAG;AACrE;AAEA,SAAS,sBAAsB,EAAE,MAAM,GAAG,GAAU;AAClD,SAAK,+BAAc,mBAGf,CAAC,+BAA+B,KAAK,EAAE,KAAK,iBAAiB,KAAK,IAAI,SACxE,0BAAQ,+BAAoB,2BAAS,QAAQ,IAAI,GAAG,EAAE,CAAC,EAAE,GAClD,WAET,0BAAQ,6BAAyB,2BAAS,QAAQ,IAAI,GAAG,EAAE,CAAC,EAAE,GACvD,MAPE;AAQX;",
|
|
5
5
|
"names": ["babel"]
|
|
6
6
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolvePath } from "@vxrn/utils";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
2
|
import { readFileSync } from "node:fs";
|
|
4
3
|
import { readFile } from "node:fs/promises";
|
|
5
4
|
import { extname, join, sep } from "node:path";
|
|
@@ -11,10 +10,83 @@ import { transformSWC } from "./transformSWC";
|
|
|
11
10
|
export * from "./configure";
|
|
12
11
|
export * from "./transformBabel";
|
|
13
12
|
export * from "./transformSWC";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
async function performBabelTransform({
|
|
14
|
+
id,
|
|
15
|
+
code,
|
|
16
|
+
environment,
|
|
17
|
+
production,
|
|
18
|
+
reactForRNVersion,
|
|
19
|
+
optionsIn
|
|
20
|
+
}) {
|
|
21
|
+
const transformProps = {
|
|
22
|
+
id,
|
|
23
|
+
code,
|
|
24
|
+
development: !production,
|
|
25
|
+
environment,
|
|
26
|
+
reactForRNVersion
|
|
27
|
+
}, userTransform = optionsIn?.transform?.(transformProps);
|
|
28
|
+
if (userTransform === !1)
|
|
29
|
+
return null;
|
|
30
|
+
if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
|
|
31
|
+
const babelOptions = getBabelOptions({
|
|
32
|
+
...transformProps,
|
|
33
|
+
userSetting: userTransform
|
|
34
|
+
});
|
|
35
|
+
if (babelOptions) {
|
|
36
|
+
const babelOut = await transformBabel(id, code, babelOptions);
|
|
37
|
+
if (babelOut?.code)
|
|
38
|
+
return debug?.(`[babel] ${id}`), { code: babelOut.code, map: babelOut.map };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
async function performFullTransform({
|
|
44
|
+
codeIn,
|
|
45
|
+
_id,
|
|
46
|
+
environment,
|
|
47
|
+
production,
|
|
48
|
+
reactForRNVersion,
|
|
49
|
+
optionsIn,
|
|
50
|
+
mode
|
|
51
|
+
}) {
|
|
52
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
53
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
54
|
+
let id = _id.split("?")[0];
|
|
55
|
+
const extension = extname(id);
|
|
56
|
+
if (extension === ".css" || !validParsers.has(extension))
|
|
57
|
+
return;
|
|
58
|
+
if (id.includes("node_modules")) {
|
|
59
|
+
debug?.(`[skip node_modules] ${id}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
63
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
|
|
64
|
+
return;
|
|
65
|
+
let code = codeIn, out = null;
|
|
66
|
+
const babelResult = await performBabelTransform({
|
|
67
|
+
id,
|
|
68
|
+
code,
|
|
69
|
+
environment,
|
|
70
|
+
production,
|
|
71
|
+
reactForRNVersion,
|
|
72
|
+
optionsIn
|
|
73
|
+
});
|
|
74
|
+
babelResult && (out = babelResult, code = babelResult.code);
|
|
75
|
+
const swcOptions = {
|
|
76
|
+
environment,
|
|
77
|
+
mode: optionsIn?.mode || mode,
|
|
78
|
+
production,
|
|
79
|
+
...optionsIn
|
|
80
|
+
}, swcOut = await transformSWC(id, code, {
|
|
81
|
+
es5: !0,
|
|
82
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
83
|
+
...swcOptions
|
|
84
|
+
});
|
|
85
|
+
return swcOut && (debug?.(`[swc] ${id}`), out = {
|
|
86
|
+
code: swcOut.code,
|
|
87
|
+
map: swcOut.map
|
|
88
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
89
|
+
}
|
|
18
90
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
19
91
|
const reactVersion = await (async () => {
|
|
20
92
|
const path = resolvePath("react/package.json");
|
|
@@ -80,19 +152,52 @@ ${rootJS.code}
|
|
|
80
152
|
name: "one:compiler",
|
|
81
153
|
enforce: "pre",
|
|
82
154
|
config: () => {
|
|
83
|
-
const
|
|
84
|
-
esbuild: !1,
|
|
155
|
+
const createEnvironmentConfig = (environment) => ({
|
|
85
156
|
optimizeDeps: {
|
|
86
|
-
|
|
157
|
+
esbuildOptions: {
|
|
158
|
+
plugins: [
|
|
159
|
+
{
|
|
160
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
161
|
+
setup(build) {
|
|
162
|
+
build.onLoad(
|
|
163
|
+
{ filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/ },
|
|
164
|
+
async (args) => {
|
|
165
|
+
const production = process.env.NODE_ENV === "production", code = await readFile(args.path, "utf-8");
|
|
166
|
+
debug?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
167
|
+
const result = await performBabelTransform({
|
|
168
|
+
id: args.path,
|
|
169
|
+
code,
|
|
170
|
+
environment,
|
|
171
|
+
production,
|
|
172
|
+
reactForRNVersion,
|
|
173
|
+
optionsIn
|
|
174
|
+
});
|
|
175
|
+
if (!result)
|
|
176
|
+
return null;
|
|
177
|
+
const ext = extname(args.path), loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
178
|
+
return {
|
|
179
|
+
contents: result.code,
|
|
180
|
+
loader
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
87
188
|
},
|
|
88
189
|
define: {
|
|
89
|
-
"process.env.NATIVEWIND_OS":
|
|
190
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(
|
|
191
|
+
environment === "ios" || environment === "android" ? "native" : "web"
|
|
192
|
+
)
|
|
90
193
|
}
|
|
91
|
-
};
|
|
194
|
+
});
|
|
92
195
|
return {
|
|
93
196
|
environments: {
|
|
94
|
-
ios:
|
|
95
|
-
android:
|
|
197
|
+
ios: createEnvironmentConfig("ios"),
|
|
198
|
+
android: createEnvironmentConfig("android"),
|
|
199
|
+
client: createEnvironmentConfig("client"),
|
|
200
|
+
ssr: createEnvironmentConfig("ssr")
|
|
96
201
|
}
|
|
97
202
|
};
|
|
98
203
|
},
|
|
@@ -102,63 +207,22 @@ ${rootJS.code}
|
|
|
102
207
|
async transform(codeIn, _id) {
|
|
103
208
|
let code = codeIn;
|
|
104
209
|
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";
|
|
105
|
-
|
|
106
|
-
return isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
210
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
107
211
|
${code}`), isNative && configuration.enableNativewind && (code = `import * as x from 'nativewind'
|
|
108
|
-
${code}`), code
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const cacheId = getCacheId(environment, _id), cacheHash = getCacheHash(code), cached = memoryCache[cacheId];
|
|
112
|
-
if (cached?.hash === cacheHash)
|
|
113
|
-
return debug?.(`Using cache ${_id} ${cacheId}`), cached.out;
|
|
114
|
-
let id = _id.split("?")[0];
|
|
115
|
-
const extension = extname(id);
|
|
116
|
-
if (extension === ".css" || !validParsers.has(extension))
|
|
117
|
-
return;
|
|
118
|
-
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
119
|
-
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
|
|
120
|
-
return;
|
|
121
|
-
const transformProps = {
|
|
122
|
-
id,
|
|
123
|
-
code,
|
|
124
|
-
development: !production,
|
|
125
|
-
environment,
|
|
126
|
-
reactForRNVersion
|
|
127
|
-
}, userTransform = optionsIn?.transform?.(transformProps);
|
|
128
|
-
if (userTransform === !1)
|
|
129
|
-
return;
|
|
130
|
-
let out = null;
|
|
131
|
-
if (!isPreProcess && userTransform !== "swc") {
|
|
132
|
-
const babelOptions = getBabelOptions({
|
|
133
|
-
...transformProps,
|
|
134
|
-
userSetting: userTransform
|
|
135
|
-
});
|
|
136
|
-
if (babelOptions) {
|
|
137
|
-
const babelOut = await transformBabel(id, code, babelOptions);
|
|
138
|
-
babelOut?.code && (debug?.(`[${id}] transformed with babel options: ${JSON.stringify(babelOptions)}`), out = { code: babelOut.code, map: babelOut.map });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const swcOptions = {
|
|
212
|
+
${code}`), code) : performFullTransform({
|
|
213
|
+
codeIn,
|
|
214
|
+
_id,
|
|
142
215
|
environment,
|
|
143
|
-
mode: optionsIn?.mode || config.command,
|
|
144
216
|
production,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// dont need refresh for ssr, but do for client
|
|
149
|
-
noHMR: isPreProcess || environment === "ssr",
|
|
150
|
-
...swcOptions
|
|
217
|
+
reactForRNVersion,
|
|
218
|
+
optionsIn,
|
|
219
|
+
mode: config.command
|
|
151
220
|
});
|
|
152
|
-
return swcOut && (out = {
|
|
153
|
-
code: swcOut?.code,
|
|
154
|
-
map: swcOut?.map
|
|
155
|
-
}), 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;
|
|
156
221
|
}
|
|
157
222
|
}
|
|
158
223
|
];
|
|
159
224
|
}
|
|
160
225
|
export {
|
|
161
|
-
clearCompilerCache,
|
|
162
226
|
createVXRNCompilerPlugin
|
|
163
227
|
};
|
|
164
228
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": "AAKA,SAAS,mBAAmB;AAC5B,SAAS,
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AAKA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,SAAS,MAAM,WAAW;AACnC,SAAS,+BAA+B;AAGxC,SAAS,qBAAqB;AAC9B,SAAS,OAAO,mBAAmB,oBAAoB;AACvD,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,oBAAoB;AAG7B,cAAc;AACd,cAAc;AACd,cAAc;AAId,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,eAAe,gBAAgB;AAAA,MACnC,GAAG;AAAA,MACH,aAAa;AAAA,IACf,CAAC;AAED,QAAI,cAAc;AAChB,YAAM,WAAW,MAAM,eAAe,IAAI,MAAM,YAAY;AAC5D,UAAI,UAAU;AACZ,uBAAQ,WAAW,EAAE,EAAE,GAChB,EAAE,MAAM,SAAS,MAAM,KAAK,SAAS,IAAI;AAAA,IAEpD;AAAA,EACF;AAEA,SAAO;AACT;AAGA,eAAe,qBAAq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
|
6
6
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolvePath } from "@vxrn/utils";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
2
|
import { readFileSync } from "node:fs";
|
|
4
3
|
import { readFile } from "node:fs/promises";
|
|
5
4
|
import { extname, join, sep } from "node:path";
|
|
@@ -11,13 +10,85 @@ import { transformSWC } from "./transformSWC.mjs";
|
|
|
11
10
|
export * from "./configure.mjs";
|
|
12
11
|
export * from "./transformBabel.mjs";
|
|
13
12
|
export * from "./transformSWC.mjs";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
async function performBabelTransform({
|
|
14
|
+
id,
|
|
15
|
+
code,
|
|
16
|
+
environment,
|
|
17
|
+
production,
|
|
18
|
+
reactForRNVersion,
|
|
19
|
+
optionsIn
|
|
20
|
+
}) {
|
|
21
|
+
const transformProps = {
|
|
22
|
+
id,
|
|
23
|
+
code,
|
|
24
|
+
development: !production,
|
|
25
|
+
environment,
|
|
26
|
+
reactForRNVersion
|
|
27
|
+
},
|
|
28
|
+
userTransform = optionsIn?.transform?.(transformProps);
|
|
29
|
+
if (userTransform === !1) return null;
|
|
30
|
+
if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
|
|
31
|
+
const babelOptions = getBabelOptions({
|
|
32
|
+
...transformProps,
|
|
33
|
+
userSetting: userTransform
|
|
34
|
+
});
|
|
35
|
+
if (babelOptions) {
|
|
36
|
+
const babelOut = await transformBabel(id, code, babelOptions);
|
|
37
|
+
if (babelOut?.code) return debug?.(`[babel] ${id}`), {
|
|
38
|
+
code: babelOut.code,
|
|
39
|
+
map: babelOut.map
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
async function performFullTransform({
|
|
46
|
+
codeIn,
|
|
47
|
+
_id,
|
|
48
|
+
environment,
|
|
49
|
+
production,
|
|
50
|
+
reactForRNVersion,
|
|
51
|
+
optionsIn,
|
|
52
|
+
mode
|
|
53
|
+
}) {
|
|
54
|
+
const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
|
|
55
|
+
shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
|
|
56
|
+
let id = _id.split("?")[0];
|
|
57
|
+
const extension = extname(id);
|
|
58
|
+
if (extension === ".css" || !validParsers.has(extension)) return;
|
|
59
|
+
if (id.includes("node_modules")) {
|
|
60
|
+
debug?.(`[skip node_modules] ${id}`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
64
|
+
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
|
|
65
|
+
let code = codeIn,
|
|
66
|
+
out = null;
|
|
67
|
+
const babelResult = await performBabelTransform({
|
|
68
|
+
id,
|
|
69
|
+
code,
|
|
70
|
+
environment,
|
|
71
|
+
production,
|
|
72
|
+
reactForRNVersion,
|
|
73
|
+
optionsIn
|
|
74
|
+
});
|
|
75
|
+
babelResult && (out = babelResult, code = babelResult.code);
|
|
76
|
+
const swcOptions = {
|
|
77
|
+
environment,
|
|
78
|
+
mode: optionsIn?.mode || mode,
|
|
79
|
+
production,
|
|
80
|
+
...optionsIn
|
|
81
|
+
},
|
|
82
|
+
swcOut = await transformSWC(id, code, {
|
|
83
|
+
es5: !0,
|
|
84
|
+
noHMR: isPreProcess || environment === "ssr",
|
|
85
|
+
...swcOptions
|
|
86
|
+
});
|
|
87
|
+
return swcOut && (debug?.(`[swc] ${id}`), out = {
|
|
88
|
+
code: swcOut.code,
|
|
89
|
+
map: swcOut.map
|
|
90
|
+
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
|
|
91
|
+
}
|
|
21
92
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
22
93
|
const reactVersion = await (async () => {
|
|
23
94
|
const path = resolvePath("react/package.json");
|
|
@@ -86,19 +157,48 @@ ${rootJS.code}
|
|
|
86
157
|
name: "one:compiler",
|
|
87
158
|
enforce: "pre",
|
|
88
159
|
config: () => {
|
|
89
|
-
const
|
|
90
|
-
esbuild: !1,
|
|
160
|
+
const createEnvironmentConfig = environment => ({
|
|
91
161
|
optimizeDeps: {
|
|
92
|
-
|
|
162
|
+
esbuildOptions: {
|
|
163
|
+
plugins: [{
|
|
164
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
165
|
+
setup(build) {
|
|
166
|
+
build.onLoad({
|
|
167
|
+
filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/
|
|
168
|
+
}, async args => {
|
|
169
|
+
const production = process.env.NODE_ENV === "production",
|
|
170
|
+
code = await readFile(args.path, "utf-8");
|
|
171
|
+
debug?.(`[esbuild optimizeDeps] ${args.path}`);
|
|
172
|
+
const result = await performBabelTransform({
|
|
173
|
+
id: args.path,
|
|
174
|
+
code,
|
|
175
|
+
environment,
|
|
176
|
+
production,
|
|
177
|
+
reactForRNVersion,
|
|
178
|
+
optionsIn
|
|
179
|
+
});
|
|
180
|
+
if (!result) return null;
|
|
181
|
+
const ext = extname(args.path),
|
|
182
|
+
loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
|
|
183
|
+
return {
|
|
184
|
+
contents: result.code,
|
|
185
|
+
loader
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}]
|
|
190
|
+
}
|
|
93
191
|
},
|
|
94
192
|
define: {
|
|
95
|
-
"process.env.NATIVEWIND_OS": "native"
|
|
193
|
+
"process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
|
|
96
194
|
}
|
|
97
|
-
};
|
|
195
|
+
});
|
|
98
196
|
return {
|
|
99
197
|
environments: {
|
|
100
|
-
ios:
|
|
101
|
-
android:
|
|
198
|
+
ios: createEnvironmentConfig("ios"),
|
|
199
|
+
android: createEnvironmentConfig("android"),
|
|
200
|
+
client: createEnvironmentConfig("client"),
|
|
201
|
+
ssr: createEnvironmentConfig("ssr")
|
|
102
202
|
}
|
|
103
203
|
};
|
|
104
204
|
},
|
|
@@ -110,64 +210,19 @@ ${rootJS.code}
|
|
|
110
210
|
const environment = getEnvName(this.environment.name),
|
|
111
211
|
isNative = environment === "ios" || environment === "android",
|
|
112
212
|
production = process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
113
|
-
|
|
213
|
+
return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
|
|
114
214
|
${code}`), isNative && configuration.enableNativewind && (code = `import * as x from 'nativewind'
|
|
115
|
-
${code}`), code
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (extension === ".css" || !validParsers.has(extension)) return;
|
|
125
|
-
const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
|
|
126
|
-
if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
|
|
127
|
-
const transformProps = {
|
|
128
|
-
id,
|
|
129
|
-
code,
|
|
130
|
-
development: !production,
|
|
131
|
-
environment,
|
|
132
|
-
reactForRNVersion
|
|
133
|
-
},
|
|
134
|
-
userTransform = optionsIn?.transform?.(transformProps);
|
|
135
|
-
if (userTransform === !1) return;
|
|
136
|
-
let out = null;
|
|
137
|
-
if (!isPreProcess && userTransform !== "swc") {
|
|
138
|
-
const babelOptions = getBabelOptions({
|
|
139
|
-
...transformProps,
|
|
140
|
-
userSetting: userTransform
|
|
141
|
-
});
|
|
142
|
-
if (babelOptions) {
|
|
143
|
-
const babelOut = await transformBabel(id, code, babelOptions);
|
|
144
|
-
babelOut?.code && (debug?.(`[${id}] transformed with babel options: ${JSON.stringify(babelOptions)}`), out = {
|
|
145
|
-
code: babelOut.code,
|
|
146
|
-
map: babelOut.map
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const swcOptions = {
|
|
151
|
-
environment,
|
|
152
|
-
mode: optionsIn?.mode || config.command,
|
|
153
|
-
production,
|
|
154
|
-
...optionsIn
|
|
155
|
-
},
|
|
156
|
-
swcOut = await transformSWC(id, out?.code || code, {
|
|
157
|
-
es5: !0,
|
|
158
|
-
// dont need refresh for ssr, but do for client
|
|
159
|
-
noHMR: isPreProcess || environment === "ssr",
|
|
160
|
-
...swcOptions
|
|
161
|
-
});
|
|
162
|
-
return swcOut && (out = {
|
|
163
|
-
code: swcOut?.code,
|
|
164
|
-
map: swcOut?.map
|
|
165
|
-
}), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out && (cacheSize += out?.code.length, cacheSize > 52428800 && clearCompilerCache(), memoryCache[cacheId] = {
|
|
166
|
-
out,
|
|
167
|
-
hash: cacheHash
|
|
168
|
-
}), out;
|
|
215
|
+
${code}`), code) : performFullTransform({
|
|
216
|
+
codeIn,
|
|
217
|
+
_id,
|
|
218
|
+
environment,
|
|
219
|
+
production,
|
|
220
|
+
reactForRNVersion,
|
|
221
|
+
optionsIn,
|
|
222
|
+
mode: config.command
|
|
223
|
+
});
|
|
169
224
|
}
|
|
170
225
|
}];
|
|
171
226
|
}
|
|
172
|
-
export {
|
|
227
|
+
export { createVXRNCompilerPlugin };
|
|
173
228
|
//# sourceMappingURL=index.mjs.map
|