@vxrn/compiler 1.10.6-1773677542781 → 1.10.6-1773696008276

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.
@@ -28,8 +28,7 @@ __export(cache_exports, {
28
28
  module.exports = __toCommonJS(cache_exports);
29
29
  var import_node_crypto = require("node:crypto"),
30
30
  import_node_fs = require("node:fs"),
31
- import_node_path = require("node:path"),
32
- import_configure = require("./configure.cjs");
31
+ import_node_path = require("node:path");
33
32
  const stats = {
34
33
  hits: 0,
35
34
  misses: 0,
@@ -41,16 +40,8 @@ function getCacheDir() {
41
40
  recursive: !0
42
41
  }), cacheDir;
43
42
  }
44
- function getConfigFingerprint() {
45
- return (0, import_node_crypto.createHash)("sha1").update(JSON.stringify({
46
- compiler: import_configure.configuration.enableCompiler,
47
- reanimated: import_configure.configuration.enableReanimated,
48
- nativewind: import_configure.configuration.enableNativewind,
49
- nativeCSS: import_configure.configuration.enableNativeCSS
50
- })).digest("hex").slice(0, 8);
51
- }
52
43
  function getCacheKey(filePath, environment) {
53
- return (0, import_node_crypto.createHash)("sha1").update(`${environment}:${filePath}:${getConfigFingerprint()}`).digest("hex");
44
+ return (0, import_node_crypto.createHash)("sha1").update(`${environment}:${filePath}`).digest("hex");
54
45
  }
55
46
  function getContentHash(code) {
56
47
  return (0, import_node_crypto.createHash)("sha1").update(code).digest("hex").slice(0, 16);
package/dist/cjs/cache.js CHANGED
@@ -20,24 +20,14 @@ __export(cache_exports, {
20
20
  setCachedTransform: () => setCachedTransform
21
21
  });
22
22
  module.exports = __toCommonJS(cache_exports);
23
- var import_node_crypto = require("node:crypto"), import_node_fs = require("node:fs"), import_node_path = require("node:path"), import_configure = require("./configure");
23
+ var import_node_crypto = require("node:crypto"), import_node_fs = require("node:fs"), import_node_path = require("node:path");
24
24
  const stats = { hits: 0, misses: 0, writes: 0 };
25
25
  function getCacheDir() {
26
26
  const cacheDir = (0, import_node_path.join)(process.cwd(), "node_modules", ".vxrn", "compiler-cache");
27
27
  return (0, import_node_fs.existsSync)(cacheDir) || (0, import_node_fs.mkdirSync)(cacheDir, { recursive: !0 }), cacheDir;
28
28
  }
29
- function getConfigFingerprint() {
30
- return (0, import_node_crypto.createHash)("sha1").update(
31
- JSON.stringify({
32
- compiler: import_configure.configuration.enableCompiler,
33
- reanimated: import_configure.configuration.enableReanimated,
34
- nativewind: import_configure.configuration.enableNativewind,
35
- nativeCSS: import_configure.configuration.enableNativeCSS
36
- })
37
- ).digest("hex").slice(0, 8);
38
- }
39
29
  function getCacheKey(filePath, environment) {
40
- return (0, import_node_crypto.createHash)("sha1").update(`${environment}:${filePath}:${getConfigFingerprint()}`).digest("hex");
30
+ return (0, import_node_crypto.createHash)("sha1").update(`${environment}:${filePath}`).digest("hex");
41
31
  }
42
32
  function getContentHash(code) {
43
33
  return (0, import_node_crypto.createHash)("sha1").update(code).digest("hex").slice(0, 16);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/cache.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B,wBAC3B,iBAA6E,oBAC7E,mBAAqB,sBACrB,mBAA8B;AAwB9B,MAAM,QAAoB,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE;AAE1D,SAAS,cAAsB;AAE7B,QAAM,eAAW,uBAAK,QAAQ,IAAI,GAAG,gBAAgB,SAAS,gBAAgB;AAC9E,aAAK,2BAAW,QAAQ,SACtB,0BAAU,UAAU,EAAE,WAAW,GAAK,CAAC,GAElC;AACT;AAGA,SAAS,uBAA+B;AACtC,aAAO,+BAAW,MAAM,EACrB;AAAA,IACC,KAAK,UAAU;AAAA,MACb,UAAU,+BAAc;AAAA,MACxB,YAAY,+BAAc;AAAA,MAC1B,YAAY,+BAAc;AAAA,MAC1B,WAAW,+BAAc;AAAA,IAC3B,CAAC;AAAA,EACH,EACC,OAAO,KAA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A,0BAAsB,MAAM,IAAI,WAAW,MAAM,MAAM,YAAY,OAAO,gBAAgB,MAAM,MAAM;AAAA,EACxG;AACF;",
5
5
  "names": []
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/configure.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,gBAAsB;AAAA,EACjC,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,iBAAiB;AACnB;AAEO,SAAS,4BAA4B,GAAS;AACnD,SAAO,OAAO,eAAe,CAAC;AAChC;",
4
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,MAAM,gBAAsB;AAAA,EACjC,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,iBAAiB;AACnB;AAEO,SAAS,4BAA4B,GAAS;AACnD,SAAO,OAAO,eAAe,CAAC;AAChC;",
5
5
  "names": []
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/constants.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAExB,MAAM,EAAE,MAAM,QAAI,6BAAe,sBAAsB,GAEjD,oBAAoB,mBAEpB,sBAAsB,yCAGtB,UAA+B;AAAA,EAC1C,QAAQ,EAAE,QAAQ,cAAc,KAAK,IAAM,YAAY,GAAK;AAAA,EAC5D,OAAO,EAAE,QAAQ,cAAc,KAAK,IAAO,YAAY,GAAK;AAAA,EAC5D,QAAQ;AAAA,IACN,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,kBAAkB;AAAA,IAClB,4BAA4B;AAAA,EAC9B;AAAA,EACA,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,kBAAkB;AAAA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OAAO,KAAK,OAAO,GAAG,MAAM,CAAC;",
5
5
  "names": []
6
6
  }
@@ -33,6 +33,7 @@ var import_node_fs = require("node:fs"),
33
33
  import_configure = require("./configure.cjs"),
34
34
  import_constants = require("./constants.cjs"),
35
35
  import_transformBabel = require("./transformBabel.cjs"),
36
+ import_transformSWC = require("./transformSWC.cjs"),
36
37
  import_cache = require("./cache.cjs");
37
38
  __reExport(index_exports, require("./configure.cjs"), module.exports);
38
39
  __reExport(index_exports, require("./transformBabel.cjs"), module.exports);
@@ -82,21 +83,19 @@ async function performBabelTransform({
82
83
  },
83
84
  userTransform = optionsIn?.transform?.(transformProps);
84
85
  if (userTransform === !1) return null;
85
- if (userTransform !== "swc") {
86
+ if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
86
87
  const babelOptions = (0, import_transformBabel.getBabelOptions)({
87
88
  ...transformProps,
88
89
  userSetting: userTransform
89
90
  });
90
91
  if (babelOptions) {
91
- const hasCompilerPlugin = babelOptions.plugins?.some(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler"),
92
- relId = (0, import_node_path.relative)(process.cwd(), id),
93
- cached = (0, import_cache.getCachedTransform)(id, code, environment);
94
- if (cached) return perfStats.babel.byEnvironment[environment].transforms++, hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime")) && console.info(` \u{1FA84} [compiler] ${relId} (cached)`), (0, import_constants.debug)?.(`[babel/cached] ${id}`), cached;
92
+ const cached = (0, import_cache.getCachedTransform)(id, code, environment);
93
+ if (cached) return perfStats.babel.byEnvironment[environment].transforms++, (0, import_constants.debug)?.(`[babel/cached] ${id}`), cached;
95
94
  const startTime = Date.now(),
96
95
  babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions),
97
96
  babelTime = Date.now() - startTime;
98
97
  if (babelOut?.code) {
99
- perfStats.babel.totalTransforms++, perfStats.babel.totalTime += babelTime, perfStats.babel.byEnvironment[environment].transforms++, perfStats.babel.byEnvironment[environment].time += babelTime, hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime")) && console.info(` \u{1FA84} [compiler] ${relId} (${babelTime}ms)`), (0, import_constants.debug)?.(`[babel] ${id}`);
98
+ perfStats.babel.totalTransforms++, perfStats.babel.totalTime += babelTime, perfStats.babel.byEnvironment[environment].transforms++, perfStats.babel.byEnvironment[environment].time += babelTime, (0, import_constants.debug)?.(`[babel] ${id}`);
100
99
  const result = {
101
100
  code: `${babelOut.code}
102
101
  // vxrn-did-babel`,
@@ -108,6 +107,51 @@ async function performBabelTransform({
108
107
  }
109
108
  return null;
110
109
  }
110
+ async function performFullTransform({
111
+ codeIn,
112
+ _id,
113
+ environment,
114
+ production,
115
+ reactForRNVersion,
116
+ optionsIn,
117
+ mode
118
+ }) {
119
+ const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
120
+ shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
121
+ let id = _id.split("?")[0];
122
+ const extension = (0, import_node_path.extname)(id);
123
+ if (extension === ".css" || !import_constants.validParsers.has(extension)) return;
124
+ const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
125
+ if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:")) return;
126
+ let code = codeIn,
127
+ out = null;
128
+ if (codeIn.endsWith("// vxrn-did-babel")) (0, import_constants.debug)?.(`[skip babel] ${id}`);else {
129
+ const babelResult = await performBabelTransform({
130
+ id,
131
+ code,
132
+ environment,
133
+ production,
134
+ reactForRNVersion,
135
+ optionsIn
136
+ });
137
+ babelResult && (out = babelResult, code = babelResult.code);
138
+ }
139
+ const swcOptions = {
140
+ environment,
141
+ mode: optionsIn?.mode || mode,
142
+ production,
143
+ ...optionsIn
144
+ },
145
+ swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
146
+ es5: !0,
147
+ noHMR: isPreProcess || environment === "ssr",
148
+ ...swcOptions
149
+ });
150
+ return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
151
+ code: swcOut.code,
152
+ map: swcOut.map
153
+ }), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
154
+ }
111
155
  async function createVXRNCompilerPlugin(optionsIn) {
112
156
  const reactVersion = await (async () => {
113
157
  const path = (0, import_utils.resolvePath)("react/package.json");
@@ -125,8 +169,8 @@ async function createVXRNCompilerPlugin(optionsIn) {
125
169
  }
126
170
  const reactForRNVersion = reactVersion.split(".")[0],
127
171
  cssTransformCache = /* @__PURE__ */new Map(),
128
- rolldownPath = (0, import_utils.resolvePath)("rolldown"),
129
- rolldownNodeMods = rolldownPath.slice(0, rolldownPath.indexOf(import_node_path.sep + "node_modules"));
172
+ rollupPath = (0, import_utils.resolvePath)("rollup"),
173
+ rollupNodeMods = rollupPath.slice(0, rollupPath.indexOf(import_node_path.sep + "node_modules"));
130
174
  let config;
131
175
  return [{
132
176
  name: "one:compiler-resolve-refresh-runtime",
@@ -152,7 +196,7 @@ async function createVXRNCompilerPlugin(optionsIn) {
152
196
  inlineRem: 16
153
197
  }))})`,
154
198
  newId = `${id}.js`,
155
- cssId = newId.replace(rolldownNodeMods + import_node_path.sep, "");
199
+ cssId = newId.replace(rollupNodeMods + import_node_path.sep, "");
156
200
  return cssTransformCache.set(cssId, code), {
157
201
  code,
158
202
  id: newId,
@@ -184,49 +228,55 @@ ${rootJS.code}
184
228
  name: "one:compiler",
185
229
  enforce: "pre",
186
230
  config: () => {
187
- const nodeModulesFilter = /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/,
188
- createEnvironmentConfig = environment => (perfStats.optimizeDeps.byEnvironment[environment] || (perfStats.optimizeDeps.byEnvironment[environment] = {
189
- filesChecked: 0,
190
- filesTransformed: 0,
191
- startTime: Date.now()
192
- }), {
193
- optimizeDeps: {
194
- rolldownOptions: {
195
- plugins: [{
196
- name: `transform-before-optimize-deps-${environment}`,
197
- async transform(code, id) {
198
- if (!nodeModulesFilter.test(id)) return null;
231
+ const createEnvironmentConfig = environment => ({
232
+ optimizeDeps: {
233
+ esbuildOptions: {
234
+ plugins: [{
235
+ name: `transform-before-optimize-deps-${environment}`,
236
+ setup(build) {
237
+ perfStats.optimizeDeps.byEnvironment[environment] || (perfStats.optimizeDeps.byEnvironment[environment] = {
238
+ filesChecked: 0,
239
+ filesTransformed: 0,
240
+ startTime: Date.now()
241
+ }), build.onLoad({
242
+ filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/
243
+ }, async args => {
199
244
  perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
200
- const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
201
- (0, import_constants.debug)?.(`[rolldown optimizeDeps] ${id}`);
245
+ const production = process.env.NODE_ENV === "production",
246
+ code = await (0, import_promises.readFile)(args.path, "utf-8");
247
+ (0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
202
248
  const result = await performBabelTransform({
203
- id,
249
+ id: args.path,
204
250
  code,
205
251
  environment,
206
252
  production,
207
253
  reactForRNVersion,
208
254
  optionsIn
209
255
  });
210
- return result ? (perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++, {
211
- code: result.code,
212
- map: result.map
213
- }) : null;
214
- },
215
- buildEnd() {
256
+ if (!result) return null;
257
+ perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
258
+ const ext = (0, import_node_path.extname)(args.path),
259
+ loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
260
+ return {
261
+ contents: result.code,
262
+ loader
263
+ };
264
+ }), build.onEnd(() => {
216
265
  if (process.env.DEBUG_COMPILER_PERF) {
217
266
  const stats = perfStats.optimizeDeps.byEnvironment[environment],
218
267
  elapsed = Date.now() - stats.startTime;
219
268
  console.info(`[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`);
220
269
  }
221
270
  Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2 && ((0, import_cache.logCacheStats)(), logPerfSummary());
222
- }
223
- }]
224
- }
225
- },
226
- define: {
227
- "process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
271
+ });
272
+ }
273
+ }]
228
274
  }
229
- });
275
+ },
276
+ define: {
277
+ "process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
278
+ }
279
+ });
230
280
  return {
231
281
  environments: {
232
282
  ios: createEnvironmentConfig("ios"),
@@ -243,66 +293,18 @@ ${rootJS.code}
243
293
  let code = codeIn;
244
294
  const environment = getEnvName(this.environment.name),
245
295
  isNative = environment === "ios" || environment === "android",
246
- production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
247
- if (_id.includes("one-entry-native")) return isNative && !production && (code = `import '@vxrn/vite-native-client'
296
+ production = process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
297
+ return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
248
298
  ${code}`), isNative && import_configure.configuration.enableNativewind && (code = `import * as x from 'nativewind'
249
- ${code}`), code;
250
- const id = _id.split("?")[0],
251
- extension = (0, import_node_path.extname)(id);
252
- if (!(extension === ".css" || !import_constants.validParsers.has(extension)) && !id.includes("virtual:")) {
253
- if (codeIn.endsWith("// vxrn-did-babel")) {
254
- (0, import_constants.debug)?.(`[skip babel] ${id}`);
255
- return;
256
- }
257
- return performBabelTransform({
258
- id,
259
- code: codeIn,
260
- environment,
261
- production,
262
- reactForRNVersion,
263
- optionsIn
264
- });
265
- }
266
- }
267
- },
268
- // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept
269
- // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code
270
- {
271
- name: "one:react-refresh-web",
272
- apply: "serve",
273
- transform(code, _id) {
274
- if (this.environment.name !== "client" || code.includes(import_constants.runtimePublicPath)) return;
275
- const id = _id.split("?")[0];
276
- if (id.includes("node_modules") || id.includes("virtual:") || id === import_constants.runtimePublicPath) return;
277
- const ext = (0, import_node_path.extname)(id);
278
- if (ext !== ".tsx" && ext !== ".jsx") return;
279
- const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
280
- let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
281
-
282
- `;
283
- return hasRefreshCalls && (out += `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
284
- const prevRefreshReg = window.$RefreshReg$;
285
- const prevRefreshSig = window.$RefreshSig$;
286
- window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
287
- window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
288
-
289
- `), out += code, hasRefreshCalls && (out += `
290
-
291
- window.$RefreshReg$ = prevRefreshReg;
292
- window.$RefreshSig$ = prevRefreshSig;
293
- `), out += `
294
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
295
- RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
296
- import.meta.hot.accept((nextExports) => {
297
- if (!nextExports) return;
298
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
299
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
300
- });
301
- });
302
- `, {
303
- code: out,
304
- map: null
305
- };
299
+ ${code}`), code) : performFullTransform({
300
+ codeIn,
301
+ _id,
302
+ environment,
303
+ production,
304
+ reactForRNVersion,
305
+ optionsIn,
306
+ mode: config.command
307
+ });
306
308
  }
307
309
  }];
308
310
  }
package/dist/cjs/index.js CHANGED
@@ -17,7 +17,7 @@ __export(index_exports, {
17
17
  createVXRNCompilerPlugin: () => createVXRNCompilerPlugin
18
18
  });
19
19
  module.exports = __toCommonJS(index_exports);
20
- var import_node_fs = require("node:fs"), import_promises = require("node:fs/promises"), import_node_path = require("node:path"), import_node_url = require("node:url"), 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_cache = require("./cache");
20
+ var import_node_fs = require("node:fs"), import_promises = require("node:fs/promises"), import_node_path = require("node:path"), import_node_url = require("node:url"), 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"), import_cache = require("./cache");
21
21
  __reExport(index_exports, require("./configure"), module.exports);
22
22
  __reExport(index_exports, require("./transformBabel"), module.exports);
23
23
  __reExport(index_exports, require("./transformSWC"), module.exports);
@@ -68,20 +68,18 @@ async function performBabelTransform({
68
68
  }, userTransform = optionsIn?.transform?.(transformProps);
69
69
  if (userTransform === !1)
70
70
  return null;
71
- if (userTransform !== "swc") {
71
+ if (!id.startsWith("vxrn-swc-preprocess:") && userTransform !== "swc") {
72
72
  const babelOptions = (0, import_transformBabel.getBabelOptions)({
73
73
  ...transformProps,
74
74
  userSetting: userTransform
75
75
  });
76
76
  if (babelOptions) {
77
- const hasCompilerPlugin = babelOptions.plugins?.some(
78
- (x) => Array.isArray(x) && x[0] === "babel-plugin-react-compiler"
79
- ), relId = (0, import_node_path.relative)(process.cwd(), id), cached = (0, import_cache.getCachedTransform)(id, code, environment);
77
+ const cached = (0, import_cache.getCachedTransform)(id, code, environment);
80
78
  if (cached)
81
- return perfStats.babel.byEnvironment[environment].transforms++, hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime")) && console.info(` \u{1FA84} [compiler] ${relId} (cached)`), (0, import_constants.debug)?.(`[babel/cached] ${id}`), cached;
79
+ return perfStats.babel.byEnvironment[environment].transforms++, (0, import_constants.debug)?.(`[babel/cached] ${id}`), cached;
82
80
  const startTime = Date.now(), babelOut = await (0, import_transformBabel.transformBabel)(id, code, babelOptions), babelTime = Date.now() - startTime;
83
81
  if (babelOut?.code) {
84
- perfStats.babel.totalTransforms++, perfStats.babel.totalTime += babelTime, perfStats.babel.byEnvironment[environment].transforms++, perfStats.babel.byEnvironment[environment].time += babelTime, hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime")) && console.info(` \u{1FA84} [compiler] ${relId} (${babelTime}ms)`), (0, import_constants.debug)?.(`[babel] ${id}`);
82
+ perfStats.babel.totalTransforms++, perfStats.babel.totalTime += babelTime, perfStats.babel.byEnvironment[environment].transforms++, perfStats.babel.byEnvironment[environment].time += babelTime, (0, import_constants.debug)?.(`[babel] ${id}`);
85
83
  const result = { code: `${babelOut.code}
86
84
  // vxrn-did-babel`, map: babelOut.map };
87
85
  return (0, import_cache.setCachedTransform)(id, code, result, environment), result;
@@ -90,6 +88,53 @@ async function performBabelTransform({
90
88
  }
91
89
  return null;
92
90
  }
91
+ async function performFullTransform({
92
+ codeIn,
93
+ _id,
94
+ environment,
95
+ production,
96
+ reactForRNVersion,
97
+ optionsIn,
98
+ mode
99
+ }) {
100
+ const shouldDebug = process.env.NODE_ENV === "development" && codeIn.startsWith("// debug");
101
+ shouldDebug && (console.info(`[one] ${_id} input:`), console.info(codeIn));
102
+ let id = _id.split("?")[0];
103
+ const extension = (0, import_node_path.extname)(id);
104
+ if (extension === ".css" || !import_constants.validParsers.has(extension))
105
+ return;
106
+ const isPreProcess = id.startsWith("vxrn-swc-preprocess:");
107
+ if (isPreProcess && (id = id.replace("vxrn-swc-preprocess:", "")), id.includes("virtual:"))
108
+ return;
109
+ let code = codeIn, out = null;
110
+ if (codeIn.endsWith("// vxrn-did-babel"))
111
+ (0, import_constants.debug)?.(`[skip babel] ${id}`);
112
+ else {
113
+ const babelResult = await performBabelTransform({
114
+ id,
115
+ code,
116
+ environment,
117
+ production,
118
+ reactForRNVersion,
119
+ optionsIn
120
+ });
121
+ babelResult && (out = babelResult, code = babelResult.code);
122
+ }
123
+ const swcOptions = {
124
+ environment,
125
+ mode: optionsIn?.mode || mode,
126
+ production,
127
+ ...optionsIn
128
+ }, swcOut = await (0, import_transformSWC.transformSWC)(id, code, {
129
+ es5: !0,
130
+ noHMR: isPreProcess || environment === "ssr",
131
+ ...swcOptions
132
+ });
133
+ return swcOut && ((0, import_constants.debug)?.(`[swc] ${id}`), out = {
134
+ code: swcOut.code,
135
+ map: swcOut.map
136
+ }), shouldDebug && (console.info("swcOptions", swcOptions), console.info("final output:", out?.code)), out;
137
+ }
93
138
  async function createVXRNCompilerPlugin(optionsIn) {
94
139
  const reactVersion = await (async () => {
95
140
  const path = (0, import_utils.resolvePath)("react/package.json");
@@ -104,10 +149,7 @@ async function createVXRNCompilerPlugin(optionsIn) {
104
149
  if (!envNames[name]) throw new Error(`Invalid env: ${name}`);
105
150
  return name;
106
151
  }
107
- const reactForRNVersion = reactVersion.split(".")[0], cssTransformCache = /* @__PURE__ */ new Map(), rolldownPath = (0, import_utils.resolvePath)("rolldown"), rolldownNodeMods = rolldownPath.slice(
108
- 0,
109
- rolldownPath.indexOf(import_node_path.sep + "node_modules")
110
- );
152
+ const reactForRNVersion = reactVersion.split(".")[0], cssTransformCache = /* @__PURE__ */ new Map(), rollupPath = (0, import_utils.resolvePath)("rollup"), rollupNodeMods = rollupPath.slice(0, rollupPath.indexOf(import_node_path.sep + "node_modules"));
111
153
  let config;
112
154
  return [
113
155
  {
@@ -134,7 +176,7 @@ async function createVXRNCompilerPlugin(optionsIn) {
134
176
  if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android") && (0, import_node_path.extname)(id) === ".css") {
135
177
  const code = `require("nativewind/dist/index.js").__require().StyleSheet.registerCompiled(${JSON.stringify(
136
178
  (0, import_css_to_rn.cssToReactNativeRuntime)(codeIn, { inlineRem: 16 })
137
- )})`, newId = `${id}.js`, cssId = newId.replace(rolldownNodeMods + import_node_path.sep, "");
179
+ )})`, newId = `${id}.js`, cssId = newId.replace(rollupNodeMods + import_node_path.sep, "");
138
180
  return cssTransformCache.set(cssId, code), {
139
181
  code,
140
182
  id: newId,
@@ -169,43 +211,49 @@ ${rootJS.code}
169
211
  name: "one:compiler",
170
212
  enforce: "pre",
171
213
  config: () => {
172
- const nodeModulesFilter = /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/, createEnvironmentConfig = (environment) => (perfStats.optimizeDeps.byEnvironment[environment] || (perfStats.optimizeDeps.byEnvironment[environment] = {
173
- filesChecked: 0,
174
- filesTransformed: 0,
175
- startTime: Date.now()
176
- }), {
214
+ const createEnvironmentConfig = (environment) => ({
177
215
  optimizeDeps: {
178
- rolldownOptions: {
216
+ esbuildOptions: {
179
217
  plugins: [
180
218
  {
181
219
  name: `transform-before-optimize-deps-${environment}`,
182
- async transform(code, id) {
183
- if (!nodeModulesFilter.test(id))
184
- return null;
185
- perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
186
- const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
187
- (0, import_constants.debug)?.(`[rolldown optimizeDeps] ${id}`);
188
- const result = await performBabelTransform({
189
- id,
190
- code,
191
- environment,
192
- production,
193
- reactForRNVersion,
194
- optionsIn
220
+ setup(build) {
221
+ perfStats.optimizeDeps.byEnvironment[environment] || (perfStats.optimizeDeps.byEnvironment[environment] = {
222
+ filesChecked: 0,
223
+ filesTransformed: 0,
224
+ startTime: Date.now()
225
+ }), build.onLoad(
226
+ { filter: /node_modules\/.*\.(tsx?|jsx?|mjs|cjs)$/ },
227
+ async (args) => {
228
+ perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
229
+ const production = process.env.NODE_ENV === "production", code = await (0, import_promises.readFile)(args.path, "utf-8");
230
+ (0, import_constants.debug)?.(`[esbuild optimizeDeps] ${args.path}`);
231
+ const result = await performBabelTransform({
232
+ id: args.path,
233
+ code,
234
+ environment,
235
+ production,
236
+ reactForRNVersion,
237
+ optionsIn
238
+ });
239
+ if (!result)
240
+ return null;
241
+ perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
242
+ const ext = (0, import_node_path.extname)(args.path), loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
243
+ return {
244
+ contents: result.code,
245
+ loader
246
+ };
247
+ }
248
+ ), build.onEnd(() => {
249
+ if (process.env.DEBUG_COMPILER_PERF) {
250
+ const stats = perfStats.optimizeDeps.byEnvironment[environment], elapsed = Date.now() - stats.startTime;
251
+ console.info(
252
+ `[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`
253
+ );
254
+ }
255
+ Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2 && ((0, import_cache.logCacheStats)(), logPerfSummary());
195
256
  });
196
- return result ? (perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++, {
197
- code: result.code,
198
- map: result.map
199
- }) : null;
200
- },
201
- buildEnd() {
202
- if (process.env.DEBUG_COMPILER_PERF) {
203
- const stats = perfStats.optimizeDeps.byEnvironment[environment], elapsed = Date.now() - stats.startTime;
204
- console.info(
205
- `[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`
206
- );
207
- }
208
- Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2 && ((0, import_cache.logCacheStats)(), logPerfSummary());
209
257
  }
210
258
  }
211
259
  ]
@@ -231,65 +279,20 @@ ${rootJS.code}
231
279
  },
232
280
  async transform(codeIn, _id) {
233
281
  let code = codeIn;
234
- const environment = getEnvName(this.environment.name), isNative = environment === "ios" || environment === "android", production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(
282
+ const environment = getEnvName(this.environment.name), isNative = environment === "ios" || environment === "android", production = process.env.NODE_ENV === "production" || JSON.parse(
235
283
  this.environment.config?.define?.["process.env.NODE_ENV"] || '""'
236
284
  ) === "production";
237
- if (_id.includes("one-entry-native"))
238
- return isNative && !production && (code = `import '@vxrn/vite-native-client'
285
+ return _id.includes("one-entry-native") ? (isNative && !production && (code = `import '@vxrn/vite-native-client'
239
286
  ${code}`), isNative && import_configure.configuration.enableNativewind && (code = `import * as x from 'nativewind'
240
- ${code}`), code;
241
- const id = _id.split("?")[0], extension = (0, import_node_path.extname)(id);
242
- if (!(extension === ".css" || !import_constants.validParsers.has(extension)) && !id.includes("virtual:")) {
243
- if (codeIn.endsWith("// vxrn-did-babel")) {
244
- (0, import_constants.debug)?.(`[skip babel] ${id}`);
245
- return;
246
- }
247
- return performBabelTransform({
248
- id,
249
- code: codeIn,
250
- environment,
251
- production,
252
- reactForRNVersion,
253
- optionsIn
254
- });
255
- }
256
- }
257
- },
258
- // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept
259
- // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code
260
- {
261
- name: "one:react-refresh-web",
262
- apply: "serve",
263
- transform(code, _id) {
264
- if (this.environment.name !== "client" || code.includes(import_constants.runtimePublicPath)) return;
265
- const id = _id.split("?")[0];
266
- if (id.includes("node_modules") || id.includes("virtual:") || id === import_constants.runtimePublicPath) return;
267
- const ext = (0, import_node_path.extname)(id);
268
- if (ext !== ".tsx" && ext !== ".jsx") return;
269
- const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
270
- let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
271
-
272
- `;
273
- return hasRefreshCalls && (out += `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
274
- const prevRefreshReg = window.$RefreshReg$;
275
- const prevRefreshSig = window.$RefreshSig$;
276
- window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
277
- window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
278
-
279
- `), out += code, hasRefreshCalls && (out += `
280
-
281
- window.$RefreshReg$ = prevRefreshReg;
282
- window.$RefreshSig$ = prevRefreshSig;
283
- `), out += `
284
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
285
- RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
286
- import.meta.hot.accept((nextExports) => {
287
- if (!nextExports) return;
288
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
289
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
290
- });
291
- });
292
- `, { code: out, map: null };
287
+ ${code}`), code) : performFullTransform({
288
+ codeIn,
289
+ _id,
290
+ environment,
291
+ production,
292
+ reactForRNVersion,
293
+ optionsIn,
294
+ mode: config.command
295
+ });
293
296
  }
294
297
  }
295
298
  ];