Skip to content

Commit

Permalink
feat(metro-config): fork entire transform worker (#25833)
Browse files Browse the repository at this point in the history
# Why

- Alternative to #25774 -- we'll fork
the transform worker and serializer (already done) and implement custom
asset hashing that is platform-specific and won't modify native output.
- I've been meaning to do this for a while since we already moved the
inline constants plugin to babel-preset-expo to fix Platform shaking.
Because of this, ~~we can remove an entire babel transform pass in
development when inline requires and experimental export support are
disabled (default, possibly forever).~~ need to keep this enabled for
some mystery reason, will re-approach in the future.
- To emulate the default behavior prescribed by the upstream tests, I've
added support for automatically disabling the import/export transform
based on if `experimentalImportSupport` is enabled. We do this by
passing the Babel-standard caller flag `supportsStaticESM` to
`babel-preset-expo`, which actually makes the entire cjs conversion
bundler agnostic (for bundlers that support Babel).
- I've locked the `babel/generator` version as there appears to be a bug
(or fix?) in the newer patch that silently makes source maps only apply
to the output code and not the input, which breaks the upstream tests.
This could possibly be the missing solution to my tree-shaking branch
and why I couldn't get the transforms to match in the serializer.
- Most of this PR is just adding types for everything and porting the
tests.
- This PR adds built-in centralized hashing for production export assets
on web-only. We don't need to modify the output pipeline anymore since
everything is handled in the transformer logic.

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
EvanBacon and expo-bot committed Dec 11, 2023
1 parent 40c1761 commit 3ba3d6e
Show file tree
Hide file tree
Showing 51 changed files with 2,641 additions and 130 deletions.
9 changes: 5 additions & 4 deletions packages/@expo/cli/e2e/__tests__/export-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ describe('server', () => {
async () => {
const projectRoot = await setupTestProjectAsync('basic-export', 'with-assets');
// `npx expo export`
await execa('node', [bin, 'export', '--dump-sourcemap', '--dump-assetmap'], {
await execa('node', [bin, 'export', '--source-maps', '--dump-assetmap'], {
cwd: projectRoot,
env: {
NODE_ENV: 'production',
TEST_BABEL_PRESET_EXPO_MODULE_ID: require.resolve('babel-preset-expo'),
EXPO_USE_FAST_RESOLVER: 'false',
},
});
Expand Down Expand Up @@ -197,9 +198,9 @@ describe('server', () => {
'assets/2f334f6c7ca5b2a504bdf8acdee104f3',
'assets/3858f62230ac3c915f300c664312c63f',
'assets/9ce7db807e4147e00df372d053c154c2',
'assets/assets/font.ttf',
'assets/assets/icon.png',
'assets/assets/icon@2x.png',
'assets/assets/font.3858f62230ac3c915f300c664312c63f.ttf',
'assets/assets/icon.8034d8318b239108719ff3f22f31ef15.png',
'assets/assets/icon.8034d8318b239108719ff3f22f31ef15@2x.png',

'assets/fb960eb5e4eb49ec8786c7f6c4a57ce2',
'debug.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-web
@keyframes r-1pzkwqh{0%{transform:translateY(100%);}100%{transform:translateY(0%);}}
@keyframes r-imtty0{0%{opacity:0;}100%{opacity:1;}}
@keyframes r-q67da2{0%{transform:translateX(-100%);}100%{transform:translateX(400%);}}
@keyframes r-t2lo5v{0%{opacity:1;}100%{opacity:0;}}</style><style id="expo-generated-fonts" type="text/css">@font-face{font-family:sweet;src:url(/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07);font-display:auto}</style><link rel="preload" href="/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07" as="font" crossorigin="" /><link rel="preload" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css" as="style"><link rel="stylesheet" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css"><link rel="preload" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css" as="style"><link rel="stylesheet" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css"></head><body><div id="root"><div class="css-175oi2r r-13awgt0"><!--$--><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0 r-1d5kdc7 r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af" style="background-color:rgba(242,242,242,1.00);display:flex"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><!--$--><div dir="auto" class="css-146c3p1" style="font-family:sweet" data-testid="index-text">Index</div><!--/$--></div></div><div class="css-175oi2r"><div class="css-175oi2r r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af r-12vffkv" style="z-index:0"><div class="css-175oi2r r-qklmqi r-13awgt0" style="box-shadow:0px 0px 0px rgba(216,216,216,1.00);background-color:rgba(255,255,255,1.00);border-bottom-color:rgba(216,216,216,1.00)"></div></div><div class="css-175oi2r r-12vffkv" style="height:64px"><div class="css-175oi2r r-633pao" style="height:0px"></div><div class="css-175oi2r r-1oszu61 r-13awgt0 r-18u37iz r-12vffkv"><div class="css-175oi2r r-1habvwh r-1777fci r-12vffkv" style="margin-left:0px"></div><div class="css-175oi2r r-1777fci r-1xpp3t0 r-12vffkv" style="max-width:-32px"><h1 dir="auto" aria-level="1" role="heading" class="css-146c3p1 r-dnmrzs r-1udh08x r-1udbk01 r-3s2u2q r-1iln25a r-1i10wst r-majxgm" style="color:rgba(28,28,30,1.00)">index</h1></div><div class="css-175oi2r r-obd0qt r-1777fci r-1iusvr4 r-16y2uox r-12vffkv" style="margin-right:0px"></div></div></div></div></div></div></div><!--/$--></div></div><script src="/_expo/static/js/web/[mock].js" defer></script>
@keyframes r-t2lo5v{0%{opacity:1;}100%{opacity:0;}}</style><style id="expo-generated-fonts" type="text/css">@font-face{font-family:sweet;src:url(/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07);font-display:auto}</style><link rel="preload" href="/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07" as="font" crossorigin="" /><link rel="preload" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css" as="style"><link rel="stylesheet" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css"><link rel="preload" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css" as="style"><link rel="stylesheet" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css"></head><body><div id="root"><div class="css-175oi2r r-13awgt0"><!--$--><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0 r-1d5kdc7 r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af" style="background-color:rgba(242,242,242,1.00);display:flex"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><!--$--><div dir="auto" class="css-146c3p1" style="font-family:sweet" data-testid="index-text">Index</div><!--/$--></div></div><div class="css-175oi2r"><div class="css-175oi2r r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af r-12vffkv" style="z-index:0"><div class="css-175oi2r r-qklmqi r-13awgt0" style="box-shadow:0px 0px 0px rgba(216,216,216,1.00);background-color:rgba(255,255,255,1.00);border-bottom-color:rgba(216,216,216,1.00)"></div></div><div class="css-175oi2r r-12vffkv" style="height:64px"><div class="css-175oi2r r-633pao" style="height:0px"></div><div class="css-175oi2r r-1oszu61 r-13awgt0 r-18u37iz r-12vffkv"><div class="css-175oi2r r-1habvwh r-1777fci r-12vffkv" style="margin-left:0px"></div><div class="css-175oi2r r-1777fci r-1xpp3t0 r-12vffkv" style="max-width:-32px"><h1 dir="auto" aria-level="1" role="heading" class="css-146c3p1 r-dnmrzs r-1udh08x r-1udbk01 r-3s2u2q r-1iln25a r-1i10wst r-majxgm" style="color:rgba(28,28,30,1.00)">index</h1></div><div class="css-175oi2r r-obd0qt r-1777fci r-1iusvr4 r-16y2uox r-12vffkv" style="margin-right:0px"></div></div></div></div></div></div></div><!--/$--></div></div><script src="/_expo/static/js/web/[mock].js" defer></script>
</body></html>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-web
@keyframes r-1pzkwqh{0%{transform:translateY(100%);}100%{transform:translateY(0%);}}
@keyframes r-imtty0{0%{opacity:0;}100%{opacity:1;}}
@keyframes r-q67da2{0%{transform:translateX(-100%);}100%{transform:translateX(400%);}}
@keyframes r-t2lo5v{0%{opacity:1;}100%{opacity:0;}}</style><style id="expo-generated-fonts" type="text/css">@font-face{font-family:sweet;src:url(/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07);font-display:auto}</style><link rel="preload" href="/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07" as="font" crossorigin="" /><link rel="preload" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css" as="style"><link rel="stylesheet" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css"><link rel="preload" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css" as="style"><link rel="stylesheet" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css"></head><body><div id="root"><div class="css-175oi2r r-13awgt0"><!--$--><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0 r-1d5kdc7 r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af" style="background-color:rgba(242,242,242,1.00);display:flex"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><!--$--><div dir="auto" class="css-146c3p1" style="font-family:sweet" data-testid="index-text">Index</div><!--/$--></div></div><div class="css-175oi2r"><div class="css-175oi2r r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af r-12vffkv" style="z-index:0"><div class="css-175oi2r r-qklmqi r-13awgt0" style="box-shadow:0px 0px 0px rgba(216,216,216,1.00);background-color:rgba(255,255,255,1.00);border-bottom-color:rgba(216,216,216,1.00)"></div></div><div class="css-175oi2r r-12vffkv" style="height:64px"><div class="css-175oi2r r-633pao" style="height:0px"></div><div class="css-175oi2r r-1oszu61 r-13awgt0 r-18u37iz r-12vffkv"><div class="css-175oi2r r-1habvwh r-1777fci r-12vffkv" style="margin-left:0px"></div><div class="css-175oi2r r-1777fci r-1xpp3t0 r-12vffkv" style="max-width:-32px"><h1 dir="auto" aria-level="1" role="heading" class="css-146c3p1 r-dnmrzs r-1udh08x r-1udbk01 r-3s2u2q r-1iln25a r-1i10wst r-majxgm" style="color:rgba(28,28,30,1.00)">index</h1></div><div class="css-175oi2r r-obd0qt r-1777fci r-1iusvr4 r-16y2uox r-12vffkv" style="margin-right:0px"></div></div></div></div></div></div></div><!--/$--></div></div><script src="/_expo/static/js/web/[mock].js" defer></script>
@keyframes r-t2lo5v{0%{opacity:1;}100%{opacity:0;}}</style><style id="expo-generated-fonts" type="text/css">@font-face{font-family:sweet;src:url(/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07);font-display:auto}</style><link rel="preload" href="/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07" as="font" crossorigin="" /><link rel="preload" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css" as="style"><link rel="stylesheet" href="/_expo/static/css/global-1f3e4578a1313411a410a9d3f593ae38.css"><link rel="preload" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css" as="style"><link rel="stylesheet" href="/_expo/static/css/test.module-ebac9311dfba7117ea126f23f39e1627.css"></head><body><div id="root"><div class="css-175oi2r r-13awgt0"><!--$--><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0 r-1d5kdc7 r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af" style="background-color:rgba(242,242,242,1.00);display:flex"><div class="css-175oi2r r-13awgt0"><div class="css-175oi2r r-13awgt0"><!--$--><div dir="auto" class="css-146c3p1" style="font-family:sweet" data-testid="index-text">Index</div><!--/$--></div></div><div class="css-175oi2r"><div class="css-175oi2r r-1p0dtai r-1d2f490 r-u8s1d r-zchlnj r-ipm5af r-12vffkv" style="z-index:0"><div class="css-175oi2r r-qklmqi r-13awgt0" style="box-shadow:0px 0px 0px rgba(216,216,216,1.00);background-color:rgba(255,255,255,1.00);border-bottom-color:rgba(216,216,216,1.00)"></div></div><div class="css-175oi2r r-12vffkv" style="height:64px"><div class="css-175oi2r r-633pao" style="height:0px"></div><div class="css-175oi2r r-1oszu61 r-13awgt0 r-18u37iz r-12vffkv"><div class="css-175oi2r r-1habvwh r-1777fci r-12vffkv" style="margin-left:0px"></div><div class="css-175oi2r r-1777fci r-1xpp3t0 r-12vffkv" style="max-width:-32px"><h1 dir="auto" aria-level="1" role="heading" class="css-146c3p1 r-dnmrzs r-1udh08x r-1udbk01 r-3s2u2q r-1iln25a r-1i10wst r-majxgm" style="color:rgba(28,28,30,1.00)">index</h1></div><div class="css-175oi2r r-obd0qt r-1777fci r-1iusvr4 r-16y2uox r-12vffkv" style="margin-right:0px"></div></div></div></div></div></div></div><!--/$--></div></div><script src="/_expo/static/js/web/[mock].js" defer></script>
</body></html>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ describe('exports static', () => {
const links = indexHtml.querySelectorAll('html > head > link[as="font"]');
expect(links.length).toBe(1);
expect(links[0].attributes.href).toBe(
'/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07'
'/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07'
);

expect(links[0].toString()).toMatch(
/<link rel="preload" href="\/assets\/__e2e__\/static-rendering\/sweet\.ttf\?platform=web&hash=[\d\w]+" as="font" crossorigin="" >/
/<link rel="preload" href="\/assets\/__e2e__\/static-rendering\/sweet\.[a-zA-Z0-9]{32}\.ttf\?platform=web&hash=[a-zA-Z0-9]{32}" as="font" crossorigin="" >/
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ describe('exports static with bundle splitting', () => {
const links = indexHtml.querySelectorAll('html > head > link[as="font"]');
expect(links.length).toBe(1);
expect(links[0].attributes.href).toBe(
'/assets/__e2e__/static-rendering/sweet.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07'
'/assets/__e2e__/static-rendering/sweet.7c9263d3cffcda46ff7a4d9c00472c07.ttf?platform=web&hash=7c9263d3cffcda46ff7a4d9c00472c07'
);

expect(links[0].toString()).toMatch(
/<link rel="preload" href="\/assets\/__e2e__\/static-rendering\/sweet\.ttf\?platform=web&hash=[\d\w]+" as="font" crossorigin="" >/
/<link rel="preload" href="\/assets\/__e2e__\/static-rendering\/sweet\.[a-zA-Z0-9]{32}\.ttf\?platform=web&hash=[a-zA-Z0-9]{32}" as="font" crossorigin="" >/
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe('exports with tailwind and postcss', () => {
expect.stringMatching(/_expo\/static\/css\/global-.*\.css/),
expect.stringMatching(/_expo\/static\/js\/web\/index-.*\.js/),
'_sitemap.html',
'assets/__packages/expo-router/assets/error.png',
'assets/__packages/expo-router/assets/file.png',
'assets/__packages/expo-router/assets/forward.png',
'assets/__packages/expo-router/assets/pkg.png',
'assets/__packages/expo-router/assets/error.563d5e3294b67811d0a1aede6f601e30.png',
'assets/__packages/expo-router/assets/file.b6c297a501e289394b0bc5dc69c265e6.png',
'assets/__packages/expo-router/assets/forward.9d9c5644f55c2f6e4b7f247c378b2fe9.png',
'assets/__packages/expo-router/assets/pkg.5974eb3e1c5314e8d5a822702d7d0740.png',
'index.html',
]);
});
Expand Down
8 changes: 7 additions & 1 deletion packages/@expo/cli/e2e/fixtures/with-assets/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports = function (api) {
api.cache(true);
return {
presets: [['babel-preset-expo', { web: { disableImportExportTransform: false } }]],
presets: [
[
// `babel-preset-expo` from the monorepo.
process.env.TEST_BABEL_PRESET_EXPO_MODULE_ID,
{ web: { disableImportExportTransform: false } },
],
],
};
};
7 changes: 2 additions & 5 deletions packages/@expo/cli/src/export/fork-bundleAsync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExpoConfig, getConfigFilePaths, Platform, ProjectConfig } from '@expo/config';
import { LoadOptions } from '@expo/metro-config';
import { SerialAsset } from '@expo/metro-config/build/serializer/serializerAssets';
import getMetroAssets from '@expo/metro-config/build/transform-worker/getAssets';
import assert from 'assert';
import Metro, { MixedOutput, Module, ReadOnlyGraph } from 'metro';
import getMetroAssets from 'metro/src/DeltaBundler/Serializers/getAssets';
import type { TransformInputOptions } from 'metro/src/DeltaBundler/types';
import IncrementalBundler from 'metro/src/IncrementalBundler';
import Server from 'metro/src/Server';
Expand Down Expand Up @@ -200,10 +200,7 @@ async function bundleProductionMetroClientAsync(

// Forked out of Metro because the `this._getServerRootDir()` doesn't match the development
// behavior.
export async function getAssets(
metro: Metro.Server,
options: MetroBundleOptions
): Promise<readonly BundleAssetWithFileHashes[]> {
export async function getAssets(metro: Metro.Server, options: MetroBundleOptions) {
const { entryFile, onProgress, resolverOptions, transformOptions } = splitBundleOptions(options);

// @ts-expect-error: _bundler isn't exposed on the type.
Expand Down
3 changes: 2 additions & 1 deletion packages/@expo/cli/src/export/metroAssetLocalPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ function getAssetLocalPathDefault(
{ baseUrl, scale }: { baseUrl?: string; scale: number }
): string {
const suffix = scale === 1 ? '' : `@${scale}x`;
const fileName = `${asset.name + suffix}.${asset.type}`;
const fileName = `${asset.name}${suffix}.${asset.type}`;

const adjustedHttpServerLocation = stripAssetPrefix(asset.httpServerLocation, baseUrl);

return path.join(
// Assets can have relative paths outside of the project root.
// Replace `../` with `_` to make sure they don't end up outside of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type IncrementalBundler from 'metro/src/IncrementalBundler';
import splitBundleOptions from 'metro/src/lib/splitBundleOptions';
import path from 'path';

// import { getAssetData } from 'metro/src/Assets';

type Options = {
processModuleFilter: (modules: Module) => boolean;
assetPlugins: readonly string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ declare module 'metro-babel-transformer' {
enableBabelRuntime: boolean;
experimentalImportSupport?: boolean;
hot: boolean;
inlineRequires: boolean;
inlineRequires?: boolean;
minify: boolean;
unstable_disableES6Transforms?: boolean;
platform: ?string;
platform: string | null;
projectRoot: string;
publicPath: string;
extendsBabelConfigPath?: string;
hermesParser?: boolean;
globalPrefix?: string;
};

export type BabelTransformerArgs = {
Expand All @@ -37,7 +38,11 @@ declare module 'metro-babel-transformer' {
export type BabelTransformer = {
transform: (args: BabelTransformerArgs) => {
ast: Ast;
metadata?: BabelFileMetadata;
metadata?: BabelFileMetadata & {
metro?: {
functionMap?: FBSourceFunctionMap | null;
};
};
code?: string | null;
functionMap?: FBSourceFunctionMap | null;
};
Expand Down
3 changes: 3 additions & 0 deletions packages/@expo/cli/ts-declarations/metro-cache-key/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'metro-cache-key' {
export default function getCacheKey(files: string[]): string;
}
50 changes: 31 additions & 19 deletions packages/@expo/cli/ts-declarations/metro-source-map/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
declare module 'metro-source-map' {
import type {
BasicSourceMap,
FBSourceFunctionMap,
MetroSourceMapSegmentTuple,
} from 'metro-source-map/src/source-map';

type GeneratedCodeMapping = [number, number];
type SourceMapping = [number, number, number, number];
type SourceMappingWithName = [number, number, number, number, string];
Expand All @@ -12,27 +18,10 @@ declare module 'metro-source-map' {

type FBSourcesArray = Readonly<Array<FBSourceMetadata | null>>;
type FBSourceMetadata = [FBSourceFunctionMap | null];
export type FBSourceFunctionMap = {
names: Readonly<Array<string>>;
mappings: string;
};

type FBSegmentMap = { [id: string]: MixedSourceMap };
export { FBSourceFunctionMap };

interface BasicSourceMap {
file?: string;
mappings: string;
names: Array<string>;
sourceRoot?: string;
sources: Array<string>;
sourcesContent?: Array<string | null>;
version: number;
x_facebook_offsets?: Array<number>;
x_metro_module_paths?: Array<string>;
x_facebook_sources?: FBSourcesArray;
x_facebook_segments?: FBSegmentMap;
x_hermes_function_offsets?: HermesFunctionOffsets;
}
type FBSegmentMap = { [id: string]: MixedSourceMap };

interface IndexMapSection {
map: IndexMap | BasicSourceMap;
Expand Down Expand Up @@ -86,4 +75,27 @@ declare module 'metro-source-map' {
// `composeSourceMaps` is not exported from metro.
// This ts-declarations is used and shared for `@expo/dev-server`.
export function composeSourceMaps(maps: Readonly<MixedSourceMap[]>): MixedSourceMap;

import type { GeneratorResult } from '@babel/generator';

type BabelSourceMapSegment = NonNullable<GeneratorResult['map']>;

export function toSegmentTuple(mapping: BasicSourceMap): MetroSourceMapSegmentTuple;

export function toBabelSegments(mapping: BasicSourceMap): BasicSourceMap[];

export function functionMapBabelPlugin(): unknown;

export function fromRawMappings(
modules: {
map: MetroSourceMapSegmentTuple[] | null;
functionMap: FBSourceFunctionMap | null;
path: string;
source: string;
code: string;
isIgnored: boolean;
lineCount?: number;
}[],
offsetLines?: number
): any;
}

0 comments on commit 3ba3d6e

Please sign in to comment.