@gfean/react-native-bundle-drop 0.1.35 → 0.1.37
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/CLIENT_README.md +16 -0
- package/README.md +16 -0
- package/lib/CLI/cli.js +7 -0
- package/lib/CLI/scripts/init-metro-config.d.ts +2 -0
- package/lib/CLI/scripts/init-metro-config.js +66 -0
- package/lib/loadConfig.js +4 -9
- package/package.json +1 -1
- package/lib/bootstrap.d.ts +0 -1
- package/lib/bootstrap.js +0 -13
package/CLIENT_README.md
CHANGED
|
@@ -14,6 +14,22 @@ Add the Android bootstrap side-effect import (resolver patches):
|
|
|
14
14
|
import '@gfean/react-native-bundle-drop/bootstrap';
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
### Metro config (resolve bundle.drop.config.js from node_modules)
|
|
18
|
+
If Metro can’t find `bundle.drop.config.js` when a package requires it, add an alias:
|
|
19
|
+
```js
|
|
20
|
+
// metro.config.js
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
resolver: {
|
|
25
|
+
extraNodeModules: {
|
|
26
|
+
// Lets packages do: require('bundle-drop-config')
|
|
27
|
+
'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
17
33
|
## 2) App config
|
|
18
34
|
Add `bundle.drop.config.js` to your project root:
|
|
19
35
|
```js
|
package/README.md
CHANGED
|
@@ -14,6 +14,22 @@ Add the Android bootstrap side-effect import once (images resolver patch):
|
|
|
14
14
|
import '@gfean/react-native-bundle-drop/bootstrap';
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
### Metro config (to resolve bundle.drop.config.js from node_modules)
|
|
18
|
+
If Metro cannot resolve `bundle.drop.config.js` from within `node_modules`, add an alias in `metro.config.js`:
|
|
19
|
+
```js
|
|
20
|
+
// metro.config.js
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
resolver: {
|
|
25
|
+
extraNodeModules: {
|
|
26
|
+
// Allows packages to do: require('bundle-drop-config')
|
|
27
|
+
'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
17
33
|
## Prerequisites
|
|
18
34
|
- `bundle.drop.config.js` in your app root:
|
|
19
35
|
```js
|
package/lib/CLI/cli.js
CHANGED
|
@@ -99,6 +99,13 @@ program
|
|
|
99
99
|
//eslint-disable-next-line
|
|
100
100
|
require('../CLI/scripts/init-native-config').initNativeConfig();
|
|
101
101
|
});
|
|
102
|
+
program
|
|
103
|
+
.command('init-metro')
|
|
104
|
+
.description('Ensure Metro can resolve bundle.drop.config.js via extraNodeModules alias')
|
|
105
|
+
.action(() => {
|
|
106
|
+
//eslint-disable-next-line
|
|
107
|
+
require('../CLI/scripts/init-metro-config').initMetroConfig();
|
|
108
|
+
});
|
|
102
109
|
program
|
|
103
110
|
.command('whoami')
|
|
104
111
|
.description('Show currently logged in user')
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initMetroConfig = initMetroConfig;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function findProjectRoot(startDir) {
|
|
11
|
+
let dir = path_1.default.resolve(startDir);
|
|
12
|
+
const MAX_UP = 12;
|
|
13
|
+
for (let i = 0; i < MAX_UP; i++) {
|
|
14
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
const parent = path_1.default.dirname(dir);
|
|
18
|
+
if (parent === dir)
|
|
19
|
+
break;
|
|
20
|
+
dir = parent;
|
|
21
|
+
}
|
|
22
|
+
return startDir;
|
|
23
|
+
}
|
|
24
|
+
const APPEND_SNIPPET = `
|
|
25
|
+
// Bundle Drop: ensure bundle.drop.config.js is resolvable from node_modules
|
|
26
|
+
(() => {
|
|
27
|
+
const path = require('path');
|
|
28
|
+
module.exports = module.exports || {};
|
|
29
|
+
module.exports.resolver = module.exports.resolver || {};
|
|
30
|
+
module.exports.resolver.extraNodeModules = {
|
|
31
|
+
...(module.exports.resolver.extraNodeModules || {}),
|
|
32
|
+
'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
`;
|
|
36
|
+
const NEW_METRO_TEMPLATE = `const path = require('path');
|
|
37
|
+
const { getDefaultConfig } = require('@react-native/metro-config');
|
|
38
|
+
|
|
39
|
+
const config = getDefaultConfig(__dirname);
|
|
40
|
+
config.resolver = config.resolver || {};
|
|
41
|
+
config.resolver.extraNodeModules = {
|
|
42
|
+
...(config.resolver.extraNodeModules || {}),
|
|
43
|
+
'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports = config;
|
|
47
|
+
${APPEND_SNIPPET}
|
|
48
|
+
`;
|
|
49
|
+
async function initMetroConfig() {
|
|
50
|
+
const projectRoot = findProjectRoot(process.cwd());
|
|
51
|
+
const metroPath = path_1.default.join(projectRoot, 'metro.config.js');
|
|
52
|
+
if (!fs_extra_1.default.existsSync(metroPath)) {
|
|
53
|
+
fs_extra_1.default.writeFileSync(metroPath, NEW_METRO_TEMPLATE.trim() + '\n', 'utf8');
|
|
54
|
+
console.log(chalk_1.default.green(`✅ Created metro.config.js with Bundle Drop alias at ${metroPath}`));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const content = fs_extra_1.default.readFileSync(metroPath, 'utf8');
|
|
58
|
+
if (content.includes('bundle-drop-config')) {
|
|
59
|
+
console.log(chalk_1.default.gray('ℹ️ metro.config.js already contains bundle-drop-config alias.'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const updated = `${content.trim()}\n${APPEND_SNIPPET}`;
|
|
63
|
+
fs_extra_1.default.writeFileSync(metroPath, updated, 'utf8');
|
|
64
|
+
console.log(chalk_1.default.green(`✅ Added bundle-drop-config alias to metro.config.js`));
|
|
65
|
+
}
|
|
66
|
+
exports.default = initMetroConfig;
|
package/lib/loadConfig.js
CHANGED
|
@@ -2,19 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadConfig = loadConfig;
|
|
4
4
|
const react_native_1 = require("react-native");
|
|
5
|
-
// Simpler, fixed path load to match the prior behavior.
|
|
6
5
|
function loadConfig() {
|
|
7
6
|
try {
|
|
8
|
-
//
|
|
9
|
-
// node_modules/@gfean/react-native-bundle-drop/lib/loadConfig.js
|
|
10
|
-
// so we walk four levels up to the app root.
|
|
7
|
+
// ✅ Resolved via Metro alias in the host app (extraNodeModules)
|
|
11
8
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
12
|
-
const cfg = require('
|
|
9
|
+
const cfg = require('bundle-drop-config');
|
|
13
10
|
if (!cfg?.serverUrl || !cfg?.project?.slug || !cfg?.org?.slug) {
|
|
14
11
|
throw new Error('bundle.drop.config.js missing serverUrl, org.slug or project.slug');
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
if (debugLocal) {
|
|
13
|
+
if (cfg.debugLocal === true) {
|
|
18
14
|
return {
|
|
19
15
|
...cfg,
|
|
20
16
|
serverUrl: react_native_1.Platform.OS === 'android' ? 'http://10.0.2.2:4000' : 'http://localhost:4000',
|
|
@@ -24,8 +20,7 @@ function loadConfig() {
|
|
|
24
20
|
return cfg;
|
|
25
21
|
}
|
|
26
22
|
catch (e) {
|
|
27
|
-
console.log(e);
|
|
28
|
-
// In production this should fail fast; for now return localhost defaults.
|
|
23
|
+
console.log('[BundleDrop] loadConfig failed:', e);
|
|
29
24
|
return {
|
|
30
25
|
serverUrl: 'http://localhost:4000',
|
|
31
26
|
org: { slug: 'default-org' },
|
package/package.json
CHANGED
package/lib/bootstrap.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/bootstrap.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_native_1 = require("react-native");
|
|
4
|
-
const injectImageResolver_1 = require("./injectImageResolver");
|
|
5
|
-
const patchImageAutoResolve_1 = require("./patchImageAutoResolve");
|
|
6
|
-
(() => {
|
|
7
|
-
if (react_native_1.Platform.OS !== 'android') {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
// Apply the shared resolver/renderer patches early during app startup.
|
|
11
|
-
(0, injectImageResolver_1.injectBundleDropImageResolver)();
|
|
12
|
-
(0, patchImageAutoResolve_1.patchImageRenderToForceResolve)();
|
|
13
|
-
})();
|