babel-plugin-reactylon 1.3.2 → 1.3.4
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/.claude/settings.local.json +8 -0
- package/build/ParserUtils.js +9 -2
- package/build/index.js +26 -0
- package/package.json +3 -3
package/build/ParserUtils.js
CHANGED
|
@@ -75,11 +75,18 @@ class ParserUtils {
|
|
|
75
75
|
const rel = path.relative(pkgRoot, fullPath).replace(/\.(js|mjs|ts)$/, '');
|
|
76
76
|
const importPath = path.posix.join(pkgName, rel.split(path.sep).join('/'));
|
|
77
77
|
const { exports, sideEffects } = this.getExportsAndSideEffects(fullPath);
|
|
78
|
+
// After PR #18441 (https://github.com/BabylonJS/Babylon.js/pull/18441), exports and
|
|
79
|
+
// side effects live in .pure files. For both, we map to the wrapper (same name without
|
|
80
|
+
// .pure): the wrapper does `export * from ".pure"` so the export is still accessible,
|
|
81
|
+
// and it calls Register*() so side effects are properly executed. Before the PR no
|
|
82
|
+
// .pure files existed, so this branch is never taken and behaviour is unchanged.
|
|
83
|
+
const resolvedPath = importPath.endsWith('.pure') ? importPath.slice(0, -5) : importPath;
|
|
78
84
|
exports.forEach(exp => {
|
|
79
|
-
exportsMap[exp] =
|
|
85
|
+
exportsMap[exp] = resolvedPath;
|
|
80
86
|
});
|
|
87
|
+
const sideEffectPath = resolvedPath;
|
|
81
88
|
sideEffects.forEach(sideEffect => {
|
|
82
|
-
sideEffectsMap[sideEffect] =
|
|
89
|
+
sideEffectsMap[sideEffect] = sideEffectPath;
|
|
83
90
|
});
|
|
84
91
|
}
|
|
85
92
|
});
|
package/build/index.js
CHANGED
|
@@ -55,10 +55,29 @@ const ROOT_REACTYLON_COMPONENTS = new Set([
|
|
|
55
55
|
const constructorCoreSideEffectsMap = {
|
|
56
56
|
ShadowGenerator: ['@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent']
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Side effects needed implicitly by Babylon itself, so they never appear in user code.
|
|
60
|
+
* - standardMaterial: default material for meshes without one (otherwise they are not rendered)
|
|
61
|
+
* and GetClass("BABYLON.StandardMaterial") in AdvancedDynamicTexture.CreateForMesh.
|
|
62
|
+
* - ray: scene picking used by pointer events (otherwise scene.pick() returns an empty result).
|
|
63
|
+
*/
|
|
64
|
+
const REACTYLON_SCENE_SIDE_EFFECTS = [
|
|
65
|
+
'@babylonjs/core/Materials/standardMaterial',
|
|
66
|
+
'@babylonjs/core/Culling/ray'
|
|
67
|
+
];
|
|
58
68
|
let shouldSkipFile = false;
|
|
59
69
|
function capitalizeFirstLetter(str) {
|
|
60
70
|
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
|
|
61
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* True when the file imports something from Reactylon at runtime (e.g. <Engine>, <Scene>, hooks),
|
|
74
|
+
* so it can build a scene even if all its meshes are created imperatively.
|
|
75
|
+
*/
|
|
76
|
+
function importsReactylon(program) {
|
|
77
|
+
return program.node.body.some(node => t.isImportDeclaration(node) &&
|
|
78
|
+
node.importKind !== 'type' &&
|
|
79
|
+
(node.source.value === 'reactylon' || node.source.value.startsWith('reactylon/')));
|
|
80
|
+
}
|
|
62
81
|
export default declare((api) => {
|
|
63
82
|
api.assertVersion(7);
|
|
64
83
|
return {
|
|
@@ -226,6 +245,13 @@ export default declare((api) => {
|
|
|
226
245
|
}
|
|
227
246
|
});
|
|
228
247
|
const hasJSXReactylon = babylonImportsSpecifiers.size > 0;
|
|
248
|
+
// Every file that renders Reactylon content gets the side effects any scene relies on,
|
|
249
|
+
// so each file keeps working on its own (code splitting, reuse in other apps)
|
|
250
|
+
if (hasJSXReactylon || importsReactylon(path)) {
|
|
251
|
+
for (const sideEffectPath of REACTYLON_SCENE_SIDE_EFFECTS) {
|
|
252
|
+
fileSideEffects.add(sideEffectPath);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
229
255
|
const hasFileSideEffects = fileSideEffects.size > 0;
|
|
230
256
|
if (!hasJSXReactylon && !hasFileSideEffects) {
|
|
231
257
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-reactylon",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Babel plugin to enable tree-shaking of Babylon.js classes within a Reactylon application.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@babel/core": "^7.26.10",
|
|
17
|
-
"@babylonjs/core": "^9",
|
|
18
|
-
"@babylonjs/gui": "^9",
|
|
17
|
+
"@babylonjs/core": "^9.8.0",
|
|
18
|
+
"@babylonjs/gui": "^9.8.0",
|
|
19
19
|
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
20
20
|
"@types/jest": "^29.5.14",
|
|
21
21
|
"@types/node": "^20.1.7",
|