@vxrn/compiler 1.25.4 → 1.25.5
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/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/transformBabel.test.ts +44 -2
- package/src/transformBabel.ts +2 -7
- package/src/types.ts +1 -0
- package/types/types.d.ts +1 -0
- package/dist/cjs/cache.cjs +0 -132
- package/dist/cjs/configure.cjs +0 -37
- package/dist/cjs/constants.cjs +0 -77
- package/dist/cjs/index.cjs +0 -425
- package/dist/cjs/refresh-runtime.cjs +0 -452
- package/dist/cjs/transformBabel.cjs +0 -271
- package/dist/cjs/transformBabel.test.cjs +0 -19
- package/dist/cjs/transformSWC.cjs +0 -318
- package/dist/cjs/types.cjs +0 -18
- package/dist/esm/cache.mjs +0 -104
- package/dist/esm/cache.mjs.map +0 -1
- package/dist/esm/configure.mjs +0 -11
- package/dist/esm/configure.mjs.map +0 -1
- package/dist/esm/constants.mjs +0 -48
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/index.js +0 -398
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs +0 -398
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/refresh-runtime.mjs +0 -421
- package/dist/esm/refresh-runtime.mjs.map +0 -1
- package/dist/esm/transformBabel.mjs +0 -233
- package/dist/esm/transformBabel.mjs.map +0 -1
- package/dist/esm/transformBabel.test.mjs +0 -20
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformSWC.mjs +0 -292
- package/dist/esm/transformSWC.mjs.map +0 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.mjs.map +0 -1
- package/types/cache.d.ts.map +0 -1
- package/types/configure.d.ts.map +0 -1
- package/types/constants.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/transformBabel.d.ts.map +0 -1
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformSWC.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/compiler",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package.json": "./package.json",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@babel/plugin-transform-react-jsx": "^7.27.1",
|
|
37
37
|
"@babel/plugin-transform-regenerator": "^7.28.4",
|
|
38
38
|
"@react-native/babel-plugin-codegen": "^0.86.2",
|
|
39
|
-
"@vxrn/utils": "1.25.
|
|
40
|
-
"@vxrn/vite-native-client": "1.25.
|
|
39
|
+
"@vxrn/utils": "1.25.5",
|
|
40
|
+
"@vxrn/vite-native-client": "1.25.5",
|
|
41
41
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
42
42
|
"babel-plugin-syntax-hermes-parser": "^0.32.0",
|
|
43
43
|
"oxc-transform-react": "^0.145.0",
|
package/src/index.ts
CHANGED
|
@@ -112,6 +112,7 @@ function logCompiled(cached: boolean, ms: number) {
|
|
|
112
112
|
async function performBabelTransform({
|
|
113
113
|
id,
|
|
114
114
|
code,
|
|
115
|
+
projectRoot,
|
|
115
116
|
environment,
|
|
116
117
|
production,
|
|
117
118
|
reactForRNVersion,
|
|
@@ -119,6 +120,7 @@ async function performBabelTransform({
|
|
|
119
120
|
}: {
|
|
120
121
|
id: string
|
|
121
122
|
code: string
|
|
123
|
+
projectRoot: string
|
|
122
124
|
environment: Environment
|
|
123
125
|
production: boolean
|
|
124
126
|
reactForRNVersion: '18' | '19'
|
|
@@ -134,6 +136,7 @@ async function performBabelTransform({
|
|
|
134
136
|
const transformProps: GetTransformProps = {
|
|
135
137
|
id,
|
|
136
138
|
code,
|
|
139
|
+
projectRoot,
|
|
137
140
|
development: !production,
|
|
138
141
|
environment,
|
|
139
142
|
reactForRNVersion,
|
|
@@ -392,6 +395,7 @@ ${rootJS.code}
|
|
|
392
395
|
const result = await performBabelTransform({
|
|
393
396
|
id,
|
|
394
397
|
code,
|
|
398
|
+
projectRoot: config.root,
|
|
395
399
|
environment,
|
|
396
400
|
production,
|
|
397
401
|
reactForRNVersion,
|
|
@@ -504,6 +508,7 @@ ${rootJS.code}
|
|
|
504
508
|
return performBabelTransform({
|
|
505
509
|
id,
|
|
506
510
|
code: codeIn,
|
|
511
|
+
projectRoot: config.root,
|
|
507
512
|
environment,
|
|
508
513
|
production,
|
|
509
514
|
reactForRNVersion,
|
|
@@ -1,5 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
+
import { configureVXRNCompilerPlugin } from './configure'
|
|
6
|
+
import { getBabelOptions, transformBabel } from './transformBabel'
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
configureVXRNCompilerPlugin({ enableReanimated: false })
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('getBabelOptions Worklets resolution', () => {
|
|
13
|
+
it('uses the app-installed Worklets Babel plugin', () => {
|
|
14
|
+
const projectRoot = fs.realpathSync(
|
|
15
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-worklets-'))
|
|
16
|
+
)
|
|
17
|
+
const packageRoot = path.join(projectRoot, 'node_modules', 'react-native-worklets')
|
|
18
|
+
const pluginPath = path.join(packageRoot, 'plugin.js')
|
|
19
|
+
fs.mkdirSync(packageRoot, { recursive: true })
|
|
20
|
+
fs.writeFileSync(
|
|
21
|
+
path.join(packageRoot, 'package.json'),
|
|
22
|
+
JSON.stringify({ name: 'react-native-worklets', version: '99.0.0' })
|
|
23
|
+
)
|
|
24
|
+
fs.writeFileSync(pluginPath, 'module.exports = () => ({ visitor: {} })')
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
configureVXRNCompilerPlugin({ enableReanimated: true })
|
|
28
|
+
const options = getBabelOptions({
|
|
29
|
+
id: path.join(projectRoot, 'input.ts'),
|
|
30
|
+
code: `export const worklet = () => {
|
|
31
|
+
'worklet'
|
|
32
|
+
}`,
|
|
33
|
+
development: true,
|
|
34
|
+
environment: 'ios',
|
|
35
|
+
reactForRNVersion: '19',
|
|
36
|
+
projectRoot,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
expect(options?.plugins).toContain(pluginPath)
|
|
40
|
+
} finally {
|
|
41
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
})
|
|
3
45
|
|
|
4
46
|
describe('transformBabel Flow parsing', () => {
|
|
5
47
|
it('parses and strips React Native Flow as-casts', async () => {
|
package/src/transformBabel.ts
CHANGED
|
@@ -55,13 +55,8 @@ const getOptions = (props: Props, force = false): babel.TransformOptions | null
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (enableNativewind || shouldBabelReanimated(props)) {
|
|
58
|
-
debug?.(`Using babel
|
|
59
|
-
plugins.push(
|
|
60
|
-
// TODO make this configurable
|
|
61
|
-
process.env.VXRN_WORKLET_PLUGIN
|
|
62
|
-
? 'react-native-worklets/plugin'
|
|
63
|
-
: 'react-native-reanimated/plugin'
|
|
64
|
-
)
|
|
58
|
+
debug?.(`Using babel worklets on file ${props.id}`)
|
|
59
|
+
plugins.push(resolvePath('react-native-worklets/plugin', props.projectRoot))
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
if (shouldBabelReactCompiler(props)) {
|
package/src/types.ts
CHANGED
package/types/types.d.ts
CHANGED
package/dist/cjs/cache.cjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/cjs/configure.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/cjs/constants.cjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
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"]);
|