@gfean/react-native-bundle-drop 0.6.0 → 0.8.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.
Files changed (86) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +249 -9
  3. package/android/build.gradle +72 -5
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +137 -13
  5. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  8. package/ios/BundleDropBridge.m +27 -0
  9. package/ios/BundleDropLocator.swift +31 -15
  10. package/ios/BundleDropModule.swift +106 -3
  11. package/ios/BundleDropOtaResolver.swift +137 -29
  12. package/ios/BundleDropStartupRecovery.swift +1108 -0
  13. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  14. package/lib/CLI/cli.js +9 -5
  15. package/lib/CLI/scripts/doctor.js +28 -9
  16. package/lib/CLI/scripts/expo/configure-expo.js +2 -1
  17. package/lib/CLI/scripts/init-config.d.ts +2 -2
  18. package/lib/CLI/scripts/init-config.js +23 -14
  19. package/lib/CLI/scripts/login-cli.js +2 -3
  20. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  21. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  22. package/lib/CLI/scripts/sight-artifacts.d.ts +9 -1
  23. package/lib/CLI/scripts/sight-artifacts.js +20 -8
  24. package/lib/CLI/scripts/sight-assets.d.ts +15 -0
  25. package/lib/CLI/scripts/sight-assets.js +71 -0
  26. package/lib/CLI/scripts/sight-cli.d.ts +3 -0
  27. package/lib/CLI/scripts/sight-cli.js +50 -4
  28. package/lib/CLI/scripts/sight-compare/assets.d.ts +6 -0
  29. package/lib/CLI/scripts/sight-compare/assets.js +73 -0
  30. package/lib/CLI/scripts/sight-compare/dependencies.d.ts +22 -0
  31. package/lib/CLI/scripts/sight-compare/dependencies.js +289 -0
  32. package/lib/CLI/scripts/sight-compare/git.d.ts +22 -0
  33. package/lib/CLI/scripts/sight-compare/git.js +116 -0
  34. package/lib/CLI/scripts/sight-compare/inspect-project.d.ts +37 -0
  35. package/lib/CLI/scripts/sight-compare/inspect-project.js +191 -0
  36. package/lib/CLI/scripts/sight-compare/metadata.d.ts +4 -0
  37. package/lib/CLI/scripts/sight-compare/metadata.js +39 -0
  38. package/lib/CLI/scripts/sight-compare/process.d.ts +22 -0
  39. package/lib/CLI/scripts/sight-compare/process.js +221 -0
  40. package/lib/CLI/scripts/sight-compare/run.d.ts +3 -0
  41. package/lib/CLI/scripts/sight-compare/run.js +290 -0
  42. package/lib/CLI/scripts/sight-compare/snapshot.d.ts +26 -0
  43. package/lib/CLI/scripts/sight-compare/snapshot.js +279 -0
  44. package/lib/CLI/scripts/sight-compare/types.d.ts +87 -0
  45. package/lib/CLI/scripts/sight-compare/types.js +2 -0
  46. package/lib/CLI/scripts/sight-ota.d.ts +18 -0
  47. package/lib/CLI/scripts/sight-ota.js +260 -0
  48. package/lib/CLI/scripts/sight-session.d.ts +9 -2
  49. package/lib/CLI/scripts/sight-session.js +58 -20
  50. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  51. package/lib/CLI/scripts/upload-cli.js +74 -11
  52. package/lib/CLI/serverUrl.d.ts +3 -0
  53. package/lib/CLI/serverUrl.js +31 -0
  54. package/lib/bundleInfo.d.ts +2 -0
  55. package/lib/bundleInfo.js +16 -1
  56. package/lib/context.js +12 -2
  57. package/lib/fs/bundlePointer.d.ts +1 -17
  58. package/lib/fs/bundlePointer.js +5 -93
  59. package/lib/install/bundleInstallShared.js +4 -4
  60. package/lib/manager/downloadAndInstall.js +25 -22
  61. package/lib/manager/reporting.d.ts +8 -1
  62. package/lib/manager/reporting.js +17 -22
  63. package/lib/manager/rollbackState.d.ts +18 -54
  64. package/lib/manager/rollbackState.js +115 -216
  65. package/lib/manager/updateCheck.js +9 -3
  66. package/lib/manager/updateState.d.ts +2 -1
  67. package/lib/manager/updateState.js +59 -6
  68. package/lib/metro.d.ts +1 -1
  69. package/lib/metro.js +4 -3
  70. package/lib/native/bundleDropNative.d.ts +62 -0
  71. package/lib/native/bundleDropNative.js +266 -1
  72. package/lib/patch-engine/installFromPatchSet.js +2 -2
  73. package/lib/runtime/service.js +29 -71
  74. package/lib/runtime-delivery/bootstrapConfig.d.ts +29 -11
  75. package/lib/runtime-delivery/bootstrapConfig.js +83 -22
  76. package/lib/runtime-delivery/manifestState.d.ts +3 -1
  77. package/lib/runtime-delivery/manifestState.js +22 -1
  78. package/lib/runtime-delivery/manifestVerifier.js +7 -1
  79. package/lib/scripts/bundle.d.ts +12 -2
  80. package/lib/scripts/bundle.js +74 -21
  81. package/lib/scripts/download-bundle.d.ts +1 -0
  82. package/lib/scripts/download-bundle.js +2 -2
  83. package/lib/scripts/resolveModule.d.ts +2 -0
  84. package/lib/scripts/resolveModule.js +5 -0
  85. package/package.json +5 -2
  86. package/plugin/xcodeBuildPhase.js +2 -1
@@ -0,0 +1,92 @@
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.resolveNativeRuntimeIdentity = resolveNativeRuntimeIdentity;
7
+ exports.writeNativeRuntimeIdentity = writeNativeRuntimeIdentity;
8
+ exports.parseNativeRuntimeIdentityArguments = parseNativeRuntimeIdentityArguments;
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const expo_1 = require("../../../expo");
12
+ function resolveNativeRuntimeIdentity(projectRoot, platform) {
13
+ const authority = (0, expo_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform);
14
+ if (authority.source === 'expo') {
15
+ return { schemaVersion: 1, platform, source: 'expo' };
16
+ }
17
+ return {
18
+ schemaVersion: 1,
19
+ platform,
20
+ source: 'bundle-drop',
21
+ runtimeVersion: authority.runtimeVersion,
22
+ };
23
+ }
24
+ function writeAtomically(outputPath, content) {
25
+ const absoluteOutputPath = path_1.default.resolve(outputPath);
26
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(absoluteOutputPath));
27
+ const temporaryPath = path_1.default.join(path_1.default.dirname(absoluteOutputPath), `.${path_1.default.basename(absoluteOutputPath)}-${process.pid}-${Date.now()}.tmp`);
28
+ try {
29
+ fs_extra_1.default.writeFileSync(temporaryPath, content, 'utf8');
30
+ const descriptor = fs_extra_1.default.openSync(temporaryPath, 'r');
31
+ try {
32
+ fs_extra_1.default.fsyncSync(descriptor);
33
+ }
34
+ finally {
35
+ fs_extra_1.default.closeSync(descriptor);
36
+ }
37
+ fs_extra_1.default.renameSync(temporaryPath, absoluteOutputPath);
38
+ }
39
+ catch (error) {
40
+ try {
41
+ fs_extra_1.default.removeSync(temporaryPath);
42
+ }
43
+ catch {
44
+ // Preserve the original failure.
45
+ }
46
+ throw error;
47
+ }
48
+ }
49
+ function writeNativeRuntimeIdentity(options) {
50
+ const identity = resolveNativeRuntimeIdentity(options.projectRoot, options.platform);
51
+ const content = `${JSON.stringify(identity)}\n`;
52
+ if (options.outputPath) {
53
+ writeAtomically(options.outputPath, content);
54
+ }
55
+ return identity;
56
+ }
57
+ function parseNativeRuntimeIdentityArguments(argv) {
58
+ const values = new Map();
59
+ for (let index = 0; index < argv.length; index += 2) {
60
+ const flag = argv[index];
61
+ const value = argv[index + 1];
62
+ if (!['--project-root', '--platform', '--output'].includes(flag) || !value) {
63
+ throw new Error('Usage: write-runtime-identity --project-root <path> --platform ios|android [--output <path>]');
64
+ }
65
+ if (values.has(flag))
66
+ throw new Error(`Duplicate argument ${flag}.`);
67
+ values.set(flag, value);
68
+ }
69
+ const projectRoot = values.get('--project-root');
70
+ const platform = values.get('--platform');
71
+ if (!projectRoot || (platform !== 'ios' && platform !== 'android')) {
72
+ throw new Error('Usage: write-runtime-identity --project-root <path> --platform ios|android [--output <path>]');
73
+ }
74
+ return {
75
+ projectRoot,
76
+ platform,
77
+ ...(values.get('--output') ? { outputPath: values.get('--output') } : {}),
78
+ };
79
+ }
80
+ /* istanbul ignore next */
81
+ if (require.main === module) {
82
+ try {
83
+ const identity = writeNativeRuntimeIdentity(parseNativeRuntimeIdentityArguments(process.argv.slice(2)));
84
+ if (!process.argv.includes('--output')) {
85
+ process.stdout.write(`${JSON.stringify(identity)}\n`);
86
+ }
87
+ }
88
+ catch (error) {
89
+ process.stderr.write(`${error.message}\n`);
90
+ process.exitCode = 1;
91
+ }
92
+ }
@@ -4,6 +4,7 @@ export type SightArtifacts = {
4
4
  bundlePath: string;
5
5
  sourceMapPath: string;
6
6
  temporary: boolean;
7
+ assetManifestPath?: string;
7
8
  };
8
9
  export type GenerateSightArtifactsOptions = {
9
10
  projectRoot: string;
@@ -12,6 +13,13 @@ export type GenerateSightArtifactsOptions = {
12
13
  output?: string;
13
14
  keep?: boolean;
14
15
  entryFile?: string;
16
+ /** Comparison builds supply an isolated, cancellable process runner. */
17
+ runCommand?: (projectRoot: string, cliPath: string, args: string[]) => Promise<void>;
18
+ sourceMapRoot?: string;
19
+ /** Opt-in destination for emitted assets; callers own its lifecycle. */
20
+ assetsDirectory?: string;
21
+ /** Environment for the default project-local bundler process. */
22
+ env?: NodeJS.ProcessEnv;
15
23
  };
16
24
  export declare function validateSightArtifacts(bundlePath: string, sourceMapPath: string): void;
17
- export declare function generateSightArtifacts({ projectRoot, projectType, platform, output, keep, entryFile: explicitEntryFile, }: GenerateSightArtifactsOptions): Promise<SightArtifacts>;
25
+ export declare function generateSightArtifacts({ projectRoot, projectType, platform, output, keep, entryFile: explicitEntryFile, env, runCommand, sourceMapRoot, assetsDirectory, }: GenerateSightArtifactsOptions): Promise<SightArtifacts>;
@@ -77,11 +77,11 @@ function resolveExpoEntryFile(projectRoot, platform) {
77
77
  }
78
78
  return path_1.default.isAbsolute(entryFile) ? entryFile : path_1.default.resolve(projectRoot, entryFile);
79
79
  }
80
- function runMetroCommand(projectRoot, cliPath, args) {
80
+ function runMetroCommand(projectRoot, cliPath, args, env) {
81
81
  return new Promise((resolve, reject) => {
82
82
  const child = (0, child_process_1.spawn)(process.execPath, [cliPath, ...args], {
83
83
  cwd: projectRoot,
84
- env: { ...process.env, NODE_ENV: 'production' },
84
+ env: { ...env, NODE_ENV: 'production' },
85
85
  stdio: 'inherit',
86
86
  });
87
87
  child.once('error', reject);
@@ -144,20 +144,28 @@ function validateSightArtifacts(bundlePath, sourceMapPath) {
144
144
  throw new Error('The generated bundle and source map have different debug IDs.');
145
145
  }
146
146
  }
147
- async function generateSightArtifacts({ projectRoot, projectType, platform, output, keep = false, entryFile: explicitEntryFile, }) {
147
+ async function generateSightArtifacts({ projectRoot, projectType, platform, output, keep = false, entryFile: explicitEntryFile, env = process.env, runCommand = (root, command, args) => runMetroCommand(root, command, args, env), sourceMapRoot, assetsDirectory, }) {
148
148
  const absoluteProjectRoot = path_1.default.resolve(projectRoot);
149
149
  const { outputDirectory, temporary } = ensureOutputDirectory(absoluteProjectRoot, output, keep);
150
150
  const bundlePath = path_1.default.join(outputDirectory, `main.${platform}.jsbundle`);
151
151
  const sourceMapPath = `${bundlePath}.map`;
152
+ const comparisonArguments = sourceMapRoot
153
+ ? [
154
+ ...(projectType === 'bare' ? ['--sourcemap-sources-root', sourceMapRoot] : []),
155
+ '--reset-cache', '--max-workers', '2',
156
+ ]
157
+ : [];
152
158
  try {
159
+ if (assetsDirectory)
160
+ fs_1.default.mkdirSync(assetsDirectory, { recursive: true, mode: 0o700 });
153
161
  if (projectType === 'expo') {
154
162
  const cliPath = resolveExpoModule(absoluteProjectRoot, '@expo/cli');
155
163
  const entryFile = explicitEntryFile
156
164
  ? path_1.default.resolve(absoluteProjectRoot, explicitEntryFile)
157
165
  : resolveExpoEntryFile(absoluteProjectRoot, platform);
158
- const assetsDirectory = path_1.default.join(outputDirectory, 'assets');
159
- fs_1.default.mkdirSync(assetsDirectory, { recursive: true, mode: 0o755 });
160
- await runMetroCommand(absoluteProjectRoot, cliPath, [
166
+ const expoAssetsDirectory = assetsDirectory ?? path_1.default.join(outputDirectory, 'assets');
167
+ fs_1.default.mkdirSync(expoAssetsDirectory, { recursive: true, mode: 0o755 });
168
+ await runCommand(absoluteProjectRoot, cliPath, [
161
169
  'export:embed',
162
170
  '--platform',
163
171
  platform,
@@ -168,17 +176,18 @@ async function generateSightArtifacts({ projectRoot, projectType, platform, outp
168
176
  '--sourcemap-output',
169
177
  sourceMapPath,
170
178
  '--assets-dest',
171
- assetsDirectory,
179
+ expoAssetsDirectory,
172
180
  '--dev',
173
181
  'false',
174
182
  '--minify',
175
183
  'true',
184
+ ...comparisonArguments,
176
185
  ]);
177
186
  }
178
187
  else {
179
188
  const cliPath = resolveProjectModule(absoluteProjectRoot, 'react-native/cli.js');
180
189
  const entryFile = resolveBareEntryFile(absoluteProjectRoot, explicitEntryFile);
181
- await runMetroCommand(absoluteProjectRoot, cliPath, [
190
+ await runCommand(absoluteProjectRoot, cliPath, [
182
191
  'bundle',
183
192
  '--platform',
184
193
  platform,
@@ -190,6 +199,9 @@ async function generateSightArtifacts({ projectRoot, projectType, platform, outp
190
199
  bundlePath,
191
200
  '--sourcemap-output',
192
201
  sourceMapPath,
202
+ ...(sourceMapRoot ? ['--minify', 'true'] : []),
203
+ ...(assetsDirectory ? ['--assets-dest', assetsDirectory] : []),
204
+ ...comparisonArguments,
193
205
  ]);
194
206
  }
195
207
  validateSightArtifacts(bundlePath, sourceMapPath);
@@ -0,0 +1,15 @@
1
+ import { type GenerateSightArtifactsOptions, type SightArtifacts } from './sight-artifacts';
2
+ import type { ComparisonArtifact, ComparisonAssetEntry, SightOtaMeasurement } from './sight-compare/types';
3
+ export type SightAssetManifest = {
4
+ version: 1;
5
+ mode: 'analyze';
6
+ metric: 'emitted-asset-bytes';
7
+ artifacts: {
8
+ bundle: ComparisonArtifact;
9
+ sourceMap: ComparisonArtifact;
10
+ };
11
+ assets: ComparisonAssetEntry[];
12
+ ota?: SightOtaMeasurement;
13
+ };
14
+ /** Single-analysis CLI wrapper; the generic builder retains its existing defaults. */
15
+ export declare function generateSightAnalysisArtifacts(options: GenerateSightArtifactsOptions): Promise<SightArtifacts>;
@@ -0,0 +1,71 @@
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.generateSightAnalysisArtifacts = generateSightAnalysisArtifacts;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const sight_artifacts_1 = require("./sight-artifacts");
12
+ const assets_1 = require("./sight-compare/assets");
13
+ const metadata_1 = require("./sight-compare/metadata");
14
+ const sight_ota_1 = require("./sight-ota");
15
+ const process_1 = require("./sight-compare/process");
16
+ /** Single-analysis CLI wrapper; the generic builder retains its existing defaults. */
17
+ async function generateSightAnalysisArtifacts(options) {
18
+ const assetsDirectory = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'bundle-drop-sight-assets-'));
19
+ const controller = new AbortController();
20
+ const cancel = () => controller.abort();
21
+ process.on('SIGINT', cancel);
22
+ process.on('SIGTERM', cancel);
23
+ let artifacts;
24
+ try {
25
+ const env = { ...(options.env || process.env), NODE_ENV: 'production', BUNDLE_DROP_OTA_BUILD: '1' };
26
+ const runCommand = options.runCommand ?? (async (cwd, command, args) => {
27
+ await (0, process_1.runComparisonProcess)({
28
+ command: process.execPath, args: [command, ...args], cwd, env,
29
+ phase: 'Build Sight analysis', signal: controller.signal, inheritStdin: true, inheritOutput: true,
30
+ });
31
+ });
32
+ artifacts = await (0, sight_artifacts_1.generateSightArtifacts)({ ...options, assetsDirectory, env, runCommand });
33
+ (0, process_1.checkComparisonAbort)(controller.signal);
34
+ const assets = await (0, assets_1.collectComparisonAssets)(assetsDirectory, controller.signal);
35
+ console.log(chalk_1.default.gray('Measuring the Bundle Drop OTA archive with the project’s JavaScript engine…'));
36
+ const ota = await (0, sight_ota_1.measureSightOta)({
37
+ projectRoot: options.projectRoot, projectType: options.projectType, platform: options.platform,
38
+ entryFile: options.entryFile,
39
+ bundlePath: artifacts.bundlePath, sourceMapPath: artifacts.sourceMapPath,
40
+ assetsDirectory, workDirectory: artifacts.outputDirectory,
41
+ }, { env, signal: controller.signal });
42
+ (0, process_1.checkComparisonAbort)(controller.signal);
43
+ console.log(ota.status === 'available'
44
+ ? chalk_1.default.green(`✓ Bundle Drop OTA size: ${ota.zipBytes} bytes (${ota.engine})`)
45
+ : chalk_1.default.yellow(`Bundle Drop OTA size unavailable: ${ota.reason}`));
46
+ const manifest = {
47
+ version: 1, mode: 'analyze', metric: 'emitted-asset-bytes',
48
+ artifacts: {
49
+ bundle: (0, metadata_1.describeArtifact)(artifacts.outputDirectory, artifacts.bundlePath),
50
+ sourceMap: (0, metadata_1.describeArtifact)(artifacts.outputDirectory, artifacts.sourceMapPath),
51
+ },
52
+ assets, ota,
53
+ };
54
+ const json = JSON.stringify(manifest) + '\n';
55
+ if (Buffer.byteLength(json) > assets_1.MAX_ASSET_MANIFEST_BYTES)
56
+ throw new Error('Sight asset manifest exceeds 4 MiB.');
57
+ const assetManifestPath = path_1.default.join(artifacts.outputDirectory, 'analysis-assets.json');
58
+ fs_1.default.writeFileSync(assetManifestPath, json, { mode: 0o600 });
59
+ return { ...artifacts, assetManifestPath };
60
+ }
61
+ catch (error) {
62
+ if (artifacts?.temporary)
63
+ fs_1.default.rmSync(artifacts.outputDirectory, { recursive: true, force: true });
64
+ throw error;
65
+ }
66
+ finally {
67
+ process.removeListener('SIGINT', cancel);
68
+ process.removeListener('SIGTERM', cancel);
69
+ fs_1.default.rmSync(assetsDirectory, { recursive: true, force: true });
70
+ }
71
+ }
@@ -6,5 +6,8 @@ export type SightCommandOptions = {
6
6
  keep?: boolean;
7
7
  output?: string;
8
8
  entryFile?: string;
9
+ compare?: string;
10
+ fetch?: boolean;
11
+ include?: string[];
9
12
  };
10
13
  export declare function runSightCommand(options: SightCommandOptions): Promise<void>;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -8,8 +41,9 @@ const fs_1 = __importDefault(require("fs"));
8
41
  const path_1 = __importDefault(require("path"));
9
42
  const chalk_1 = __importDefault(require("chalk"));
10
43
  const prompts_1 = __importDefault(require("prompts"));
44
+ const logo_1 = require("../logo");
11
45
  const expo_1 = require("../../expo");
12
- const sight_artifacts_1 = require("./sight-artifacts");
46
+ const sight_assets_1 = require("./sight-assets");
13
47
  const sight_session_1 = require("./sight-session");
14
48
  const DEFAULT_SIGHT_URL = 'https://bundledrop.app/sight';
15
49
  function detectAvailablePlatforms(projectRoot) {
@@ -41,10 +75,12 @@ function printArtifactPaths(artifacts, heading) {
41
75
  console.log(chalk_1.default.green(`\n${heading}`));
42
76
  console.log(` Bundle: ${artifacts.bundlePath}`);
43
77
  console.log(` Source map: ${artifacts.sourceMapPath}`);
78
+ console.log(` Assets: ${artifacts.assetManifestPath}`);
44
79
  }
45
80
  function printManualInstructions(artifacts) {
46
81
  printArtifactPaths(artifacts, 'Source files have been generated here:');
47
- console.log(chalk_1.default.cyan(`\nOpen ${DEFAULT_SIGHT_URL} and attach both files for analysis.`));
82
+ console.log(chalk_1.default.cyan(`\nOpen ${DEFAULT_SIGHT_URL} and attach the bundle and source map for JavaScript analysis.`));
83
+ console.log('analysis-assets.json is a local record. Run Sight with browser opening enabled to include assets through the CLI handoff.');
48
84
  }
49
85
  function removeTemporaryArtifacts(artifacts) {
50
86
  if (artifacts.temporary) {
@@ -58,16 +94,25 @@ async function runSightCommand(options) {
58
94
  if (options.projectType && !['expo', 'bare'].includes(options.projectType)) {
59
95
  throw new Error('--project-type must be expo or bare.');
60
96
  }
97
+ if (options.compare !== undefined) {
98
+ const { runSightComparison } = await Promise.resolve().then(() => __importStar(require('./sight-compare/run')));
99
+ await runSightComparison(options);
100
+ return;
101
+ }
102
+ if (options.fetch || options.include?.length) {
103
+ throw new Error('--fetch and --include require --compare <ref>.');
104
+ }
61
105
  const projectRoot = process.cwd();
62
106
  const projectType = (0, expo_1.detectProjectType)({
63
107
  projectRoot,
64
108
  explicitType: options.projectType,
65
109
  });
66
110
  const platform = await resolvePlatform(projectRoot, options.platform);
111
+ console.log((0, logo_1.buildBundleDropLogo)());
67
112
  console.log(chalk_1.default.bold.cyan('\nBundle Drop Sight'));
68
113
  console.log(chalk_1.default.gray(`Detected ${projectType === 'expo' ? 'Expo' : 'bare React Native'} project`));
69
114
  console.log(chalk_1.default.gray(`Generating a production ${platform} bundle and source map…`));
70
- const artifacts = await (0, sight_artifacts_1.generateSightArtifacts)({
115
+ const artifacts = await (0, sight_assets_1.generateSightAnalysisArtifacts)({
71
116
  projectRoot,
72
117
  projectType,
73
118
  platform,
@@ -77,6 +122,7 @@ async function runSightCommand(options) {
77
122
  });
78
123
  console.log(chalk_1.default.green(`✓ Generated ${platform} production bundle`));
79
124
  console.log(chalk_1.default.green('✓ Generated matching source map'));
125
+ console.log(chalk_1.default.green('✓ Inventoried emitted assets separately from JavaScript'));
80
126
  const shouldOpen = options.open === false
81
127
  ? false
82
128
  : (await (0, prompts_1.default)({
@@ -110,7 +156,7 @@ async function runSightCommand(options) {
110
156
  }
111
157
  await session.waitForTransfer();
112
158
  transferSucceeded = true;
113
- console.log(chalk_1.default.green('✓ Bundle and source map loaded into Sight'));
159
+ console.log(chalk_1.default.green('✓ Bundle, source map and asset inventory loaded into Sight'));
114
160
  }
115
161
  finally {
116
162
  await session.close();
@@ -0,0 +1,6 @@
1
+ import type { ComparisonAssetEntry, ComparisonAssetManifest } from './types';
2
+ export declare const MAX_ASSET_MANIFEST_BYTES: number;
3
+ export declare const MAX_COMPARISON_ASSETS_PER_SIDE = 10000;
4
+ /** Inventory emitted files, never source directories or assets discovered by filename. */
5
+ export declare function collectComparisonAssets(directory: string, signal: AbortSignal): Promise<ComparisonAssetEntry[]>;
6
+ export declare function writeComparisonAssetManifest(filePath: string, manifest: ComparisonAssetManifest): void;
@@ -0,0 +1,73 @@
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.MAX_COMPARISON_ASSETS_PER_SIDE = exports.MAX_ASSET_MANIFEST_BYTES = void 0;
7
+ exports.collectComparisonAssets = collectComparisonAssets;
8
+ exports.writeComparisonAssetManifest = writeComparisonAssetManifest;
9
+ const crypto_1 = require("crypto");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ exports.MAX_ASSET_MANIFEST_BYTES = 4 * 1024 * 1024;
13
+ exports.MAX_COMPARISON_ASSETS_PER_SIDE = 10000;
14
+ /** Inventory emitted files, never source directories or assets discovered by filename. */
15
+ async function collectComparisonAssets(directory, signal) {
16
+ signal.throwIfAborted();
17
+ const rootStats = fs_1.default.lstatSync(directory);
18
+ if (!rootStats.isDirectory()) {
19
+ throw new Error('Sight emitted assets must be a real directory.');
20
+ }
21
+ const entries = [];
22
+ let manifestBytes = 0;
23
+ let totalBytes = 0;
24
+ async function visit(currentDirectory, prefix) {
25
+ for (const name of fs_1.default.readdirSync(currentDirectory).sort()) {
26
+ signal.throwIfAborted();
27
+ const relativePath = prefix + name;
28
+ if (/[\\:\x00-\x1f\x7f]/.test(name) || name === '.' || name === '..') {
29
+ throw new Error(`Sight cannot represent this emitted asset path: ${JSON.stringify(relativePath)}.`);
30
+ }
31
+ const filePath = path_1.default.join(currentDirectory, name);
32
+ const stats = fs_1.default.lstatSync(filePath);
33
+ if (stats.isDirectory()) {
34
+ await visit(filePath, relativePath + '/');
35
+ continue;
36
+ }
37
+ if (!stats.isFile()) {
38
+ throw new Error(`Sight emitted asset is not a regular file: ${relativePath}.`);
39
+ }
40
+ totalBytes += stats.size;
41
+ if (!Number.isSafeInteger(stats.size) || stats.size < 0 || !Number.isSafeInteger(totalBytes)) {
42
+ throw new Error(`Sight emitted asset sizes exceed the supported byte range: ${relativePath}.`);
43
+ }
44
+ if (entries.length >= exports.MAX_COMPARISON_ASSETS_PER_SIDE) {
45
+ throw new Error('Sight emitted assets exceed 10000 files per comparison side.');
46
+ }
47
+ const hash = (0, crypto_1.createHash)('sha256');
48
+ const stream = fs_1.default.createReadStream(filePath, { signal });
49
+ for await (const chunk of stream)
50
+ hash.update(chunk);
51
+ signal.throwIfAborted();
52
+ const after = fs_1.default.lstatSync(filePath);
53
+ if (!after.isFile() || after.size !== stats.size || after.mtimeMs !== stats.mtimeMs || after.ino !== stats.ino) {
54
+ throw new Error(`Sight emitted asset changed during inventory: ${relativePath}.`);
55
+ }
56
+ const entry = { path: relativePath, bytes: stats.size, sha256: hash.digest('hex') };
57
+ manifestBytes += Buffer.byteLength(JSON.stringify(entry)) + 1;
58
+ if (manifestBytes > exports.MAX_ASSET_MANIFEST_BYTES) {
59
+ throw new Error('Sight asset manifest exceeds 4 MiB.');
60
+ }
61
+ entries.push(entry);
62
+ }
63
+ }
64
+ await visit(directory, '');
65
+ return entries;
66
+ }
67
+ function writeComparisonAssetManifest(filePath, manifest) {
68
+ const json = JSON.stringify(manifest) + '\n';
69
+ if (Buffer.byteLength(json) > exports.MAX_ASSET_MANIFEST_BYTES) {
70
+ throw new Error('Sight asset manifest exceeds 4 MiB.');
71
+ }
72
+ fs_1.default.writeFileSync(filePath, json, { mode: 0o600 });
73
+ }
@@ -0,0 +1,22 @@
1
+ export type ComparisonPackageManager = {
2
+ name: 'npm' | 'yarn' | 'pnpm';
3
+ version: string;
4
+ };
5
+ export type DependencyPlan = {
6
+ snapshotRoot: string;
7
+ projectRoot: string;
8
+ installRoot: string;
9
+ packageManager: ComparisonPackageManager;
10
+ installArgs: string[];
11
+ inputFiles: string[];
12
+ };
13
+ export type DependencyProcessOptions = {
14
+ signal?: AbortSignal;
15
+ env?: NodeJS.ProcessEnv;
16
+ logPath?: string;
17
+ };
18
+ export declare function inspectDependencyPlan(options: {
19
+ snapshotRoot: string;
20
+ projectRelativePath: string;
21
+ } & DependencyProcessOptions): Promise<DependencyPlan>;
22
+ export declare function installDependencies(plan: DependencyPlan, options?: DependencyProcessOptions): Promise<void>;