@gfean/react-native-bundle-drop 0.1.36 → 0.1.38

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/lib/CLI/cli.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const commander_1 = require("commander");
9
9
  const figures_1 = __importDefault(require("figures"));
10
+ const prompts_1 = __importDefault(require("prompts"));
10
11
  const upload_cli_1 = __importDefault(require("./scripts/upload-cli"));
11
12
  const package_json_1 = __importDefault(require("../../package.json"));
12
13
  const program = new commander_1.Command();
@@ -68,7 +69,7 @@ program
68
69
  program
69
70
  .command('init')
70
71
  .description('Generate bundle.drop.config.js from your logged-in account context')
71
- .action(() => {
72
+ .action(async () => {
72
73
  //eslint-disable-next-line
73
74
  const fs = require('fs');
74
75
  //eslint-disable-next-line
@@ -91,6 +92,39 @@ program
91
92
  organizations,
92
93
  downloadApiKey,
93
94
  });
95
+ // Offer to set up Metro alias for bundle.drop.config.js resolution
96
+ const { runMetro } = await (0, prompts_1.default)({
97
+ type: 'confirm',
98
+ name: 'runMetro',
99
+ message: 'Also add the Metro alias for bundle.drop.config.js (recommended)?',
100
+ initial: true,
101
+ });
102
+ if (runMetro) {
103
+ try {
104
+ //eslint-disable-next-line
105
+ await require('../CLI/scripts/init-metro-config').initMetroConfig();
106
+ }
107
+ catch (err) {
108
+ console.log(`⚠️ Failed to initialize Metro config; please refer to manual setup instructions. (${err?.message || err})`);
109
+ }
110
+ }
111
+ // Offer to patch native entrypoints
112
+ const { runNative } = await (0, prompts_1.default)({
113
+ type: 'confirm',
114
+ name: 'runNative',
115
+ message: 'Patch native entrypoints (MainApplication/AppDelegate) to prefer OTA? (Standard RN setups only)',
116
+ initial: false,
117
+ });
118
+ if (runNative) {
119
+ try {
120
+ //eslint-disable-next-line
121
+ await require('../CLI/scripts/init-native-config').initNativeConfig();
122
+ console.log('⚠️ Please double-check the native changes in MainApplication/AppDelegate.');
123
+ }
124
+ catch (err) {
125
+ console.log(`⚠️ Failed to initialize native config; please refer to manual setup instructions. (${err?.message || err})`);
126
+ }
127
+ }
94
128
  });
95
129
  program
96
130
  .command('init-native')
@@ -99,6 +133,13 @@ program
99
133
  //eslint-disable-next-line
100
134
  require('../CLI/scripts/init-native-config').initNativeConfig();
101
135
  });
136
+ program
137
+ .command('init-metro')
138
+ .description('Ensure Metro can resolve bundle.drop.config.js via extraNodeModules alias')
139
+ .action(() => {
140
+ //eslint-disable-next-line
141
+ require('../CLI/scripts/init-metro-config').initMetroConfig();
142
+ });
102
143
  program
103
144
  .command('whoami')
104
145
  .description('Show currently logged in user')
@@ -0,0 +1,2 @@
1
+ export declare function initMetroConfig(): Promise<void>;
2
+ export default initMetroConfig;
@@ -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;
@@ -56,7 +56,7 @@ function patchAndroidMainApplication(filePath) {
56
56
  }
57
57
  content = content.replace(methodRegex, match => {
58
58
  return (match +
59
- ` val bundlePath = BundleDropModule.getDownloadedBundlePath(this)\n` +
59
+ ` val bundlePath = BundleDropModule.getDownloadedBundlePath(application)\n` +
60
60
  ` if (bundlePath != null) {\n` +
61
61
  ` return bundlePath\n` +
62
62
  ` }\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "react native ota by gFean",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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
- })();