@expo/cli 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bin/cli +2 -2
- package/build/src/export/createMetadataJson.js +1 -0
- package/build/src/export/createMetadataJson.js.map +1 -1
- package/build/src/export/exportApp.js +19 -7
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/exportStaticAsync.js +54 -3
- package/build/src/export/exportStaticAsync.js.map +1 -1
- package/build/src/export/getPublicExpoManifest.js +2 -2
- package/build/src/export/getPublicExpoManifest.js.map +1 -1
- package/build/src/export/writeContents.js +2 -2
- package/build/src/export/writeContents.js.map +1 -1
- package/build/src/start/server/getStaticRenderFunctions.js +6 -2
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +69 -47
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/bundleApiRoutes.js +67 -0
- package/build/src/start/server/metro/bundleApiRoutes.js.map +1 -0
- package/build/src/start/server/metro/createServerRouteMiddleware.js +112 -0
- package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -0
- package/build/src/start/server/metro/fetchRouterManifest.js +60 -0
- package/build/src/start/server/metro/fetchRouterManifest.js.map +1 -0
- package/build/src/start/server/metro/instantiateMetro.js +12 -12
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +70 -10
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/router.js +32 -0
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js +22 -0
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +4 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js +5 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js +2 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js.map +1 -1
- package/build/src/start/server/type-generation/routes.js +3 -4
- package/build/src/start/server/type-generation/routes.js.map +1 -1
- package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js +1 -3
- package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js.map +1 -1
- package/build/src/utils/analytics/rudderstackClient.js +2 -2
- package/package.json +7 -4
package/build/bin/cli
CHANGED
|
@@ -132,7 +132,7 @@ const args = (0, _arg).default({
|
|
|
132
132
|
});
|
|
133
133
|
if (args["--version"]) {
|
|
134
134
|
// Version is added in the build script.
|
|
135
|
-
console.log("0.13.
|
|
135
|
+
console.log("0.13.2");
|
|
136
136
|
process.exit(0);
|
|
137
137
|
}
|
|
138
138
|
if (args["--non-interactive"]) {
|
|
@@ -262,7 +262,7 @@ commands[command]().then((exec)=>{
|
|
|
262
262
|
logEventAsync("action", {
|
|
263
263
|
action: `expo ${command}`,
|
|
264
264
|
source: "expo/cli",
|
|
265
|
-
source_version: "0.13.
|
|
265
|
+
source_version: "0.13.2"
|
|
266
266
|
});
|
|
267
267
|
});
|
|
268
268
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/createMetadataJson.ts"],"sourcesContent":["import path from 'path';\n\nimport { BundleOutput } from './fork-bundleAsync';\n\nexport type BundlePlatform = 'android' | 'ios';\n\ntype PlatformMetadataAsset = { path: string; ext: string };\n\ntype PlatformMetadata = { bundle: string; assets: PlatformMetadataAsset[] };\n\ntype FileMetadata = {\n [key in BundlePlatform]: PlatformMetadata;\n};\n\nexport function createMetadataJson({\n bundles,\n fileNames,\n}: {\n bundles: Partial<Record<BundlePlatform, Pick<BundleOutput, 'assets'>>>;\n fileNames: Record<string, string>;\n}): {\n version: 0;\n bundler: 'metro';\n fileMetadata: FileMetadata;\n} {\n // Build metadata.json\n return {\n version: 0,\n bundler: 'metro',\n fileMetadata: Object.entries(bundles).reduce<Record<string, Partial<PlatformMetadata>>>(\n (metadata, [platform, bundle]) => ({\n
|
|
1
|
+
{"version":3,"sources":["../../../src/export/createMetadataJson.ts"],"sourcesContent":["import path from 'path';\n\nimport { BundleOutput } from './fork-bundleAsync';\n\nexport type BundlePlatform = 'android' | 'ios';\n\ntype PlatformMetadataAsset = { path: string; ext: string };\n\ntype PlatformMetadata = { bundle: string; assets: PlatformMetadataAsset[] };\n\ntype FileMetadata = {\n [key in BundlePlatform]: PlatformMetadata;\n};\n\nexport function createMetadataJson({\n bundles,\n fileNames,\n}: {\n bundles: Partial<Record<BundlePlatform, Pick<BundleOutput, 'assets'>>>;\n fileNames: Record<string, string>;\n}): {\n version: 0;\n bundler: 'metro';\n fileMetadata: FileMetadata;\n} {\n // Build metadata.json\n return {\n version: 0,\n bundler: 'metro',\n fileMetadata: Object.entries(bundles).reduce<Record<string, Partial<PlatformMetadata>>>(\n (metadata, [platform, bundle]) => {\n if (platform === 'web') return metadata;\n\n return {\n ...metadata,\n [platform]: {\n // Get the filename for each platform's bundle.\n bundle: path.join('bundles', fileNames[platform]!),\n // Collect all of the assets and convert them to the serial format.\n assets: bundle.assets\n .map(\n (asset) =>\n // Each asset has multiple hashes which we convert and then flatten.\n asset.fileHashes?.map((hash) => ({\n path: path.join('assets', hash),\n ext: asset.type,\n }))\n )\n .filter(Boolean)\n .flat(),\n },\n };\n },\n {}\n ) as FileMetadata,\n };\n}\n"],"names":["createMetadataJson","bundles","fileNames","version","bundler","fileMetadata","Object","entries","reduce","metadata","platform","bundle","path","join","assets","map","asset","fileHashes","hash","ext","type","filter","Boolean","flat"],"mappings":"AAAA;;;;QAcgBA,kBAAkB,GAAlBA,kBAAkB;AAdjB,IAAA,KAAM,kCAAN,MAAM,EAAA;;;;;;AAchB,SAASA,kBAAkB,CAAC,EACjCC,OAAO,CAAA,EACPC,SAAS,CAAA,EAIV,EAIC;IACA,sBAAsB;IACtB,OAAO;QACLC,OAAO,EAAE,CAAC;QACVC,OAAO,EAAE,OAAO;QAChBC,YAAY,EAAEC,MAAM,CAACC,OAAO,CAACN,OAAO,CAAC,CAACO,MAAM,CAC1C,CAACC,QAAQ,EAAE,CAACC,QAAQ,EAAEC,MAAM,CAAC,GAAK;YAChC,IAAID,QAAQ,KAAK,KAAK,EAAE,OAAOD,QAAQ,CAAC;YAExC,OAAO;gBACL,GAAGA,QAAQ;gBACX,CAACC,QAAQ,CAAC,EAAE;oBACV,+CAA+C;oBAC/CC,MAAM,EAAEC,KAAI,QAAA,CAACC,IAAI,CAAC,SAAS,EAAEX,SAAS,CAACQ,QAAQ,CAAC,CAAE;oBAClD,mEAAmE;oBACnEI,MAAM,EAAEH,MAAM,CAACG,MAAM,CAClBC,GAAG,CACF,CAACC,KAAK;4BACJ,oEAAoE;wBACpEA,GAAgB;wBAAhBA,OAAAA,CAAAA,GAAgB,GAAhBA,KAAK,CAACC,UAAU,SAAK,GAArBD,KAAAA,CAAqB,GAArBA,GAAgB,CAAED,GAAG,CAAC,CAACG,IAAI,GAAK,CAAC;gCAC/BN,IAAI,EAAEA,KAAI,QAAA,CAACC,IAAI,CAAC,QAAQ,EAAEK,IAAI,CAAC;gCAC/BC,GAAG,EAAEH,KAAK,CAACI,IAAI;6BAChB,CAAC;wBAAA,CAAC,CAAA;qBAAA,CACN,CACAC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,EAAE;iBACV;aACF,CAAC;SACH,EACD,EAAE,CACH;KACF,CAAC;CACH"}
|
|
@@ -49,10 +49,17 @@ async function exportAppAsync(projectRoot, { platforms , outputDir , clear , dev
|
|
|
49
49
|
var ref, ref1, ref2;
|
|
50
50
|
(0, _nodeEnv).setNodeEnv(dev ? "development" : "production");
|
|
51
51
|
require("@expo/env").load(projectRoot);
|
|
52
|
-
const exp = await (0, _getPublicExpoManifest).getPublicExpoManifestAsync(projectRoot
|
|
53
|
-
|
|
52
|
+
const exp = await (0, _getPublicExpoManifest).getPublicExpoManifestAsync(projectRoot, {
|
|
53
|
+
// Web doesn't require validation.
|
|
54
|
+
skipValidation: platforms.length === 1 && platforms[0] === "web"
|
|
55
|
+
});
|
|
54
56
|
var ref3;
|
|
55
|
-
const
|
|
57
|
+
const useServerRendering = [
|
|
58
|
+
"static",
|
|
59
|
+
"server"
|
|
60
|
+
].includes((ref3 = (ref = exp.web) == null ? void 0 : ref.output) != null ? ref3 : "");
|
|
61
|
+
var ref4;
|
|
62
|
+
const basePath = ((ref4 = (ref1 = exp.experiments) == null ? void 0 : (ref2 = ref1.basePath) == null ? void 0 : ref2.replace(/\/+$/, "")) != null ? ref4 : "").trim();
|
|
56
63
|
// Print out logs
|
|
57
64
|
if (basePath) {
|
|
58
65
|
Log.log();
|
|
@@ -79,7 +86,9 @@ async function exportAppAsync(projectRoot, { platforms , outputDir , clear , dev
|
|
|
79
86
|
platforms,
|
|
80
87
|
minify,
|
|
81
88
|
// TODO: Breaks asset exports
|
|
82
|
-
// platforms:
|
|
89
|
+
// platforms: useServerRendering
|
|
90
|
+
// ? platforms.filter((platform) => platform !== 'web')
|
|
91
|
+
// : platforms,
|
|
83
92
|
dev
|
|
84
93
|
});
|
|
85
94
|
const bundleEntries = Object.entries(bundles);
|
|
@@ -105,17 +114,20 @@ async function exportAppAsync(projectRoot, { platforms , outputDir , clear , dev
|
|
|
105
114
|
// Write the JS bundles to disk, and get the bundle file names (this could change with async chunk loading support).
|
|
106
115
|
const { hashes , fileNames } = await (0, _writeContents).writeBundlesAsync({
|
|
107
116
|
bundles,
|
|
108
|
-
|
|
117
|
+
useServerRendering,
|
|
109
118
|
outputDir: bundlesPath
|
|
110
119
|
});
|
|
111
120
|
Log.log("Finished saving JS Bundles");
|
|
112
121
|
if (platforms.includes("web")) {
|
|
113
|
-
if (
|
|
122
|
+
if (useServerRendering) {
|
|
123
|
+
var ref5;
|
|
114
124
|
await (0, _exportStaticAsync).unstable_exportStaticAsync(projectRoot, {
|
|
115
125
|
outputDir: outputPath,
|
|
116
126
|
minify,
|
|
117
127
|
basePath,
|
|
118
|
-
includeMaps: dumpSourcemap
|
|
128
|
+
includeMaps: dumpSourcemap,
|
|
129
|
+
// @ts-expect-error: server not on type yet
|
|
130
|
+
exportServer: ((ref5 = exp.web) == null ? void 0 : ref5.output) === "server"
|
|
119
131
|
});
|
|
120
132
|
Log.log("Finished saving static files");
|
|
121
133
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/exportApp.ts"],"sourcesContent":["import chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { createBundlesAsync } from './createBundles';\nimport { exportAssetsAsync, exportCssAssetsAsync } from './exportAssets';\nimport { unstable_exportStaticAsync } from './exportStaticAsync';\nimport { getVirtualFaviconAssetsAsync } from './favicon';\nimport { getPublicExpoManifestAsync } from './getPublicExpoManifest';\nimport { persistMetroAssetsAsync } from './persistMetroAssets';\nimport { printBundleSizes } from './printBundleSizes';\nimport { Options } from './resolveOptions';\nimport {\n writeAssetMapAsync,\n writeBundlesAsync,\n writeDebugHtmlAsync,\n writeMetadataJsonAsync,\n writeSourceMapsAsync,\n} from './writeContents';\nimport * as Log from '../log';\nimport { createTemplateHtmlFromExpoConfigAsync } from '../start/server/webTemplate';\nimport { copyAsync, ensureDirectoryAsync } from '../utils/dir';\nimport { env } from '../utils/env';\nimport { setNodeEnv } from '../utils/nodeEnv';\n\n/**\n * The structure of the outputDir will be:\n *\n * ```\n * ├── assets\n * │ └── *\n * ├── bundles\n * │ ├── android-01ee6e3ab3e8c16a4d926c91808d5320.js\n * │ └── ios-ee8206cc754d3f7aa9123b7f909d94ea.js\n * └── metadata.json\n * ```\n */\nexport async function exportAppAsync(\n projectRoot: string,\n {\n platforms,\n outputDir,\n clear,\n dev,\n dumpAssetmap,\n dumpSourcemap,\n minify,\n }: Pick<\n Options,\n 'dumpAssetmap' | 'dumpSourcemap' | 'dev' | 'clear' | 'outputDir' | 'platforms' | 'minify'\n >\n): Promise<void> {\n setNodeEnv(dev ? 'development' : 'production');\n require('@expo/env').load(projectRoot);\n\n const exp = await getPublicExpoManifestAsync(projectRoot);\n\n const useWebSSG = exp.web?.output === 'static';\n const basePath = (exp.experiments?.basePath?.replace(/\\/+$/, '') ?? '').trim();\n\n // Print out logs\n if (basePath) {\n Log.log();\n Log.log(chalk.gray`Using (experimental) base path: ${basePath}`);\n // Warn if not using an absolute path.\n if (!basePath.startsWith('/')) {\n Log.log(\n chalk.yellow` Base path does not start with a slash. Requests will not be absolute.`\n );\n }\n }\n\n const publicPath = path.resolve(projectRoot, env.EXPO_PUBLIC_FOLDER);\n\n const outputPath = path.resolve(projectRoot, outputDir);\n const staticFolder = outputPath;\n const assetsPath = path.join(staticFolder, 'assets');\n const bundlesPath = path.join(staticFolder, 'bundles');\n\n await Promise.all([assetsPath, bundlesPath].map(ensureDirectoryAsync));\n\n await copyPublicFolderAsync(publicPath, staticFolder);\n\n // Run metro bundler and create the JS bundles/source maps.\n const bundles = await createBundlesAsync(\n projectRoot,\n { resetCache: !!clear },\n {\n platforms,\n minify,\n // TODO: Breaks asset exports\n // platforms: useWebSSG ? platforms.filter((platform) => platform !== 'web') : platforms,\n dev,\n // TODO: Disable source map generation if we aren't outputting them.\n }\n );\n\n const bundleEntries = Object.entries(bundles);\n if (bundleEntries.length) {\n // Log bundle size info to the user\n printBundleSizes(\n Object.fromEntries(\n bundleEntries.map(([key, value]) => {\n if (!dumpSourcemap) {\n return [\n key,\n {\n ...value,\n // Remove source maps from the bundles if they aren't going to be written.\n map: undefined,\n },\n ];\n }\n\n return [key, value];\n })\n )\n );\n }\n\n // Write the JS bundles to disk, and get the bundle file names (this could change with async chunk loading support).\n const { hashes, fileNames } = await writeBundlesAsync({\n bundles,\n useWebSSG,\n outputDir: bundlesPath,\n });\n\n Log.log('Finished saving JS Bundles');\n\n if (platforms.includes('web')) {\n if (useWebSSG) {\n await unstable_exportStaticAsync(projectRoot, {\n outputDir: outputPath,\n minify,\n basePath,\n includeMaps: dumpSourcemap,\n });\n Log.log('Finished saving static files');\n } else {\n const cssLinks = await exportCssAssetsAsync({\n outputDir,\n bundles,\n basePath,\n });\n let html = await createTemplateHtmlFromExpoConfigAsync(projectRoot, {\n scripts: [`${basePath}/bundles/${fileNames.web}`],\n cssLinks,\n });\n // Add the favicon assets to the HTML.\n const modifyHtml = await getVirtualFaviconAssetsAsync(projectRoot, {\n outputDir,\n basePath,\n });\n if (modifyHtml) {\n html = modifyHtml(html);\n }\n // Generate SPA-styled HTML file.\n // If web exists, then write the template HTML file.\n await fs.promises.writeFile(path.join(staticFolder, 'index.html'), html);\n }\n\n // TODO: Use a different mechanism for static web.\n if (bundles.web) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // TODO: Update React Native Web to support loading files from asset hashes.\n await persistMetroAssetsAsync(bundles.web.assets, {\n platform: 'web',\n outputDirectory: staticFolder,\n basePath,\n });\n }\n }\n\n // Can be empty during web-only SSG.\n // TODO: Use same asset system across platforms again.\n if (Object.keys(fileNames).length) {\n const { assets } = await exportAssetsAsync(projectRoot, {\n exp,\n outputDir: staticFolder,\n bundles,\n });\n\n if (dumpAssetmap) {\n Log.log('Dumping asset map');\n await writeAssetMapAsync({ outputDir: staticFolder, assets });\n }\n // build source maps\n if (dumpSourcemap) {\n Log.log('Dumping source maps');\n await writeSourceMapsAsync({\n bundles,\n hashes,\n outputDir: bundlesPath,\n fileNames,\n });\n\n Log.log('Preparing additional debugging files');\n // If we output source maps, then add a debug HTML file which the user can open in\n // the web browser to inspect the output like web.\n await writeDebugHtmlAsync({\n outputDir: staticFolder,\n fileNames,\n });\n }\n\n // Generate a `metadata.json` and the export is complete.\n await writeMetadataJsonAsync({ outputDir: staticFolder, bundles, fileNames });\n }\n}\n\n/**\n * Copy the contents of the public folder into the output folder.\n * This enables users to add static files like `favicon.ico` or `serve.json`.\n *\n * The contents of this folder are completely universal since they refer to\n * static network requests which fall outside the scope of React Native's magic\n * platform resolution patterns.\n */\nasync function copyPublicFolderAsync(publicFolder: string, outputFolder: string) {\n if (fs.existsSync(publicFolder)) {\n await copyAsync(publicFolder, outputFolder);\n }\n}\n"],"names":["exportAppAsync","Log","projectRoot","platforms","outputDir","clear","dev","dumpAssetmap","dumpSourcemap","minify","exp","setNodeEnv","require","load","getPublicExpoManifestAsync","useWebSSG","web","output","basePath","experiments","replace","trim","log","chalk","gray","startsWith","yellow","publicPath","path","resolve","env","EXPO_PUBLIC_FOLDER","outputPath","staticFolder","assetsPath","join","bundlesPath","Promise","all","map","ensureDirectoryAsync","copyPublicFolderAsync","bundles","createBundlesAsync","resetCache","bundleEntries","Object","entries","length","printBundleSizes","fromEntries","key","value","undefined","hashes","fileNames","writeBundlesAsync","includes","unstable_exportStaticAsync","includeMaps","cssLinks","exportCssAssetsAsync","html","createTemplateHtmlFromExpoConfigAsync","scripts","modifyHtml","getVirtualFaviconAssetsAsync","fs","promises","writeFile","persistMetroAssetsAsync","assets","platform","outputDirectory","keys","exportAssetsAsync","writeAssetMapAsync","writeSourceMapsAsync","writeDebugHtmlAsync","writeMetadataJsonAsync","publicFolder","outputFolder","existsSync","copyAsync"],"mappings":"AAAA;;;;QAqCsBA,cAAc,GAAdA,cAAc;AArClB,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEY,IAAA,cAAiB,WAAjB,iBAAiB,CAAA;AACI,IAAA,aAAgB,WAAhB,gBAAgB,CAAA;AAC7B,IAAA,kBAAqB,WAArB,qBAAqB,CAAA;AACnB,IAAA,QAAW,WAAX,WAAW,CAAA;AACb,IAAA,sBAAyB,WAAzB,yBAAyB,CAAA;AAC5B,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AAC7B,IAAA,iBAAoB,WAApB,oBAAoB,CAAA;AAQ9C,IAAA,cAAiB,WAAjB,iBAAiB,CAAA;AACZC,IAAAA,GAAG,mCAA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AqC,CAAA,mBAArC,CAAC;gBAAExE,SAAS,EAAE6B,YAAY;gBAAEsC,MAAM;aAAE,CAAC,CAAC;SAC/D;QACD,oBAAoB;QACpB,IAAI/D,aAAa,EAAE;YACjBP,GAAG,CAACqB,GAAG,CAAC,qBAAqB,CAAC,CAAC;YAC/B,MAAMuD,CAAAA,GAAAA,cAAoB,AAKxB,CAAA,qBALwB,CAAC;gBACzBnC,OAAO;gBACPY,MAAM;gBACNlD,SAAS,EAAEgC,WAAW;gBACtBmB,SAAS;aACV,CAAC,CAAC;YAEHtD,GAAG,CAACqB,GAAG,CAAC,sCAAsC,CAAC,CAAC;YAChD,kFAAkF;YAClF,kDAAkD;YAClD,MAAMwD,CAAAA,GAAAA,cAAmB,AAGvB,CAAA,oBAHuB,CAAC;gBACxB1E,SAAS,EAAE6B,YAAY;gBACvBsB,SAAS;aACV,CAAC,CAAC;SACJ;QAED,yDAAyD;QACzD,MAAMwB,CAAAA,GAAAA,cAAsB,AAAiD,CAAA,uBAAjD,CAAC;YAAE3E,SAAS,EAAE6B,YAAY;YAAES,OAAO;YAAEa,SAAS;SAAE,CAAC,CAAC;KAC/E;CACF;AAED;;;;;;;GAOG,CACH,eAAed,qBAAqB,CAACuC,YAAoB,EAAEC,YAAoB,EAAE;IAC/E,IAAId,GAAE,QAAA,CAACe,UAAU,CAACF,YAAY,CAAC,EAAE;QAC/B,MAAMG,CAAAA,GAAAA,IAAS,AAA4B,CAAA,UAA5B,CAACH,YAAY,EAAEC,YAAY,CAAC,CAAC;KAC7C;CACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/export/exportApp.ts"],"sourcesContent":["import chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { createBundlesAsync } from './createBundles';\nimport { exportAssetsAsync, exportCssAssetsAsync } from './exportAssets';\nimport { unstable_exportStaticAsync } from './exportStaticAsync';\nimport { getVirtualFaviconAssetsAsync } from './favicon';\nimport { getPublicExpoManifestAsync } from './getPublicExpoManifest';\nimport { persistMetroAssetsAsync } from './persistMetroAssets';\nimport { printBundleSizes } from './printBundleSizes';\nimport { Options } from './resolveOptions';\nimport {\n writeAssetMapAsync,\n writeBundlesAsync,\n writeDebugHtmlAsync,\n writeMetadataJsonAsync,\n writeSourceMapsAsync,\n} from './writeContents';\nimport * as Log from '../log';\nimport { createTemplateHtmlFromExpoConfigAsync } from '../start/server/webTemplate';\nimport { copyAsync, ensureDirectoryAsync } from '../utils/dir';\nimport { env } from '../utils/env';\nimport { setNodeEnv } from '../utils/nodeEnv';\n\n/**\n * The structure of the outputDir will be:\n *\n * ```\n * ├── assets\n * │ └── *\n * ├── bundles\n * │ ├── android-01ee6e3ab3e8c16a4d926c91808d5320.js\n * │ └── ios-ee8206cc754d3f7aa9123b7f909d94ea.js\n * └── metadata.json\n * ```\n */\nexport async function exportAppAsync(\n projectRoot: string,\n {\n platforms,\n outputDir,\n clear,\n dev,\n dumpAssetmap,\n dumpSourcemap,\n minify,\n }: Pick<\n Options,\n 'dumpAssetmap' | 'dumpSourcemap' | 'dev' | 'clear' | 'outputDir' | 'platforms' | 'minify'\n >\n): Promise<void> {\n setNodeEnv(dev ? 'development' : 'production');\n require('@expo/env').load(projectRoot);\n\n const exp = await getPublicExpoManifestAsync(projectRoot, {\n // Web doesn't require validation.\n skipValidation: platforms.length === 1 && platforms[0] === 'web',\n });\n\n const useServerRendering = ['static', 'server'].includes(exp.web?.output ?? '');\n const basePath = (exp.experiments?.basePath?.replace(/\\/+$/, '') ?? '').trim();\n\n // Print out logs\n if (basePath) {\n Log.log();\n Log.log(chalk.gray`Using (experimental) base path: ${basePath}`);\n // Warn if not using an absolute path.\n if (!basePath.startsWith('/')) {\n Log.log(\n chalk.yellow` Base path does not start with a slash. Requests will not be absolute.`\n );\n }\n }\n\n const publicPath = path.resolve(projectRoot, env.EXPO_PUBLIC_FOLDER);\n\n const outputPath = path.resolve(projectRoot, outputDir);\n const staticFolder = outputPath;\n const assetsPath = path.join(staticFolder, 'assets');\n const bundlesPath = path.join(staticFolder, 'bundles');\n\n await Promise.all([assetsPath, bundlesPath].map(ensureDirectoryAsync));\n\n await copyPublicFolderAsync(publicPath, staticFolder);\n\n // Run metro bundler and create the JS bundles/source maps.\n const bundles = await createBundlesAsync(\n projectRoot,\n { resetCache: !!clear },\n {\n platforms,\n minify,\n // TODO: Breaks asset exports\n // platforms: useServerRendering\n // ? platforms.filter((platform) => platform !== 'web')\n // : platforms,\n dev,\n // TODO: Disable source map generation if we aren't outputting them.\n }\n );\n\n const bundleEntries = Object.entries(bundles);\n if (bundleEntries.length) {\n // Log bundle size info to the user\n printBundleSizes(\n Object.fromEntries(\n bundleEntries.map(([key, value]) => {\n if (!dumpSourcemap) {\n return [\n key,\n {\n ...value,\n // Remove source maps from the bundles if they aren't going to be written.\n map: undefined,\n },\n ];\n }\n\n return [key, value];\n })\n )\n );\n }\n\n // Write the JS bundles to disk, and get the bundle file names (this could change with async chunk loading support).\n const { hashes, fileNames } = await writeBundlesAsync({\n bundles,\n useServerRendering,\n outputDir: bundlesPath,\n });\n\n Log.log('Finished saving JS Bundles');\n\n if (platforms.includes('web')) {\n if (useServerRendering) {\n await unstable_exportStaticAsync(projectRoot, {\n outputDir: outputPath,\n minify,\n basePath,\n includeMaps: dumpSourcemap,\n // @ts-expect-error: server not on type yet\n exportServer: exp.web?.output === 'server',\n });\n Log.log('Finished saving static files');\n } else {\n const cssLinks = await exportCssAssetsAsync({\n outputDir,\n bundles,\n basePath,\n });\n let html = await createTemplateHtmlFromExpoConfigAsync(projectRoot, {\n scripts: [`${basePath}/bundles/${fileNames.web}`],\n cssLinks,\n });\n // Add the favicon assets to the HTML.\n const modifyHtml = await getVirtualFaviconAssetsAsync(projectRoot, {\n outputDir,\n basePath,\n });\n if (modifyHtml) {\n html = modifyHtml(html);\n }\n // Generate SPA-styled HTML file.\n // If web exists, then write the template HTML file.\n await fs.promises.writeFile(path.join(staticFolder, 'index.html'), html);\n }\n\n // TODO: Use a different mechanism for static web.\n if (bundles.web) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // TODO: Update React Native Web to support loading files from asset hashes.\n await persistMetroAssetsAsync(bundles.web.assets, {\n platform: 'web',\n outputDirectory: staticFolder,\n basePath,\n });\n }\n }\n\n // Can be empty during web-only SSG.\n // TODO: Use same asset system across platforms again.\n if (Object.keys(fileNames).length) {\n const { assets } = await exportAssetsAsync(projectRoot, {\n exp,\n outputDir: staticFolder,\n bundles,\n });\n\n if (dumpAssetmap) {\n Log.log('Dumping asset map');\n await writeAssetMapAsync({ outputDir: staticFolder, assets });\n }\n // build source maps\n if (dumpSourcemap) {\n Log.log('Dumping source maps');\n await writeSourceMapsAsync({\n bundles,\n hashes,\n outputDir: bundlesPath,\n fileNames,\n });\n\n Log.log('Preparing additional debugging files');\n // If we output source maps, then add a debug HTML file which the user can open in\n // the web browser to inspect the output like web.\n await writeDebugHtmlAsync({\n outputDir: staticFolder,\n fileNames,\n });\n }\n\n // Generate a `metadata.json` and the export is complete.\n await writeMetadataJsonAsync({ outputDir: staticFolder, bundles, fileNames });\n }\n}\n\n/**\n * Copy the contents of the public folder into the output folder.\n * This enables users to add static files like `favicon.ico` or `serve.json`.\n *\n * The contents of this folder are completely universal since they refer to\n * static network requests which fall outside the scope of React Native's magic\n * platform resolution patterns.\n */\nasync function copyPublicFolderAsync(publicFolder: string, outputFolder: string) {\n if (fs.existsSync(publicFolder)) {\n await copyAsync(publicFolder, outputFolder);\n }\n}\n"],"names":["exportAppAsync","Log","projectRoot","platforms","outputDir","clear","dev","dumpAssetmap","dumpSourcemap","minify","exp","setNodeEnv","require","load","getPublicExpoManifestAsync","skipValidation","length","useServerRendering","includes","web","output","basePath","experiments","replace","trim","log","chalk","gray","startsWith","yellow","publicPath","path","resolve","env","EXPO_PUBLIC_FOLDER","outputPath","staticFolder","assetsPath","join","bundlesPath","Promise","all","map","ensureDirectoryAsync","copyPublicFolderAsync","bundles","createBundlesAsync","resetCache","bundleEntries","Object","entries","printBundleSizes","fromEntries","key","value","undefined","hashes","fileNames","writeBundlesAsync","unstable_exportStaticAsync","includeMaps","exportServer","cssLinks","exportCssAssetsAsync","html","createTemplateHtmlFromExpoConfigAsync","scripts","modifyHtml","getVirtualFaviconAssetsAsync","fs","promises","writeFile","persistMetroAssetsAsync","assets","platform","outputDirectory","keys","exportAssetsAsync","writeAssetMapAsync","writeSourceMapsAsync","writeDebugHtmlAsync","writeMetadataJsonAsync","publicFolder","outputFolder","existsSync","copyAsync"],"mappings":"AAAA;;;;QAqCsBA,cAAc,GAAdA,cAAc;AArClB,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEY,IAAA,cAAiB,WAAjB,iBAAiB,CAAA;AACI,IAAA,aAAgB,WAAhB,gBAAgB,CAAA;AAC7B,IAAA,kBAAqB,WAArB,qBAAqB,CAAA;AACnB,IAAA,QAAW,WAAX,WAAW,CAAA;AACb,IAAA,sBAAyB,WAAzB,yBAAyB,CAAA;AAC5B,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AAC7B,IAAA,iBAAoB,WAApB,oBAAoB,CAAA;AAQ9C,IAAA,cAAiB,WAAjB,iBAAiB,CAAA;AACZC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACuC,IAAA,YAA6B,WAA7B,6BAA6B,CAAA;AACnC,IAAA,IAAc,WAAd,cAAc,CAAA;AAC1C,IAAA,IAAc,WAAd,cAAc,CAAA;AACP,IAAA,QAAkB,WAAlB,kBAAkB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AActC,eAAeD,cAAc,CAClCE,WAAmB,EACnB,EACEC,SAAS,CAAA,EACTC,SAAS,CAAA,EACTC,KAAK,CAAA,EACLC,GAAG,CAAA,EACHC,YAAY,CAAA,EACZC,aAAa,CAAA,EACbC,MAAM,CAAA,EAIP,EACc;QAS0CC,GAAO,EAC9CA,IAAe;IATjCC,CAAAA,GAAAA,QAAU,AAA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AqC,CAAA,mBAArC,CAAC;gBAAE1E,SAAS,EAAEgC,YAAY;gBAAEqC,MAAM;aAAE,CAAC,CAAC;SAC/D;QACD,oBAAoB;QACpB,IAAIjE,aAAa,EAAE;YACjBP,GAAG,CAACwB,GAAG,CAAC,qBAAqB,CAAC,CAAC;YAC/B,MAAMsD,CAAAA,GAAAA,cAAoB,AAKxB,CAAA,qBALwB,CAAC;gBACzBlC,OAAO;gBACPW,MAAM;gBACNpD,SAAS,EAAEmC,WAAW;gBACtBkB,SAAS;aACV,CAAC,CAAC;YAEHxD,GAAG,CAACwB,GAAG,CAAC,sCAAsC,CAAC,CAAC;YAChD,kFAAkF;YAClF,kDAAkD;YAClD,MAAMuD,CAAAA,GAAAA,cAAmB,AAGvB,CAAA,oBAHuB,CAAC;gBACxB5E,SAAS,EAAEgC,YAAY;gBACvBqB,SAAS;aACV,CAAC,CAAC;SACJ;QAED,yDAAyD;QACzD,MAAMwB,CAAAA,GAAAA,cAAsB,AAAiD,CAAA,uBAAjD,CAAC;YAAE7E,SAAS,EAAEgC,YAAY;YAAES,OAAO;YAAEY,SAAS;SAAE,CAAC,CAAC;KAC/E;CACF;AAED;;;;;;;GAOG,CACH,eAAeb,qBAAqB,CAACsC,YAAoB,EAAEC,YAAoB,EAAE;IAC/E,IAAId,GAAE,QAAA,CAACe,UAAU,CAACF,YAAY,CAAC,EAAE;QAC/B,MAAMG,CAAAA,GAAAA,IAAS,AAA4B,CAAA,UAA5B,CAACH,YAAY,EAAEC,YAAY,CAAC,CAAC;KAC7C;CACF"}
|
|
@@ -8,6 +8,7 @@ exports.exportFromServerAsync = exportFromServerAsync;
|
|
|
8
8
|
exports.modifyBundlesWithSourceMaps = modifyBundlesWithSourceMaps;
|
|
9
9
|
exports.getHtmlFiles = getHtmlFiles;
|
|
10
10
|
exports.getPathVariations = getPathVariations;
|
|
11
|
+
var _config = require("@expo/config");
|
|
11
12
|
var _assert = _interopRequireDefault(require("assert"));
|
|
12
13
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
13
14
|
var _fs = _interopRequireDefault(require("fs"));
|
|
@@ -19,6 +20,7 @@ var _log = require("../log");
|
|
|
19
20
|
var _devServerManager = require("../start/server/DevServerManager");
|
|
20
21
|
var _metroBundlerDevServer = require("../start/server/metro/MetroBundlerDevServer");
|
|
21
22
|
var _metroErrorInterface = require("../start/server/metro/metroErrorInterface");
|
|
23
|
+
var _router = require("../start/server/metro/router");
|
|
22
24
|
var _link = require("../utils/link");
|
|
23
25
|
function _interopRequireDefault(obj) {
|
|
24
26
|
return obj && obj.__esModule ? obj : {
|
|
@@ -74,10 +76,14 @@ async function getFilesToExportFromServerAsync(projectRoot, { manifest , renderA
|
|
|
74
76
|
}));
|
|
75
77
|
return files;
|
|
76
78
|
}
|
|
77
|
-
async function exportFromServerAsync(projectRoot, devServerManager, { outputDir , basePath , minify , includeMaps }) {
|
|
79
|
+
async function exportFromServerAsync(projectRoot, devServerManager, { outputDir , basePath , exportServer , minify , includeMaps }) {
|
|
80
|
+
const { exp } = (0, _config).getConfig(projectRoot, {
|
|
81
|
+
skipSDKVersionRequirement: true
|
|
82
|
+
});
|
|
83
|
+
const appDir = (0, _router).getRouterDirectoryWithManifest(projectRoot, exp);
|
|
78
84
|
const injectFaviconTag = await (0, _favicon).getVirtualFaviconAssetsAsync(projectRoot, {
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
outputDir,
|
|
86
|
+
basePath
|
|
81
87
|
});
|
|
82
88
|
const devServer = devServerManager.getDefaultDevServer();
|
|
83
89
|
(0, _assert).default(devServer instanceof _metroBundlerDevServer.MetroBundlerDevServer);
|
|
@@ -115,6 +121,19 @@ async function exportFromServerAsync(projectRoot, devServerManager, { outputDir
|
|
|
115
121
|
resources.forEach((resource)=>{
|
|
116
122
|
files.set(resource.filename, modifyBundlesWithSourceMaps(resource.filename, resource.source, includeMaps));
|
|
117
123
|
});
|
|
124
|
+
if (exportServer) {
|
|
125
|
+
const apiRoutes = await exportApiRoutesAsync({
|
|
126
|
+
outputDir,
|
|
127
|
+
server: devServer,
|
|
128
|
+
appDir
|
|
129
|
+
});
|
|
130
|
+
// Add the api routes to the files to export.
|
|
131
|
+
for (const [route, contents] of apiRoutes){
|
|
132
|
+
files.set(route, contents);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
warnPossibleInvalidExportType(appDir);
|
|
136
|
+
}
|
|
118
137
|
_fs.default.mkdirSync(_path.default.join(outputDir), {
|
|
119
138
|
recursive: true
|
|
120
139
|
});
|
|
@@ -215,5 +234,37 @@ function getPathVariations(routePath) {
|
|
|
215
234
|
generateVariations(segments1, 0);
|
|
216
235
|
return Array.from(variations);
|
|
217
236
|
}
|
|
237
|
+
async function exportApiRoutesAsync({ outputDir , server , appDir }) {
|
|
238
|
+
const funcDir = _path.default.join(outputDir, "_expo/functions");
|
|
239
|
+
_fs.default.mkdirSync(_path.default.join(funcDir), {
|
|
240
|
+
recursive: true
|
|
241
|
+
});
|
|
242
|
+
const [manifest, files1] = await Promise.all([
|
|
243
|
+
server.getExpoRouterRoutesManifestAsync({
|
|
244
|
+
appDir
|
|
245
|
+
}),
|
|
246
|
+
server.exportExpoRouterApiRoutesAsync({
|
|
247
|
+
mode: "production",
|
|
248
|
+
appDir
|
|
249
|
+
}).then((routes)=>{
|
|
250
|
+
const files = new Map();
|
|
251
|
+
for (const [route, contents] of routes){
|
|
252
|
+
files.set(_path.default.join("_expo/functions", route), contents);
|
|
253
|
+
}
|
|
254
|
+
return files;
|
|
255
|
+
}),
|
|
256
|
+
]);
|
|
257
|
+
_log.Log.log(_chalk.default.bold`Exporting ${files1.size} API Routes.`);
|
|
258
|
+
files1.set("_expo/routes.json", JSON.stringify(manifest, null, 2));
|
|
259
|
+
return files1;
|
|
260
|
+
}
|
|
261
|
+
function warnPossibleInvalidExportType(appDir) {
|
|
262
|
+
const apiRoutes = (0, _router).getApiRoutesForDirectory(appDir);
|
|
263
|
+
if (apiRoutes.length) {
|
|
264
|
+
// TODO: Allow API Routes for native-only.
|
|
265
|
+
_log.Log.warn(_chalk.default.yellow`Skipping export for API routes because \`web.output\` is not "server". You may want to remove the routes: ${apiRoutes.map((v)=>_path.default.relative(appDir, v)
|
|
266
|
+
).join(", ")}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
218
269
|
|
|
219
270
|
//# sourceMappingURL=exportStaticAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/exportStaticAsync.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport assert from 'assert';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\nimport prettyBytes from 'pretty-bytes';\nimport { inspect } from 'util';\n\nimport { getVirtualFaviconAssetsAsync } from './favicon';\nimport { Log } from '../log';\nimport { DevServerManager } from '../start/server/DevServerManager';\nimport { MetroBundlerDevServer } from '../start/server/metro/MetroBundlerDevServer';\nimport { logMetroErrorAsync } from '../start/server/metro/metroErrorInterface';\nimport { learnMore } from '../utils/link';\n\nconst debug = require('debug')('expo:export:generateStaticRoutes') as typeof console.log;\n\ntype Options = { outputDir: string; minify: boolean; basePath: string; includeMaps: boolean };\n\n/** @private */\nexport async function unstable_exportStaticAsync(projectRoot: string, options: Options) {\n Log.warn(\n `Experimental static rendering is enabled. ` +\n learnMore('https://docs.expo.dev/router/reference/static-rendering/')\n );\n\n // TODO: Prevent starting the watcher.\n const devServerManager = new DevServerManager(projectRoot, {\n minify: options.minify,\n mode: 'production',\n location: {},\n });\n await devServerManager.startAsync([\n {\n type: 'metro',\n options: {\n location: {},\n isExporting: true,\n },\n },\n ]);\n\n try {\n await exportFromServerAsync(projectRoot, devServerManager, options);\n } finally {\n await devServerManager.stopAsync();\n }\n}\n\n/** Match `(page)` -> `page` */\nfunction matchGroupName(name: string): string | undefined {\n return name.match(/^\\(([^/]+?)\\)$/)?.[1];\n}\n\nexport async function getFilesToExportFromServerAsync(\n projectRoot: string,\n {\n manifest,\n renderAsync,\n }: {\n manifest: any;\n renderAsync: (pathname: string) => Promise<string>;\n }\n): Promise<Map<string, string>> {\n // name : contents\n const files = new Map<string, string>();\n\n await Promise.all(\n getHtmlFiles({ manifest }).map(async (outputPath) => {\n const pathname = outputPath.replace(/(?:index)?\\.html$/, '');\n try {\n files.set(outputPath, '');\n const data = await renderAsync(pathname);\n files.set(outputPath, data);\n } catch (e: any) {\n await logMetroErrorAsync({ error: e, projectRoot });\n throw new Error('Failed to statically export route: ' + pathname);\n }\n })\n );\n\n return files;\n}\n\n/** Perform all fs commits */\nexport async function exportFromServerAsync(\n projectRoot: string,\n devServerManager: DevServerManager,\n { outputDir, basePath, minify, includeMaps }: Options\n): Promise<void> {\n const injectFaviconTag = await getVirtualFaviconAssetsAsync(projectRoot, {\n basePath,\n outputDir,\n });\n\n const devServer = devServerManager.getDefaultDevServer();\n assert(devServer instanceof MetroBundlerDevServer);\n\n const [resources, { manifest, renderAsync }] = await Promise.all([\n devServer.getStaticResourcesAsync({ mode: 'production', minify, includeMaps }),\n devServer.getStaticRenderFunctionAsync({\n mode: 'production',\n minify,\n }),\n ]);\n\n debug('Routes:\\n', inspect(manifest, { colors: true, depth: null }));\n\n const files = await getFilesToExportFromServerAsync(projectRoot, {\n manifest,\n async renderAsync(pathname: string) {\n const template = await renderAsync(pathname);\n let html = await devServer.composeResourcesWithHtml({\n mode: 'production',\n resources,\n template,\n basePath,\n });\n\n if (injectFaviconTag) {\n html = injectFaviconTag(html);\n }\n\n return html;\n },\n });\n\n resources.forEach((resource) => {\n files.set(\n resource.filename,\n modifyBundlesWithSourceMaps(resource.filename, resource.source, includeMaps)\n );\n });\n\n fs.mkdirSync(path.join(outputDir), { recursive: true });\n\n Log.log('');\n Log.log(chalk.bold`Exporting ${files.size} files:`);\n await Promise.all(\n [...files.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(async ([file, contents]) => {\n const length = Buffer.byteLength(contents, 'utf8');\n Log.log(file, chalk.gray`(${prettyBytes(length)})`);\n const outputPath = path.join(outputDir, file);\n await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.promises.writeFile(outputPath, contents);\n })\n );\n Log.log('');\n}\n\nexport function modifyBundlesWithSourceMaps(\n filename: string,\n source: string,\n includeMaps: boolean\n): string {\n if (filename.endsWith('.js')) {\n // If the bundle ends with source map URLs then update them to point to the correct location.\n\n // TODO: basePath support\n const normalizedFilename = '/' + filename.replace(/^\\/+/, '');\n //# sourceMappingURL=//localhost:8085/index.map?platform=web&dev=false&hot=false&lazy=true&minify=true&resolver.environment=client&transform.environment=client&serializer.output=static\n //# sourceURL=http://localhost:8085/index.bundle//&platform=web&dev=false&hot=false&lazy=true&minify=true&resolver.environment=client&transform.environment=client&serializer.output=static\n return source.replace(/^\\/\\/# (sourceMappingURL|sourceURL)=.*$/gm, (...props) => {\n if (includeMaps) {\n if (props[1] === 'sourceURL') {\n return `//# ${props[1]}=` + normalizedFilename;\n } else if (props[1] === 'sourceMappingURL') {\n const mapName = normalizedFilename + '.map';\n return `//# ${props[1]}=` + mapName;\n }\n }\n return '';\n });\n }\n return source;\n}\n\nexport function getHtmlFiles({ manifest }: { manifest: any }): string[] {\n const htmlFiles = new Set<string>();\n\n function traverseScreens(screens: string | { screens: any; path: string }, basePath = '') {\n for (const value of Object.values(screens)) {\n if (typeof value === 'string') {\n let filePath = basePath + value;\n if (value === '') {\n filePath =\n basePath === ''\n ? 'index'\n : basePath.endsWith('/')\n ? basePath + 'index'\n : basePath.slice(0, -1);\n }\n // TODO: Dedupe requests for alias routes.\n addOptionalGroups(filePath);\n } else if (typeof value === 'object' && value?.screens) {\n const newPath = basePath + value.path + '/';\n traverseScreens(value.screens, newPath);\n }\n }\n }\n\n function addOptionalGroups(path: string) {\n const variations = getPathVariations(path);\n for (const variation of variations) {\n htmlFiles.add(variation);\n }\n }\n\n traverseScreens(manifest.screens);\n\n return Array.from(htmlFiles).map((value) => {\n const parts = value.split('/');\n // Replace `:foo` with `[foo]` and `*foo` with `[...foo]`\n const partsWithGroups = parts.map((part) => {\n if (part.startsWith(':')) {\n return `[${part.slice(1)}]`;\n } else if (part.startsWith('*')) {\n return `[...${part.slice(1)}]`;\n }\n return part;\n });\n return partsWithGroups.join('/') + '.html';\n });\n}\n\n// Given a route like `(foo)/bar/(baz)`, return all possible variations of the route.\n// e.g. `(foo)/bar/(baz)`, `(foo)/bar/baz`, `foo/bar/(baz)`, `foo/bar/baz`,\nexport function getPathVariations(routePath: string): string[] {\n const variations = new Set<string>([routePath]);\n const segments = routePath.split('/');\n\n function generateVariations(segments: string[], index: number): void {\n if (index >= segments.length) {\n return;\n }\n\n const newSegments = [...segments];\n while (\n index < newSegments.length &&\n matchGroupName(newSegments[index]) &&\n newSegments.length > 1\n ) {\n newSegments.splice(index, 1);\n variations.add(newSegments.join('/'));\n generateVariations(newSegments, index + 1);\n }\n\n generateVariations(segments, index + 1);\n }\n\n generateVariations(segments, 0);\n\n return Array.from(variations);\n}\n"],"names":["unstable_exportStaticAsync","getFilesToExportFromServerAsync","exportFromServerAsync","modifyBundlesWithSourceMaps","getHtmlFiles","getPathVariations","debug","require","projectRoot","options","Log","warn","learnMore","devServerManager","DevServerManager","minify","mode","location","startAsync","type","isExporting","stopAsync","matchGroupName","name","match","manifest","renderAsync","files","Map","Promise","all","map","outputPath","pathname","replace","set","data","e","logMetroErrorAsync","error","Error","outputDir","basePath","includeMaps","injectFaviconTag","getVirtualFaviconAssetsAsync","devServer","getDefaultDevServer","assert","MetroBundlerDevServer","resources","getStaticResourcesAsync","getStaticRenderFunctionAsync","inspect","colors","depth","template","html","composeResourcesWithHtml","forEach","resource","filename","source","fs","mkdirSync","path","join","recursive","log","chalk","bold","size","entries","sort","a","b","localeCompare","file","contents","length","Buffer","byteLength","gray","prettyBytes","promises","mkdir","dirname","writeFile","endsWith","normalizedFilename","props","mapName","htmlFiles","Set","traverseScreens","screens","value","Object","values","filePath","slice","addOptionalGroups","newPath","variations","variation","add","Array","from","parts","split","partsWithGroups","part","startsWith","routePath","segments","generateVariations","index","newSegments","splice"],"mappings":"AAMA;;;;QAmBsBA,0BAA0B,GAA1BA,0BAA0B;QAkC1BC,+BAA+B,GAA/BA,+BAA+B;QA+B/BC,qBAAqB,GAArBA,qBAAqB;QAmE3BC,2BAA2B,GAA3BA,2BAA2B;QA2B3BC,YAAY,GAAZA,YAAY;QAkDZC,iBAAiB,GAAjBA,iBAAiB;AApOd,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACT,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AACd,IAAA,KAAM,WAAN,MAAM,CAAA;AAEe,IAAA,QAAW,WAAX,WAAW,CAAA;AACpC,IAAA,IAAQ,WAAR,QAAQ,CAAA;AACK,IAAA,iBAAkC,WAAlC,kCAAkC,CAAA;AAC7B,IAAA,sBAA6C,WAA7C,6CAA6C,CAAA;AAChD,IAAA,oBAA2C,WAA3C,2CAA2C,CAAA;AACpD,IAAA,KAAe,WAAf,eAAe,CAAA;;;;;;AAEzC,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,kCAAkC,CAAC,AAAsB,AAAC;AAKlF,eAAeP,0BAA0B,CAACQ,WAAmB,EAAEC,OAAgB,EAAE;IACtFC,IAAG,IAAA,CAACC,IAAI,CACN,CAAC,0CAA0C,CAAC,GAC1CC,CAAAA,GAAAA,KAAS,AAA4D,CAAA,UAA5D,CAAC,0DAA0D,CAAC,CACxE,CAAC;IAEF,sCAAsC;IACtC,MAAMC,gBAAgB,GAAG,IAAIC,iBAAgB,iBAAA,CAACN,WAAW,EAAE;QACzDO,MAAM,EAAEN,OAAO,CAACM,MAAM;QACtBC,IAAI,EAAE,YAAY;QAClBC,QAAQ,EAAE,EAAE;KACb,CAAC,AAAC;IACH,MAAM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,QAAQ;SAAC,AAAC;QAClC,MACEE,KAAK,GAAGC,WAAW,CAACtC,MAAM,IAC1BzD,cAAc,CAAC+F,WAAW,CAACD,KAAK,CAAC,CAAC,IAClCC,WAAW,CAACtC,MAAM,GAAG,CAAC,CACtB;YACAsC,WAAW,CAACC,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC,CAAC;YAC7Bb,UAAU,CAACE,GAAG,CAACY,WAAW,CAACnD,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACtCiD,kBAAkB,CAACE,WAAW,EAAED,KAAK,GAAG,CAAC,CAAC,CAAC;SAC5C;QAEDD,kBAAkB,CAACD,QAAQ,EAAEE,KAAK,GAAG,CAAC,CAAC,CAAC;KACzC;IAEDD,kBAAkB,CAACD,SAAQ,EAAE,CAAC,CAAC,CAAC;IAEhC,OAAOR,KAAK,CAACC,IAAI,CAACJ,UAAU,CAAC,CAAC;CAC/B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/export/exportStaticAsync.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { getConfig } from '@expo/config';\nimport assert from 'assert';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\nimport prettyBytes from 'pretty-bytes';\nimport { inspect } from 'util';\n\nimport { getVirtualFaviconAssetsAsync } from './favicon';\nimport { Log } from '../log';\nimport { DevServerManager } from '../start/server/DevServerManager';\nimport { MetroBundlerDevServer } from '../start/server/metro/MetroBundlerDevServer';\nimport { logMetroErrorAsync } from '../start/server/metro/metroErrorInterface';\nimport {\n getApiRoutesForDirectory,\n getRouterDirectoryWithManifest,\n} from '../start/server/metro/router';\nimport { learnMore } from '../utils/link';\n\nconst debug = require('debug')('expo:export:generateStaticRoutes') as typeof console.log;\n\ntype Options = {\n outputDir: string;\n minify: boolean;\n exportServer: boolean;\n basePath: string;\n includeMaps: boolean;\n};\n\n/** @private */\nexport async function unstable_exportStaticAsync(projectRoot: string, options: Options) {\n Log.warn(\n `Experimental static rendering is enabled. ` +\n learnMore('https://docs.expo.dev/router/reference/static-rendering/')\n );\n\n // TODO: Prevent starting the watcher.\n const devServerManager = new DevServerManager(projectRoot, {\n minify: options.minify,\n mode: 'production',\n location: {},\n });\n await devServerManager.startAsync([\n {\n type: 'metro',\n options: {\n location: {},\n isExporting: true,\n },\n },\n ]);\n\n try {\n await exportFromServerAsync(projectRoot, devServerManager, options);\n } finally {\n await devServerManager.stopAsync();\n }\n}\n\n/** Match `(page)` -> `page` */\nfunction matchGroupName(name: string): string | undefined {\n return name.match(/^\\(([^/]+?)\\)$/)?.[1];\n}\n\nexport async function getFilesToExportFromServerAsync(\n projectRoot: string,\n {\n manifest,\n renderAsync,\n }: {\n manifest: any;\n renderAsync: (pathname: string) => Promise<string>;\n }\n): Promise<Map<string, string>> {\n // name : contents\n const files = new Map<string, string>();\n\n await Promise.all(\n getHtmlFiles({ manifest }).map(async (outputPath) => {\n const pathname = outputPath.replace(/(?:index)?\\.html$/, '');\n try {\n files.set(outputPath, '');\n const data = await renderAsync(pathname);\n files.set(outputPath, data);\n } catch (e: any) {\n await logMetroErrorAsync({ error: e, projectRoot });\n throw new Error('Failed to statically export route: ' + pathname);\n }\n })\n );\n\n return files;\n}\n\n/** Perform all fs commits */\nexport async function exportFromServerAsync(\n projectRoot: string,\n devServerManager: DevServerManager,\n { outputDir, basePath, exportServer, minify, includeMaps }: Options\n): Promise<void> {\n const { exp } = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n const appDir = getRouterDirectoryWithManifest(projectRoot, exp);\n\n const injectFaviconTag = await getVirtualFaviconAssetsAsync(projectRoot, { outputDir, basePath });\n\n const devServer = devServerManager.getDefaultDevServer();\n assert(devServer instanceof MetroBundlerDevServer);\n\n const [resources, { manifest, renderAsync }] = await Promise.all([\n devServer.getStaticResourcesAsync({ mode: 'production', minify, includeMaps }),\n devServer.getStaticRenderFunctionAsync({\n mode: 'production',\n minify,\n }),\n ]);\n\n debug('Routes:\\n', inspect(manifest, { colors: true, depth: null }));\n\n const files = await getFilesToExportFromServerAsync(projectRoot, {\n manifest,\n async renderAsync(pathname: string) {\n const template = await renderAsync(pathname);\n let html = await devServer.composeResourcesWithHtml({\n mode: 'production',\n resources,\n template,\n basePath,\n });\n\n if (injectFaviconTag) {\n html = injectFaviconTag(html);\n }\n\n return html;\n },\n });\n\n resources.forEach((resource) => {\n files.set(\n resource.filename,\n modifyBundlesWithSourceMaps(resource.filename, resource.source, includeMaps)\n );\n });\n\n if (exportServer) {\n const apiRoutes = await exportApiRoutesAsync({ outputDir, server: devServer, appDir });\n\n // Add the api routes to the files to export.\n for (const [route, contents] of apiRoutes) {\n files.set(route, contents);\n }\n } else {\n warnPossibleInvalidExportType(appDir);\n }\n\n fs.mkdirSync(path.join(outputDir), { recursive: true });\n\n Log.log('');\n Log.log(chalk.bold`Exporting ${files.size} files:`);\n await Promise.all(\n [...files.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(async ([file, contents]) => {\n const length = Buffer.byteLength(contents, 'utf8');\n Log.log(file, chalk.gray`(${prettyBytes(length)})`);\n const outputPath = path.join(outputDir, file);\n await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.promises.writeFile(outputPath, contents);\n })\n );\n Log.log('');\n}\n\nexport function modifyBundlesWithSourceMaps(\n filename: string,\n source: string,\n includeMaps: boolean\n): string {\n if (filename.endsWith('.js')) {\n // If the bundle ends with source map URLs then update them to point to the correct location.\n\n // TODO: basePath support\n const normalizedFilename = '/' + filename.replace(/^\\/+/, '');\n //# sourceMappingURL=//localhost:8085/index.map?platform=web&dev=false&hot=false&lazy=true&minify=true&resolver.environment=client&transform.environment=client&serializer.output=static\n //# sourceURL=http://localhost:8085/index.bundle//&platform=web&dev=false&hot=false&lazy=true&minify=true&resolver.environment=client&transform.environment=client&serializer.output=static\n return source.replace(/^\\/\\/# (sourceMappingURL|sourceURL)=.*$/gm, (...props) => {\n if (includeMaps) {\n if (props[1] === 'sourceURL') {\n return `//# ${props[1]}=` + normalizedFilename;\n } else if (props[1] === 'sourceMappingURL') {\n const mapName = normalizedFilename + '.map';\n return `//# ${props[1]}=` + mapName;\n }\n }\n return '';\n });\n }\n return source;\n}\n\nexport function getHtmlFiles({ manifest }: { manifest: any }): string[] {\n const htmlFiles = new Set<string>();\n\n function traverseScreens(screens: string | { screens: any; path: string }, basePath = '') {\n for (const value of Object.values(screens)) {\n if (typeof value === 'string') {\n let filePath = basePath + value;\n if (value === '') {\n filePath =\n basePath === ''\n ? 'index'\n : basePath.endsWith('/')\n ? basePath + 'index'\n : basePath.slice(0, -1);\n }\n // TODO: Dedupe requests for alias routes.\n addOptionalGroups(filePath);\n } else if (typeof value === 'object' && value?.screens) {\n const newPath = basePath + value.path + '/';\n traverseScreens(value.screens, newPath);\n }\n }\n }\n\n function addOptionalGroups(path: string) {\n const variations = getPathVariations(path);\n for (const variation of variations) {\n htmlFiles.add(variation);\n }\n }\n\n traverseScreens(manifest.screens);\n\n return Array.from(htmlFiles).map((value) => {\n const parts = value.split('/');\n // Replace `:foo` with `[foo]` and `*foo` with `[...foo]`\n const partsWithGroups = parts.map((part) => {\n if (part.startsWith(':')) {\n return `[${part.slice(1)}]`;\n } else if (part.startsWith('*')) {\n return `[...${part.slice(1)}]`;\n }\n return part;\n });\n return partsWithGroups.join('/') + '.html';\n });\n}\n\n// Given a route like `(foo)/bar/(baz)`, return all possible variations of the route.\n// e.g. `(foo)/bar/(baz)`, `(foo)/bar/baz`, `foo/bar/(baz)`, `foo/bar/baz`,\nexport function getPathVariations(routePath: string): string[] {\n const variations = new Set<string>([routePath]);\n const segments = routePath.split('/');\n\n function generateVariations(segments: string[], index: number): void {\n if (index >= segments.length) {\n return;\n }\n\n const newSegments = [...segments];\n while (\n index < newSegments.length &&\n matchGroupName(newSegments[index]) &&\n newSegments.length > 1\n ) {\n newSegments.splice(index, 1);\n variations.add(newSegments.join('/'));\n generateVariations(newSegments, index + 1);\n }\n\n generateVariations(segments, index + 1);\n }\n\n generateVariations(segments, 0);\n\n return Array.from(variations);\n}\n\nasync function exportApiRoutesAsync({\n outputDir,\n server,\n appDir,\n}: {\n outputDir: string;\n server: MetroBundlerDevServer;\n appDir: string;\n}): Promise<Map<string, string>> {\n const funcDir = path.join(outputDir, '_expo/functions');\n fs.mkdirSync(path.join(funcDir), { recursive: true });\n\n const [manifest, files] = await Promise.all([\n server.getExpoRouterRoutesManifestAsync({\n appDir,\n }),\n server\n .exportExpoRouterApiRoutesAsync({\n mode: 'production',\n appDir,\n })\n .then((routes) => {\n const files = new Map<string, string>();\n for (const [route, contents] of routes) {\n files.set(path.join('_expo/functions', route), contents);\n }\n return files;\n }),\n ]);\n\n Log.log(chalk.bold`Exporting ${files.size} API Routes.`);\n\n files.set('_expo/routes.json', JSON.stringify(manifest, null, 2));\n\n return files;\n}\n\nfunction warnPossibleInvalidExportType(appDir: string) {\n const apiRoutes = getApiRoutesForDirectory(appDir);\n if (apiRoutes.length) {\n // TODO: Allow API Routes for native-only.\n Log.warn(\n chalk.yellow`Skipping export for API routes because \\`web.output\\` is not \"server\". You may want to remove the routes: ${apiRoutes\n .map((v) => path.relative(appDir, v))\n .join(', ')}`\n );\n }\n}\n"],"names":["unstable_exportStaticAsync","getFilesToExportFromServerAsync","exportFromServerAsync","modifyBundlesWithSourceMaps","getHtmlFiles","getPathVariations","debug","require","projectRoot","options","Log","warn","learnMore","devServerManager","DevServerManager","minify","mode","location","startAsync","type","isExporting","stopAsync","matchGroupName","name","match","manifest","renderAsync","files","Map","Promise","all","map","outputPath","pathname","replace","set","data","e","logMetroErrorAsync","error","Error","outputDir","basePath","exportServer","includeMaps","exp","getConfig","skipSDKVersionRequirement","appDir","getRouterDirectoryWithManifest","injectFaviconTag","getVirtualFaviconAssetsAsync","devServer","getDefaultDevServer","assert","MetroBundlerDevServer","resources","getStaticResourcesAsync","getStaticRenderFunctionAsync","inspect","colors","depth","template","html","composeResourcesWithHtml","forEach","resource","filename","source","apiRoutes","exportApiRoutesAsync","server","route","contents","warnPossibleInvalidExportType","fs","mkdirSync","path","join","recursive","log","chalk","bold","size","entries","sort","a","b","localeCompare","file","length","Buffer","byteLength","gray","prettyBytes","promises","mkdir","dirname","writeFile","endsWith","normalizedFilename","props","mapName","htmlFiles","Set","traverseScreens","screens","value","Object","values","filePath","slice","addOptionalGroups","newPath","variations","variation","add","Array","from","parts","split","partsWithGroups","part","startsWith","routePath","segments","generateVariations","index","newSegments","splice","funcDir","getExpoRouterRoutesManifestAsync","exportExpoRouterApiRoutesAsync","then","routes","JSON","stringify","getApiRoutesForDirectory","yellow","v","relative"],"mappings":"AAMA;;;;QA8BsBA,0BAA0B,GAA1BA,0BAA0B;QAkC1BC,+BAA+B,GAA/BA,+BAA+B;QA+B/BC,qBAAqB,GAArBA,qBAAqB;QA8E3BC,2BAA2B,GAA3BA,2BAA2B;QA2B3BC,YAAY,GAAZA,YAAY;QAkDZC,iBAAiB,GAAjBA,iBAAiB;AA1PP,IAAA,OAAc,WAAd,cAAc,CAAA;AACrB,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACT,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AACd,IAAA,KAAM,WAAN,MAAM,CAAA;AAEe,IAAA,QAAW,WAAX,WAAW,CAAA;AACpC,IAAA,IAAQ,WAAR,QAAQ,CAAA;AACK,IAAA,iBAAkC,WAAlC,kCAAkC,CAAA;AAC7B,IAAA,sBAA6C,WAA7C,6CAA6C,CAAA;AAChD,IAAA,oBAA2C,WAA3C,2CAA2C,CAAA;AAIvE,IAAA,OAA8B,WAA9B,8BAA8B,CAAA;AACX,IAAA,KAAe,WAAf,eAAe,CAAA;;;;;;AAEzC,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,kCAAkC,CAAC,A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C;aAC1D;YACD,OAAO9C,KAAK,CAAC;SACd,CAAC;KACL,CAAC,AAAC;IAEHjB,IAAG,IAAA,CAACsE,GAAG,CAACC,MAAK,QAAA,CAACC,IAAI,CAAC,UAAU,EAAEvD,MAAK,CAACwD,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEzDxD,MAAK,CAACQ,GAAG,CAAC,mBAAmB,EAAEoG,IAAI,CAACC,SAAS,CAAC/G,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAElE,OAAOE,MAAK,CAAC;CACd;AAED,SAAS+C,6BAA6B,CAAC1B,MAAc,EAAE;IACrD,MAAMqB,SAAS,GAAGoE,CAAAA,GAAAA,OAAwB,AAAQ,CAAA,yBAAR,CAACzF,MAAM,CAAC,AAAC;IACnD,IAAIqB,SAAS,CAACqB,MAAM,EAAE;QACpB,0CAA0C;QAC1ChF,IAAG,IAAA,CAACC,IAAI,CACNsE,MAAK,QAAA,CAACyD,MAAM,CAAC,0GAA0G,EAAErE,SAAS,CAC/HtC,GAAG,CAAC,CAAC4G,CAAC,GAAK9D,KAAI,QAAA,CAAC+D,QAAQ,CAAC5F,MAAM,EAAE2F,CAAC,CAAC;QAAA,CAAC,CACpC7D,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAChB,CAAC;KACH;CACF"}
|
|
@@ -7,7 +7,7 @@ var _config = require("@expo/config");
|
|
|
7
7
|
var _getResolvedLocales = require("./getResolvedLocales");
|
|
8
8
|
var _env = require("../utils/env");
|
|
9
9
|
var _errors = require("../utils/errors");
|
|
10
|
-
async function getPublicExpoManifestAsync(projectRoot) {
|
|
10
|
+
async function getPublicExpoManifestAsync(projectRoot, { skipValidation } = {}) {
|
|
11
11
|
// Read the config in public mode which strips the `hooks`.
|
|
12
12
|
const { exp } = (0, _config).getConfig(projectRoot, {
|
|
13
13
|
isPublicConfig: true,
|
|
@@ -15,7 +15,7 @@ async function getPublicExpoManifestAsync(projectRoot) {
|
|
|
15
15
|
skipSDKVersionRequirement: true
|
|
16
16
|
});
|
|
17
17
|
// Only allow projects to be published with UNVERSIONED if a correct token is set in env
|
|
18
|
-
if (exp.sdkVersion === "UNVERSIONED" && !_env.env.EXPO_SKIP_MANIFEST_VALIDATION_TOKEN) {
|
|
18
|
+
if (!skipValidation && exp.sdkVersion === "UNVERSIONED" && !_env.env.EXPO_SKIP_MANIFEST_VALIDATION_TOKEN) {
|
|
19
19
|
throw new _errors.CommandError("INVALID_OPTIONS", "Cannot publish with sdkVersion UNVERSIONED.");
|
|
20
20
|
}
|
|
21
21
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/getPublicExpoManifest.ts"],"sourcesContent":["import { ExpoConfig, getConfig } from '@expo/config';\n\nimport { LocaleMap, getResolvedLocalesAsync } from './getResolvedLocales';\nimport { env } from '../utils/env';\nimport { CommandError } from '../utils/errors';\n\n/** Get the public Expo manifest from the local project config. */\nexport async function getPublicExpoManifestAsync(\n projectRoot: string\n): Promise<ExpoConfig & { locales: LocaleMap; sdkVersion: string }> {\n // Read the config in public mode which strips the `hooks`.\n const { exp } = getConfig(projectRoot, {\n isPublicConfig: true,\n // This shouldn't be needed since the CLI is vendored in `expo`.\n skipSDKVersionRequirement: true,\n });\n\n // Only allow projects to be published with UNVERSIONED if a correct token is set in env\n if (exp.sdkVersion === 'UNVERSIONED'
|
|
1
|
+
{"version":3,"sources":["../../../src/export/getPublicExpoManifest.ts"],"sourcesContent":["import { ExpoConfig, getConfig } from '@expo/config';\n\nimport { LocaleMap, getResolvedLocalesAsync } from './getResolvedLocales';\nimport { env } from '../utils/env';\nimport { CommandError } from '../utils/errors';\n\n/** Get the public Expo manifest from the local project config. */\nexport async function getPublicExpoManifestAsync(\n projectRoot: string,\n { skipValidation }: { skipValidation?: boolean } = {}\n): Promise<ExpoConfig & { locales: LocaleMap; sdkVersion: string }> {\n // Read the config in public mode which strips the `hooks`.\n const { exp } = getConfig(projectRoot, {\n isPublicConfig: true,\n // This shouldn't be needed since the CLI is vendored in `expo`.\n skipSDKVersionRequirement: true,\n });\n\n // Only allow projects to be published with UNVERSIONED if a correct token is set in env\n if (\n !skipValidation &&\n exp.sdkVersion === 'UNVERSIONED' &&\n !env.EXPO_SKIP_MANIFEST_VALIDATION_TOKEN\n ) {\n throw new CommandError('INVALID_OPTIONS', 'Cannot publish with sdkVersion UNVERSIONED.');\n }\n\n return {\n ...exp,\n locales: await getResolvedLocalesAsync(projectRoot, exp),\n sdkVersion: exp.sdkVersion!,\n };\n}\n"],"names":["getPublicExpoManifestAsync","projectRoot","skipValidation","exp","getConfig","isPublicConfig","skipSDKVersionRequirement","sdkVersion","env","EXPO_SKIP_MANIFEST_VALIDATION_TOKEN","CommandError","locales","getResolvedLocalesAsync"],"mappings":"AAAA;;;;QAOsBA,0BAA0B,GAA1BA,0BAA0B;AAPV,IAAA,OAAc,WAAd,cAAc,CAAA;AAED,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACrD,IAAA,IAAc,WAAd,cAAc,CAAA;AACL,IAAA,OAAiB,WAAjB,iBAAiB,CAAA;AAGvC,eAAeA,0BAA0B,CAC9CC,WAAmB,EACnB,EAAEC,cAAc,CAAA,EAAgC,GAAG,EAAE,EACa;IAClE,2DAA2D;IAC3D,MAAM,EAAEC,GAAG,CAAA,EAAE,GAAGC,CAAAA,GAAAA,OAAS,AAIvB,CAAA,UAJuB,CAACH,WAAW,EAAE;QACrCI,cAAc,EAAE,IAAI;QACpB,gEAAgE;QAChEC,yBAAyB,EAAE,IAAI;KAChC,CAAC,AAAC;IAEH,wFAAwF;IACxF,IACE,CAACJ,cAAc,IACfC,GAAG,CAACI,UAAU,KAAK,aAAa,IAChC,CAACC,IAAG,IAAA,CAACC,mCAAmC,EACxC;QACA,MAAM,IAAIC,OAAY,aAAA,CAAC,iBAAiB,EAAE,6CAA6C,CAAC,CAAC;KAC1F;IAED,OAAO;QACL,GAAGP,GAAG;QACNQ,OAAO,EAAE,MAAMC,CAAAA,GAAAA,mBAAuB,AAAkB,CAAA,wBAAlB,CAACX,WAAW,EAAEE,GAAG,CAAC;QACxDI,UAAU,EAAEJ,GAAG,CAACI,UAAU;KAC3B,CAAC;CACH"}
|
|
@@ -31,12 +31,12 @@ const debug = require("debug")("expo:export:write");
|
|
|
31
31
|
*/ function createBundleHash(bundle) {
|
|
32
32
|
return _crypto.default.createHash("md5").update(bundle).digest("hex");
|
|
33
33
|
}
|
|
34
|
-
async function writeBundlesAsync({ bundles , outputDir ,
|
|
34
|
+
async function writeBundlesAsync({ bundles , outputDir , useServerRendering }) {
|
|
35
35
|
const hashes = {};
|
|
36
36
|
const fileNames = {};
|
|
37
37
|
for (const [platform, bundleOutput] of Object.entries(bundles)){
|
|
38
38
|
// TODO: Move native to use the newer `_expo/...` bundle writing system.
|
|
39
|
-
if (platform === "web" &&
|
|
39
|
+
if (platform === "web" && useServerRendering) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
var _hermesBytecodeBundle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/writeContents.ts"],"sourcesContent":["import { Platform } from '@expo/config';\nimport crypto from 'crypto';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { createMetadataJson } from './createMetadataJson';\nimport { BundleOutput } from './fork-bundleAsync';\nimport { Asset } from './saveAssets';\n\nconst debug = require('debug')('expo:export:write') as typeof console.log;\n\n/**\n * @param props.platform native platform for the bundle\n * @param props.format extension to use for the name\n * @param props.hash crypto hash for the bundle contents\n * @returns filename for the JS bundle.\n */\nfunction createBundleFileName({\n platform,\n format,\n hash,\n}: {\n platform: string;\n format: 'javascript' | 'bytecode';\n hash: string;\n}): string {\n return `${platform}-${hash}.${format === 'javascript' ? 'js' : 'hbc'}`;\n}\n\n/**\n * @param bundle JS bundle as a string\n * @returns crypto hash for the provided bundle\n */\nfunction createBundleHash(bundle: string | Uint8Array): string {\n return crypto.createHash('md5').update(bundle).digest('hex');\n}\n\nexport async function writeBundlesAsync({\n bundles,\n outputDir,\n useWebSSG,\n}: {\n bundles: Partial<Record<Platform, Pick<BundleOutput, 'hermesBytecodeBundle' | 'code'>>>;\n outputDir: string;\n useWebSSG?: boolean;\n}) {\n const hashes: Partial<Record<Platform, string>> = {};\n const fileNames: Partial<Record<Platform, string>> = {};\n\n for (const [platform, bundleOutput] of Object.entries(bundles) as [\n Platform,\n Pick<BundleOutput, 'hermesBytecodeBundle' | 'code'>,\n ][]) {\n // TODO: Move native to use the newer `_expo/...` bundle writing system.\n if (platform === 'web' && useWebSSG) {\n continue;\n }\n const bundle = bundleOutput.hermesBytecodeBundle ?? bundleOutput.code;\n const hash = createBundleHash(bundle);\n const fileName = createBundleFileName({\n platform,\n format: bundleOutput.hermesBytecodeBundle ? 'bytecode' : 'javascript',\n hash,\n });\n\n hashes[platform] = hash;\n fileNames[platform] = fileName;\n await fs.writeFile(path.join(outputDir, fileName), bundle);\n }\n\n return { hashes, fileNames };\n}\n\ntype SourceMapWriteResult = {\n platform: string;\n fileName: string;\n hash: string;\n map: string;\n comment: string;\n};\n\nexport async function writeSourceMapsAsync({\n bundles,\n hashes,\n fileNames,\n outputDir,\n}: {\n bundles: Record<\n string,\n Pick<BundleOutput, 'hermesSourcemap' | 'map' | 'hermesBytecodeBundle' | 'code'>\n >;\n hashes?: Record<string, string>;\n fileNames?: Record<string, string>;\n outputDir: string;\n}): Promise<SourceMapWriteResult[]> {\n return (\n await Promise.all(\n Object.entries(bundles).map(async ([platform, bundle]) => {\n const sourceMap = bundle.hermesSourcemap ?? bundle.map;\n if (!sourceMap) {\n debug(`Skip writing sourcemap (platform: ${platform})`);\n return null;\n }\n\n const hash =\n hashes?.[platform] ?? createBundleHash(bundle.hermesBytecodeBundle ?? bundle.code);\n const mapName = `${platform}-${hash}.map`;\n await fs.writeFile(path.join(outputDir, mapName), sourceMap);\n\n const jsBundleFileName =\n fileNames?.[platform] ??\n createBundleFileName({\n platform,\n format: bundle.hermesBytecodeBundle ? 'bytecode' : 'javascript',\n hash,\n });\n const jsPath = path.join(outputDir, jsBundleFileName);\n\n // Add correct mapping to sourcemap paths\n const mappingComment = `\\n//# sourceMappingURL=${mapName}`;\n await fs.appendFile(jsPath, mappingComment);\n return {\n platform,\n fileName: mapName,\n hash,\n map: sourceMap,\n comment: mappingComment,\n };\n })\n )\n ).filter(Boolean) as SourceMapWriteResult[];\n}\n\nexport async function writeMetadataJsonAsync({\n outputDir,\n bundles,\n fileNames,\n}: {\n outputDir: string;\n bundles: Record<string, Pick<BundleOutput, 'assets'>>;\n fileNames: Record<string, string>;\n}) {\n const contents = createMetadataJson({\n bundles,\n fileNames,\n });\n const metadataPath = path.join(outputDir, 'metadata.json');\n debug(`Writing metadata.json to ${metadataPath}`);\n await fs.writeFile(metadataPath, JSON.stringify(contents));\n return contents;\n}\n\nexport async function writeAssetMapAsync({\n outputDir,\n assets,\n}: {\n outputDir: string;\n assets: Asset[];\n}) {\n // Convert the assets array to a k/v pair where the asset hash is the key and the asset is the value.\n const contents = Object.fromEntries(assets.map((asset) => [asset.hash, asset]));\n await fs.writeFile(path.join(outputDir, 'assetmap.json'), JSON.stringify(contents));\n return contents;\n}\n\nexport async function writeDebugHtmlAsync({\n outputDir,\n fileNames,\n}: {\n outputDir: string;\n fileNames: Record<string, string>;\n}) {\n // Make a debug html so user can debug their bundles\n const contents = `\n ${Object.values(fileNames)\n .map((fileName) => `<script src=\"${path.join('bundles', fileName)}\"></script>`)\n .join('\\n ')}\n Open up this file in Chrome. In the JavaScript developer console, navigate to the Source tab.\n You can see a red colored folder containing the original source code from your bundle.\n `;\n\n await fs.writeFile(path.join(outputDir, 'debug.html'), contents);\n return contents;\n}\n"],"names":["writeBundlesAsync","writeSourceMapsAsync","writeMetadataJsonAsync","writeAssetMapAsync","writeDebugHtmlAsync","debug","require","createBundleFileName","platform","format","hash","createBundleHash","bundle","crypto","createHash","update","digest","bundles","outputDir","useWebSSG","hashes","fileNames","bundleOutput","Object","entries","hermesBytecodeBundle","code","fileName","fs","writeFile","path","join","Promise","all","map","sourceMap","hermesSourcemap","mapName","jsBundleFileName","jsPath","mappingComment","appendFile","comment","filter","Boolean","contents","createMetadataJson","metadataPath","JSON","stringify","assets","fromEntries","asset","values"],"mappings":"AAAA;;;;QAqCsBA,iBAAiB,GAAjBA,iBAAiB;QA4CjBC,oBAAoB,GAApBA,oBAAoB;QAoDpBC,sBAAsB,GAAtBA,sBAAsB;QAmBtBC,kBAAkB,GAAlBA,kBAAkB;QAalBC,mBAAmB,GAAnBA,mBAAmB;AApKtB,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACZ,IAAA,SAAa,kCAAb,aAAa,EAAA;AACX,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEY,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;;;;;;AAIzD,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,AAAsB,AAAC;AAE1E;;;;;GAKG,CACH,SAASC,oBAAoB,CAAC,EAC5BC,QAAQ,CAAA,EACRC,MAAM,CAAA,EACNC,IAAI,CAAA,EAKL,EAAU;IACT,OAAO,CAAC,EAAEF,QAAQ,CAAC,CAAC,EAAEE,IAAI,CAAC,CAAC,EAAED,MAAM,KAAK,YAAY,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;CACxE;AAED;;;GAGG,CACH,SAASE,gBAAgB,CAACC,MAA2B,EAAU;IAC7D,OAAOC,OAAM,QAAA,CAACC,UAAU,CAAC,KAAK,CAAC,CAACC,MAAM,CAACH,MAAM,CAAC,CAACI,MAAM,CAAC,KAAK,CAAC,CAAC;CAC9D;AAEM,eAAehB,iBAAiB,CAAC,EACtCiB,OAAO,CAAA,EACPC,SAAS,CAAA,EACTC,SAAS,CAAA,EAKV,EAAE;IACD,MAAMC,MAAM,GAAsC,EAAE,AAAC;IACrD,MAAMC,SAAS,GAAsC,EAAE,AAAC;IAExD,KAAK,MAAM,CAACb,QAAQ,EAAEc,Y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tB,MAAM,CAAC8B,MAAM,CAAChC,SAAS,CAAC,CACvBa,GAAG,CAAC,CAACP,QAAQ,GAAK,CAAC,aAAa,EAAEG,KAAI,QAAA,CAACC,IAAI,CAAC,SAAS,EAAEJ,QAAQ,CAAC,CAAC,WAAW,CAAC;IAAA,CAAC,CAC9EI,IAAI,CAAC,UAAU,CAAC,CAAC;;;MAGpB,CAAC,AAAC;IAEN,MAAMH,SAAE,QAAA,CAACC,SAAS,CAACC,KAAI,QAAA,CAACC,IAAI,CAACb,SAAS,EAAE,YAAY,CAAC,EAAE2B,QAAQ,CAAC,CAAC;IACjE,OAAOA,QAAQ,CAAC;CACjB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/export/writeContents.ts"],"sourcesContent":["import { Platform } from '@expo/config';\nimport crypto from 'crypto';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { createMetadataJson } from './createMetadataJson';\nimport { BundleOutput } from './fork-bundleAsync';\nimport { Asset } from './saveAssets';\n\nconst debug = require('debug')('expo:export:write') as typeof console.log;\n\n/**\n * @param props.platform native platform for the bundle\n * @param props.format extension to use for the name\n * @param props.hash crypto hash for the bundle contents\n * @returns filename for the JS bundle.\n */\nfunction createBundleFileName({\n platform,\n format,\n hash,\n}: {\n platform: string;\n format: 'javascript' | 'bytecode';\n hash: string;\n}): string {\n return `${platform}-${hash}.${format === 'javascript' ? 'js' : 'hbc'}`;\n}\n\n/**\n * @param bundle JS bundle as a string\n * @returns crypto hash for the provided bundle\n */\nfunction createBundleHash(bundle: string | Uint8Array): string {\n return crypto.createHash('md5').update(bundle).digest('hex');\n}\n\nexport async function writeBundlesAsync({\n bundles,\n outputDir,\n useServerRendering,\n}: {\n bundles: Partial<Record<Platform, Pick<BundleOutput, 'hermesBytecodeBundle' | 'code'>>>;\n outputDir: string;\n useServerRendering?: boolean;\n}) {\n const hashes: Partial<Record<Platform, string>> = {};\n const fileNames: Partial<Record<Platform, string>> = {};\n\n for (const [platform, bundleOutput] of Object.entries(bundles) as [\n Platform,\n Pick<BundleOutput, 'hermesBytecodeBundle' | 'code'>,\n ][]) {\n // TODO: Move native to use the newer `_expo/...` bundle writing system.\n if (platform === 'web' && useServerRendering) {\n continue;\n }\n const bundle = bundleOutput.hermesBytecodeBundle ?? bundleOutput.code;\n const hash = createBundleHash(bundle);\n const fileName = createBundleFileName({\n platform,\n format: bundleOutput.hermesBytecodeBundle ? 'bytecode' : 'javascript',\n hash,\n });\n\n hashes[platform] = hash;\n fileNames[platform] = fileName;\n await fs.writeFile(path.join(outputDir, fileName), bundle);\n }\n\n return { hashes, fileNames };\n}\n\ntype SourceMapWriteResult = {\n platform: string;\n fileName: string;\n hash: string;\n map: string;\n comment: string;\n};\n\nexport async function writeSourceMapsAsync({\n bundles,\n hashes,\n fileNames,\n outputDir,\n}: {\n bundles: Record<\n string,\n Pick<BundleOutput, 'hermesSourcemap' | 'map' | 'hermesBytecodeBundle' | 'code'>\n >;\n hashes?: Record<string, string>;\n fileNames?: Record<string, string>;\n outputDir: string;\n}): Promise<SourceMapWriteResult[]> {\n return (\n await Promise.all(\n Object.entries(bundles).map(async ([platform, bundle]) => {\n const sourceMap = bundle.hermesSourcemap ?? bundle.map;\n if (!sourceMap) {\n debug(`Skip writing sourcemap (platform: ${platform})`);\n return null;\n }\n\n const hash =\n hashes?.[platform] ?? createBundleHash(bundle.hermesBytecodeBundle ?? bundle.code);\n const mapName = `${platform}-${hash}.map`;\n await fs.writeFile(path.join(outputDir, mapName), sourceMap);\n\n const jsBundleFileName =\n fileNames?.[platform] ??\n createBundleFileName({\n platform,\n format: bundle.hermesBytecodeBundle ? 'bytecode' : 'javascript',\n hash,\n });\n const jsPath = path.join(outputDir, jsBundleFileName);\n\n // Add correct mapping to sourcemap paths\n const mappingComment = `\\n//# sourceMappingURL=${mapName}`;\n await fs.appendFile(jsPath, mappingComment);\n return {\n platform,\n fileName: mapName,\n hash,\n map: sourceMap,\n comment: mappingComment,\n };\n })\n )\n ).filter(Boolean) as SourceMapWriteResult[];\n}\n\nexport async function writeMetadataJsonAsync({\n outputDir,\n bundles,\n fileNames,\n}: {\n outputDir: string;\n bundles: Record<string, Pick<BundleOutput, 'assets'>>;\n fileNames: Record<string, string>;\n}) {\n const contents = createMetadataJson({\n bundles,\n fileNames,\n });\n const metadataPath = path.join(outputDir, 'metadata.json');\n debug(`Writing metadata.json to ${metadataPath}`);\n await fs.writeFile(metadataPath, JSON.stringify(contents));\n return contents;\n}\n\nexport async function writeAssetMapAsync({\n outputDir,\n assets,\n}: {\n outputDir: string;\n assets: Asset[];\n}) {\n // Convert the assets array to a k/v pair where the asset hash is the key and the asset is the value.\n const contents = Object.fromEntries(assets.map((asset) => [asset.hash, asset]));\n await fs.writeFile(path.join(outputDir, 'assetmap.json'), JSON.stringify(contents));\n return contents;\n}\n\nexport async function writeDebugHtmlAsync({\n outputDir,\n fileNames,\n}: {\n outputDir: string;\n fileNames: Record<string, string>;\n}) {\n // Make a debug html so user can debug their bundles\n const contents = `\n ${Object.values(fileNames)\n .map((fileName) => `<script src=\"${path.join('bundles', fileName)}\"></script>`)\n .join('\\n ')}\n Open up this file in Chrome. In the JavaScript developer console, navigate to the Source tab.\n You can see a red colored folder containing the original source code from your bundle.\n `;\n\n await fs.writeFile(path.join(outputDir, 'debug.html'), contents);\n return contents;\n}\n"],"names":["writeBundlesAsync","writeSourceMapsAsync","writeMetadataJsonAsync","writeAssetMapAsync","writeDebugHtmlAsync","debug","require","createBundleFileName","platform","format","hash","createBundleHash","bundle","crypto","createHash","update","digest","bundles","outputDir","useServerRendering","hashes","fileNames","bundleOutput","Object","entries","hermesBytecodeBundle","code","fileName","fs","writeFile","path","join","Promise","all","map","sourceMap","hermesSourcemap","mapName","jsBundleFileName","jsPath","mappingComment","appendFile","comment","filter","Boolean","contents","createMetadataJson","metadataPath","JSON","stringify","assets","fromEntries","asset","values"],"mappings":"AAAA;;;;QAqCsBA,iBAAiB,GAAjBA,iBAAiB;QA4CjBC,oBAAoB,GAApBA,oBAAoB;Q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;MAGpB,CAAC,AAAC;IAEN,MAAMH,SAAE,QAAA,CAACC,SAAS,CAACC,KAAI,QAAA,CAACC,IAAI,CAACb,SAAS,EAAE,YAAY,CAAC,EAAE2B,QAAQ,CAAC,CAAC;IACjE,OAAOA,QAAQ,CAAC;CACjB"}
|
|
@@ -7,6 +7,7 @@ exports.createMetroEndpointAsync = createMetroEndpointAsync;
|
|
|
7
7
|
exports.requireFileContentsWithMetro = requireFileContentsWithMetro;
|
|
8
8
|
exports.requireWithMetro = requireWithMetro;
|
|
9
9
|
exports.getStaticRenderFunctions = getStaticRenderFunctions;
|
|
10
|
+
exports.evalMetroAndWrapFunctions = evalMetroAndWrapFunctions;
|
|
10
11
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
12
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
12
13
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -124,11 +125,14 @@ async function requireFileContentsWithMetro(projectRoot, devServerUrl, absoluteF
|
|
|
124
125
|
}
|
|
125
126
|
async function requireWithMetro(projectRoot, devServerUrl, absoluteFilePath, options = {}) {
|
|
126
127
|
const content = await requireFileContentsWithMetro(projectRoot, devServerUrl, absoluteFilePath, options);
|
|
127
|
-
return
|
|
128
|
+
return evalMetroAndWrapFunctions(projectRoot, content);
|
|
128
129
|
}
|
|
129
130
|
async function getStaticRenderFunctions(projectRoot, devServerUrl, options = {}) {
|
|
130
131
|
const scriptContents = await getStaticRenderFunctionsContentAsync(projectRoot, devServerUrl, options);
|
|
131
|
-
|
|
132
|
+
return evalMetroAndWrapFunctions(projectRoot, scriptContents);
|
|
133
|
+
}
|
|
134
|
+
function evalMetroAndWrapFunctions(projectRoot, script) {
|
|
135
|
+
const contents = evalMetro(script);
|
|
132
136
|
// wrap each function with a try/catch that uses Metro's error formatter
|
|
133
137
|
return Object.keys(contents).reduce((acc, key)=>{
|
|
134
138
|
const fn = contents[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/getStaticRenderFunctions.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport requireString from 'require-from-string';\nimport resolveFrom from 'resolve-from';\n\nimport { logMetroError } from './metro/metroErrorInterface';\nimport { getMetroServerRoot } from './middleware/ManifestMiddleware';\nimport { stripAnsi } from '../../utils/ansi';\nimport { delayAsync } from '../../utils/delay';\nimport { SilentError } from '../../utils/errors';\nimport { memoize } from '../../utils/fn';\nimport { profile } from '../../utils/profile';\n\nconst debug = require('debug')('expo:start:server:node-renderer') as typeof console.log;\n\nfunction wrapBundle(str: string) {\n // Skip the metro runtime so debugging is a bit easier.\n // Replace the __r() call with an export statement.\n // Use gm to apply to the last require line. This is needed when the bundle has side-effects.\n return str.replace(/^(__r\\(.*\\);)$/gm, 'module.exports = $1');\n}\n\n// TODO(EvanBacon): Group all the code together and version.\nconst getRenderModuleId = (projectRoot: string): string => {\n const moduleId = resolveFrom.silent(projectRoot, 'expo-router/node/render.js');\n if (!moduleId) {\n throw new Error(\n `A version of expo-router with Node.js support is not installed in the project.`\n );\n }\n\n return moduleId;\n};\n\ntype StaticRenderOptions = {\n // Ensure the style format is `css-xxxx` (prod) instead of `css-view-xxxx` (dev)\n dev?: boolean;\n minify?: boolean;\n platform?: string;\n environment?: 'node';\n};\n\nconst moveStaticRenderFunction = memoize(async (projectRoot: string, requiredModuleId: string) => {\n // Copy the file into the project to ensure it works in monorepos.\n // This means the file cannot have any relative imports.\n const tempDir = path.join(projectRoot, '.expo/static');\n await fs.promises.mkdir(tempDir, { recursive: true });\n const moduleId = path.join(tempDir, 'render.js');\n await fs.promises.writeFile(moduleId, await fs.promises.readFile(requiredModuleId, 'utf8'));\n // Sleep to give watchman time to register the file.\n await delayAsync(50);\n return moduleId;\n});\n\n/** @returns the js file contents required to generate the static generation function. */\nexport async function getStaticRenderFunctionsContentAsync(\n projectRoot: string,\n devServerUrl: string,\n { dev = false, minify = false, environment }: StaticRenderOptions = {}\n): Promise<string> {\n const root = getMetroServerRoot(projectRoot);\n const requiredModuleId = getRenderModuleId(root);\n let moduleId = requiredModuleId;\n\n // Cannot be accessed using Metro's server API, we need to move the file\n // into the project root and try again.\n if (path.relative(root, moduleId).startsWith('..')) {\n moduleId = await moveStaticRenderFunction(projectRoot, requiredModuleId);\n }\n\n return requireFileContentsWithMetro(root, devServerUrl, moduleId, { dev, minify, environment });\n}\n\nasync function ensureFileInRootDirectory(projectRoot: string, otherFile: string) {\n // Cannot be accessed using Metro's server API, we need to move the file\n // into the project root and try again.\n if (!path.relative(projectRoot, otherFile).startsWith('../')) {\n return otherFile;\n }\n\n // Copy the file into the project to ensure it works in monorepos.\n // This means the file cannot have any relative imports.\n const tempDir = path.join(projectRoot, '.expo/static-tmp');\n await fs.promises.mkdir(tempDir, { recursive: true });\n const moduleId = path.join(tempDir, path.basename(otherFile));\n await fs.promises.writeFile(moduleId, await fs.promises.readFile(otherFile, 'utf8'));\n // Sleep to give watchman time to register the file.\n await delayAsync(50);\n return moduleId;\n}\n\nexport async function createMetroEndpointAsync(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n { dev = false, platform = 'web', minify = false, environment }: StaticRenderOptions = {}\n): Promise<string> {\n const root = getMetroServerRoot(projectRoot);\n const safeOtherFile = await ensureFileInRootDirectory(projectRoot, absoluteFilePath);\n const serverPath = path.relative(root, safeOtherFile).replace(/\\.[jt]sx?$/, '.bundle');\n debug('fetching from Metro:', root, serverPath);\n\n let url = `${devServerUrl}/${serverPath}?platform=${platform}&dev=${dev}&minify=${minify}`;\n\n if (environment) {\n url += `&resolver.environment=${environment}&transform.environment=${environment}`;\n }\n return url;\n}\n\nexport class MetroNodeError extends Error {\n constructor(\n message: string,\n public rawObject: any\n ) {\n super(message);\n }\n}\n\nexport async function requireFileContentsWithMetro(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n props: StaticRenderOptions = {}\n): Promise<string> {\n const url = await createMetroEndpointAsync(projectRoot, devServerUrl, absoluteFilePath, props);\n\n const res = await fetch(url);\n\n // TODO: Improve error handling\n if (res.status === 500) {\n const text = await res.text();\n if (text.startsWith('{\"originModulePath\"') || text.startsWith('{\"type\":\"TransformError\"')) {\n const errorObject = JSON.parse(text);\n\n throw new MetroNodeError(stripAnsi(errorObject.message) ?? errorObject.message, errorObject);\n }\n throw new Error(`[${res.status}]: ${res.statusText}\\n${text}`);\n }\n\n if (!res.ok) {\n throw new Error(`Error fetching bundle for static rendering: ${res.status} ${res.statusText}`);\n }\n\n const content = await res.text();\n\n return wrapBundle(content);\n}\nexport async function requireWithMetro<T>(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n options: StaticRenderOptions = {}\n): Promise<T> {\n const content = await requireFileContentsWithMetro(\n projectRoot,\n devServerUrl,\n absoluteFilePath,\n options\n );\n return evalMetro(content);\n}\n\nexport async function getStaticRenderFunctions(\n projectRoot: string,\n devServerUrl: string,\n options: StaticRenderOptions = {}\n): Promise<Record<string, (...args: any[]) => Promise<any>>> {\n const scriptContents = await getStaticRenderFunctionsContentAsync(\n projectRoot,\n devServerUrl,\n options\n );\n\n const contents = evalMetro(scriptContents);\n\n // wrap each function with a try/catch that uses Metro's error formatter\n return Object.keys(contents).reduce((acc, key) => {\n const fn = contents[key];\n if (typeof fn !== 'function') {\n return { ...acc, [key]: fn };\n }\n\n acc[key] = async function (...props: any[]) {\n try {\n return await fn.apply(this, props);\n } catch (error: any) {\n await logMetroError(projectRoot, { error });\n throw new SilentError(error);\n }\n };\n return acc;\n }, {} as any);\n}\n\nfunction evalMetro(src: string) {\n return profile(requireString, 'eval-metro-bundle')(src);\n}\n"],"names":["getStaticRenderFunctionsContentAsync","createMetroEndpointAsync","requireFileContentsWithMetro","requireWithMetro","getStaticRenderFunctions","debug","require","wrapBundle","str","replace","getRenderModuleId","projectRoot","moduleId","resolveFrom","silent","Error","moveStaticRenderFunction","memoize","requiredModuleId","tempDir","path","join","fs","promises","mkdir","recursive","writeFile","readFile","delayAsync","devServerUrl","dev","minify","environment","root","getMetroServerRoot","relative","startsWith","ensureFileInRootDirectory","otherFile","basename","absoluteFilePath","platform","safeOtherFile","serverPath","url","MetroNodeError","constructor","message","rawObject","props","res","fetch","status","text","errorObject","JSON","parse","stripAnsi","statusText","ok","content","options","evalMetro","scriptContents","contents","Object","keys","reduce","acc","key","fn","apply","error","logMetroError","SilentError","src","profile","requireString"],"mappings":"AAMA;;;;QAwDsBA,oCAAoC,GAApCA,oCAAoC;QAoCpCC,wBAAwB,GAAxBA,wBAAwB;QA4BxBC,4BAA4B,GAA5BA,4BAA4B;QA6B5BC,gBAAgB,GAAhBA,gBAAgB;QAehBC,wBAAwB,GAAxBA,wBAAwB;AApK/B,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACD,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;AACG,IAAA,kBAAqB,kCAArB,qBAAqB,EAAA;AACvB,IAAA,YAAc,kCAAd,cAAc,EAAA;AAER,IAAA,oBAA6B,WAA7B,6BAA6B,CAAA;AACxB,IAAA,mBAAiC,WAAjC,iCAAiC,CAAA;AAC1C,IAAA,KAAkB,WAAlB,kBAAkB,CAAA;AACjB,IAAA,MAAmB,WAAnB,mBAAmB,CAAA;AAClB,IAAA,OAAoB,WAApB,oBAAoB,CAAA;AACxB,IAAA,GAAgB,WAAhB,gBAAgB,CAAA;AAChB,IAAA,QAAqB,WAArB,qBAAqB,CAAA;;;;;;AAE7C,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,iCAAiC,CAAC,AAAsB,AAAC;AAExF,SAASC,UAAU,CAACC,GAAW,EAAE;IAC/B,uDAAuD;IACvD,mDAAmD;IACnD,6FAA6F;IAC7F,OAAOA,GAAG,CAACC,OAAO,qBAAqB,qBAAqB,CAAC,CAAC;CAC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;SACF,CAAC;QACF,OAAOJ,GAAG,CAAC;KACZ,EAAE,EAAE,CAAQ,CAAC;CACf;AAED,SAASN,SAAS,CAACa,GAAW,EAAE;IAC9B,OAAOC,CAAAA,GAAAA,QAAO,AAAoC,CAAA,QAApC,CAACC,kBAAa,QAAA,EAAE,mBAAmB,CAAC,CAACF,GAAG,CAAC,CAAC;CACzD"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/getStaticRenderFunctions.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport requireString from 'require-from-string';\nimport resolveFrom from 'resolve-from';\n\nimport { logMetroError } from './metro/metroErrorInterface';\nimport { getMetroServerRoot } from './middleware/ManifestMiddleware';\nimport { stripAnsi } from '../../utils/ansi';\nimport { delayAsync } from '../../utils/delay';\nimport { SilentError } from '../../utils/errors';\nimport { memoize } from '../../utils/fn';\nimport { profile } from '../../utils/profile';\n\nconst debug = require('debug')('expo:start:server:node-renderer') as typeof console.log;\n\nfunction wrapBundle(str: string) {\n // Skip the metro runtime so debugging is a bit easier.\n // Replace the __r() call with an export statement.\n // Use gm to apply to the last require line. This is needed when the bundle has side-effects.\n return str.replace(/^(__r\\(.*\\);)$/gm, 'module.exports = $1');\n}\n\n// TODO(EvanBacon): Group all the code together and version.\nconst getRenderModuleId = (projectRoot: string): string => {\n const moduleId = resolveFrom.silent(projectRoot, 'expo-router/node/render.js');\n if (!moduleId) {\n throw new Error(\n `A version of expo-router with Node.js support is not installed in the project.`\n );\n }\n\n return moduleId;\n};\n\ntype StaticRenderOptions = {\n // Ensure the style format is `css-xxxx` (prod) instead of `css-view-xxxx` (dev)\n dev?: boolean;\n minify?: boolean;\n platform?: string;\n environment?: 'node';\n};\n\nconst moveStaticRenderFunction = memoize(async (projectRoot: string, requiredModuleId: string) => {\n // Copy the file into the project to ensure it works in monorepos.\n // This means the file cannot have any relative imports.\n const tempDir = path.join(projectRoot, '.expo/static');\n await fs.promises.mkdir(tempDir, { recursive: true });\n const moduleId = path.join(tempDir, 'render.js');\n await fs.promises.writeFile(moduleId, await fs.promises.readFile(requiredModuleId, 'utf8'));\n // Sleep to give watchman time to register the file.\n await delayAsync(50);\n return moduleId;\n});\n\n/** @returns the js file contents required to generate the static generation function. */\nexport async function getStaticRenderFunctionsContentAsync(\n projectRoot: string,\n devServerUrl: string,\n { dev = false, minify = false, environment }: StaticRenderOptions = {}\n): Promise<string> {\n const root = getMetroServerRoot(projectRoot);\n const requiredModuleId = getRenderModuleId(root);\n let moduleId = requiredModuleId;\n\n // Cannot be accessed using Metro's server API, we need to move the file\n // into the project root and try again.\n if (path.relative(root, moduleId).startsWith('..')) {\n moduleId = await moveStaticRenderFunction(projectRoot, requiredModuleId);\n }\n\n return requireFileContentsWithMetro(root, devServerUrl, moduleId, { dev, minify, environment });\n}\n\nasync function ensureFileInRootDirectory(projectRoot: string, otherFile: string) {\n // Cannot be accessed using Metro's server API, we need to move the file\n // into the project root and try again.\n if (!path.relative(projectRoot, otherFile).startsWith('../')) {\n return otherFile;\n }\n\n // Copy the file into the project to ensure it works in monorepos.\n // This means the file cannot have any relative imports.\n const tempDir = path.join(projectRoot, '.expo/static-tmp');\n await fs.promises.mkdir(tempDir, { recursive: true });\n const moduleId = path.join(tempDir, path.basename(otherFile));\n await fs.promises.writeFile(moduleId, await fs.promises.readFile(otherFile, 'utf8'));\n // Sleep to give watchman time to register the file.\n await delayAsync(50);\n return moduleId;\n}\n\nexport async function createMetroEndpointAsync(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n { dev = false, platform = 'web', minify = false, environment }: StaticRenderOptions = {}\n): Promise<string> {\n const root = getMetroServerRoot(projectRoot);\n const safeOtherFile = await ensureFileInRootDirectory(projectRoot, absoluteFilePath);\n const serverPath = path.relative(root, safeOtherFile).replace(/\\.[jt]sx?$/, '.bundle');\n debug('fetching from Metro:', root, serverPath);\n\n let url = `${devServerUrl}/${serverPath}?platform=${platform}&dev=${dev}&minify=${minify}`;\n\n if (environment) {\n url += `&resolver.environment=${environment}&transform.environment=${environment}`;\n }\n return url;\n}\n\nexport class MetroNodeError extends Error {\n constructor(\n message: string,\n public rawObject: any\n ) {\n super(message);\n }\n}\n\nexport async function requireFileContentsWithMetro(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n props: StaticRenderOptions = {}\n): Promise<string> {\n const url = await createMetroEndpointAsync(projectRoot, devServerUrl, absoluteFilePath, props);\n\n const res = await fetch(url);\n\n // TODO: Improve error handling\n if (res.status === 500) {\n const text = await res.text();\n if (text.startsWith('{\"originModulePath\"') || text.startsWith('{\"type\":\"TransformError\"')) {\n const errorObject = JSON.parse(text);\n\n throw new MetroNodeError(stripAnsi(errorObject.message) ?? errorObject.message, errorObject);\n }\n throw new Error(`[${res.status}]: ${res.statusText}\\n${text}`);\n }\n\n if (!res.ok) {\n throw new Error(`Error fetching bundle for static rendering: ${res.status} ${res.statusText}`);\n }\n\n const content = await res.text();\n\n return wrapBundle(content);\n}\n\nexport async function requireWithMetro<T extends Record<string, (...args: any[]) => Promise<any>>>(\n projectRoot: string,\n devServerUrl: string,\n absoluteFilePath: string,\n options: StaticRenderOptions = {}\n): Promise<T> {\n const content = await requireFileContentsWithMetro(\n projectRoot,\n devServerUrl,\n absoluteFilePath,\n options\n );\n return evalMetroAndWrapFunctions<T>(projectRoot, content);\n}\n\nexport async function getStaticRenderFunctions(\n projectRoot: string,\n devServerUrl: string,\n options: StaticRenderOptions = {}\n): Promise<Record<string, (...args: any[]) => Promise<any>>> {\n const scriptContents = await getStaticRenderFunctionsContentAsync(\n projectRoot,\n devServerUrl,\n options\n );\n\n return evalMetroAndWrapFunctions(projectRoot, scriptContents);\n}\n\nexport function evalMetroAndWrapFunctions<T = Record<string, (...args: any[]) => Promise<any>>>(\n projectRoot: string,\n script: string\n): Promise<T> {\n const contents = evalMetro(script);\n\n // wrap each function with a try/catch that uses Metro's error formatter\n return Object.keys(contents).reduce((acc, key) => {\n const fn = contents[key];\n if (typeof fn !== 'function') {\n return { ...acc, [key]: fn };\n }\n\n acc[key] = async function (...props: any[]) {\n try {\n return await fn.apply(this, props);\n } catch (error: any) {\n await logMetroError(projectRoot, { error });\n throw new SilentError(error);\n }\n };\n return acc;\n }, {} as any);\n}\n\nfunction evalMetro(src: string) {\n return profile(requireString, 'eval-metro-bundle')(src);\n}\n"],"names":["getStaticRenderFunctionsContentAsync","createMetroEndpointAsync","requireFileContentsWithMetro","requireWithMetro","getStaticRenderFunctions","evalMetroAndWrapFunctions","debug","require","wrapBundle","str","replace","getRenderModuleId","projectRoot","moduleId","resolveFrom","silent","Error","moveStaticRenderFunction","memoize","requiredModuleId","tempDir","path","join","fs","promises","mkdir","recursive","writeFile","readFile","delayAsync","devServerUrl","dev","minify","environment","root","getMetroServerRoot","relative","startsWith","ensureFileInRootDirectory","otherFile","basename","absoluteFilePath","platform","safeOtherFile","serverPath","url","MetroNodeError","constructor","message","rawObject","props","res","fetch","status","text","errorObject","JSON","parse","stripAnsi","statusText","ok","content","options","scriptContents","script","contents","evalMetro","Object","keys","reduce","acc","key","fn","apply","error","logMetroError","SilentError","src","profile","requireString"],"mappings":"AAMA;;;;QAwDsBA,oCAAoC,GAApCA,oCAAoC;QAoCpCC,wBAAwB,GAAxBA,wBAAwB;QA4BxBC,4BAA4B,GAA5BA,4BAA4B;QA8B5BC,gBAAgB,GAAhBA,gBAAgB;QAehBC,wBAAwB,GAAxBA,wBAAwB;QAc9BC,yBAAyB,GAAzBA,yBAAyB;AAnL1B,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACD,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;AACG,IAAA,kBAAqB,kCAArB,qBAAqB,EAAA;AACvB,IAAA,YAAc,kCAAd,cAAc,EAAA;AAER,IAAA,oBAA6B,WAA7B,6BAA6B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