FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

33
node_modules/metro/src/shared/output/RamBundle.d.ts generated vendored Normal file
View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<bef82861a3de459220bf62515fd5900c>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {RamBundleInfo} from '../../DeltaBundler/Serializers/getRamBundleInfo';
import type {OutputOptions, RequestOptions} from '../types';
import Server from '../../Server';
export declare function build(
packagerClient: Server,
requestOptions: RequestOptions,
): Promise<RamBundleInfo>;
export declare function save(
bundle: RamBundleInfo,
options: OutputOptions,
log: (x: string) => void,
): Promise<unknown>;
export declare const formatName: 'bundle';
export declare type formatName = typeof formatName;

27
node_modules/metro/src/shared/output/RamBundle.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.build = build;
exports.formatName = void 0;
exports.save = save;
var _Server = _interopRequireDefault(require("../../Server"));
var _asAssets = _interopRequireDefault(require("./RamBundle/as-assets"));
var _asIndexedFile = require("./RamBundle/as-indexed-file");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
async function build(packagerClient, requestOptions) {
const options = {
..._Server.default.DEFAULT_BUNDLE_OPTIONS,
...requestOptions,
};
return await packagerClient.getRamBundleInfo(options);
}
function save(bundle, options, log) {
return options.platform === "android" && !(options.indexedRamBundle === true)
? (0, _asAssets.default)(bundle, options, log)
: (0, _asIndexedFile.save)(bundle, options, log);
}
const formatName = (exports.formatName = "bundle");

45
node_modules/metro/src/shared/output/RamBundle.js.flow generated vendored Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {RamBundleInfo} from '../../DeltaBundler/Serializers/getRamBundleInfo';
import type {OutputOptions, RequestOptions} from '../types';
import Server from '../../Server';
import asAssets from './RamBundle/as-assets';
import {save as asIndexedFile} from './RamBundle/as-indexed-file';
export async function build(
packagerClient: Server,
requestOptions: RequestOptions,
): Promise<RamBundleInfo> {
const options = {
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions,
};
/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
* https://fburl.com/gdoc/y8dn025u */
return await packagerClient.getRamBundleInfo(options);
}
export function save(
bundle: RamBundleInfo,
options: OutputOptions,
log: (x: string) => void,
): Promise<unknown> {
// We fork here depending on the platform: while Android is pretty good at
// loading individual assets, iOS has a large overhead when reading hundreds
// of assets from disk.
return options.platform === 'android' && !(options.indexedRamBundle === true)
? asAssets(bundle, options, log)
: asIndexedFile(bundle, options, log);
}
export const formatName = 'bundle';

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<02d7f6eec9c93d02612c9b2fdef18cef>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/as-assets.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
import type {OutputOptions} from '../../types';
/**
* Saves all JS modules of an app as single files
* The startup code (prelude, polyfills etc.) are written to the file
* designated by the `bundleOuput` option.
* All other modules go into a 'js-modules' folder that in the same parent
* directory as the startup file.
*/
declare function saveAsAssets(
bundle: RamBundleInfo,
options: OutputOptions,
log: (...args: Array<string>) => void,
): Promise<unknown>;
export default saveAsAssets;

View File

@@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = saveAsAssets;
var _relativizeSourceMap = _interopRequireDefault(
require("../../../lib/relativizeSourceMap"),
);
var _writeFile = _interopRequireDefault(require("../writeFile"));
var _buildSourcemapWithMetadata = _interopRequireDefault(
require("./buildSourcemapWithMetadata"),
);
var _magicNumber = _interopRequireDefault(require("./magic-number"));
var _util = require("./util");
var _writeSourcemap = _interopRequireDefault(require("./write-sourcemap"));
var _fs = require("fs");
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const MAGIC_RAM_BUNDLE_FILENAME = "UNBUNDLE";
const MODULES_DIR = "js-modules";
function saveAsAssets(bundle, options, log) {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
log("start");
const { startupModules, lazyModules } = bundle;
log("finish");
const startupCode = (0, _util.joinModules)(startupModules);
log("Writing bundle output to:", bundleOutput);
const modulesDir = _path.default.join(
_path.default.dirname(bundleOutput),
MODULES_DIR,
);
const writeUnbundle = createDir(modulesDir).then(() =>
Promise.all([
writeModules(lazyModules, modulesDir, encoding),
(0, _writeFile.default)(bundleOutput, startupCode, encoding),
writeMagicFlagFile(modulesDir),
]),
);
writeUnbundle.then(() => log("Done writing unbundle output"));
if (sourcemapOutput) {
const sourceMap = (0, _buildSourcemapWithMetadata.default)({
fixWrapperOffset: true,
lazyModules: lazyModules.concat(),
moduleGroups: null,
startupModules: startupModules.concat(),
});
if (sourcemapSourcesRoot != null) {
(0, _relativizeSourceMap.default)(sourceMap, sourcemapSourcesRoot);
}
const wroteSourceMap = (0, _writeSourcemap.default)(
sourcemapOutput,
JSON.stringify(sourceMap),
log,
);
return Promise.all([writeUnbundle, wroteSourceMap]);
} else {
return writeUnbundle;
}
}
function createDir(dirName) {
return _fs.promises.mkdir(dirName, {
recursive: true,
});
}
function writeModuleFile(module, modulesDir, encoding) {
const { code, id } = module;
return (0, _writeFile.default)(
_path.default.join(modulesDir, id + ".js"),
code,
encoding,
);
}
function writeModules(modules, modulesDir, encoding) {
const writeFiles = modules.map((module) =>
writeModuleFile(module, modulesDir, encoding),
);
return Promise.all(writeFiles);
}
function writeMagicFlagFile(outputDir) {
const buffer = Buffer.alloc(4);
buffer.writeUInt32LE(_magicNumber.default, 0);
return (0, _writeFile.default)(
_path.default.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME),
buffer,
);
}

View File

@@ -0,0 +1,124 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
import type {ModuleTransportLike} from '../../../shared/types';
import type {OutputOptions} from '../../types';
import relativizeSourceMapInline from '../../../lib/relativizeSourceMap';
import writeFile from '../writeFile';
import buildSourcemapWithMetadata from './buildSourcemapWithMetadata';
import MAGIC_RAM_BUNDLE_NUMBER from './magic-number';
import {joinModules} from './util';
import writeSourceMap from './write-sourcemap';
import {promises as fsPromises} from 'fs';
import path from 'path';
// must not start with a dot, as that won't go into the apk
const MAGIC_RAM_BUNDLE_FILENAME = 'UNBUNDLE';
const MODULES_DIR = 'js-modules';
/**
* Saves all JS modules of an app as single files
* The startup code (prelude, polyfills etc.) are written to the file
* designated by the `bundleOuput` option.
* All other modules go into a 'js-modules' folder that in the same parent
* directory as the startup file.
*/
export default function saveAsAssets(
bundle: RamBundleInfo,
options: OutputOptions,
log: (...args: Array<string>) => void,
): Promise<unknown> {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
log('start');
const {startupModules, lazyModules} = bundle;
log('finish');
const startupCode = joinModules(startupModules);
log('Writing bundle output to:', bundleOutput);
const modulesDir = path.join(path.dirname(bundleOutput), MODULES_DIR);
const writeUnbundle = createDir(modulesDir).then(
// create the modules directory first
() =>
Promise.all([
writeModules(lazyModules, modulesDir, encoding),
writeFile(bundleOutput, startupCode, encoding),
writeMagicFlagFile(modulesDir),
]),
);
// $FlowFixMe[unused-promise]
writeUnbundle.then(() => log('Done writing unbundle output'));
if (sourcemapOutput) {
const sourceMap = buildSourcemapWithMetadata({
fixWrapperOffset: true,
lazyModules: lazyModules.concat<
ModuleTransportLike,
ModuleTransportLike,
>(),
moduleGroups: null,
startupModules: startupModules.concat<
ModuleTransportLike,
ModuleTransportLike,
>(),
});
if (sourcemapSourcesRoot != null) {
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
}
const wroteSourceMap = writeSourceMap(
sourcemapOutput,
JSON.stringify(sourceMap),
log,
);
return Promise.all([writeUnbundle, wroteSourceMap]);
} else {
return writeUnbundle;
}
}
function createDir(dirName: string): Promise<void> {
return fsPromises.mkdir(dirName, {recursive: true});
}
function writeModuleFile(
module: ModuleTransportLike,
modulesDir: string,
encoding: void | 'ascii' | 'utf16le' | 'utf8',
): Promise<unknown> {
const {code, id} = module;
return writeFile(path.join(modulesDir, id + '.js'), code, encoding);
}
function writeModules(
modules: ReadonlyArray<ModuleTransportLike>,
modulesDir: string,
encoding: void | 'ascii' | 'utf16le' | 'utf8',
): Promise<Array<unknown>> {
const writeFiles = modules.map(
(module: ModuleTransportLike): Promise<unknown> =>
writeModuleFile(module, modulesDir, encoding),
);
return Promise.all(writeFiles);
}
function writeMagicFlagFile(outputDir: string): Promise<unknown> {
const buffer = Buffer.alloc(4);
buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
}

View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<cf05d2127a356bae7e3789c2fefa25d3>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/as-indexed-file.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
import type {
ModuleGroups,
ModuleTransportLike,
OutputOptions,
} from '../../types';
/**
* Saves all JS modules of an app as a single file, separated with null bytes.
* The file begins with an offset table that contains module ids and their
* lengths/offsets.
* The module id for the startup code (prelude, polyfills etc.) is the
* empty string.
*/
export declare function save(
bundle: RamBundleInfo,
options: OutputOptions,
log: (...args: Array<string>) => void,
): Promise<unknown>;
export declare function buildTableAndContents(
startupCode: string,
modules: ReadonlyArray<ModuleTransportLike>,
moduleGroups: ModuleGroups,
encoding?: 'utf8' | 'utf16le' | 'ascii',
): Array<Buffer>;
export declare function createModuleGroups(
groups: Map<number, Set<number>>,
modules: ReadonlyArray<ModuleTransportLike>,
): ModuleGroups;

View File

@@ -0,0 +1,153 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.buildTableAndContents = buildTableAndContents;
exports.createModuleGroups = createModuleGroups;
exports.save = save;
var _relativizeSourceMap = _interopRequireDefault(
require("../../../lib/relativizeSourceMap"),
);
var _buildSourcemapWithMetadata = _interopRequireDefault(
require("./buildSourcemapWithMetadata"),
);
var _magicNumber = _interopRequireDefault(require("./magic-number"));
var _util = require("./util");
var _writeSourcemap = _interopRequireDefault(require("./write-sourcemap"));
var _fs = _interopRequireDefault(require("fs"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const SIZEOF_UINT32 = 4;
function save(bundle, options, log) {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
log("start");
const { startupModules, lazyModules, groups } = bundle;
log("finish");
const moduleGroups = createModuleGroups(groups, lazyModules);
const startupCode = (0, _util.joinModules)(startupModules);
log("Writing unbundle output to:", bundleOutput);
const writeUnbundle = writeBuffers(
_fs.default.createWriteStream(bundleOutput),
buildTableAndContents(startupCode, lazyModules, moduleGroups, encoding),
).then(() => log("Done writing unbundle output"));
if (sourcemapOutput) {
const sourceMap = (0, _buildSourcemapWithMetadata.default)({
startupModules: startupModules.concat(),
lazyModules: lazyModules.concat(),
moduleGroups,
fixWrapperOffset: true,
});
if (sourcemapSourcesRoot != null) {
(0, _relativizeSourceMap.default)(sourceMap, sourcemapSourcesRoot);
}
const wroteSourceMap = (0, _writeSourcemap.default)(
sourcemapOutput,
JSON.stringify(sourceMap),
log,
);
return Promise.all([writeUnbundle, wroteSourceMap]);
} else {
return writeUnbundle;
}
}
const fileHeader = Buffer.alloc(4);
fileHeader.writeUInt32LE(_magicNumber.default, 0);
const nullByteBuffer = Buffer.alloc(1).fill(0);
function writeBuffers(stream, buffers) {
buffers.forEach((buffer) => stream.write(buffer));
return new Promise((resolve, reject) => {
stream.on("error", reject);
stream.on("finish", () => resolve());
stream.end();
});
}
function nullTerminatedBuffer(contents, encoding) {
return Buffer.concat([Buffer.from(contents, encoding), nullByteBuffer]);
}
function moduleToBuffer(id, code, encoding) {
return {
id,
buffer: nullTerminatedBuffer(code, encoding),
};
}
function entryOffset(n) {
return (2 + n * 2) * SIZEOF_UINT32;
}
function buildModuleTable(startupCode, moduleBuffers, moduleGroups) {
const moduleIds = [...moduleGroups.modulesById.keys()];
const maxId = moduleIds.reduce((max, id) => Math.max(max, id));
const numEntries = maxId + 1;
const table = Buffer.alloc(entryOffset(numEntries)).fill(0);
table.writeUInt32LE(numEntries, 0);
table.writeUInt32LE(startupCode.length, SIZEOF_UINT32);
let codeOffset = startupCode.length;
moduleBuffers.forEach(({ id, buffer }) => {
const group = moduleGroups.groups.get(id);
const idsInGroup = group ? [id].concat(Array.from(group)) : [id];
idsInGroup.forEach((moduleId) => {
const offset = entryOffset(moduleId);
table.writeUInt32LE(codeOffset, offset);
table.writeUInt32LE(buffer.length, offset + SIZEOF_UINT32);
});
codeOffset += buffer.length;
});
return table;
}
function groupCode(rootCode, moduleGroup, modulesById) {
if (!moduleGroup || !moduleGroup.size) {
return rootCode;
}
const code = [rootCode];
for (const id of moduleGroup) {
code.push(
(
modulesById.get(id) || {
code: "",
}
).code,
);
}
return code.join("\n");
}
function buildModuleBuffers(modules, moduleGroups, encoding) {
return modules
.filter((m) => !moduleGroups.modulesInGroups.has(m.id))
.map(({ id, code }) =>
moduleToBuffer(
id,
groupCode(code, moduleGroups.groups.get(id), moduleGroups.modulesById),
encoding,
),
);
}
function buildTableAndContents(startupCode, modules, moduleGroups, encoding) {
const startupCodeBuffer = nullTerminatedBuffer(startupCode, encoding);
const moduleBuffers = buildModuleBuffers(modules, moduleGroups, encoding);
const table = buildModuleTable(
startupCodeBuffer,
moduleBuffers,
moduleGroups,
);
return [fileHeader, table, startupCodeBuffer].concat(
moduleBuffers.map(({ buffer }) => buffer),
);
}
function createModuleGroups(groups, modules) {
return {
groups,
modulesById: new Map(modules.map((m) => [m.id, m])),
modulesInGroups: new Set(concat(groups.values())),
};
}
function* concat(iterators) {
for (const it of iterators) {
yield* it;
}
}

View File

@@ -0,0 +1,260 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
import type {
ModuleGroups,
ModuleTransportLike,
OutputOptions,
} from '../../types';
import type {WriteStream} from 'fs';
import relativizeSourceMapInline from '../../../lib/relativizeSourceMap';
import buildSourcemapWithMetadata from './buildSourcemapWithMetadata';
import MAGIC_UNBUNDLE_FILE_HEADER from './magic-number';
import {joinModules} from './util';
import writeSourceMap from './write-sourcemap';
import fs from 'fs';
const SIZEOF_UINT32 = 4;
/**
* Saves all JS modules of an app as a single file, separated with null bytes.
* The file begins with an offset table that contains module ids and their
* lengths/offsets.
* The module id for the startup code (prelude, polyfills etc.) is the
* empty string.
*/
export function save(
bundle: RamBundleInfo,
options: OutputOptions,
log: (...args: Array<string>) => void,
): Promise<unknown> {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
log('start');
const {startupModules, lazyModules, groups} = bundle;
log('finish');
const moduleGroups = createModuleGroups(groups, lazyModules);
const startupCode = joinModules(startupModules);
log('Writing unbundle output to:', bundleOutput);
const writeUnbundle = writeBuffers(
fs.createWriteStream(bundleOutput),
buildTableAndContents(startupCode, lazyModules, moduleGroups, encoding),
).then(() => log('Done writing unbundle output'));
if (sourcemapOutput) {
const sourceMap = buildSourcemapWithMetadata({
startupModules: startupModules.concat<
ModuleTransportLike,
ModuleTransportLike,
>(),
lazyModules: lazyModules.concat<
ModuleTransportLike,
ModuleTransportLike,
>(),
moduleGroups,
fixWrapperOffset: true,
});
if (sourcemapSourcesRoot != null) {
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
}
const wroteSourceMap = writeSourceMap(
sourcemapOutput,
JSON.stringify(sourceMap),
log,
);
return Promise.all([writeUnbundle, wroteSourceMap]);
} else {
return writeUnbundle;
}
}
const fileHeader = Buffer.alloc(4);
fileHeader.writeUInt32LE(MAGIC_UNBUNDLE_FILE_HEADER, 0);
const nullByteBuffer: Buffer = Buffer.alloc(1).fill(0);
function writeBuffers(
stream: WriteStream,
buffers: Array<Buffer>,
): Promise<void> {
buffers.forEach((buffer: Buffer) => stream.write(buffer));
return new Promise((resolve: () => void, reject: unknown => unknown) => {
stream.on('error', reject);
stream.on('finish', () => resolve());
stream.end();
});
}
function nullTerminatedBuffer(
contents: string,
encoding: void | 'ascii' | 'utf16le' | 'utf8',
): Buffer {
return Buffer.concat([Buffer.from(contents, encoding), nullByteBuffer]);
}
function moduleToBuffer(
id: number,
code: string,
encoding: void | 'ascii' | 'utf16le' | 'utf8',
): {buffer: Buffer, id: number} {
return {
id,
buffer: nullTerminatedBuffer(code, encoding),
};
}
function entryOffset(n: number): number {
// 2: num_entries + startup_code_len
// n * 2: each entry consists of two uint32s
return (2 + n * 2) * SIZEOF_UINT32;
}
function buildModuleTable(
startupCode: Buffer,
moduleBuffers: Array<{
buffer: Buffer,
id: number,
...
}>,
moduleGroups: ModuleGroups,
): Buffer {
// table format:
// - num_entries: uint_32 number of entries
// - startup_code_len: uint_32 length of the startup section
// - entries: entry...
//
// entry:
// - module_offset: uint_32 offset into the modules blob
// - module_length: uint_32 length of the module code in bytes
const moduleIds = [...moduleGroups.modulesById.keys()];
const maxId = moduleIds.reduce((max: number, id: number) =>
Math.max(max, id),
);
const numEntries = maxId + 1;
const table: Buffer = Buffer.alloc(entryOffset(numEntries)).fill(0);
// num_entries
table.writeUInt32LE(numEntries, 0);
// startup_code_len
table.writeUInt32LE(startupCode.length, SIZEOF_UINT32);
// entries
let codeOffset = startupCode.length;
moduleBuffers.forEach(({id, buffer}) => {
const group = moduleGroups.groups.get(id);
const idsInGroup: Array<number> = group
? [id].concat(Array.from(group))
: [id];
idsInGroup.forEach((moduleId: number) => {
const offset = entryOffset(moduleId);
// module_offset
table.writeUInt32LE(codeOffset, offset);
// module_length
table.writeUInt32LE(buffer.length, offset + SIZEOF_UINT32);
});
codeOffset += buffer.length;
});
return table;
}
function groupCode(
rootCode: string,
moduleGroup: void | Set<number>,
modulesById: Map<number, ModuleTransportLike>,
): string {
if (!moduleGroup || !moduleGroup.size) {
return rootCode;
}
const code = [rootCode];
for (const id of moduleGroup) {
code.push((modulesById.get(id) || {code: ''}).code);
}
return code.join('\n');
}
function buildModuleBuffers(
modules: ReadonlyArray<ModuleTransportLike>,
moduleGroups: ModuleGroups,
encoding: void | 'ascii' | 'utf16le' | 'utf8',
): Array<{
buffer: Buffer,
id: number,
...
}> {
return modules
.filter((m: ModuleTransportLike) => !moduleGroups.modulesInGroups.has(m.id))
.map(({id, code}) =>
moduleToBuffer(
id,
groupCode(code, moduleGroups.groups.get(id), moduleGroups.modulesById),
encoding,
),
);
}
export function buildTableAndContents(
startupCode: string,
modules: ReadonlyArray<ModuleTransportLike>,
moduleGroups: ModuleGroups,
encoding?: 'utf8' | 'utf16le' | 'ascii',
): Array<Buffer> {
// file contents layout:
// - magic number char[4] 0xE5 0xD1 0x0B 0xFB (0xFB0BD1E5 uint32 LE)
// - offset table table see `buildModuleTables`
// - code blob char[] null-terminated code strings, starting with
// the startup code
const startupCodeBuffer = nullTerminatedBuffer(startupCode, encoding);
const moduleBuffers = buildModuleBuffers(modules, moduleGroups, encoding);
const table = buildModuleTable(
startupCodeBuffer,
moduleBuffers,
moduleGroups,
);
return [fileHeader, table, startupCodeBuffer].concat(
moduleBuffers.map(({buffer}) => buffer),
);
}
export function createModuleGroups(
groups: Map<number, Set<number>>,
modules: ReadonlyArray<ModuleTransportLike>,
): ModuleGroups {
return {
groups,
modulesById: new Map(modules.map((m: ModuleTransportLike) => [m.id, m])),
modulesInGroups: new Set(concat(groups.values())),
};
}
function* concat(
iterators: Iterator<Set<number>>,
): Generator<number, void, void> {
for (const it of iterators) {
yield* it;
}
}

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<669a46ab2a802ea2b93d98edf337fff0>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/buildSourcemapWithMetadata.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {ModuleGroups, ModuleTransportLike} from '../../types';
import type {IndexMap} from 'metro-source-map';
type Params = {
fixWrapperOffset: boolean;
lazyModules: ReadonlyArray<ModuleTransportLike>;
moduleGroups: null | undefined | ModuleGroups;
startupModules: ReadonlyArray<ModuleTransportLike>;
};
declare const $$EXPORT_DEFAULT_DECLARATION$$: ($$PARAM_0$$: Params) => IndexMap;
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
typeof $$EXPORT_DEFAULT_DECLARATION$$;
export default $$EXPORT_DEFAULT_DECLARATION$$;

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = void 0;
var _util = require("./util");
var _default = ({
fixWrapperOffset,
lazyModules,
moduleGroups,
startupModules,
}) => {
const options = fixWrapperOffset
? {
fixWrapperOffset: true,
}
: undefined;
const startupModule = {
code: (0, _util.joinModules)(startupModules),
id: Number.MIN_SAFE_INTEGER,
map: (0, _util.combineSourceMaps)(startupModules, undefined, options),
sourcePath: "",
};
const module_paths = [];
startupModules.forEach((m) => {
module_paths[m.id] = m.sourcePath;
});
lazyModules.forEach((m) => {
module_paths[m.id] = m.sourcePath;
});
const map = (0, _util.combineSourceMapsAddingOffsets)(
[startupModule].concat(lazyModules),
module_paths,
moduleGroups,
options,
);
if (map.x_facebook_offsets != null) {
delete map.x_facebook_offsets[Number.MIN_SAFE_INTEGER];
}
return map;
};
exports.default = _default;

View File

@@ -0,0 +1,62 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {ModuleGroups, ModuleTransportLike} from '../../types';
import type {IndexMap} from 'metro-source-map';
import {
combineSourceMaps,
combineSourceMapsAddingOffsets,
joinModules,
} from './util';
type Params = {
fixWrapperOffset: boolean,
lazyModules: ReadonlyArray<ModuleTransportLike>,
moduleGroups: ?ModuleGroups,
startupModules: ReadonlyArray<ModuleTransportLike>,
};
export default ({
fixWrapperOffset,
lazyModules,
moduleGroups,
startupModules,
}: Params): IndexMap => {
const options = fixWrapperOffset ? {fixWrapperOffset: true} : undefined;
const startupModule: ModuleTransportLike = {
code: joinModules(startupModules),
id: Number.MIN_SAFE_INTEGER,
map: combineSourceMaps(startupModules, undefined, options),
sourcePath: '',
};
// Add map of module id -> source to sourcemap
const module_paths = [];
startupModules.forEach((m: ModuleTransportLike) => {
module_paths[m.id] = m.sourcePath;
});
lazyModules.forEach((m: ModuleTransportLike) => {
module_paths[m.id] = m.sourcePath;
});
const map = combineSourceMapsAddingOffsets(
[startupModule].concat(lazyModules),
module_paths,
moduleGroups,
options,
);
if (map.x_facebook_offsets != null) {
delete map.x_facebook_offsets[Number.MIN_SAFE_INTEGER];
}
return map;
};

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<94cd41a2f04528e81f82e6c2feadaf52>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/magic-number.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
declare const $$EXPORT_DEFAULT_DECLARATION$$: 0xfb0bd1e5;
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
typeof $$EXPORT_DEFAULT_DECLARATION$$;
export default $$EXPORT_DEFAULT_DECLARATION$$;

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = void 0;
var _default = (exports.default = 0xfb0bd1e5);

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
export default 0xfb0bd1e5;

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<cb3371e2f23da9cd30e08ed76ec4f7db>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/util.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {ModuleGroups, ModuleTransportLike} from '../../types';
import type {BasicSourceMap, IndexMap} from 'metro-source-map';
import countLines from '../../../lib/countLines';
declare function lineToLineSourceMap(
source: string,
filename?: string,
): BasicSourceMap;
type CombineOptions = {fixWrapperOffset: boolean};
declare function combineSourceMaps(
modules: ReadonlyArray<ModuleTransportLike>,
moduleGroups?: ModuleGroups,
options?: null | undefined | CombineOptions,
): IndexMap;
declare function combineSourceMapsAddingOffsets(
modules: ReadonlyArray<ModuleTransportLike>,
x_metro_module_paths: Array<string>,
moduleGroups?: null | undefined | ModuleGroups,
options?: null | undefined | CombineOptions,
): IndexMap;
declare const joinModules: (
modules: ReadonlyArray<{readonly code: string}>,
) => string;
export {
combineSourceMaps,
combineSourceMapsAddingOffsets,
countLines,
joinModules,
lineToLineSourceMap,
};

111
node_modules/metro/src/shared/output/RamBundle/util.js generated vendored Normal file
View File

@@ -0,0 +1,111 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.combineSourceMaps = combineSourceMaps;
exports.combineSourceMapsAddingOffsets = combineSourceMapsAddingOffsets;
Object.defineProperty(exports, "countLines", {
enumerable: true,
get: function () {
return _countLines.default;
},
});
exports.joinModules = void 0;
exports.lineToLineSourceMap = lineToLineSourceMap;
var _countLines = _interopRequireDefault(require("../../../lib/countLines"));
var _invariant = _interopRequireDefault(require("invariant"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
function lineToLineSourceMap(source, filename = "") {
const firstLine = "AAAA;";
const line = "AACA;";
return {
file: filename,
mappings: firstLine + Array((0, _countLines.default)(source)).join(line),
sources: [filename],
names: [],
version: 3,
};
}
const wrapperEnd = (wrappedCode) => wrappedCode.indexOf("{") + 1;
const Section = (line, column, map) => ({
map,
offset: {
line,
column,
},
});
function combineSourceMaps(modules, moduleGroups, options) {
const sections = combineMaps(modules, null, moduleGroups, options);
return {
sections,
version: 3,
};
}
function combineSourceMapsAddingOffsets(
modules,
x_metro_module_paths,
moduleGroups,
options,
) {
const x_facebook_offsets = [];
const sections = combineMaps(
modules,
x_facebook_offsets,
moduleGroups,
options,
);
return {
sections,
version: 3,
x_facebook_offsets,
x_metro_module_paths,
};
}
function combineMaps(modules, offsets, moduleGroups, options) {
const sections = [];
let line = 0;
modules.forEach((moduleTransport) => {
const { code, id, name } = moduleTransport;
let column = 0;
let group;
let groupLines = 0;
let { map } = moduleTransport;
if (moduleGroups && moduleGroups.modulesInGroups.has(id)) {
return;
}
if (offsets != null) {
group = moduleGroups && moduleGroups.groups.get(id);
if (group && moduleGroups) {
const { modulesById } = moduleGroups;
const otherModules = Array.from(group || [])
.map((moduleId) => modulesById.get(moduleId))
.filter(Boolean);
otherModules.forEach((m) => {
groupLines += (0, _countLines.default)(m.code);
});
map = combineSourceMaps([moduleTransport].concat(otherModules));
}
column = options && options.fixWrapperOffset ? wrapperEnd(code) : 0;
}
(0, _invariant.default)(
!Array.isArray(map),
"Random Access Bundle source maps cannot be built from raw mappings",
);
sections.push(
Section(line, column, map || lineToLineSourceMap(code, name)),
);
if (offsets != null && id != null) {
offsets[id] = line;
for (const moduleId of group || []) {
offsets[moduleId] = line;
}
}
line += (0, _countLines.default)(code) + groupLines;
});
return sections;
}
const joinModules = (modules) => modules.map((m) => m.code).join("\n");
exports.joinModules = joinModules;

View File

@@ -0,0 +1,147 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {ModuleGroups, ModuleTransportLike} from '../../types';
import type {
BasicSourceMap,
IndexMap,
IndexMapSection,
MixedSourceMap,
} from 'metro-source-map';
import countLines from '../../../lib/countLines';
import invariant from 'invariant';
function lineToLineSourceMap(
source: string,
filename: string = '',
): BasicSourceMap {
// The first line mapping in our package is the base64vlq code for zeros (A).
const firstLine = 'AAAA;';
// Most other lines in our mappings are all zeros (for module, column etc)
// except for the lineno mapping: curLineno - prevLineno = 1; Which is C.
const line = 'AACA;';
return {
file: filename,
mappings: firstLine + Array(countLines(source)).join(line),
sources: [filename],
names: [],
version: 3,
};
}
const wrapperEnd = (wrappedCode: string) => wrappedCode.indexOf('{') + 1;
const Section = (line: number, column: number, map: MixedSourceMap) => ({
map,
offset: {line, column},
});
type CombineOptions = {fixWrapperOffset: boolean, ...};
function combineSourceMaps(
modules: ReadonlyArray<ModuleTransportLike>,
moduleGroups?: ModuleGroups,
options?: ?CombineOptions,
): IndexMap {
const sections = combineMaps(modules, null, moduleGroups, options);
return {sections, version: 3};
}
function combineSourceMapsAddingOffsets(
modules: ReadonlyArray<ModuleTransportLike>,
x_metro_module_paths: Array<string>,
moduleGroups?: ?ModuleGroups,
options?: ?CombineOptions,
): IndexMap {
const x_facebook_offsets: Array<number> = [];
const sections = combineMaps(
modules,
x_facebook_offsets,
moduleGroups,
options,
);
return {sections, version: 3, x_facebook_offsets, x_metro_module_paths};
}
function combineMaps(
modules: ReadonlyArray<ModuleTransportLike>,
offsets: ?Array<number>,
moduleGroups: ?ModuleGroups,
options: ?CombineOptions,
): Array<IndexMapSection> {
const sections: Array<IndexMapSection> = [];
let line = 0;
modules.forEach((moduleTransport: ModuleTransportLike) => {
const {code, id, name} = moduleTransport;
let column = 0;
let group;
let groupLines = 0;
let {map} = moduleTransport;
if (moduleGroups && moduleGroups.modulesInGroups.has(id)) {
// this is a module appended to another module
return;
}
if (offsets != null) {
group = moduleGroups && moduleGroups.groups.get(id);
if (group && moduleGroups) {
const {modulesById} = moduleGroups;
const otherModules: ReadonlyArray<ModuleTransportLike> = Array.from(
group || [],
)
.map((moduleId: number) => modulesById.get(moduleId))
.filter(Boolean); // needed to appease flow
otherModules.forEach((m: ModuleTransportLike) => {
groupLines += countLines(m.code);
});
map = combineSourceMaps([moduleTransport].concat(otherModules));
}
column = options && options.fixWrapperOffset ? wrapperEnd(code) : 0;
}
invariant(
!Array.isArray(map),
'Random Access Bundle source maps cannot be built from raw mappings',
);
sections.push(
/* $FlowFixMe[incompatible-exact] Natural Inference rollout. See
* https://fburl.com/gdoc/y8dn025u */
// $FlowFixMe[incompatible-type]
Section(line, column, map || lineToLineSourceMap(code, name)),
);
if (offsets != null && id != null) {
offsets[id] = line;
for (const moduleId of group || []) {
offsets[moduleId] = line;
}
}
line += countLines(code) + groupLines;
});
return sections;
}
const joinModules = (modules: ReadonlyArray<{+code: string, ...}>): string =>
modules.map((m: {+code: string, ...}) => m.code).join('\n');
export {
combineSourceMaps,
combineSourceMapsAddingOffsets,
countLines,
joinModules,
lineToLineSourceMap,
};

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<000f29900c01342de92d247507075575>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/RamBundle/write-sourcemap.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
declare function writeSourcemap(
fileName: string,
contents: string,
log: (...args: Array<string>) => void,
): Promise<unknown>;
export default writeSourcemap;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = writeSourcemap;
var _writeFile = _interopRequireDefault(require("../writeFile"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
function writeSourcemap(fileName, contents, log) {
if (!fileName) {
return Promise.resolve();
}
log("Writing sourcemap output to:", fileName);
const writeMap = (0, _writeFile.default)(fileName, contents);
writeMap.then(() => log("Done writing sourcemap output"));
return writeMap;
}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import writeFile from '../writeFile';
export default function writeSourcemap(
fileName: string,
contents: string,
log: (...args: Array<string>) => void,
): Promise<unknown> {
if (!fileName) {
return Promise.resolve();
}
log('Writing sourcemap output to:', fileName);
const writeMap = writeFile(fileName, contents);
// $FlowFixMe[unused-promise]
writeMap.then(() => log('Done writing sourcemap output'));
return writeMap;
}

34
node_modules/metro/src/shared/output/bundle.d.ts generated vendored Normal file
View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<d9877b2ba27e8e3f279901c80c7ad895>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/bundle.flow.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {AssetData} from '../../Assets';
import type {BuildOptions, OutputOptions, RequestOptions} from '../types';
import Server from '../../Server';
export declare function build(
packagerClient: Server,
requestOptions: RequestOptions,
buildOptions?: BuildOptions,
): Promise<{code: string; map: string; assets?: ReadonlyArray<AssetData>}>;
export declare function save(
bundle: {code: string; map: string},
options: OutputOptions,
log: ($$PARAM_0$$: string) => void,
): Promise<unknown>;
export declare const formatName: 'bundle';
export declare type formatName = typeof formatName;

74
node_modules/metro/src/shared/output/bundle.flow.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.build = build;
exports.formatName = void 0;
exports.save = save;
var _relativizeSourceMap = _interopRequireDefault(
require("../../lib/relativizeSourceMap"),
);
var _Server = _interopRequireDefault(require("../../Server"));
var _writeFile = _interopRequireDefault(require("./writeFile"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const DEFAULTS = _Server.default.DEFAULT_BUNDLE_OPTIONS;
function build(packagerClient, requestOptions, buildOptions = {}) {
return packagerClient.build(
{
...DEFAULTS,
...requestOptions,
...{
customResolverOptions:
requestOptions.customResolverOptions ??
DEFAULTS.customResolverOptions,
customTransformOptions:
requestOptions.customTransformOptions ??
DEFAULTS.customTransformOptions,
dev: requestOptions.dev ?? DEFAULTS.dev,
inlineSourceMap:
requestOptions.inlineSourceMap ?? DEFAULTS.inlineSourceMap,
unstable_transformProfile:
requestOptions.unstable_transformProfile ??
DEFAULTS.unstable_transformProfile,
},
},
buildOptions,
);
}
function relativateSerializedMap(map, sourceMapSourcesRoot) {
const sourceMap = JSON.parse(map);
(0, _relativizeSourceMap.default)(sourceMap, sourceMapSourcesRoot);
return JSON.stringify(sourceMap);
}
async function save(bundle, options, log) {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
const writeFns = [];
writeFns.push(async () => {
log(`Writing bundle output to: ${bundleOutput}`);
await (0, _writeFile.default)(bundleOutput, bundle.code, encoding);
log("Done writing bundle output");
});
if (sourcemapOutput) {
let { map } = bundle;
if (sourcemapSourcesRoot != null) {
log("start relativating source map");
map = relativateSerializedMap(map, sourcemapSourcesRoot);
log("finished relativating");
}
writeFns.push(async () => {
log(`Writing sourcemap output to: ${sourcemapOutput}`);
await (0, _writeFile.default)(sourcemapOutput, map);
log("Done writing sourcemap output");
});
}
await Promise.all(writeFns.map((cb) => cb()));
}
const formatName = (exports.formatName = "bundle");

View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
import type {AssetData} from '../../Assets';
import type {BuildOptions, OutputOptions, RequestOptions} from '../types';
import type {MixedSourceMap} from 'metro-source-map';
import relativizeSourceMapInline from '../../lib/relativizeSourceMap';
import Server from '../../Server';
import writeFile from './writeFile';
const DEFAULTS = Server.DEFAULT_BUNDLE_OPTIONS;
export function build(
packagerClient: Server,
requestOptions: RequestOptions,
buildOptions?: BuildOptions = {},
): Promise<{
code: string,
map: string,
assets?: ReadonlyArray<AssetData>,
...
}> {
return packagerClient.build(
{
...DEFAULTS,
...requestOptions,
...{
customResolverOptions:
requestOptions.customResolverOptions ??
DEFAULTS.customResolverOptions,
customTransformOptions:
requestOptions.customTransformOptions ??
DEFAULTS.customTransformOptions,
dev: requestOptions.dev ?? DEFAULTS.dev,
inlineSourceMap:
requestOptions.inlineSourceMap ?? DEFAULTS.inlineSourceMap,
unstable_transformProfile:
requestOptions.unstable_transformProfile ??
DEFAULTS.unstable_transformProfile,
},
},
buildOptions,
);
}
function relativateSerializedMap(
map: string,
sourceMapSourcesRoot: string,
): string {
const sourceMap: MixedSourceMap = JSON.parse(map);
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
return JSON.stringify(sourceMap);
}
export async function save(
bundle: {
code: string,
map: string,
...
},
options: OutputOptions,
log: string => void,
): Promise<unknown> {
const {
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput,
sourcemapSourcesRoot,
} = options;
const writeFns = [];
writeFns.push(async () => {
log(`Writing bundle output to: ${bundleOutput}`);
await writeFile(bundleOutput, bundle.code, encoding);
log('Done writing bundle output');
});
if (sourcemapOutput) {
let {map} = bundle;
if (sourcemapSourcesRoot != null) {
log('start relativating source map');
map = relativateSerializedMap(map, sourcemapSourcesRoot);
log('finished relativating');
}
writeFns.push(async () => {
log(`Writing sourcemap output to: ${sourcemapOutput}`);
await writeFile(sourcemapOutput, map);
log('Done writing sourcemap output');
});
}
// Wait until everything is written to disk.
await Promise.all(writeFns.map((cb: void => unknown) => cb()));
}
export const formatName = 'bundle';

6
node_modules/metro/src/shared/output/bundle.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
"use strict";
try {
require("metro-babel-register").unstable_registerForMetroMonorepo();
} catch {}
module.exports = require("./bundle.flow");

24
node_modules/metro/src/shared/output/bundle.js.flow generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
/* eslint-disable import/no-commonjs */
'use strict';
/*::
export type * from './bundle.flow';
*/
try {
require('metro-babel-register').unstable_registerForMetroMonorepo();
} catch {}
module.exports = require('./bundle.flow');

22
node_modules/metro/src/shared/output/meta.d.ts generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<17ae3fc242dc6b3915a72d04dad032b8>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/meta.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
declare function meta(
code: Buffer | string,
encoding?: 'ascii' | 'utf16le' | 'utf8',
): Buffer;
export default meta;

49
node_modules/metro/src/shared/output/meta.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = meta;
var _crypto = _interopRequireDefault(require("crypto"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const isUTF8 = (encoding) => /^utf-?8$/i.test(encoding);
const constantFor = (encoding) =>
/^ascii$/i.test(encoding)
? 1
: isUTF8(encoding)
? 2
: /^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding)
? 3
: 0;
function meta(code, encoding = "utf8") {
const buffer = asBuffer(code, encoding);
const hash = _crypto.default.createHash("sha1");
hash.update(buffer);
const digest = hash.digest("buffer");
const signature = Buffer.alloc(digest.length + 1);
digest.copy(signature);
signature.writeUInt8(
constantFor(tryAsciiPromotion(buffer, encoding)),
signature.length - 1,
);
return signature;
}
function tryAsciiPromotion(buffer, encoding) {
if (!isUTF8(encoding)) {
return encoding;
}
for (let i = 0, n = buffer.length; i < n; i++) {
if (buffer[i] > 0x7f) {
return encoding;
}
}
return "ascii";
}
function asBuffer(x, encoding) {
if (typeof x !== "string") {
return x;
}
return Buffer.from(x, encoding);
}

66
node_modules/metro/src/shared/output/meta.js.flow generated vendored Normal file
View File

@@ -0,0 +1,66 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
import crypto from 'crypto';
const isUTF8 = (encoding: 'ascii' | 'utf16le' | 'utf8') =>
/^utf-?8$/i.test(encoding);
const constantFor = (encoding: 'ascii' | 'utf16le' | 'utf8') =>
/^ascii$/i.test(encoding)
? 1
: isUTF8(encoding)
? 2
: /^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding)
? 3
: 0;
export default function meta(
code: Buffer | string,
encoding: 'ascii' | 'utf16le' | 'utf8' = 'utf8',
): Buffer {
const buffer: Buffer = asBuffer(code, encoding);
const hash = crypto.createHash('sha1');
hash.update(buffer);
const digest = hash.digest('buffer');
const signature = Buffer.alloc(digest.length + 1);
digest.copy(signature);
signature.writeUInt8(
constantFor(tryAsciiPromotion(buffer, encoding)),
signature.length - 1,
);
return signature;
}
function tryAsciiPromotion(
buffer: Buffer,
encoding: 'ascii' | 'utf16le' | 'utf8',
): 'ascii' | 'utf16le' | 'utf8' {
if (!isUTF8(encoding)) {
return encoding;
}
for (let i = 0, n = buffer.length; i < n; i++) {
if (buffer[i] > 0x7f) {
return encoding;
}
}
return 'ascii';
}
function asBuffer(
x: Buffer | string,
encoding: 'ascii' | 'utf16le' | 'utf8',
): Buffer {
if (typeof x !== 'string') {
return x;
}
return Buffer.from(x, encoding);
}

18
node_modules/metro/src/shared/output/unbundle.d.ts generated vendored Normal file
View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<12b27507f799c8170067738c227bb2f3>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/unbundle.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
export * from './RamBundle';

16
node_modules/metro/src/shared/output/unbundle.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
var _RamBundle = require("./RamBundle");
Object.keys(_RamBundle).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _RamBundle[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _RamBundle[key];
},
});
});

14
node_modules/metro/src/shared/output/unbundle.js.flow generated vendored Normal file
View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
/* This is for retro-compatibility of React Native with older versions of
* Metro. Use the `RamBundle` module directly. */
export * from './RamBundle';

23
node_modules/metro/src/shared/output/writeFile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<37de849e415f8aa1e94b73289a573ee3>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/output/writeFile.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
declare function writeFile(
filePath: string,
data: string | Buffer | Uint8Array,
encoding?: string,
): Promise<void>;
export default writeFile;

18
node_modules/metro/src/shared/output/writeFile.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = writeFile;
var _fs = _interopRequireDefault(require("fs"));
var _throat = _interopRequireDefault(require("throat"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const writeFileWithThroat = (0, _throat.default)(
128,
_fs.default.promises.writeFile,
);
function writeFile(filePath, data, encoding) {
return writeFileWithThroat(filePath, data, encoding);
}

26
node_modules/metro/src/shared/output/writeFile.js.flow generated vendored Normal file
View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import fs from 'fs';
import throat from 'throat';
const writeFileWithThroat: typeof fs.promises.writeFile = throat(
128,
fs.promises.writeFile,
);
export default function writeFile(
filePath: string,
data: string | Buffer | Uint8Array,
encoding?: string,
): Promise<void> {
return writeFileWithThroat(filePath, data, encoding);
}

152
node_modules/metro/src/shared/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,152 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @oncall react_native
* @generated SignedSource<<31593693c0cafcd55eaf4885efddc6be>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/metro/src/shared/types.js
* To regenerate, run:
* js1 build metro-ts-defs (internal) OR
* yarn run build-ts-defs (OSS)
*/
import type {
Options as DeltaBundlerOptions,
TransformInputOptions,
} from '../DeltaBundler/types';
import type {TransformProfile} from 'metro-babel-transformer';
import type {CustomResolverOptions} from 'metro-resolver';
import type {
MetroSourceMapSegmentTuple,
MixedSourceMap,
} from 'metro-source-map';
import type {
CustomTransformOptions,
MinifierOptions,
} from 'metro-transform-worker';
type MetroSourceMapOrMappings =
| MixedSourceMap
| Array<MetroSourceMapSegmentTuple>;
export declare enum SourcePathsMode {
Absolute = 'absolute',
ServerUrl = 'url-server',
}
export declare namespace SourcePathsMode {
export function cast(value: string | null | undefined): SourcePathsMode;
export function isValid(
value: string | null | undefined,
): value is SourcePathsMode;
export function members(): IterableIterator<SourcePathsMode>;
export function getName(value: SourcePathsMode): string;
}
export type ReadonlySourceLocation = Readonly<{
start: Readonly<{line: number; column: number}>;
end: Readonly<{line: number; column: number}>;
}>;
export type BundleOptions = {
readonly customResolverOptions: CustomResolverOptions;
customTransformOptions: CustomTransformOptions;
dev: boolean;
entryFile: string;
readonly excludeSource: boolean;
readonly inlineSourceMap: boolean;
readonly lazy: boolean;
minify: boolean;
readonly modulesOnly: boolean;
onProgress:
| null
| undefined
| ((doneCont: number, totalCount: number) => unknown);
readonly platform: null | undefined | string;
readonly runModule: boolean;
readonly shallow: boolean;
sourceMapUrl: null | undefined | string;
sourceUrl: null | undefined | string;
createModuleIdFactory?: () => (path: string) => number;
readonly unstable_transformProfile: TransformProfile;
readonly sourcePaths: SourcePathsMode;
};
export type BuildOptions = Readonly<{withAssets?: boolean}>;
export type ResolverInputOptions = Readonly<{
customResolverOptions?: CustomResolverOptions;
dev: boolean;
}>;
export type SerializerOptions = {
readonly sourceMapUrl: null | undefined | string;
readonly sourceUrl: null | undefined | string;
readonly runModule: boolean;
readonly excludeSource: boolean;
readonly inlineSourceMap: boolean;
readonly modulesOnly: boolean;
readonly sourcePaths: SourcePathsMode;
};
export type GraphOptions = {
readonly lazy: boolean;
readonly shallow: boolean;
};
export type SplitBundleOptions = Readonly<{
entryFile: string;
resolverOptions: ResolverInputOptions;
transformOptions: TransformInputOptions;
serializerOptions: SerializerOptions;
graphOptions: GraphOptions;
onProgress: DeltaBundlerOptions['onProgress'];
}>;
export type ModuleGroups = {
groups: Map<number, Set<number>>;
modulesById: Map<number, ModuleTransportLike>;
modulesInGroups: Set<number>;
};
export type ModuleTransportLike = {
readonly code: string;
readonly id: number;
readonly map: null | undefined | MetroSourceMapOrMappings;
readonly name?: string;
readonly sourcePath: string;
};
export type ModuleTransportLikeStrict = {
readonly code: string;
readonly id: number;
readonly map: null | undefined | MetroSourceMapOrMappings;
readonly name?: string;
readonly sourcePath: string;
};
export type RamModuleTransport = Omit<
ModuleTransportLikeStrict,
keyof {readonly source: string; readonly type: string}
> & {readonly source: string; readonly type: string};
export type OutputOptions = {
bundleOutput: string;
bundleEncoding?: 'utf8' | 'utf16le' | 'ascii';
dev?: boolean;
indexedRamBundle?: boolean;
platform: string;
sourcemapOutput?: string;
sourcemapSourcesRoot?: string;
sourcemapUseAbsolutePath?: boolean;
};
type SafeOptionalProps<T> = {
[K in keyof T]: T[K] extends void ? void | T[K] : T[K];
};
export type RequestOptions = Readonly<
SafeOptionalProps<{
entryFile: string;
inlineSourceMap?: boolean;
sourceMapUrl?: string;
dev?: boolean;
minify: boolean;
platform: string;
createModuleIdFactory?: () => (path: string) => number;
onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
customResolverOptions?: CustomResolverOptions;
customTransformOptions?: CustomTransformOptions;
unstable_transformProfile?: TransformProfile;
}>
>;
export type {MinifierOptions};

11
node_modules/metro/src/shared/types.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.SourcePathsMode = void 0;
const SourcePathsMode = (exports.SourcePathsMode =
require("flow-enums-runtime")({
Absolute: "absolute",
ServerUrl: "url-server",
}));

163
node_modules/metro/src/shared/types.js.flow generated vendored Normal file
View File

@@ -0,0 +1,163 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {
Options as DeltaBundlerOptions,
TransformInputOptions,
} from '../DeltaBundler/types';
import type {TransformProfile} from 'metro-babel-transformer';
import type {CustomResolverOptions} from 'metro-resolver';
import type {
MetroSourceMapSegmentTuple,
MixedSourceMap,
} from 'metro-source-map';
import type {
CustomTransformOptions,
MinifierOptions,
} from 'metro-transform-worker';
type MetroSourceMapOrMappings =
| MixedSourceMap
| Array<MetroSourceMapSegmentTuple>;
export enum SourcePathsMode {
/* Use absolute paths for source files in source maps (default). */
Absolute = 'absolute',
/* Use server-relative URL paths for source files in source maps. */
ServerUrl = 'url-server',
}
export type ReadonlySourceLocation = Readonly<{
start: Readonly<{
line: number,
column: number,
}>,
end: Readonly<{
line: number,
column: number,
}>,
}>;
export type BundleOptions = {
+customResolverOptions: CustomResolverOptions,
customTransformOptions: CustomTransformOptions,
dev: boolean,
entryFile: string,
+excludeSource: boolean,
+inlineSourceMap: boolean,
+lazy: boolean,
minify: boolean,
+modulesOnly: boolean,
onProgress: ?(doneCont: number, totalCount: number) => unknown,
+platform: ?string,
+runModule: boolean,
+shallow: boolean,
sourceMapUrl: ?string,
sourceUrl: ?string,
createModuleIdFactory?: () => (path: string) => number,
+unstable_transformProfile: TransformProfile,
+sourcePaths: SourcePathsMode,
};
export type BuildOptions = Readonly<{
withAssets?: boolean,
}>;
export type ResolverInputOptions = Readonly<{
customResolverOptions?: CustomResolverOptions,
dev: boolean,
}>;
export type SerializerOptions = {
+sourceMapUrl: ?string,
+sourceUrl: ?string,
+runModule: boolean,
+excludeSource: boolean,
+inlineSourceMap: boolean,
+modulesOnly: boolean,
+sourcePaths: SourcePathsMode,
};
export type GraphOptions = {
+lazy: boolean,
+shallow: boolean,
};
// Stricter representation of BundleOptions.
export type SplitBundleOptions = Readonly<{
entryFile: string,
resolverOptions: ResolverInputOptions,
transformOptions: TransformInputOptions,
serializerOptions: SerializerOptions,
graphOptions: GraphOptions,
onProgress: DeltaBundlerOptions<>['onProgress'],
}>;
export type ModuleGroups = {
groups: Map<number, Set<number>>,
modulesById: Map<number, ModuleTransportLike>,
modulesInGroups: Set<number>,
};
export type ModuleTransportLike = {
+code: string,
+id: number,
+map: ?MetroSourceMapOrMappings,
+name?: string,
+sourcePath: string,
...
};
export type ModuleTransportLikeStrict = {
+code: string,
+id: number,
+map: ?MetroSourceMapOrMappings,
+name?: string,
+sourcePath: string,
};
export type RamModuleTransport = {
...ModuleTransportLikeStrict,
+source: string,
+type: string,
};
export type OutputOptions = {
bundleOutput: string,
bundleEncoding?: 'utf8' | 'utf16le' | 'ascii',
dev?: boolean,
indexedRamBundle?: boolean,
platform: string,
sourcemapOutput?: string,
sourcemapSourcesRoot?: string,
sourcemapUseAbsolutePath?: boolean,
...
};
type SafeOptionalProps<T> = {
[K in keyof T]: T[K] extends void ? void | T[K] : T[K],
};
export type RequestOptions = Readonly<
SafeOptionalProps<{
entryFile: string,
inlineSourceMap?: boolean,
sourceMapUrl?: string,
dev?: boolean,
minify: boolean,
platform: string,
createModuleIdFactory?: () => (path: string) => number,
onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
customResolverOptions?: CustomResolverOptions,
customTransformOptions?: CustomTransformOptions,
unstable_transformProfile?: TransformProfile,
}>,
>;
export type {MinifierOptions};