@vxrn/compiler 1.25.5 → 1.25.7

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.
Files changed (38) hide show
  1. package/dist/cjs/cache.cjs +132 -0
  2. package/dist/cjs/configure.cjs +37 -0
  3. package/dist/cjs/constants.cjs +77 -0
  4. package/dist/cjs/index.cjs +429 -0
  5. package/dist/cjs/refresh-runtime.cjs +452 -0
  6. package/dist/cjs/transformBabel.cjs +269 -0
  7. package/dist/cjs/transformBabel.test.cjs +88 -0
  8. package/dist/cjs/transformSWC.cjs +318 -0
  9. package/dist/cjs/types.cjs +18 -0
  10. package/dist/esm/cache.mjs +104 -0
  11. package/dist/esm/cache.mjs.map +1 -0
  12. package/dist/esm/configure.mjs +11 -0
  13. package/dist/esm/configure.mjs.map +1 -0
  14. package/dist/esm/constants.mjs +48 -0
  15. package/dist/esm/constants.mjs.map +1 -0
  16. package/dist/esm/index.js +402 -0
  17. package/dist/esm/index.js.map +1 -0
  18. package/dist/esm/index.mjs +402 -0
  19. package/dist/esm/index.mjs.map +1 -0
  20. package/dist/esm/refresh-runtime.mjs +421 -0
  21. package/dist/esm/refresh-runtime.mjs.map +1 -0
  22. package/dist/esm/transformBabel.mjs +231 -0
  23. package/dist/esm/transformBabel.mjs.map +1 -0
  24. package/dist/esm/transformBabel.test.mjs +65 -0
  25. package/dist/esm/transformBabel.test.mjs.map +1 -0
  26. package/dist/esm/transformSWC.mjs +292 -0
  27. package/dist/esm/transformSWC.mjs.map +1 -0
  28. package/dist/esm/types.mjs +2 -0
  29. package/dist/esm/types.mjs.map +1 -0
  30. package/package.json +3 -3
  31. package/types/cache.d.ts.map +1 -0
  32. package/types/configure.d.ts.map +1 -0
  33. package/types/constants.d.ts.map +1 -0
  34. package/types/index.d.ts.map +1 -0
  35. package/types/transformBabel.d.ts.map +1 -0
  36. package/types/transformBabel.test.d.ts.map +1 -0
  37. package/types/transformSWC.d.ts.map +1 -0
  38. package/types/types.d.ts.map +1 -0
@@ -0,0 +1,132 @@
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 cache_exports = {};
24
+ __export(cache_exports, {
25
+ getCacheStats: () => getCacheStats,
26
+ getCachedTransform: () => getCachedTransform,
27
+ logCacheStats: () => logCacheStats,
28
+ setCachedTransform: () => setCachedTransform
29
+ });
30
+ module.exports = __toCommonJS(cache_exports);
31
+ var import_node_crypto = require("node:crypto");
32
+ var import_node_fs = require("node:fs");
33
+ var import_node_path = require("node:path");
34
+ var import_configure = require("./configure.cjs");
35
+ const stats = {
36
+ hits: 0,
37
+ misses: 0,
38
+ writes: 0
39
+ };
40
+ function getCacheDir() {
41
+ const cacheDir = (0, import_node_path.join)(process.cwd(), "node_modules", ".vxrn", "compiler-cache");
42
+ if (!(0, import_node_fs.existsSync)(cacheDir)) {
43
+ (0, import_node_fs.mkdirSync)(cacheDir, {
44
+ recursive: true
45
+ });
46
+ }
47
+ return cacheDir;
48
+ }
49
+ function getConfigFingerprint() {
50
+ return (0, import_node_crypto.createHash)("sha1").update(JSON.stringify({
51
+ compiler: import_configure.configuration.enableCompiler,
52
+ reanimated: import_configure.configuration.enableReanimated,
53
+ nativewind: import_configure.configuration.enableNativewind,
54
+ nativeCSS: import_configure.configuration.enableNativeCSS,
55
+ // bump when the transform engine changes, so entries written by a
56
+ // previous engine aren't served for the same source
57
+ engine: "oxc-react-compiler"
58
+ })).digest("hex").slice(0, 8);
59
+ }
60
+ function getCacheKey(filePath, environment) {
61
+ const hash = (0, import_node_crypto.createHash)("sha1").update(`${environment}:${filePath}:${getConfigFingerprint()}`).digest("hex");
62
+ return hash;
63
+ }
64
+ function getContentHash(code) {
65
+ return (0, import_node_crypto.createHash)("sha1").update(code).digest("hex").slice(0, 16);
66
+ }
67
+ function getCachedTransform(filePath, code, environment) {
68
+ try {
69
+ const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath;
70
+ const cacheDir = getCacheDir();
71
+ const cacheKey = getCacheKey(cleanPath, environment);
72
+ const cachePath = (0, import_node_path.join)(cacheDir, `${cacheKey}.json`);
73
+ if (!(0, import_node_fs.existsSync)(cachePath)) {
74
+ stats.misses++;
75
+ return null;
76
+ }
77
+ const cached = JSON.parse((0, import_node_fs.readFileSync)(cachePath, "utf-8"));
78
+ const currentMtime = (0, import_node_fs.statSync)(cleanPath).mtimeMs;
79
+ if (cached.mtime !== currentMtime) {
80
+ stats.misses++;
81
+ return null;
82
+ }
83
+ const currentHash = getContentHash(code);
84
+ if (cached.hash !== currentHash) {
85
+ stats.misses++;
86
+ return null;
87
+ }
88
+ stats.hits++;
89
+ return {
90
+ code: cached.code,
91
+ map: cached.map
92
+ };
93
+ } catch (err) {
94
+ stats.misses++;
95
+ return null;
96
+ }
97
+ }
98
+ function setCachedTransform(filePath, code, result, environment) {
99
+ try {
100
+ const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath;
101
+ const cacheDir = getCacheDir();
102
+ const cacheKey = getCacheKey(cleanPath, environment);
103
+ const cachePath = (0, import_node_path.join)(cacheDir, `${cacheKey}.json`);
104
+ const mtime = (0, import_node_fs.statSync)(cleanPath).mtimeMs;
105
+ const hash = getContentHash(code);
106
+ const entry = {
107
+ mtime,
108
+ hash,
109
+ code: result.code,
110
+ map: result.map
111
+ };
112
+ (0, import_node_fs.writeFileSync)(cachePath, JSON.stringify(entry), "utf-8");
113
+ stats.writes++;
114
+ } catch (err) {
115
+ console.warn(`[cache] Failed to write cache for ${filePath}:`, err);
116
+ }
117
+ }
118
+ function getCacheStats() {
119
+ return {
120
+ ...stats
121
+ };
122
+ }
123
+ function logCacheStats() {
124
+ if (!process.env.DEBUG_COMPILER_PERF) {
125
+ return;
126
+ }
127
+ const total = stats.hits + stats.misses;
128
+ if (total === 0) return;
129
+ const hitRate = (stats.hits / total * 100).toFixed(1);
130
+ console.info(`
131
+ \u{1F4BE} [Cache Stats] ${stats.hits} hits / ${stats.misses} misses (${hitRate}% hit rate), ${stats.writes} writes`);
132
+ }
@@ -0,0 +1,37 @@
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 configure_exports = {};
24
+ __export(configure_exports, {
25
+ configuration: () => configuration,
26
+ configureVXRNCompilerPlugin: () => configureVXRNCompilerPlugin
27
+ });
28
+ module.exports = __toCommonJS(configure_exports);
29
+ const configuration = {
30
+ enableNativewind: false,
31
+ enableReanimated: false,
32
+ enableCompiler: false,
33
+ enableNativeCSS: false
34
+ };
35
+ function configureVXRNCompilerPlugin(_) {
36
+ Object.assign(configuration, _);
37
+ }
@@ -0,0 +1,77 @@
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 constants_exports = {};
24
+ __export(constants_exports, {
25
+ asyncGeneratorRegex: () => asyncGeneratorRegex,
26
+ debug: () => debug,
27
+ parsers: () => parsers,
28
+ runtimePublicPath: () => runtimePublicPath,
29
+ validParsers: () => validParsers
30
+ });
31
+ module.exports = __toCommonJS(constants_exports);
32
+ var import_utils = require("@vxrn/utils");
33
+ const {
34
+ debug
35
+ } = (0, import_utils.createDebugger)("vxrn:compiler-plugin");
36
+ const runtimePublicPath = "/@react-refresh";
37
+ const asyncGeneratorRegex = /(async \*|async function\*|for await)/;
38
+ const parsers = {
39
+ ".tsx": {
40
+ syntax: "typescript",
41
+ tsx: true,
42
+ decorators: true
43
+ },
44
+ ".ts": {
45
+ syntax: "typescript",
46
+ tsx: false,
47
+ decorators: true
48
+ },
49
+ ".jsx": {
50
+ syntax: "ecmascript",
51
+ jsx: true,
52
+ importAttributes: true,
53
+ explicitResourceManagement: true
54
+ },
55
+ ".js": {
56
+ syntax: "ecmascript",
57
+ importAttributes: true,
58
+ explicitResourceManagement: true
59
+ },
60
+ ".mjs": {
61
+ syntax: "ecmascript",
62
+ importAttributes: true,
63
+ explicitResourceManagement: true
64
+ },
65
+ ".cjs": {
66
+ syntax: "ecmascript",
67
+ importAttributes: true,
68
+ explicitResourceManagement: true
69
+ },
70
+ ".mdx": {
71
+ syntax: "ecmascript",
72
+ jsx: true,
73
+ importAttributes: true,
74
+ explicitResourceManagement: true
75
+ }
76
+ };
77
+ const validParsers = /* @__PURE__ */new Set([...Object.keys(parsers), ".css"]);
@@ -0,0 +1,429 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
22
+ value: true
23
+ }), mod);
24
+ var index_exports = {};
25
+ __export(index_exports, {
26
+ createVXRNCompilerPlugin: () => createVXRNCompilerPlugin
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_node_fs = require("node:fs");
30
+ var import_promises = require("node:fs/promises");
31
+ var import_node_path = require("node:path");
32
+ var import_node_url = require("node:url");
33
+ var import_utils = require("@vxrn/utils");
34
+ var import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js");
35
+ var import_configure = require("./configure.cjs");
36
+ var import_constants = require("./constants.cjs");
37
+ var import_transformBabel = require("./transformBabel.cjs");
38
+ var import_cache = require("./cache.cjs");
39
+ __reExport(index_exports, require("./configure.cjs"), module.exports);
40
+ __reExport(index_exports, require("./transformBabel.cjs"), module.exports);
41
+ __reExport(index_exports, require("./transformSWC.cjs"), module.exports);
42
+ const import_meta = {};
43
+ const perfStats = {
44
+ babel: {
45
+ totalCalls: 0,
46
+ totalTransforms: 0,
47
+ totalTime: 0,
48
+ byEnvironment: {}
49
+ },
50
+ optimizeDeps: {
51
+ byEnvironment: {}
52
+ }
53
+ };
54
+ function logPerfSummary() {
55
+ if (!process.env.DEBUG_COMPILER_PERF) {
56
+ return;
57
+ }
58
+ console.info("\n\u{1F4CA} [Compiler Performance Summary]");
59
+ console.info(`Babel: ${perfStats.babel.totalTransforms} transforms / ${perfStats.babel.totalCalls} calls (${(perfStats.babel.totalTransforms / Math.max(perfStats.babel.totalCalls, 1) * 100).toFixed(1)}% transform rate)`);
60
+ console.info(`Babel total time: ${perfStats.babel.totalTime}ms`);
61
+ for (const [env, stats] of Object.entries(perfStats.babel.byEnvironment)) {
62
+ if (stats.transforms > 0) {
63
+ console.info(` ${env}: ${stats.transforms} transforms, ${stats.time}ms (${(stats.time / stats.transforms).toFixed(1)}ms avg)`);
64
+ }
65
+ }
66
+ for (const [env, stats] of Object.entries(perfStats.optimizeDeps.byEnvironment)) {
67
+ const elapsed = Date.now() - stats.startTime;
68
+ console.info(`optimizeDeps ${env}: checked ${stats.filesChecked} files, transformed ${stats.filesTransformed} (${elapsed}ms)`);
69
+ }
70
+ }
71
+ const compilerLog = {
72
+ compiled: 0,
73
+ cached: 0,
74
+ time: 0,
75
+ // typed loose because the dom lib types setTimeout as number, but node gives
76
+ // us a Timeout we need to unref so the debounce never holds the process open
77
+ timer: null
78
+ };
79
+ function logCompiled(cached, ms) {
80
+ if (cached) {
81
+ compilerLog.cached++;
82
+ } else {
83
+ compilerLog.compiled++;
84
+ compilerLog.time += ms;
85
+ }
86
+ if (compilerLog.timer) clearTimeout(compilerLog.timer);
87
+ compilerLog.timer = setTimeout(() => {
88
+ const total = compilerLog.compiled + compilerLog.cached;
89
+ const detail = compilerLog.compiled ? `${compilerLog.compiled} compiled in ${compilerLog.time}ms${compilerLog.cached ? `, ${compilerLog.cached} cached` : ""}` : `all cached`;
90
+ console.info(` \u{1FA84} [compiler] ${total} file${total === 1 ? "" : "s"} (${detail})`);
91
+ compilerLog.compiled = 0;
92
+ compilerLog.cached = 0;
93
+ compilerLog.time = 0;
94
+ compilerLog.timer = null;
95
+ }, 500);
96
+ compilerLog.timer.unref?.();
97
+ }
98
+ async function performBabelTransform({
99
+ id,
100
+ code,
101
+ projectRoot,
102
+ environment,
103
+ production,
104
+ reactForRNVersion,
105
+ optionsIn
106
+ }) {
107
+ perfStats.babel.totalCalls++;
108
+ if (!perfStats.babel.byEnvironment[environment]) {
109
+ perfStats.babel.byEnvironment[environment] = {
110
+ calls: 0,
111
+ transforms: 0,
112
+ time: 0
113
+ };
114
+ }
115
+ perfStats.babel.byEnvironment[environment].calls++;
116
+ const transformProps = {
117
+ id,
118
+ code,
119
+ projectRoot,
120
+ development: !production,
121
+ environment,
122
+ reactForRNVersion
123
+ };
124
+ const userTransform = optionsIn?.transform?.(transformProps);
125
+ if (userTransform === false) {
126
+ return null;
127
+ }
128
+ if (userTransform !== "swc") {
129
+ const babelOptions = (0, import_transformBabel.getBabelOptions)({
130
+ ...transformProps,
131
+ userSetting: userTransform
132
+ });
133
+ if (babelOptions) {
134
+ const hasCompilerPlugin = babelOptions.plugins?.some(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler");
135
+ const cached = (0, import_cache.getCachedTransform)(id, code, environment);
136
+ if (cached) {
137
+ perfStats.babel.byEnvironment[environment].transforms++;
138
+ if (hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime"))) {
139
+ (0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (cached)`);
140
+ logCompiled(true, 0);
141
+ }
142
+ (0, import_constants.debug)?.(`[babel/cached] ${id}`);
143
+ return cached;
144
+ }
145
+ const compilerOnly = hasCompilerPlugin && babelOptions.plugins?.length === 1;
146
+ const compilerTarget = compilerOnly ? babelOptions.plugins[0][1]?.target ?? "19" : "19";
147
+ const startTime = Date.now();
148
+ const babelOut = compilerOnly ? await (0, import_transformBabel.transformOxcReactCompiler)(id, code, compilerTarget) : await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
149
+ const babelTime = Date.now() - startTime;
150
+ if (babelOut?.code) {
151
+ perfStats.babel.totalTransforms++;
152
+ perfStats.babel.totalTime += babelTime;
153
+ perfStats.babel.byEnvironment[environment].transforms++;
154
+ perfStats.babel.byEnvironment[environment].time += babelTime;
155
+ if (hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime"))) {
156
+ (0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (${babelTime}ms)`);
157
+ logCompiled(false, babelTime);
158
+ }
159
+ (0, import_constants.debug)?.(`[babel] ${id}`);
160
+ const outCode = `${babelOut.code}
161
+ // vxrn-did-babel`;
162
+ const result = {
163
+ code: outCode,
164
+ map: babelOut.map
165
+ };
166
+ (0, import_cache.setCachedTransform)(id, code, result, environment);
167
+ return result;
168
+ }
169
+ }
170
+ }
171
+ return null;
172
+ }
173
+ async function createVXRNCompilerPlugin(optionsIn) {
174
+ const reactVersion = await (async () => {
175
+ const path = (0, import_utils.resolvePath)("react/package.json");
176
+ const json = JSON.parse(await (0, import_promises.readFile)(path, "utf-8"));
177
+ return json.version;
178
+ })();
179
+ const envNames = {
180
+ ios: true,
181
+ android: true,
182
+ client: true,
183
+ ssr: true
184
+ };
185
+ function getEnvName(name) {
186
+ if (!envNames[name]) throw new Error(`Invalid env: ${name}`);
187
+ return name;
188
+ }
189
+ const reactForRNVersion = reactVersion.split(".")[0];
190
+ const cssTransformCache = /* @__PURE__ */new Map();
191
+ const rolldownPath = (0, import_utils.resolvePath)("rolldown");
192
+ const rolldownNodeMods = rolldownPath.slice(0, rolldownPath.indexOf(import_node_path.sep + "node_modules"));
193
+ let config;
194
+ return [{
195
+ name: "one:compiler-resolve-refresh-runtime",
196
+ apply: "serve",
197
+ enforce: "pre",
198
+ // Run before Vite default resolve to avoid syscalls
199
+ resolveId: id => id === import_constants.runtimePublicPath || id === `${import_constants.runtimePublicPath}.map` ? id : void 0,
200
+ load: id => {
201
+ const basePath = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
202
+ if (id === import_constants.runtimePublicPath) {
203
+ return (0, import_node_fs.readFileSync)((0, import_node_path.join)(basePath, "refresh-runtime.mjs"), "utf-8").replace(/\/\/# sourceMappingURL=.*/, "");
204
+ }
205
+ if (id === `${import_constants.runtimePublicPath}.map`) {
206
+ return JSON.stringify({
207
+ version: 3,
208
+ sources: [],
209
+ mappings: ""
210
+ });
211
+ }
212
+ return void 0;
213
+ }
214
+ }, {
215
+ name: `one:compiler-css-to-js`,
216
+ // only .css files can match, so let rust reject everything else
217
+ transform: {
218
+ filter: {
219
+ id: /\.css$/
220
+ },
221
+ handler(codeIn, id) {
222
+ const environment = getEnvName(this.environment.name);
223
+ if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
224
+ {
225
+ const data = JSON.stringify((0, import_css_to_rn.cssToReactNativeRuntime)(codeIn, {
226
+ inlineRem: 16
227
+ }));
228
+ const code = `require("nativewind/dist/index.js").__require().StyleSheet.registerCompiled(${data})`;
229
+ const newId = `${id}.js`;
230
+ const cssId = newId.replace(rolldownNodeMods + import_node_path.sep, "");
231
+ cssTransformCache.set(cssId, code);
232
+ return {
233
+ code,
234
+ id: newId,
235
+ map: null
236
+ };
237
+ }
238
+ }
239
+ }
240
+ },
241
+ generateBundle(_, bundle) {
242
+ const environment = getEnvName(this.environment.name);
243
+ if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
244
+ const rootJSName = Object.keys(bundle).find(i => {
245
+ const chunk = bundle[i];
246
+ return chunk.type == "chunk" && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null;
247
+ });
248
+ if (!rootJSName) {
249
+ throw new Error(`Can't find root js, internal one error`);
250
+ }
251
+ const rootJS = bundle[rootJSName];
252
+ const cssAssets = Object.keys(bundle).filter(i => bundle[i].fileName.endsWith(".css.js"));
253
+ for (const name of cssAssets) {
254
+ delete bundle[name];
255
+ const jsCSS = cssTransformCache.get(name);
256
+ rootJS.code = `
257
+ ${jsCSS}
258
+ ${rootJS.code}
259
+ `;
260
+ }
261
+ }
262
+ }
263
+ }, {
264
+ name: "one:compiler",
265
+ enforce: "pre",
266
+ config: () => {
267
+ const nodeModulesFilter = /node_modules[/\\].*\.(tsx?|jsx?|mjs|cjs)$/;
268
+ const createEnvironmentConfig = environment => {
269
+ if (!perfStats.optimizeDeps.byEnvironment[environment]) {
270
+ perfStats.optimizeDeps.byEnvironment[environment] = {
271
+ filesChecked: 0,
272
+ filesTransformed: 0,
273
+ startTime: Date.now()
274
+ };
275
+ }
276
+ return {
277
+ optimizeDeps: {
278
+ rolldownOptions: {
279
+ plugins: [{
280
+ name: `transform-before-optimize-deps-${environment}`,
281
+ async transform(code, id) {
282
+ if (!nodeModulesFilter.test(id)) {
283
+ return null;
284
+ }
285
+ perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
286
+ const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
287
+ (0, import_constants.debug)?.(`[rolldown optimizeDeps] ${id}`);
288
+ const result = await performBabelTransform({
289
+ id,
290
+ code,
291
+ projectRoot: config.root,
292
+ environment,
293
+ production,
294
+ reactForRNVersion,
295
+ optionsIn
296
+ });
297
+ if (!result) {
298
+ return null;
299
+ }
300
+ perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
301
+ return {
302
+ code: result.code,
303
+ map: result.map
304
+ };
305
+ },
306
+ buildEnd() {
307
+ if (process.env.DEBUG_COMPILER_PERF) {
308
+ const stats = perfStats.optimizeDeps.byEnvironment[environment];
309
+ const elapsed = Date.now() - stats.startTime;
310
+ console.info(`[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`);
311
+ }
312
+ const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;
313
+ if (allDone) {
314
+ (0, import_cache.logCacheStats)();
315
+ logPerfSummary();
316
+ }
317
+ }
318
+ }]
319
+ }
320
+ },
321
+ define: {
322
+ "process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
323
+ }
324
+ };
325
+ };
326
+ return {
327
+ environments: {
328
+ ios: createEnvironmentConfig("ios"),
329
+ android: createEnvironmentConfig("android"),
330
+ client: createEnvironmentConfig("client"),
331
+ ssr: createEnvironmentConfig("ssr")
332
+ }
333
+ };
334
+ },
335
+ configResolved(resolvedConfig) {
336
+ config = resolvedConfig;
337
+ },
338
+ async transform(codeIn, _id) {
339
+ let code = codeIn;
340
+ const environment = getEnvName(this.environment.name);
341
+ const isNative = environment === "ios" || environment === "android";
342
+ const production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
343
+ const isEntry = _id.includes("one-entry-native");
344
+ if (isEntry) {
345
+ if (isNative && !production) {
346
+ code = `import '@vxrn/vite-native-client'
347
+ ${code}`;
348
+ }
349
+ if (isNative && import_configure.configuration.enableNativewind) {
350
+ code = `import * as x from 'nativewind'
351
+ ${code}`;
352
+ }
353
+ return code;
354
+ }
355
+ const id = _id.split("?")[0];
356
+ const extension = (0, import_node_path.extname)(id);
357
+ if (extension === ".css" || !import_constants.validParsers.has(extension)) {
358
+ return;
359
+ }
360
+ if (id.includes(`virtual:`)) {
361
+ return;
362
+ }
363
+ if (codeIn.endsWith(`// vxrn-did-babel`)) {
364
+ (0, import_constants.debug)?.(`[skip babel] ${id}`);
365
+ return;
366
+ }
367
+ return performBabelTransform({
368
+ id,
369
+ code: codeIn,
370
+ projectRoot: config.root,
371
+ environment,
372
+ production,
373
+ reactForRNVersion,
374
+ optionsIn
375
+ });
376
+ }
377
+ },
378
+ // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept
379
+ // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code
380
+ {
381
+ name: "one:react-refresh-web",
382
+ apply: "serve",
383
+ transform(code, _id) {
384
+ if (this.environment.name !== "client") return;
385
+ if (code.includes(import_constants.runtimePublicPath)) return;
386
+ const id = _id.split("?")[0];
387
+ if (id.includes("node_modules")) return;
388
+ if (id.includes("virtual:")) return;
389
+ if (id === import_constants.runtimePublicPath) return;
390
+ const ext = (0, import_node_path.extname)(id);
391
+ if (ext !== ".tsx" && ext !== ".jsx") return;
392
+ const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
393
+ let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
394
+
395
+ `;
396
+ if (hasRefreshCalls) {
397
+ out += `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
398
+ const prevRefreshReg = window.$RefreshReg$;
399
+ const prevRefreshSig = window.$RefreshSig$;
400
+ window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
401
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
402
+
403
+ `;
404
+ }
405
+ out += code;
406
+ if (hasRefreshCalls) {
407
+ out += `
408
+
409
+ window.$RefreshReg$ = prevRefreshReg;
410
+ window.$RefreshSig$ = prevRefreshSig;
411
+ `;
412
+ }
413
+ out += `
414
+ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
415
+ RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
416
+ import.meta.hot.accept((nextExports) => {
417
+ if (!nextExports) return;
418
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
419
+ if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
420
+ });
421
+ });
422
+ `;
423
+ return {
424
+ code: out,
425
+ map: null
426
+ };
427
+ }
428
+ }];
429
+ }