@gfean/react-native-bundle-drop 0.7.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 (34) hide show
  1. package/README.md +215 -0
  2. package/android/build.gradle +7 -5
  3. package/lib/CLI/cli.js +5 -0
  4. package/lib/CLI/scripts/sight-artifacts.d.ts +9 -1
  5. package/lib/CLI/scripts/sight-artifacts.js +20 -8
  6. package/lib/CLI/scripts/sight-assets.d.ts +15 -0
  7. package/lib/CLI/scripts/sight-assets.js +71 -0
  8. package/lib/CLI/scripts/sight-cli.d.ts +3 -0
  9. package/lib/CLI/scripts/sight-cli.js +50 -4
  10. package/lib/CLI/scripts/sight-compare/assets.d.ts +6 -0
  11. package/lib/CLI/scripts/sight-compare/assets.js +73 -0
  12. package/lib/CLI/scripts/sight-compare/dependencies.d.ts +22 -0
  13. package/lib/CLI/scripts/sight-compare/dependencies.js +289 -0
  14. package/lib/CLI/scripts/sight-compare/git.d.ts +22 -0
  15. package/lib/CLI/scripts/sight-compare/git.js +116 -0
  16. package/lib/CLI/scripts/sight-compare/inspect-project.d.ts +37 -0
  17. package/lib/CLI/scripts/sight-compare/inspect-project.js +191 -0
  18. package/lib/CLI/scripts/sight-compare/metadata.d.ts +4 -0
  19. package/lib/CLI/scripts/sight-compare/metadata.js +39 -0
  20. package/lib/CLI/scripts/sight-compare/process.d.ts +22 -0
  21. package/lib/CLI/scripts/sight-compare/process.js +221 -0
  22. package/lib/CLI/scripts/sight-compare/run.d.ts +3 -0
  23. package/lib/CLI/scripts/sight-compare/run.js +290 -0
  24. package/lib/CLI/scripts/sight-compare/snapshot.d.ts +26 -0
  25. package/lib/CLI/scripts/sight-compare/snapshot.js +279 -0
  26. package/lib/CLI/scripts/sight-compare/types.d.ts +87 -0
  27. package/lib/CLI/scripts/sight-compare/types.js +2 -0
  28. package/lib/CLI/scripts/sight-ota.d.ts +18 -0
  29. package/lib/CLI/scripts/sight-ota.js +260 -0
  30. package/lib/CLI/scripts/sight-session.d.ts +9 -2
  31. package/lib/CLI/scripts/sight-session.js +58 -20
  32. package/lib/scripts/bundle.d.ts +3 -0
  33. package/lib/scripts/bundle.js +7 -4
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -43,6 +43,8 @@ runtime identity. Native changes still require a new App Store or Play Store bui
43
43
  - **Runtime gating** — updates only reach compatible native binaries.
44
44
  - **Observability metadata** — bundle hashes and source maps keep crash reports attributable to the correct release.
45
45
  - **CI/CD support** — upload with a Personal Access Token from any pipeline.
46
+ - **Bundle Drop Sight** — inspect JavaScript bundle sizes locally, including
47
+ working-tree comparisons against a Git baseline.
46
48
 
47
49
  ## Compatibility
48
50
 
@@ -87,6 +89,219 @@ cd ios && pod install
87
89
  React Native autolinking handles the package on both platforms. The setup command
88
90
  adds the app-entry integration that allows a Release build to start an installed OTA.
89
91
 
92
+ ## Bundle Drop Sight
93
+
94
+ Sight analyzes production JavaScript bundles and emitted assets in your browser. It
95
+ does not require a Bundle Drop account, OTA project configuration, login, or native
96
+ integration. Run it from the app directory containing `package.json`:
97
+
98
+ ```bash
99
+ npx bundle-drop sight --platform android
100
+ npx bundle-drop sight --compare main --platform android
101
+ npx bundle-drop sight --compare origin/main --fetch --platform ios
102
+ ```
103
+
104
+ The first command analyzes the current app using its installed dependencies and
105
+ includes emitted assets through the automatic CLI handoff.
106
+ `--compare` builds both an explicit Git baseline and a captured copy of your current
107
+ working tree. Both builds run locally, including when the baseline is a remote
108
+ tracking branch. Sight compares **raw UTF-8 bytes in minified JavaScript** and uses
109
+ source maps to attribute changes to packages and files. Both CLI modes include a
110
+ **Bundled assets** breakdown for files emitted by the same Metro/Expo build, such as
111
+ images and fonts. Assets do not change the JavaScript totals or treemap.
112
+
113
+ **Bundle Drop OTA size** measures a locally generated full OTA archive using Bundle Drop's
114
+ canonical packaging. Each revision uses its own JavaScript engine configuration:
115
+ Hermes is compiled with project-local tooling when enabled. JavaScript attribution
116
+ and raw asset sizes remain separate; they are not bytecode attribution.
117
+
118
+ Measurement adds compilation and archive compression after the JavaScript build, once
119
+ per side in a comparison. Expo's Hermes path also performs a separate bytecode
120
+ export to preserve its upload-specific minification behavior. It requires a resolvable app/runtime identity. When that
121
+ identity or required compiler is unavailable, Sight keeps the JavaScript and asset
122
+ analysis and marks the OTA measurement unavailable with a reason. It never fills in
123
+ an estimated archive size. Comparing this metric requires Bundle Drop to be configured
124
+ on both branches with a resolvable app/runtime identity. The archive describes the selected Sight entry and build
125
+ environment; upload overrides or different inputs can produce another size.
126
+
127
+ Asset sizes count each emitted output file once, including emitted density variants.
128
+ Identical contents at different output paths count separately; a changed hash at the
129
+ same path is a change even when the byte size is unchanged. Only emitted files are
130
+ counted, not every asset in the repository. Native-only resources and network-loaded
131
+ assets are outside this measurement. The OTA archive includes delivery metadata and asset
132
+ manifests, and excludes source maps. It is not APK/IPA size. File size changes do
133
+ not measure startup time or memory use.
134
+
135
+ No native app build is needed for asset analysis or comparison. The existing JavaScript bundling
136
+ step emits the files into private temporary directories; the CLI records relative
137
+ output paths, byte lengths, and SHA-256 hashes, then removes the emitted asset copies.
138
+ Only the inventory is passed to Sight, with no image previews or binary asset uploads.
139
+ This collection code stays in the CLI and adds no runtime dependencies or mobile SDK
140
+ code.
141
+
142
+ The CLI transfers the generated files to Sight through a short-lived loopback
143
+ session. Source code, bundles, source maps, and comparison metadata are not uploaded
144
+ to Bundle Drop servers. Loading the Sight web page still needs browser access to
145
+ `bundledrop.app`.
146
+
147
+ ### Comparison options
148
+
149
+ | Option | Behavior |
150
+ | --- | --- |
151
+ | `--compare <ref>` | Resolve a branch, tag, or commit to an immutable baseline commit before building. |
152
+ | `--fetch` | Refresh the explicitly named remote branch, such as `origin/main`, using ordinary Git credentials. Requires `--compare`. |
153
+ | `--platform ios\|android` | Compare one platform per invocation. If ambiguous, interactive use prompts; noninteractive use requires the flag. |
154
+ | `--project-type bare\|expo` | Override project detection consistently for both sides. |
155
+ | `--entry-file <path>` | Choose an app-relative entry file that must exist in both snapshots. |
156
+ | `--include <path>` | Copy an extra local file or directory identically into both snapshots; repeat for multiple inputs. |
157
+ | `--no-open` | Keep the generated files and print manual browser instructions. |
158
+ | `--keep` | Keep the comparison files after a successful browser transfer. |
159
+ | `--output <path>` | Write persistent output to an empty directory. |
160
+
161
+ Without `--fetch`, Sight uses locally available refs and does not contact a Git
162
+ remote. `main` is never silently substituted with `origin/main`. Explicit refresh
163
+ requires a configured remote branch; use normal Git commands first to obtain a
164
+ missing tag, commit, or additional shallow history. Sight neither requests nor
165
+ stores repository credentials.
166
+
167
+ ### What each side builds
168
+
169
+ The current snapshot contains tracked working-tree contents, including uncommitted
170
+ edits and deletions, plus nonignored untracked files. Ignored inputs such as local
171
+ environment files are excluded unless explicitly included:
172
+
173
+ ```bash
174
+ npx bundle-drop sight --compare main --platform android \
175
+ --include .env.production --include local-build-config
176
+ ```
177
+
178
+ Included paths must stay inside the repository. They cannot overwrite files
179
+ tracked on either side or supply dependency manifests, lockfiles, or installed
180
+ dependencies. The same captured contents are added to both sides, so the baseline
181
+ remains a comparison under the same explicitly supplied local configuration.
182
+
183
+ Sight creates private temporary Git worktrees for the two builds. Both have a
184
+ detached `HEAD`: baseline points at the resolved baseline commit, and current
185
+ points at your original `HEAD` with captured working-tree files overlaid. Your
186
+ original staging partition is not reproduced; scripts that distinguish staged
187
+ from unstaged changes, or depend on an attached branch name, may behave differently.
188
+ Sight does not switch, stash, reset, or stage your original checkout.
189
+
190
+ The private repository has independent object storage and preserves the captured
191
+ local branch/tag/remote-tracking refs and available history. `git rev-parse HEAD`
192
+ and ancestry queries use each side's own commit. `git describe` evaluates the
193
+ captured tags from that commit; these are today's locally available refs, not
194
+ their historical state at the baseline date. Missing shallow history or tags may
195
+ change its output, and Sight does not fetch them implicitly. Branch-name queries
196
+ observe detached HEAD; the original branch label is metadata only.
197
+
198
+ `git describe --dirty` reflects each private worktree, including explicit includes
199
+ and build-script changes. Original dirty status is recorded separately. Builds
200
+ depending on attached branches or staging partitions must accommodate these
201
+ semantics through their existing configuration/environment. Sight verifies pinned
202
+ HEADs and refs around build phases and rejects mutations that invalidate provenance.
203
+ It rechecks captured files, modes, symlinks, HEAD, and index for observed concurrent
204
+ changes; the copy is not an atomic filesystem snapshot.
205
+
206
+ Both sides use the same Node executable, platform, production/minification settings,
207
+ and logical entrypoint. Each revision retains its own dependencies and bundler
208
+ configuration. Sight records framework/package-manager versions and warns when
209
+ relevant inputs differ. A framework upgrade or configuration change can legitimately
210
+ affect the result. Required environment variables must be available to both builds;
211
+ there is no automatic fallback from a failed build to the other revision's output.
212
+
213
+ ### Dependencies and supported repository layouts
214
+
215
+ Comparison installs fresh dependencies for each side from its own lockfile. It
216
+ supports npm, pnpm, Yarn Classic, and modern Yarn with `nodeLinker: node-modules`.
217
+ An exact `packageManager` declaration must match the available executable; tracked
218
+ `yarnPath` configurations are honored. Without a declaration, a unique lockfile
219
+ family selects the available manager and its actual version is recorded. Sight
220
+ does not automatically download package-manager binaries or change a lockfile to
221
+ make installation succeed.
222
+
223
+ Dependency installation can access package registries and execute project lifecycle
224
+ scripts. Existing script policies are preserved. For declared `engines.node` ranges,
225
+ Sight uses the installed `npm` executable to check a temporary dependency-free
226
+ manifest with an offline, script-disabled dry run before the real installs. This
227
+ check also requires npm when the project uses Yarn or pnpm. Build/configuration
228
+ scripts execute as ordinary local processes; the temporary worktrees are not a
229
+ security sandbox for untrusted project code.
230
+
231
+ Apps in a single npm, Yarn, or pnpm workspace root can use other packages inside
232
+ the same Git repository. Installation runs at the workspace root; bundling runs
233
+ from the app directory. Nested/ambiguous workspace roots, nested app lockfiles,
234
+ external local dependencies or symlinks, Bun, and Plug'n'Play installations are not
235
+ supported. npm workspaces require a v2 or newer lockfile. Unresolved Git conflicts,
236
+ sparse/partial clones, required Git submodules, Git LFS/checkout filters, and tracked
237
+ `node_modules` are also unsupported. There is no comparison build or dependency-tree
238
+ cache in this version.
239
+
240
+ Actual workspace frozen installs have been verified on macOS arm64 with Node
241
+ 22.13.0 using npm 10.9.2, pnpm 11.24.0, Yarn 1.22.22, and Yarn 3.8.3. These installer
242
+ checks cover a registry dependency, a local workspace dependency, lifecycle scripts,
243
+ and unchanged manifests/lockfiles. Real comparisons were also verified with npm
244
+ 10.9.2, React Native 0.83.1, and Expo 55.0.0: dirty source capture, package additions,
245
+ identical inputs, and automatic browser attribution after source cleanup.
246
+ An Expo Router 55.0.18 app also passed a real comparison using `expo-router/entry`.
247
+ Windows/Linux hosts and full framework builds with pnpm or Yarn remain unverified;
248
+ the installer checks alone do not establish those combinations.
249
+
250
+ ### Keeping files and opening Sight manually
251
+
252
+ ```bash
253
+ npx bundle-drop sight --platform android --no-open --output ./sight-analysis
254
+ npx bundle-drop sight --compare main --platform android \
255
+ --no-open --output ./sight-comparison
256
+ ```
257
+
258
+ Single analysis keeps a bundle/source-map pair and `analysis-assets.json`, a local
259
+ record of emitted paths, sizes, hashes, and the exact bundle/map hashes. The automatic
260
+ CLI handoff verifies this binding before including assets in the analysis.
261
+
262
+ Comparison output contains `baseline/` and `current/` bundle/source-map pairs plus
263
+ `comparison.json` and `comparison-assets.json` as local records. Automatic CLI
264
+ loading verifies these files and includes Git labels, build context, and asset
265
+ sizes. The browser does not expose metadata or inventory upload controls.
266
+
267
+ For a manual JavaScript-only comparison, open
268
+ [Bundle Drop Sight](https://bundledrop.app/sight), select Compare, and attach the
269
+ four bundle/map files. Manual Analyze still takes one bundle and its matching map;
270
+ manual Compare still takes two pairs. Neither requires the Bundle Drop SDK or extra
271
+ JSON files. Git labels and asset sizes appear only through the CLI handoff. Changing
272
+ a file after a CLI handoff clears its comparison context.
273
+
274
+ Comparison metadata remains limited to 64 KiB. Each asset inventory is limited to
275
+ 4 MiB and 10,000 files per build; oversized inventories fail explicitly
276
+ instead of producing partial totals. Inventory paths are output-relative and are
277
+ never opened by the browser.
278
+
279
+ Temporary worktrees and dependencies are removed after success, failure, or
280
+ cancellation. Completed files from either CLI mode are retained when browser handoff
281
+ fails; the CLI prints their location, and comparisons also print the diagnostics
282
+ directory. `--keep`, `--no-open`, and `--output` retain the requested artifacts,
283
+ including the local asset record. A failure before complete artifacts
284
+ exist removes owned temporary output; explicitly requested output directories are
285
+ kept for inspection.
286
+
287
+ The metadata contains local temporary source roots so unchanged source maps remain
288
+ attributable after cleanup. Sight excludes those roots from displayed/exported
289
+ provenance and analytics. Manual file loading uses ordinary JavaScript comparison
290
+ behavior without the CLI source-path context.
291
+
292
+ Removal failures report the owned directory for manual recovery. An uncatchable
293
+ termination, such as a forced process kill or power loss, can leave temporary
294
+ `bundle-drop-sight-*` directories. After confirming the invocation and its build
295
+ processes have stopped, remove only those reported/identified temporary directories;
296
+ keep completed comparison output if it is still needed.
297
+
298
+ On macOS/Linux, Sight stops ordinary child process groups before removing the
299
+ worktrees, including background children left after a command exits. On Windows,
300
+ cancellation uses `taskkill` for the active process tree, but this version has no
301
+ Job Object containment: background descendants can survive if their parent has
302
+ already exited. Scripts that deliberately detach into a separate process group
303
+ also fall outside process-group cleanup.
304
+
90
305
  ## First-Time Setup
91
306
 
92
307
  Run these commands from your app's project root:
@@ -33,7 +33,13 @@ buildscript {
33
33
 
34
34
 
35
35
  apply plugin: "com.android.library"
36
- apply plugin: "kotlin-android"
36
+ // AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
37
+ // itself. Applying the Kotlin plugin on top of it fails configuration with
38
+ // "Cannot add extension with name 'kotlin'". Only apply it when nothing has
39
+ // registered that extension yet.
40
+ if (project.extensions.findByName('kotlin') == null) {
41
+ apply plugin: "kotlin-android"
42
+ }
37
43
 
38
44
  if (project.hasProperty("standalone")) {
39
45
  apply plugin: "jacoco"
@@ -92,10 +98,6 @@ android {
92
98
  targetCompatibility JavaVersion.VERSION_1_8
93
99
  }
94
100
 
95
- kotlinOptions {
96
- jvmTarget = "1.8"
97
- }
98
-
99
101
  externalNativeBuild {
100
102
  cmake {
101
103
  path "src/main/cpp/CMakeLists.txt"
package/lib/CLI/cli.js CHANGED
@@ -120,6 +120,9 @@ ${chalk_1.default.gray('Uploading →')} ${chalk_1.default.underline.gray(DOCS_U
120
120
  ${chalk_1.default.gray('CI/CD →')} ${chalk_1.default.underline.gray(DOCS_CI_CD_URL)}\n`);
121
121
  program
122
122
  .command('sight')
123
+ .option('--compare <ref>', 'Compare the working tree with an explicit Git baseline')
124
+ .option('--fetch', 'Refresh the explicitly named remote branch before comparing')
125
+ .option('--include <path>', 'Copy an ignored local input identically into both builds (repeatable)', (value, previous) => [...previous, value], [])
123
126
  .option('--platform <platform>', 'Platform to analyze: ios or android')
124
127
  .option('--project-type <type>', 'Force project type: expo or bare')
125
128
  .option('--entry-file <path>', 'Override the React Native entry file')
@@ -133,6 +136,8 @@ ${chalk_1.default.bold('Examples:')}
133
136
  ${chalk_1.default.gray('bundle-drop sight --platform android')}
134
137
  ${chalk_1.default.gray('bundle-drop sight --platform ios --keep')}
135
138
  ${chalk_1.default.gray('bundle-drop sight --no-open --output ./sight-analysis')}
139
+ ${chalk_1.default.gray('bundle-drop sight --compare main --platform android')}
140
+ ${chalk_1.default.gray('bundle-drop sight --compare origin/main --fetch --include .env.production')}
136
141
  `)
137
142
  .action(sight_cli_1.runSightCommand);
138
143
  program
@@ -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;