@vxrn/compiler 1.14.4 → 1.15.0
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/cache.cjs +65 -44
- package/dist/cjs/configure.cjs +16 -14
- package/dist/cjs/constants.cjs +55 -53
- package/dist/cjs/index.cjs +217 -136
- package/dist/cjs/refresh-runtime.cjs +284 -125
- package/dist/cjs/transformBabel.cjs +180 -95
- package/dist/cjs/transformSWC.cjs +188 -131
- package/dist/cjs/types.cjs +7 -5
- package/dist/esm/cache.mjs +49 -30
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +4 -4
- package/dist/esm/constants.mjs +43 -43
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +182 -103
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +182 -103
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +272 -115
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +151 -68
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +171 -116
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var transformSWC_exports = {};
|
|
22
24
|
__export(transformSWC_exports, {
|
|
@@ -24,128 +26,169 @@ __export(transformSWC_exports, {
|
|
|
24
26
|
transformSWCStripJSX: () => transformSWCStripJSX
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(transformSWC_exports);
|
|
27
|
-
var import_node_path = require("node:path")
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
var import_node_path = require("node:path");
|
|
30
|
+
var import_core = require("@swc/core");
|
|
31
|
+
var import_ts_deepmerge = require("ts-deepmerge");
|
|
32
|
+
var import_configure = require("./configure.cjs");
|
|
33
|
+
var import_constants = require("./constants.cjs");
|
|
32
34
|
const ignoreId = new RegExp(`node_modules\\${import_node_path.sep}(\\.vite|vite)\\${import_node_path.sep}`);
|
|
33
35
|
async function transformSWC(id, code, options, swcOptions) {
|
|
34
|
-
if (ignoreId.test(id)
|
|
36
|
+
if (ignoreId.test(id)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
id = id.split("?")[0].replace(process.cwd(), "");
|
|
40
|
+
if (id === import_constants.runtimePublicPath) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
35
43
|
const parser = getParser(id, options.forceJSX);
|
|
36
|
-
if (!parser)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
if (!parser) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
|
|
48
|
+
const reactConfig = {
|
|
49
|
+
refresh,
|
|
50
|
+
development: !options.forceJSX && !options.production,
|
|
51
|
+
runtime: "automatic",
|
|
52
|
+
importSource: "react",
|
|
53
|
+
...(import_configure.configuration.enableNativewind && !id.includes("node_modules") ? {
|
|
54
|
+
importSource: "nativewind"
|
|
55
|
+
// pragma: 'createInteropElement',
|
|
56
|
+
// pragmaFrag: '_InteropFragment',
|
|
57
|
+
// swc doesnt actually change the import right
|
|
58
|
+
// runtime: 'classic',
|
|
59
|
+
} : {})
|
|
60
|
+
};
|
|
61
|
+
const transformOptions = (() => {
|
|
62
|
+
if (options.environment === "client" || options.environment === "ssr") {
|
|
63
|
+
return {
|
|
53
64
|
sourceMaps: shouldSourceMap(),
|
|
54
65
|
jsc: {
|
|
55
66
|
target: "es2020",
|
|
56
67
|
parser,
|
|
57
68
|
transform: {
|
|
58
|
-
useDefineForClassFields:
|
|
69
|
+
useDefineForClassFields: true,
|
|
59
70
|
react: reactConfig
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
73
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
}
|
|
75
|
+
const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code);
|
|
76
|
+
const opts = shouldEs5Transform ? {
|
|
77
|
+
jsc: {
|
|
78
|
+
parser,
|
|
79
|
+
target: "es5",
|
|
80
|
+
transform: {
|
|
81
|
+
useDefineForClassFields: true,
|
|
82
|
+
react: reactConfig
|
|
71
83
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
}
|
|
85
|
+
} : {
|
|
86
|
+
...(!options.forceJSX && {
|
|
87
|
+
env: SWC_ENV
|
|
88
|
+
}),
|
|
89
|
+
jsc: {
|
|
90
|
+
...(options.forceJSX && {
|
|
91
|
+
target: "esnext"
|
|
75
92
|
}),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
parser,
|
|
81
|
-
transform: {
|
|
82
|
-
useDefineForClassFields: !0,
|
|
83
|
-
react: reactConfig
|
|
84
|
-
}
|
|
93
|
+
parser,
|
|
94
|
+
transform: {
|
|
95
|
+
useDefineForClassFields: true,
|
|
96
|
+
react: reactConfig
|
|
85
97
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
sourceMaps: shouldSourceMap(),
|
|
102
|
+
module: {
|
|
103
|
+
importInterop: "none",
|
|
104
|
+
type: "nodenext"
|
|
105
|
+
},
|
|
106
|
+
...(options.mode === "serve-cjs" && {
|
|
89
107
|
module: {
|
|
90
108
|
importInterop: "none",
|
|
91
|
-
type: "
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
|
|
118
|
-
match && (e.line = match[1], e.column = match[2]);
|
|
109
|
+
type: "commonjs",
|
|
110
|
+
strict: true
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
...opts
|
|
114
|
+
};
|
|
115
|
+
})();
|
|
116
|
+
const finalOptions = (0, import_ts_deepmerge.merge)({
|
|
117
|
+
filename: id,
|
|
118
|
+
swcrc: false,
|
|
119
|
+
configFile: false,
|
|
120
|
+
...transformOptions
|
|
121
|
+
}, swcOptions || {});
|
|
122
|
+
const result = await (async () => {
|
|
123
|
+
try {
|
|
124
|
+
(0, import_constants.debug)?.(`transformSWC ${id} using options:
|
|
125
|
+
${JSON.stringify(finalOptions, null, 2)}`);
|
|
126
|
+
return await (0, import_core.transform)(code, finalOptions);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
const message = e.message;
|
|
129
|
+
const fileStartIndex = message.indexOf("\u256D\u2500[");
|
|
130
|
+
if (fileStartIndex !== -1) {
|
|
131
|
+
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
|
|
132
|
+
if (match) {
|
|
133
|
+
e.line = match[1];
|
|
134
|
+
e.column = match[2];
|
|
119
135
|
}
|
|
120
|
-
throw e;
|
|
121
136
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
if (import_configure.configuration.enableNativeCSS) {
|
|
141
|
+
if (result.code.includes(`createInteropElement(`)) {
|
|
142
|
+
result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
|
|
143
|
+
${result.code}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
125
146
|
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
|
|
126
147
|
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && parser.syntax === "typescript") {
|
|
127
148
|
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
128
|
-
if (typeExportsMatch)
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
149
|
+
if (typeExportsMatch) {
|
|
150
|
+
for (const typeExport of Array.from(typeExportsMatch)) {
|
|
151
|
+
const [_export, _type, name] = typeExport.split(/\s+/);
|
|
152
|
+
if (name.startsWith("{")) continue;
|
|
153
|
+
if (name.includes("<")) continue;
|
|
154
|
+
const alreadyExported = new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code);
|
|
155
|
+
if (!alreadyExported) {
|
|
156
|
+
const fakeExport = `export let ${name} = {};`;
|
|
157
|
+
console.info(` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`);
|
|
158
|
+
result.code += `
|
|
134
159
|
${fakeExport}
|
|
135
160
|
`;
|
|
161
|
+
}
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
164
|
}
|
|
139
|
-
|
|
165
|
+
if (result && !options.production && !options.noHMR) {
|
|
166
|
+
return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
140
169
|
}
|
|
141
170
|
function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
142
|
-
|
|
171
|
+
if (options.environment === "ssr") {
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
if (options.environment === "client") {
|
|
175
|
+
return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);
|
|
176
|
+
}
|
|
177
|
+
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
|
|
143
178
|
}
|
|
144
179
|
function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
|
|
145
180
|
const sourceMap = result.map ? JSON.parse(result.map) : void 0;
|
|
146
|
-
|
|
181
|
+
if (sourceMap) {
|
|
182
|
+
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
183
|
+
}
|
|
184
|
+
result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
147
185
|
|
|
148
|
-
${result.code}
|
|
186
|
+
${result.code}`;
|
|
187
|
+
if (hasRefreshRuntime) {
|
|
188
|
+
if (sourceMap) {
|
|
189
|
+
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
190
|
+
}
|
|
191
|
+
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
149
192
|
const prevRefreshReg = window.$RefreshReg$;
|
|
150
193
|
const prevRefreshSig = window.$RefreshSig$;
|
|
151
194
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
@@ -155,7 +198,9 @@ ${result.code}
|
|
|
155
198
|
|
|
156
199
|
window.$RefreshReg$ = prevRefreshReg;
|
|
157
200
|
window.$RefreshSig$ = prevRefreshSig;
|
|
158
|
-
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
result.code += `
|
|
159
204
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
160
205
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
161
206
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -164,7 +209,8 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
164
209
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
165
210
|
});
|
|
166
211
|
});
|
|
167
|
-
|
|
212
|
+
`;
|
|
213
|
+
return {
|
|
168
214
|
code: result.code,
|
|
169
215
|
map: sourceMap
|
|
170
216
|
};
|
|
@@ -187,11 +233,10 @@ const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
|
187
233
|
globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
|
|
188
234
|
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
189
235
|
module.url = '${id}'
|
|
190
|
-
module.hot = createHotContext(module.url)
|
|
191
|
-
|
|
236
|
+
module.hot = createHotContext(module.url)`;
|
|
237
|
+
const sourceMap = result.map ? JSON.parse(result.map) : void 0;
|
|
192
238
|
if (sourceMap) {
|
|
193
|
-
const prefixLen = prefixCode.split(
|
|
194
|
-
`).length + 1;
|
|
239
|
+
const prefixLen = prefixCode.split("\n").length + 1;
|
|
195
240
|
sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
|
|
196
241
|
}
|
|
197
242
|
return {
|
|
@@ -209,50 +254,62 @@ ${postfixCode}
|
|
|
209
254
|
map: sourceMap
|
|
210
255
|
};
|
|
211
256
|
}
|
|
212
|
-
|
|
257
|
+
result.code += postfixCode;
|
|
258
|
+
return result;
|
|
213
259
|
}
|
|
214
260
|
const SWC_ENV = {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
},
|
|
218
|
-
// debug: true,
|
|
219
|
-
include: [],
|
|
220
|
-
// this breaks the uniswap app for any file with a ...spread
|
|
221
|
-
exclude: ["transform-spread", "transform-destructuring", "transform-object-rest-spread",
|
|
222
|
-
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
223
|
-
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
224
|
-
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
225
|
-
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
226
|
-
"transform-async-to-generator", "transform-regenerator"
|
|
227
|
-
// Similar to above
|
|
228
|
-
]
|
|
261
|
+
targets: {
|
|
262
|
+
node: "4"
|
|
229
263
|
},
|
|
230
|
-
|
|
264
|
+
// debug: true,
|
|
265
|
+
include: [],
|
|
266
|
+
// this breaks the uniswap app for any file with a ...spread
|
|
267
|
+
exclude: ["transform-spread", "transform-destructuring", "transform-object-rest-spread",
|
|
268
|
+
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
269
|
+
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
270
|
+
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
271
|
+
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
272
|
+
"transform-async-to-generator", "transform-regenerator"
|
|
273
|
+
// Similar to above
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
231
277
|
function shouldSourceMap() {
|
|
232
278
|
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
233
279
|
}
|
|
234
|
-
function getParser(id, forceJSX =
|
|
235
|
-
if (id.endsWith("one-entry-native"))
|
|
280
|
+
function getParser(id, forceJSX = false) {
|
|
281
|
+
if (id.endsWith("one-entry-native")) {
|
|
282
|
+
return import_constants.parsers[".tsx"];
|
|
283
|
+
}
|
|
236
284
|
const extension = (0, import_node_path.extname)(id);
|
|
237
|
-
let parser = extension ? import_constants.parsers[
|
|
238
|
-
|
|
285
|
+
let parser = !extension ? import_constants.parsers[".js"] : import_constants.parsers[extension];
|
|
286
|
+
if (extension === ".js" || extension === ".mjs") {
|
|
287
|
+
if (forceJSX) {
|
|
288
|
+
parser = import_constants.parsers[".jsx"];
|
|
289
|
+
}
|
|
290
|
+
if (id.includes("expo-modules-core")) {
|
|
291
|
+
parser = import_constants.parsers[".jsx"];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return parser;
|
|
239
295
|
}
|
|
240
296
|
const transformSWCStripJSX = async (id, code) => {
|
|
241
297
|
const parser = getParser(id);
|
|
242
|
-
if (parser) return
|
|
298
|
+
if (!parser) return;
|
|
299
|
+
return await (0, import_core.transform)(code, {
|
|
243
300
|
filename: id,
|
|
244
|
-
swcrc:
|
|
245
|
-
configFile:
|
|
301
|
+
swcrc: false,
|
|
302
|
+
configFile: false,
|
|
246
303
|
sourceMaps: shouldSourceMap(),
|
|
247
304
|
jsc: {
|
|
248
305
|
target: "es2019",
|
|
249
306
|
parser,
|
|
250
307
|
transform: {
|
|
251
|
-
useDefineForClassFields:
|
|
308
|
+
useDefineForClassFields: true,
|
|
252
309
|
react: {
|
|
253
|
-
development:
|
|
310
|
+
development: true,
|
|
254
311
|
runtime: "automatic",
|
|
255
|
-
refresh:
|
|
312
|
+
refresh: false
|
|
256
313
|
}
|
|
257
314
|
}
|
|
258
315
|
}
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -3,14 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
10
12
|
return to;
|
|
11
13
|
};
|
|
12
14
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
-
value:
|
|
15
|
+
value: true
|
|
14
16
|
}), mod);
|
|
15
17
|
var types_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(types_exports);
|
package/dist/esm/cache.mjs
CHANGED
|
@@ -9,9 +9,12 @@ const stats = {
|
|
|
9
9
|
};
|
|
10
10
|
function getCacheDir() {
|
|
11
11
|
const cacheDir = join(process.cwd(), "node_modules", ".vxrn", "compiler-cache");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (!existsSync(cacheDir)) {
|
|
13
|
+
mkdirSync(cacheDir, {
|
|
14
|
+
recursive: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return cacheDir;
|
|
15
18
|
}
|
|
16
19
|
function getConfigFingerprint() {
|
|
17
20
|
return createHash("sha1").update(JSON.stringify({
|
|
@@ -22,45 +25,59 @@ function getConfigFingerprint() {
|
|
|
22
25
|
})).digest("hex").slice(0, 8);
|
|
23
26
|
}
|
|
24
27
|
function getCacheKey(filePath, environment) {
|
|
25
|
-
|
|
28
|
+
const hash = createHash("sha1").update(`${environment}:${filePath}:${getConfigFingerprint()}`).digest("hex");
|
|
29
|
+
return hash;
|
|
26
30
|
}
|
|
27
31
|
function getContentHash(code) {
|
|
28
32
|
return createHash("sha1").update(code).digest("hex").slice(0, 16);
|
|
29
33
|
}
|
|
30
34
|
function getCachedTransform(filePath, code, environment) {
|
|
31
35
|
try {
|
|
32
|
-
const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!existsSync(cachePath))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath;
|
|
37
|
+
const cacheDir = getCacheDir();
|
|
38
|
+
const cacheKey = getCacheKey(cleanPath, environment);
|
|
39
|
+
const cachePath = join(cacheDir, `${cacheKey}.json`);
|
|
40
|
+
if (!existsSync(cachePath)) {
|
|
41
|
+
stats.misses++;
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const cached = JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
45
|
+
const currentMtime = statSync(cleanPath).mtimeMs;
|
|
46
|
+
if (cached.mtime !== currentMtime) {
|
|
47
|
+
stats.misses++;
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
40
50
|
const currentHash = getContentHash(code);
|
|
41
|
-
|
|
51
|
+
if (cached.hash !== currentHash) {
|
|
52
|
+
stats.misses++;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
stats.hits++;
|
|
56
|
+
return {
|
|
42
57
|
code: cached.code,
|
|
43
58
|
map: cached.map
|
|
44
|
-
}
|
|
45
|
-
} catch {
|
|
46
|
-
|
|
59
|
+
};
|
|
60
|
+
} catch (err) {
|
|
61
|
+
stats.misses++;
|
|
62
|
+
return null;
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
function setCachedTransform(filePath, code, result, environment) {
|
|
50
66
|
try {
|
|
51
|
-
const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
writeFileSync(cachePath, JSON.stringify(entry), "utf-8")
|
|
67
|
+
const cleanPath = filePath.startsWith("\0") ? filePath.slice(1) : filePath;
|
|
68
|
+
const cacheDir = getCacheDir();
|
|
69
|
+
const cacheKey = getCacheKey(cleanPath, environment);
|
|
70
|
+
const cachePath = join(cacheDir, `${cacheKey}.json`);
|
|
71
|
+
const mtime = statSync(cleanPath).mtimeMs;
|
|
72
|
+
const hash = getContentHash(code);
|
|
73
|
+
const entry = {
|
|
74
|
+
mtime,
|
|
75
|
+
hash,
|
|
76
|
+
code: result.code,
|
|
77
|
+
map: result.map
|
|
78
|
+
};
|
|
79
|
+
writeFileSync(cachePath, JSON.stringify(entry), "utf-8");
|
|
80
|
+
stats.writes++;
|
|
64
81
|
} catch (err) {
|
|
65
82
|
console.warn(`[cache] Failed to write cache for ${filePath}:`, err);
|
|
66
83
|
}
|
|
@@ -71,7 +88,9 @@ function getCacheStats() {
|
|
|
71
88
|
};
|
|
72
89
|
}
|
|
73
90
|
function logCacheStats() {
|
|
74
|
-
if (!process.env.DEBUG_COMPILER_PERF)
|
|
91
|
+
if (!process.env.DEBUG_COMPILER_PERF) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
75
94
|
const total = stats.hits + stats.misses;
|
|
76
95
|
if (total === 0) return;
|
|
77
96
|
const hitRate = (stats.hits / total * 100).toFixed(1);
|
package/dist/esm/cache.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHash","existsSync","mkdirSync","readFileSync","statSync","writeFileSync","join","configuration","stats","hits","misses","writes","getCacheDir","cacheDir","process","cwd","recursive","getConfigFingerprint","update","JSON","stringify","compiler","enableCompiler","reanimated","enableReanimated","nativewind","enableNativewind","nativeCSS","enableNativeCSS","digest","slice","getCacheKey","filePath","environment","getContentHash","code","getCachedTransform","cleanPath","startsWith","cacheKey","cachePath","cached","parse","currentMtime","mtimeMs","mtime","currentHash","
|
|
1
|
+
{"version":3,"names":["createHash","existsSync","mkdirSync","readFileSync","statSync","writeFileSync","join","configuration","stats","hits","misses","writes","getCacheDir","cacheDir","process","cwd","recursive","getConfigFingerprint","update","JSON","stringify","compiler","enableCompiler","reanimated","enableReanimated","nativewind","enableNativewind","nativeCSS","enableNativeCSS","digest","slice","getCacheKey","filePath","environment","hash","getContentHash","code","getCachedTransform","cleanPath","startsWith","cacheKey","cachePath","cached","parse","currentMtime","mtimeMs","mtime","currentHash","map","err","setCachedTransform","result","entry","console","warn","getCacheStats","logCacheStats","env","DEBUG_COMPILER_PERF","total","hitRate","toFixed","info"],"sources":["../../src/cache.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,UAAA,EAAYC,SAAA,EAAWC,YAAA,EAAcC,QAAA,EAAUC,aAAA,QAAqB;AAC7E,SAASC,IAAA,QAAY;AACrB,SAASC,aAAA,QAAqB;AAwB9B,MAAMC,KAAA,GAAoB;EAAEC,IAAA,EAAM;EAAGC,MAAA,EAAQ;EAAGC,MAAA,EAAQ;AAAE;AAE1D,SAASC,YAAA,EAAsB;EAE7B,MAAMC,QAAA,GAAWP,IAAA,CAAKQ,OAAA,CAAQC,GAAA,CAAI,GAAG,gBAAgB,SAAS,gBAAgB;EAC9E,IAAI,CAACd,UAAA,CAAWY,QAAQ,GAAG;IACzBX,SAAA,CAAUW,QAAA,EAAU;MAAEG,SAAA,EAAW;IAAK,CAAC;EACzC;EACA,OAAOH,QAAA;AACT;AAGA,SAASI,qBAAA,EAA+B;EACtC,OAAOjB,UAAA,CAAW,MAAM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AqCtB,QAAQ,KAAKiB,GAAG;EACpE;AACF;AAEO,SAASM,cAAA,EAA4B;EAC1C,OAAO;IAAE,GAAG/C;EAAM;AACpB;AAEO,SAASgD,cAAA,EAAsB;EAEpC,IAAI,CAAC1C,OAAA,CAAQ2C,GAAA,CAAIC,mBAAA,EAAqB;IACpC;EACF;EAEA,MAAMC,KAAA,GAAQnD,KAAA,CAAMC,IAAA,GAAOD,KAAA,CAAME,MAAA;EACjC,IAAIiD,KAAA,KAAU,GAAG;EAEjB,MAAMC,OAAA,IAAYpD,KAAA,CAAMC,IAAA,GAAOkD,KAAA,GAAS,KAAKE,OAAA,CAAQ,CAAC;EACtDR,OAAA,CAAQS,IAAA,CACN;AAAA,0BAAsBtD,KAAA,CAAMC,IAAI,WAAWD,KAAA,CAAME,MAAM,YAAYkD,OAAO,gBAAgBpD,KAAA,CAAMG,MAAM,SACxG;AACF","ignoreList":[]}
|
package/dist/esm/configure.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const configuration = {
|
|
2
|
-
enableNativewind:
|
|
3
|
-
enableReanimated:
|
|
4
|
-
enableCompiler:
|
|
5
|
-
enableNativeCSS:
|
|
2
|
+
enableNativewind: false,
|
|
3
|
+
enableReanimated: false,
|
|
4
|
+
enableCompiler: false,
|
|
5
|
+
enableNativeCSS: false
|
|
6
6
|
};
|
|
7
7
|
function configureVXRNCompilerPlugin(_) {
|
|
8
8
|
Object.assign(configuration, _);
|