babel-plugin-reactylon 1.1.0 → 1.2.0-alpha.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/build/ParserUtils.js +18 -8
- package/build/index.js +3 -4
- package/package.json +1 -1
package/build/ParserUtils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
3
4
|
class ParserUtils {
|
|
4
5
|
/**
|
|
5
6
|
* It extracts exports and side effects from a file
|
|
@@ -60,16 +61,19 @@ class ParserUtils {
|
|
|
60
61
|
* @param dir - directory to scan
|
|
61
62
|
* @param exportsMap - exports map to populate
|
|
62
63
|
* @param sideEffectsMap - side effects map to populate
|
|
64
|
+
* @param pkgRoot - package root (real path or symlinked path if the consumer is using npm/yarn link)
|
|
65
|
+
* @param pkgName - package name (es. "@babylonjs/core")
|
|
63
66
|
*/
|
|
64
|
-
static scanDirectory(dir, exportsMap, sideEffectsMap) {
|
|
67
|
+
static scanDirectory(dir, exportsMap, sideEffectsMap, pkgRoot, pkgName) {
|
|
65
68
|
const files = fs.readdirSync(dir);
|
|
66
69
|
files.forEach(file => {
|
|
67
70
|
const fullPath = path.join(dir, file);
|
|
68
71
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
69
|
-
this.scanDirectory(fullPath, exportsMap, sideEffectsMap);
|
|
72
|
+
this.scanDirectory(fullPath, exportsMap, sideEffectsMap, pkgRoot, pkgName);
|
|
70
73
|
}
|
|
71
74
|
else if (file.endsWith('.js') || file.endsWith('.mjs') || file.endsWith('.ts')) {
|
|
72
|
-
const
|
|
75
|
+
const rel = path.relative(pkgRoot, fullPath).replace(/\.(js|mjs|ts)$/, '');
|
|
76
|
+
const importPath = path.posix.join(pkgName, rel.split(path.sep).join('/'));
|
|
73
77
|
const { exports, sideEffects } = this.getExportsAndSideEffects(fullPath);
|
|
74
78
|
exports.forEach(exp => {
|
|
75
79
|
exportsMap[exp] = importPath;
|
|
@@ -85,14 +89,20 @@ class ParserUtils {
|
|
|
85
89
|
* @param moduleName - module name to analyze
|
|
86
90
|
* @returns an object containing the discovered exports and side effects maps
|
|
87
91
|
*/
|
|
88
|
-
static generateExportsAndSideEffects(moduleName
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
static generateExportsAndSideEffects(moduleName) {
|
|
93
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
94
|
+
let pkgJsonPath;
|
|
95
|
+
try {
|
|
96
|
+
pkgJsonPath = requireFromHere.resolve(`${moduleName}/package.json`);
|
|
92
97
|
}
|
|
98
|
+
catch (_a) {
|
|
99
|
+
console.error(`The module "${moduleName}" doesn't exist or cannot be resolved.`);
|
|
100
|
+
return { exports: {}, sideEffects: {} };
|
|
101
|
+
}
|
|
102
|
+
const modulePath = path.dirname(pkgJsonPath);
|
|
93
103
|
const exportsMap = {};
|
|
94
104
|
const sideEffectsMap = {};
|
|
95
|
-
this.scanDirectory(modulePath, exportsMap, sideEffectsMap);
|
|
105
|
+
this.scanDirectory(modulePath, exportsMap, sideEffectsMap, modulePath, moduleName);
|
|
96
106
|
return {
|
|
97
107
|
exports: exportsMap,
|
|
98
108
|
sideEffects: sideEffectsMap
|
package/build/index.js
CHANGED
|
@@ -23,11 +23,10 @@ export default declare((api) => {
|
|
|
23
23
|
var _a;
|
|
24
24
|
if (!initialized) {
|
|
25
25
|
const options = this.opts;
|
|
26
|
-
const
|
|
27
|
-
const coreExportsAndSideEffects = ParserUtils.generateExportsAndSideEffects('@babylonjs/core', nodeModulesPath);
|
|
26
|
+
const coreExportsAndSideEffects = ParserUtils.generateExportsAndSideEffects('@babylonjs/core');
|
|
28
27
|
coreExportsMap = coreExportsAndSideEffects.exports;
|
|
29
28
|
coreSideEffectsMap = coreExportsAndSideEffects.sideEffects;
|
|
30
|
-
const guiExportsAndSideEffects = ParserUtils.generateExportsAndSideEffects('@babylonjs/gui'
|
|
29
|
+
const guiExportsAndSideEffects = ParserUtils.generateExportsAndSideEffects('@babylonjs/gui');
|
|
31
30
|
guiExportsMap = guiExportsAndSideEffects.exports;
|
|
32
31
|
//guiSideEffectsMap = guiExportsAndSideEffects.sideEffects;
|
|
33
32
|
// Add explicit side effects (additional side effects declared by user)
|
|
@@ -167,7 +166,7 @@ export default declare((api) => {
|
|
|
167
166
|
const property = callee.property;
|
|
168
167
|
if (t.isIdentifier(property)) {
|
|
169
168
|
const sideEffectPath = coreSideEffectsMap[property.name];
|
|
170
|
-
// exclude assets folder
|
|
169
|
+
// exclude assets folder containing .wasm and relative .js files
|
|
171
170
|
if (sideEffectPath && !sideEffectPath.startsWith('@babylonjs/core/assets/')) {
|
|
172
171
|
sideEffects.push(t.importDeclaration([], t.stringLiteral(sideEffectPath)));
|
|
173
172
|
// callPath.stop();
|
package/package.json
CHANGED