@expo/cli 0.26.6 → 0.26.8
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 +1 -1
- package/build/src/prebuild/updatePackageJson.js +5 -3
- package/build/src/prebuild/updatePackageJson.js.map +1 -1
- package/build/src/run/android/resolveOptions.js +2 -2
- package/build/src/run/android/resolveOptions.js.map +1 -1
- package/build/src/run/ios/options/resolveOptions.js +2 -2
- package/build/src/run/ios/options/resolveOptions.js.map +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js +24 -3
- package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
- package/build/src/start/server/metro/createServerRouteMiddleware.js +7 -1
- package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -1
- package/build/src/start/server/metro/router.js +40 -0
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/utils/build-cache-providers/index.js.map +1 -1
- package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
- package/build/src/utils/telemetry/utils/context.js +1 -1
- package/package.json +14 -14
package/build/bin/cli
CHANGED
|
@@ -210,7 +210,7 @@ function updatePkgDependencies(projectRoot, { pkg, templatePkg, skipDependencyUp
|
|
|
210
210
|
continue;
|
|
211
211
|
}
|
|
212
212
|
// Warn users for outdated dependencies when prebuilding
|
|
213
|
-
const hasRecommendedVersion = versionRangesIntersect(pkg.dependencies[dependencyKey], String(defaultDependencies[dependencyKey]));
|
|
213
|
+
const hasRecommendedVersion = versionRangesIntersect(pkg.dependencies[dependencyKey], String(defaultDependencies[dependencyKey]), true);
|
|
214
214
|
if (!hasRecommendedVersion) {
|
|
215
215
|
nonRecommendedPackages.push([
|
|
216
216
|
`${dependencyKey}@${pkg.dependencies[dependencyKey]}`,
|
|
@@ -292,9 +292,11 @@ function createFileHash(contents) {
|
|
|
292
292
|
/**
|
|
293
293
|
* Determine if two semver ranges are overlapping or intersecting.
|
|
294
294
|
* This is a safe version of `semver.intersects` that does not throw.
|
|
295
|
-
*/ function versionRangesIntersect(rangeA, rangeB) {
|
|
295
|
+
*/ function versionRangesIntersect(rangeA, rangeB, includePrerelease = false) {
|
|
296
296
|
try {
|
|
297
|
-
return (0, _semver().intersects)(rangeA, rangeB
|
|
297
|
+
return (0, _semver().intersects)(rangeA, rangeB, {
|
|
298
|
+
includePrerelease
|
|
299
|
+
});
|
|
298
300
|
} catch {
|
|
299
301
|
return false;
|
|
300
302
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/prebuild/updatePackageJson.ts"],"sourcesContent":["import { getPackageJson, PackageJSONConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport crypto from 'crypto';\nimport fs from 'fs';\nimport path from 'path';\nimport { intersects as semverIntersects, Range as SemverRange } from 'semver';\n\nimport * as Log from '../log';\nimport { isModuleSymlinked } from '../utils/isModuleSymlinked';\nimport { logNewSection } from '../utils/ora';\n\nexport type DependenciesMap = { [key: string]: string | number };\n\nexport type DependenciesModificationResults = {\n /** A list of new values were added to the `dependencies` object in the `package.json`. */\n changedDependencies: string[];\n};\n\n/** Modifies the `package.json` with `modifyPackageJson` and format/displays the results. */\nexport async function updatePackageJSONAsync(\n projectRoot: string,\n {\n templateDirectory,\n templatePkg = getPackageJson(templateDirectory),\n pkg,\n skipDependencyUpdate,\n }: {\n templateDirectory: string;\n templatePkg?: PackageJSONConfig;\n pkg: PackageJSONConfig;\n skipDependencyUpdate?: string[];\n }\n): Promise<DependenciesModificationResults> {\n const updatingPackageJsonStep = logNewSection('Updating package.json');\n\n const results = modifyPackageJson(projectRoot, {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n });\n\n const hasChanges = results.changedDependencies.length || results.scriptsChanged;\n\n // NOTE: This is effectively bundler caching and subject to breakage if the inputs don't match the mutations.\n if (hasChanges) {\n await fs.promises.writeFile(\n path.resolve(projectRoot, 'package.json'),\n // Add new line to match the format of running yarn.\n // This prevents the `package.json` from changing when running `prebuild --no-install` multiple times.\n JSON.stringify(pkg, null, 2) + '\\n'\n );\n }\n\n updatingPackageJsonStep.succeed(\n 'Updated package.json' + (hasChanges ? '' : chalk.dim(` | no changes`))\n );\n\n return results;\n}\n\n/**\n * Make required modifications to the `package.json` file as a JSON object.\n *\n * 1. Update `package.json` `scripts`.\n * 2. Update `package.json` `dependencies` (not `devDependencies`).\n * 3. Update `package.json` `main`.\n *\n * @param projectRoot The root directory of the project.\n * @param templatePkg Template project package.json as JSON.\n * @param pkg Current package.json as JSON.\n * @param skipDependencyUpdate Array of dependencies to skip updating.\n * @returns\n */\nfunction modifyPackageJson(\n projectRoot: string,\n {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n }: {\n templatePkg: PackageJSONConfig;\n pkg: PackageJSONConfig;\n /** @deprecated Required packages are not overwritten, only added when missing */\n skipDependencyUpdate?: string[];\n }\n) {\n const scriptsChanged = updatePkgScripts({ pkg });\n\n // TODO: Move to `npx expo-doctor`\n return {\n scriptsChanged,\n ...updatePkgDependencies(projectRoot, {\n pkg,\n templatePkg,\n skipDependencyUpdate,\n }),\n };\n}\n\n/**\n * Update `package.json` dependencies by combining the `dependencies` in the\n * project we are creating with the dependencies in the template project.\n *\n * > Exposed for testing.\n */\nexport function updatePkgDependencies(\n projectRoot: string,\n {\n pkg,\n templatePkg,\n skipDependencyUpdate = [],\n }: {\n pkg: PackageJSONConfig;\n templatePkg: PackageJSONConfig;\n /** @deprecated Required packages are not overwritten, only added when missing */\n skipDependencyUpdate?: string[];\n }\n): DependenciesModificationResults {\n const { dependencies } = templatePkg;\n // The default values come from the bare-minimum template's package.json.\n // Users can change this by using different templates with the `--template` flag.\n // The main reason for allowing the changing of dependencies would be to include\n // dependencies that are required for the native project to build. For example,\n // it does not need to include dependencies that are used in the JS-code only.\n const defaultDependencies = createDependenciesMap(dependencies);\n\n // NOTE: This is a hack to ensure this doesn't trigger an extraneous change in the `package.json`\n // it isn't required for anything in the `ios` and `android` folders.\n delete defaultDependencies['expo-status-bar'];\n // NOTE: Expo splash screen is installed by default in the template but the config plugin also lives in prebuild-config\n // so we can delete it to prevent an extraneous change in the `package.json`.\n delete defaultDependencies['expo-splash-screen'];\n\n const combinedDependencies: DependenciesMap = createDependenciesMap({\n ...defaultDependencies,\n ...pkg.dependencies,\n });\n\n // These dependencies are only added, not overwritten from the project\n const requiredDependencies = [\n // TODO: This is no longer required because it's this same package.\n 'expo',\n // TODO: Drop this somehow.\n 'react-native',\n ].filter((depKey) => !!defaultDependencies[depKey]);\n\n const symlinkedPackages: [string, string][] = [];\n const nonRecommendedPackages: [string, string][] = [];\n\n for (const dependencyKey of requiredDependencies) {\n // If the local package.json defined the dependency that we want to overwrite...\n if (pkg.dependencies?.[dependencyKey]) {\n // Then ensure it isn't symlinked (i.e. the user has a custom version in their yarn workspace).\n if (isModuleSymlinked(projectRoot, { moduleId: dependencyKey, isSilent: true })) {\n // If the package is in the project's package.json and it's symlinked, then skip overwriting it.\n symlinkedPackages.push([\n `${dependencyKey}`,\n `${dependencyKey}@${defaultDependencies[dependencyKey]}`,\n ]);\n continue;\n }\n\n // Do not modify manually skipped dependencies\n if (skipDependencyUpdate.includes(dependencyKey)) {\n continue;\n }\n\n // Warn users for outdated dependencies when prebuilding\n const hasRecommendedVersion = versionRangesIntersect(\n pkg.dependencies[dependencyKey],\n String(defaultDependencies[dependencyKey])\n );\n if (!hasRecommendedVersion) {\n nonRecommendedPackages.push([\n `${dependencyKey}@${pkg.dependencies[dependencyKey]}`,\n `${dependencyKey}@${defaultDependencies[dependencyKey]}`,\n ]);\n }\n }\n }\n\n if (symlinkedPackages.length) {\n symlinkedPackages.forEach(([current, recommended]) => {\n Log.log(\n `\\u203A Using symlinked ${chalk.bold(current)} instead of recommended ${chalk.bold(recommended)}.`\n );\n });\n }\n\n if (nonRecommendedPackages.length) {\n nonRecommendedPackages.forEach(([current, recommended]) => {\n Log.warn(\n `\\u203A Using ${chalk.bold(current)} instead of recommended ${chalk.bold(recommended)}.`\n );\n });\n }\n\n // Only change the dependencies if the normalized hash changes, this helps to reduce meaningless changes.\n const hasNewDependencies =\n hashForDependencyMap(pkg.dependencies) !== hashForDependencyMap(combinedDependencies);\n // Save the dependencies\n let changedDependencies: string[] = [];\n if (hasNewDependencies) {\n changedDependencies = diffKeys(combinedDependencies, pkg.dependencies ?? {}).sort();\n // Use Object.assign to preserve the original order of dependencies, this makes it easier to see what changed in the git diff.\n pkg.dependencies = Object.assign(pkg.dependencies ?? {}, combinedDependencies);\n }\n\n return {\n changedDependencies,\n };\n}\n\nfunction diffKeys(a: Record<string, any>, b: Record<string, any>): string[] {\n return Object.keys(a).filter((key) => a[key] !== b[key]);\n}\n\n/**\n * Create an object of type DependenciesMap a dependencies object or throw if not valid.\n *\n * @param dependencies - ideally an object of type {[key]: string} - if not then this will error.\n */\nexport function createDependenciesMap(dependencies: any): DependenciesMap {\n if (typeof dependencies !== 'object') {\n throw new Error(`Dependency map is invalid, expected object but got ${typeof dependencies}`);\n } else if (!dependencies) {\n return {};\n }\n\n const outputMap: DependenciesMap = {};\n\n for (const key of Object.keys(dependencies)) {\n const value = dependencies[key];\n if (typeof value === 'string') {\n outputMap[key] = value;\n } else {\n throw new Error(\n `Dependency for key \\`${key}\\` should be a \\`string\\`, instead got: \\`{ ${key}: ${JSON.stringify(\n value\n )} }\\``\n );\n }\n }\n return outputMap;\n}\n\n/**\n * Updates the package.json scripts for prebuild if the scripts match\n * the default values used in project templates.\n */\nexport function updatePkgScripts({ pkg }: { pkg: PackageJSONConfig }) {\n let hasChanged = false;\n if (!pkg.scripts) {\n pkg.scripts = {};\n }\n if (\n !pkg.scripts.android ||\n pkg.scripts.android === 'expo start --android' ||\n pkg.scripts.android === 'react-native run-android'\n ) {\n pkg.scripts.android = 'expo run:android';\n hasChanged = true;\n }\n if (\n !pkg.scripts.ios ||\n pkg.scripts.ios === 'expo start --ios' ||\n pkg.scripts.ios === 'react-native run-ios'\n ) {\n pkg.scripts.ios = 'expo run:ios';\n hasChanged = true;\n }\n return hasChanged;\n}\n\nfunction normalizeDependencyMap(deps: DependenciesMap): string[] {\n return Object.keys(deps)\n .map((dependency) => `${dependency}@${deps[dependency]}`)\n .sort();\n}\n\nexport function hashForDependencyMap(deps: DependenciesMap = {}): string {\n const depsList = normalizeDependencyMap(deps);\n const depsString = depsList.join('\\n');\n return createFileHash(depsString);\n}\n\nexport function createFileHash(contents: string): string {\n // this doesn't need to be secure, the shorter the better.\n return crypto.createHash('sha1').update(contents).digest('hex');\n}\n\n/**\n * Determine if two semver ranges are overlapping or intersecting.\n * This is a safe version of `semver.intersects` that does not throw.\n */\nfunction versionRangesIntersect(rangeA: string | SemverRange, rangeB: string | SemverRange) {\n try {\n return semverIntersects(rangeA, rangeB);\n } catch {\n return false;\n }\n}\n"],"names":["createDependenciesMap","createFileHash","hashForDependencyMap","updatePackageJSONAsync","updatePkgDependencies","updatePkgScripts","projectRoot","templateDirectory","templatePkg","getPackageJson","pkg","skipDependencyUpdate","updatingPackageJsonStep","logNewSection","results","modifyPackageJson","hasChanges","changedDependencies","length","scriptsChanged","fs","promises","writeFile","path","resolve","JSON","stringify","succeed","chalk","dim","dependencies","defaultDependencies","combinedDependencies","requiredDependencies","filter","depKey","symlinkedPackages","nonRecommendedPackages","dependencyKey","isModuleSymlinked","moduleId","isSilent","push","includes","hasRecommendedVersion","versionRangesIntersect","String","forEach","current","recommended","Log","log","bold","warn","hasNewDependencies","diffKeys","sort","Object","assign","a","b","keys","key","Error","outputMap","value","hasChanged","scripts","android","ios","normalizeDependencyMap","deps","map","dependency","depsList","depsString","join","contents","crypto","createHash","update","digest","rangeA","rangeB","semverIntersects"],"mappings":";;;;;;;;;;;IA8NgBA,qBAAqB;eAArBA;;IAgEAC,cAAc;eAAdA;;IANAC,oBAAoB;eAApBA;;IArQMC,sBAAsB;eAAtBA;;IAsFNC,qBAAqB;eAArBA;;IAiJAC,gBAAgB;eAAhBA;;;;yBA1PkC;;;;;;;gEAChC;;;;;;;gEACC;;;;;;;gEACJ;;;;;;;gEACE;;;;;;;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I,MAAM,CAAC;AAC3D;AAEA;;;CAGC,GACD,SAASpC,uBAAuBqC,MAA4B,EAAEC,MAA4B;IACxF,IAAI;QACF,OAAOC,IAAAA,oBAAgB,EAACF,QAAQC;IAClC,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/prebuild/updatePackageJson.ts"],"sourcesContent":["import { getPackageJson, PackageJSONConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport crypto from 'crypto';\nimport fs from 'fs';\nimport path from 'path';\nimport { intersects as semverIntersects, Range as SemverRange } from 'semver';\n\nimport * as Log from '../log';\nimport { isModuleSymlinked } from '../utils/isModuleSymlinked';\nimport { logNewSection } from '../utils/ora';\n\nexport type DependenciesMap = { [key: string]: string | number };\n\nexport type DependenciesModificationResults = {\n /** A list of new values were added to the `dependencies` object in the `package.json`. */\n changedDependencies: string[];\n};\n\n/** Modifies the `package.json` with `modifyPackageJson` and format/displays the results. */\nexport async function updatePackageJSONAsync(\n projectRoot: string,\n {\n templateDirectory,\n templatePkg = getPackageJson(templateDirectory),\n pkg,\n skipDependencyUpdate,\n }: {\n templateDirectory: string;\n templatePkg?: PackageJSONConfig;\n pkg: PackageJSONConfig;\n skipDependencyUpdate?: string[];\n }\n): Promise<DependenciesModificationResults> {\n const updatingPackageJsonStep = logNewSection('Updating package.json');\n\n const results = modifyPackageJson(projectRoot, {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n });\n\n const hasChanges = results.changedDependencies.length || results.scriptsChanged;\n\n // NOTE: This is effectively bundler caching and subject to breakage if the inputs don't match the mutations.\n if (hasChanges) {\n await fs.promises.writeFile(\n path.resolve(projectRoot, 'package.json'),\n // Add new line to match the format of running yarn.\n // This prevents the `package.json` from changing when running `prebuild --no-install` multiple times.\n JSON.stringify(pkg, null, 2) + '\\n'\n );\n }\n\n updatingPackageJsonStep.succeed(\n 'Updated package.json' + (hasChanges ? '' : chalk.dim(` | no changes`))\n );\n\n return results;\n}\n\n/**\n * Make required modifications to the `package.json` file as a JSON object.\n *\n * 1. Update `package.json` `scripts`.\n * 2. Update `package.json` `dependencies` (not `devDependencies`).\n * 3. Update `package.json` `main`.\n *\n * @param projectRoot The root directory of the project.\n * @param templatePkg Template project package.json as JSON.\n * @param pkg Current package.json as JSON.\n * @param skipDependencyUpdate Array of dependencies to skip updating.\n * @returns\n */\nfunction modifyPackageJson(\n projectRoot: string,\n {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n }: {\n templatePkg: PackageJSONConfig;\n pkg: PackageJSONConfig;\n /** @deprecated Required packages are not overwritten, only added when missing */\n skipDependencyUpdate?: string[];\n }\n) {\n const scriptsChanged = updatePkgScripts({ pkg });\n\n // TODO: Move to `npx expo-doctor`\n return {\n scriptsChanged,\n ...updatePkgDependencies(projectRoot, {\n pkg,\n templatePkg,\n skipDependencyUpdate,\n }),\n };\n}\n\n/**\n * Update `package.json` dependencies by combining the `dependencies` in the\n * project we are creating with the dependencies in the template project.\n *\n * > Exposed for testing.\n */\nexport function updatePkgDependencies(\n projectRoot: string,\n {\n pkg,\n templatePkg,\n skipDependencyUpdate = [],\n }: {\n pkg: PackageJSONConfig;\n templatePkg: PackageJSONConfig;\n /** @deprecated Required packages are not overwritten, only added when missing */\n skipDependencyUpdate?: string[];\n }\n): DependenciesModificationResults {\n const { dependencies } = templatePkg;\n // The default values come from the bare-minimum template's package.json.\n // Users can change this by using different templates with the `--template` flag.\n // The main reason for allowing the changing of dependencies would be to include\n // dependencies that are required for the native project to build. For example,\n // it does not need to include dependencies that are used in the JS-code only.\n const defaultDependencies = createDependenciesMap(dependencies);\n\n // NOTE: This is a hack to ensure this doesn't trigger an extraneous change in the `package.json`\n // it isn't required for anything in the `ios` and `android` folders.\n delete defaultDependencies['expo-status-bar'];\n // NOTE: Expo splash screen is installed by default in the template but the config plugin also lives in prebuild-config\n // so we can delete it to prevent an extraneous change in the `package.json`.\n delete defaultDependencies['expo-splash-screen'];\n\n const combinedDependencies: DependenciesMap = createDependenciesMap({\n ...defaultDependencies,\n ...pkg.dependencies,\n });\n\n // These dependencies are only added, not overwritten from the project\n const requiredDependencies = [\n // TODO: This is no longer required because it's this same package.\n 'expo',\n // TODO: Drop this somehow.\n 'react-native',\n ].filter((depKey) => !!defaultDependencies[depKey]);\n\n const symlinkedPackages: [string, string][] = [];\n const nonRecommendedPackages: [string, string][] = [];\n\n for (const dependencyKey of requiredDependencies) {\n // If the local package.json defined the dependency that we want to overwrite...\n if (pkg.dependencies?.[dependencyKey]) {\n // Then ensure it isn't symlinked (i.e. the user has a custom version in their yarn workspace).\n if (isModuleSymlinked(projectRoot, { moduleId: dependencyKey, isSilent: true })) {\n // If the package is in the project's package.json and it's symlinked, then skip overwriting it.\n symlinkedPackages.push([\n `${dependencyKey}`,\n `${dependencyKey}@${defaultDependencies[dependencyKey]}`,\n ]);\n continue;\n }\n\n // Do not modify manually skipped dependencies\n if (skipDependencyUpdate.includes(dependencyKey)) {\n continue;\n }\n\n // Warn users for outdated dependencies when prebuilding\n const hasRecommendedVersion = versionRangesIntersect(\n pkg.dependencies[dependencyKey],\n String(defaultDependencies[dependencyKey]),\n true\n );\n if (!hasRecommendedVersion) {\n nonRecommendedPackages.push([\n `${dependencyKey}@${pkg.dependencies[dependencyKey]}`,\n `${dependencyKey}@${defaultDependencies[dependencyKey]}`,\n ]);\n }\n }\n }\n\n if (symlinkedPackages.length) {\n symlinkedPackages.forEach(([current, recommended]) => {\n Log.log(\n `\\u203A Using symlinked ${chalk.bold(current)} instead of recommended ${chalk.bold(recommended)}.`\n );\n });\n }\n\n if (nonRecommendedPackages.length) {\n nonRecommendedPackages.forEach(([current, recommended]) => {\n Log.warn(\n `\\u203A Using ${chalk.bold(current)} instead of recommended ${chalk.bold(recommended)}.`\n );\n });\n }\n\n // Only change the dependencies if the normalized hash changes, this helps to reduce meaningless changes.\n const hasNewDependencies =\n hashForDependencyMap(pkg.dependencies) !== hashForDependencyMap(combinedDependencies);\n // Save the dependencies\n let changedDependencies: string[] = [];\n if (hasNewDependencies) {\n changedDependencies = diffKeys(combinedDependencies, pkg.dependencies ?? {}).sort();\n // Use Object.assign to preserve the original order of dependencies, this makes it easier to see what changed in the git diff.\n pkg.dependencies = Object.assign(pkg.dependencies ?? {}, combinedDependencies);\n }\n\n return {\n changedDependencies,\n };\n}\n\nfunction diffKeys(a: Record<string, any>, b: Record<string, any>): string[] {\n return Object.keys(a).filter((key) => a[key] !== b[key]);\n}\n\n/**\n * Create an object of type DependenciesMap a dependencies object or throw if not valid.\n *\n * @param dependencies - ideally an object of type {[key]: string} - if not then this will error.\n */\nexport function createDependenciesMap(dependencies: any): DependenciesMap {\n if (typeof dependencies !== 'object') {\n throw new Error(`Dependency map is invalid, expected object but got ${typeof dependencies}`);\n } else if (!dependencies) {\n return {};\n }\n\n const outputMap: DependenciesMap = {};\n\n for (const key of Object.keys(dependencies)) {\n const value = dependencies[key];\n if (typeof value === 'string') {\n outputMap[key] = value;\n } else {\n throw new Error(\n `Dependency for key \\`${key}\\` should be a \\`string\\`, instead got: \\`{ ${key}: ${JSON.stringify(\n value\n )} }\\``\n );\n }\n }\n return outputMap;\n}\n\n/**\n * Updates the package.json scripts for prebuild if the scripts match\n * the default values used in project templates.\n */\nexport function updatePkgScripts({ pkg }: { pkg: PackageJSONConfig }) {\n let hasChanged = false;\n if (!pkg.scripts) {\n pkg.scripts = {};\n }\n if (\n !pkg.scripts.android ||\n pkg.scripts.android === 'expo start --android' ||\n pkg.scripts.android === 'react-native run-android'\n ) {\n pkg.scripts.android = 'expo run:android';\n hasChanged = true;\n }\n if (\n !pkg.scripts.ios ||\n pkg.scripts.ios === 'expo start --ios' ||\n pkg.scripts.ios === 'react-native run-ios'\n ) {\n pkg.scripts.ios = 'expo run:ios';\n hasChanged = true;\n }\n return hasChanged;\n}\n\nfunction normalizeDependencyMap(deps: DependenciesMap): string[] {\n return Object.keys(deps)\n .map((dependency) => `${dependency}@${deps[dependency]}`)\n .sort();\n}\n\nexport function hashForDependencyMap(deps: DependenciesMap = {}): string {\n const depsList = normalizeDependencyMap(deps);\n const depsString = depsList.join('\\n');\n return createFileHash(depsString);\n}\n\nexport function createFileHash(contents: string): string {\n // this doesn't need to be secure, the shorter the better.\n return crypto.createHash('sha1').update(contents).digest('hex');\n}\n\n/**\n * Determine if two semver ranges are overlapping or intersecting.\n * This is a safe version of `semver.intersects` that does not throw.\n */\nfunction versionRangesIntersect(\n rangeA: string | SemverRange,\n rangeB: string | SemverRange,\n includePrerelease: boolean = false\n) {\n try {\n return semverIntersects(rangeA, rangeB, { includePrerelease });\n } catch {\n return false;\n }\n}\n"],"names":["createDependenciesMap","createFileHash","hashForDependencyMap","updatePackageJSONAsync","updatePkgDependencies","updatePkgScripts","projectRoot","templateDirectory","templatePkg","getPackageJson","pkg","skipDependencyUpdate","updatingPackageJsonStep","logNewSection","results","modifyPackageJson","hasChanges","changedDependencies","length","scriptsChanged","fs","promises","writeFile","path","resolve","JSON","stringify","succeed","chalk","dim","dependencies","defaultDependencies","combinedDependencies","requiredDependencies","filter","depKey","symlinkedPackages","nonRecommendedPackages","dependencyKey","isModuleSymlinked","moduleId","isSilent","push","includes","hasRecommendedVersion","versionRangesIntersect","String","forEach","current","recommended","Log","log","bold","warn","hasNewDependencies","diffKeys","sort","Object","assign","a","b","keys","key","Error","outputMap","value","hasChanged","scripts","android","ios","normalizeDependencyMap","deps","map","dependency","depsList","depsString","join","contents","crypto","createHash","update","digest","rangeA","rangeB","includePrerelease","semverIntersects"],"mappings":";;;;;;;;;;;IA+NgBA,qBAAqB;eAArBA;;IAgEAC,cAAc;eAAdA;;IANAC,oBAAoB;eAApBA;;IAtQMC,sBAAsB;eAAtBA;;IAsFNC,qBAAqB;eAArBA;;IAkJAC,gBAAgB;eAAhBA;;;;yBA3PkC;;;;;;;gEAChC;;;;;;;gEACC;;;;;;;gEACJ;;;;;;;gEACE;;;;;;;yBACoD;;;;;;6DAEhD;mCACa;qBACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,MAA4B,EAC5BC,oBAA6B,KAAK;IAElC,IAAI;QACF,OAAOC,IAAAA,oBAAgB,EAACH,QAAQC,QAAQ;YAAEC;QAAkB;IAC9D,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
@@ -21,11 +21,11 @@ const _resolveLaunchProps = require("./resolveLaunchProps");
|
|
|
21
21
|
const _buildcacheproviders = require("../../utils/build-cache-providers");
|
|
22
22
|
const _resolveBundlerProps = require("../resolveBundlerProps");
|
|
23
23
|
async function resolveOptionsAsync(projectRoot, options) {
|
|
24
|
-
var
|
|
24
|
+
var _projectConfig_exp, _projectConfig_exp_experiments;
|
|
25
25
|
// Resolve the device before the gradle props because we need the device to be running to get the ABI.
|
|
26
26
|
const device = await (0, _resolveDevice.resolveDeviceAsync)(options.device);
|
|
27
27
|
const projectConfig = (0, _config().getConfig)(projectRoot);
|
|
28
|
-
const buildCacheProvider = await (0, _buildcacheproviders.resolveBuildCacheProvider)(((
|
|
28
|
+
const buildCacheProvider = await (0, _buildcacheproviders.resolveBuildCacheProvider)(((_projectConfig_exp = projectConfig.exp) == null ? void 0 : _projectConfig_exp.buildCacheProvider) ?? ((_projectConfig_exp_experiments = projectConfig.exp.experiments) == null ? void 0 : _projectConfig_exp_experiments.buildCacheProvider), projectRoot);
|
|
29
29
|
return {
|
|
30
30
|
...await (0, _resolveBundlerProps.resolveBundlerPropsAsync)(projectRoot, options),
|
|
31
31
|
...await (0, _resolveGradlePropsAsync.resolveGradlePropsAsync)(projectRoot, options, device.device),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/run/android/resolveOptions.ts"],"sourcesContent":["import { BuildCacheProvider, getConfig } from '@expo/config';\n\nimport { resolveDeviceAsync } from './resolveDevice';\nimport { GradleProps, resolveGradlePropsAsync } from './resolveGradlePropsAsync';\nimport { LaunchProps, resolveLaunchPropsAsync } from './resolveLaunchProps';\nimport { AndroidDeviceManager } from '../../start/platforms/android/AndroidDeviceManager';\nimport { resolveBuildCacheProvider } from '../../utils/build-cache-providers';\nimport { BundlerProps, resolveBundlerPropsAsync } from '../resolveBundlerProps';\n\nexport type Options = {\n variant?: string;\n device?: boolean | string;\n port?: number;\n bundler?: boolean;\n install?: boolean;\n buildCache?: boolean;\n allArch?: boolean;\n binary?: string;\n appId?: string;\n};\n\nexport type ResolvedOptions = GradleProps &\n BundlerProps &\n LaunchProps & {\n variant: string;\n buildCache: boolean;\n device: AndroidDeviceManager;\n install: boolean;\n architectures?: string;\n appId?: string;\n buildCacheProvider?: BuildCacheProvider;\n };\n\nexport async function resolveOptionsAsync(\n projectRoot: string,\n options: Options\n): Promise<ResolvedOptions> {\n // Resolve the device before the gradle props because we need the device to be running to get the ABI.\n const device = await resolveDeviceAsync(options.device);\n\n const projectConfig = getConfig(projectRoot);\n const buildCacheProvider = await resolveBuildCacheProvider(\n projectConfig.exp
|
|
1
|
+
{"version":3,"sources":["../../../../src/run/android/resolveOptions.ts"],"sourcesContent":["import { BuildCacheProvider, getConfig } from '@expo/config';\n\nimport { resolveDeviceAsync } from './resolveDevice';\nimport { GradleProps, resolveGradlePropsAsync } from './resolveGradlePropsAsync';\nimport { LaunchProps, resolveLaunchPropsAsync } from './resolveLaunchProps';\nimport { AndroidDeviceManager } from '../../start/platforms/android/AndroidDeviceManager';\nimport { resolveBuildCacheProvider } from '../../utils/build-cache-providers';\nimport { BundlerProps, resolveBundlerPropsAsync } from '../resolveBundlerProps';\n\nexport type Options = {\n variant?: string;\n device?: boolean | string;\n port?: number;\n bundler?: boolean;\n install?: boolean;\n buildCache?: boolean;\n allArch?: boolean;\n binary?: string;\n appId?: string;\n};\n\nexport type ResolvedOptions = GradleProps &\n BundlerProps &\n LaunchProps & {\n variant: string;\n buildCache: boolean;\n device: AndroidDeviceManager;\n install: boolean;\n architectures?: string;\n appId?: string;\n buildCacheProvider?: BuildCacheProvider;\n };\n\nexport async function resolveOptionsAsync(\n projectRoot: string,\n options: Options\n): Promise<ResolvedOptions> {\n // Resolve the device before the gradle props because we need the device to be running to get the ABI.\n const device = await resolveDeviceAsync(options.device);\n\n const projectConfig = getConfig(projectRoot);\n const buildCacheProvider = await resolveBuildCacheProvider(\n projectConfig.exp?.buildCacheProvider ?? projectConfig.exp.experiments?.buildCacheProvider,\n projectRoot\n );\n\n return {\n ...(await resolveBundlerPropsAsync(projectRoot, options)),\n ...(await resolveGradlePropsAsync(projectRoot, options, device.device)),\n ...(await resolveLaunchPropsAsync(projectRoot, options)),\n variant: options.variant ?? 'debug',\n // Resolve the device based on the provided device id or prompt\n // from a list of devices (connected or simulated) that are filtered by the scheme.\n device,\n buildCache: !!options.buildCache,\n install: !!options.install,\n buildCacheProvider,\n };\n}\n"],"names":["resolveOptionsAsync","projectRoot","options","projectConfig","device","resolveDeviceAsync","getConfig","buildCacheProvider","resolveBuildCacheProvider","exp","experiments","resolveBundlerPropsAsync","resolveGradlePropsAsync","resolveLaunchPropsAsync","variant","buildCache","install"],"mappings":";;;;+BAiCsBA;;;eAAAA;;;;yBAjCwB;;;;;;+BAEX;yCACkB;oCACA;qCAEX;qCACa;AA0BhD,eAAeA,oBACpBC,WAAmB,EACnBC,OAAgB;QAOdC,oBAAyCA;IAL3C,sGAAsG;IACtG,MAAMC,SAAS,MAAMC,IAAAA,iCAAkB,EAACH,QAAQE,MAAM;IAEtD,MAAMD,gBAAgBG,IAAAA,mBAAS,EAACL;IAChC,MAAMM,qBAAqB,MAAMC,IAAAA,8CAAyB,EACxDL,EAAAA,qBAAAA,cAAcM,GAAG,qBAAjBN,mBAAmBI,kBAAkB,OAAIJ,iCAAAA,cAAcM,GAAG,CAACC,WAAW,qBAA7BP,+BAA+BI,kBAAkB,GAC1FN;IAGF,OAAO;QACL,GAAI,MAAMU,IAAAA,6CAAwB,EAACV,aAAaC,QAAQ;QACxD,GAAI,MAAMU,IAAAA,gDAAuB,EAACX,aAAaC,SAASE,OAAOA,MAAM,CAAC;QACtE,GAAI,MAAMS,IAAAA,2CAAuB,EAACZ,aAAaC,QAAQ;QACvDY,SAASZ,QAAQY,OAAO,IAAI;QAC5B,+DAA+D;QAC/D,mFAAmF;QACnFV;QACAW,YAAY,CAAC,CAACb,QAAQa,UAAU;QAChCC,SAAS,CAAC,CAACd,QAAQc,OAAO;QAC1BT;IACF;AACF"}
|
|
@@ -23,7 +23,7 @@ const _buildcacheproviders = require("../../../utils/build-cache-providers");
|
|
|
23
23
|
const _profile = require("../../../utils/profile");
|
|
24
24
|
const _resolveBundlerProps = require("../../resolveBundlerProps");
|
|
25
25
|
async function resolveOptionsAsync(projectRoot, options) {
|
|
26
|
-
var
|
|
26
|
+
var _projectConfig_exp, _projectConfig_exp_experiments;
|
|
27
27
|
const xcodeProject = (0, _resolveXcodeProject.resolveXcodeProject)(projectRoot);
|
|
28
28
|
const bundlerProps = await (0, _resolveBundlerProps.resolveBundlerPropsAsync)(projectRoot, options);
|
|
29
29
|
// Resolve the scheme before the device so we can filter devices based on
|
|
@@ -42,7 +42,7 @@ async function resolveOptionsAsync(projectRoot, options) {
|
|
|
42
42
|
});
|
|
43
43
|
const isSimulator = (0, _resolveDevice.isSimulatorDevice)(device);
|
|
44
44
|
const projectConfig = (0, _config().getConfig)(projectRoot);
|
|
45
|
-
const buildCacheProvider = await (0, _buildcacheproviders.resolveBuildCacheProvider)(((
|
|
45
|
+
const buildCacheProvider = await (0, _buildcacheproviders.resolveBuildCacheProvider)(((_projectConfig_exp = projectConfig.exp) == null ? void 0 : _projectConfig_exp.buildCacheProvider) ?? ((_projectConfig_exp_experiments = projectConfig.exp.experiments) == null ? void 0 : _projectConfig_exp_experiments.buildCacheProvider), projectRoot);
|
|
46
46
|
// This optimization skips resetting the Metro cache needlessly.
|
|
47
47
|
// The cache is reset in `../node_modules/react-native/scripts/react-native-xcode.sh` when the
|
|
48
48
|
// project is running in Debug and built onto a physical device. It seems that this is done because
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/run/ios/options/resolveOptions.ts"],"sourcesContent":["import { getConfig } from '@expo/config';\n\nimport { isSimulatorDevice, resolveDeviceAsync } from './resolveDevice';\nimport { resolveNativeSchemePropsAsync } from './resolveNativeScheme';\nimport { resolveXcodeProject } from './resolveXcodeProject';\nimport { isOSType } from '../../../start/platforms/ios/simctl';\nimport { resolveBuildCacheProvider } from '../../../utils/build-cache-providers';\nimport { profile } from '../../../utils/profile';\nimport { resolveBundlerPropsAsync } from '../../resolveBundlerProps';\nimport { BuildProps, Options } from '../XcodeBuild.types';\n\n/** Resolve arguments for the `run:ios` command. */\nexport async function resolveOptionsAsync(\n projectRoot: string,\n options: Options\n): Promise<BuildProps> {\n const xcodeProject = resolveXcodeProject(projectRoot);\n\n const bundlerProps = await resolveBundlerPropsAsync(projectRoot, options);\n\n // Resolve the scheme before the device so we can filter devices based on\n // whichever scheme is selected (i.e. don't present TV devices if the scheme cannot be run on a TV).\n const { osType, name: scheme } = await resolveNativeSchemePropsAsync(\n projectRoot,\n options,\n xcodeProject\n );\n\n // Use the configuration or `Debug` if none is provided.\n const configuration = options.configuration || 'Debug';\n\n // Resolve the device based on the provided device id or prompt\n // from a list of devices (connected or simulated) that are filtered by the scheme.\n const device = await profile(resolveDeviceAsync)(options.device, {\n // It's unclear if there's any value to asserting that we haven't hardcoded the os type in the CLI.\n osType: isOSType(osType) ? osType : undefined,\n xcodeProject,\n scheme,\n configuration,\n });\n\n const isSimulator = isSimulatorDevice(device);\n\n const projectConfig = getConfig(projectRoot);\n const buildCacheProvider = await resolveBuildCacheProvider(\n projectConfig.exp
|
|
1
|
+
{"version":3,"sources":["../../../../../src/run/ios/options/resolveOptions.ts"],"sourcesContent":["import { getConfig } from '@expo/config';\n\nimport { isSimulatorDevice, resolveDeviceAsync } from './resolveDevice';\nimport { resolveNativeSchemePropsAsync } from './resolveNativeScheme';\nimport { resolveXcodeProject } from './resolveXcodeProject';\nimport { isOSType } from '../../../start/platforms/ios/simctl';\nimport { resolveBuildCacheProvider } from '../../../utils/build-cache-providers';\nimport { profile } from '../../../utils/profile';\nimport { resolveBundlerPropsAsync } from '../../resolveBundlerProps';\nimport { BuildProps, Options } from '../XcodeBuild.types';\n\n/** Resolve arguments for the `run:ios` command. */\nexport async function resolveOptionsAsync(\n projectRoot: string,\n options: Options\n): Promise<BuildProps> {\n const xcodeProject = resolveXcodeProject(projectRoot);\n\n const bundlerProps = await resolveBundlerPropsAsync(projectRoot, options);\n\n // Resolve the scheme before the device so we can filter devices based on\n // whichever scheme is selected (i.e. don't present TV devices if the scheme cannot be run on a TV).\n const { osType, name: scheme } = await resolveNativeSchemePropsAsync(\n projectRoot,\n options,\n xcodeProject\n );\n\n // Use the configuration or `Debug` if none is provided.\n const configuration = options.configuration || 'Debug';\n\n // Resolve the device based on the provided device id or prompt\n // from a list of devices (connected or simulated) that are filtered by the scheme.\n const device = await profile(resolveDeviceAsync)(options.device, {\n // It's unclear if there's any value to asserting that we haven't hardcoded the os type in the CLI.\n osType: isOSType(osType) ? osType : undefined,\n xcodeProject,\n scheme,\n configuration,\n });\n\n const isSimulator = isSimulatorDevice(device);\n\n const projectConfig = getConfig(projectRoot);\n const buildCacheProvider = await resolveBuildCacheProvider(\n projectConfig.exp?.buildCacheProvider ?? projectConfig.exp.experiments?.buildCacheProvider,\n projectRoot\n );\n\n // This optimization skips resetting the Metro cache needlessly.\n // The cache is reset in `../node_modules/react-native/scripts/react-native-xcode.sh` when the\n // project is running in Debug and built onto a physical device. It seems that this is done because\n // the script is run from Xcode and unaware of the CLI instance.\n const shouldSkipInitialBundling = configuration === 'Debug' && !isSimulator;\n\n return {\n ...bundlerProps,\n shouldStartBundler: options.configuration === 'Debug' || bundlerProps.shouldStartBundler,\n projectRoot,\n isSimulator,\n xcodeProject,\n device,\n configuration,\n shouldSkipInitialBundling,\n buildCache: options.buildCache !== false,\n scheme,\n buildCacheProvider,\n };\n}\n"],"names":["resolveOptionsAsync","projectRoot","options","projectConfig","xcodeProject","resolveXcodeProject","bundlerProps","resolveBundlerPropsAsync","osType","name","scheme","resolveNativeSchemePropsAsync","configuration","device","profile","resolveDeviceAsync","isOSType","undefined","isSimulator","isSimulatorDevice","getConfig","buildCacheProvider","resolveBuildCacheProvider","exp","experiments","shouldSkipInitialBundling","shouldStartBundler","buildCache"],"mappings":";;;;+BAYsBA;;;eAAAA;;;;yBAZI;;;;;;+BAE4B;qCACR;qCACV;wBACX;qCACiB;yBAClB;qCACiB;AAIlC,eAAeA,oBACpBC,WAAmB,EACnBC,OAAgB;QA+BdC,oBAAyCA;IA7B3C,MAAMC,eAAeC,IAAAA,wCAAmB,EAACJ;IAEzC,MAAMK,eAAe,MAAMC,IAAAA,6CAAwB,EAACN,aAAaC;IAEjE,yEAAyE;IACzE,oGAAoG;IACpG,MAAM,EAAEM,MAAM,EAAEC,MAAMC,MAAM,EAAE,GAAG,MAAMC,IAAAA,kDAA6B,EAClEV,aACAC,SACAE;IAGF,wDAAwD;IACxD,MAAMQ,gBAAgBV,QAAQU,aAAa,IAAI;IAE/C,+DAA+D;IAC/D,mFAAmF;IACnF,MAAMC,SAAS,MAAMC,IAAAA,gBAAO,EAACC,iCAAkB,EAAEb,QAAQW,MAAM,EAAE;QAC/D,mGAAmG;QACnGL,QAAQQ,IAAAA,gBAAQ,EAACR,UAAUA,SAASS;QACpCb;QACAM;QACAE;IACF;IAEA,MAAMM,cAAcC,IAAAA,gCAAiB,EAACN;IAEtC,MAAMV,gBAAgBiB,IAAAA,mBAAS,EAACnB;IAChC,MAAMoB,qBAAqB,MAAMC,IAAAA,8CAAyB,EACxDnB,EAAAA,qBAAAA,cAAcoB,GAAG,qBAAjBpB,mBAAmBkB,kBAAkB,OAAIlB,iCAAAA,cAAcoB,GAAG,CAACC,WAAW,qBAA7BrB,+BAA+BkB,kBAAkB,GAC1FpB;IAGF,gEAAgE;IAChE,8FAA8F;IAC9F,mGAAmG;IACnG,gEAAgE;IAChE,MAAMwB,4BAA4Bb,kBAAkB,WAAW,CAACM;IAEhE,OAAO;QACL,GAAGZ,YAAY;QACfoB,oBAAoBxB,QAAQU,aAAa,KAAK,WAAWN,aAAaoB,kBAAkB;QACxFzB;QACAiB;QACAd;QACAS;QACAD;QACAa;QACAE,YAAYzB,QAAQyB,UAAU,KAAK;QACnCjB;QACAW;IACF;AACF"}
|
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
MetroTerminalReporter: function() {
|
|
13
13
|
return MetroTerminalReporter;
|
|
14
14
|
},
|
|
15
|
+
extractCodeFrame: function() {
|
|
16
|
+
return extractCodeFrame;
|
|
17
|
+
},
|
|
15
18
|
formatUsingNodeStandardLibraryError: function() {
|
|
16
19
|
return formatUsingNodeStandardLibraryError;
|
|
17
20
|
},
|
|
@@ -36,6 +39,13 @@ function _path() {
|
|
|
36
39
|
};
|
|
37
40
|
return data;
|
|
38
41
|
}
|
|
42
|
+
function _util() {
|
|
43
|
+
const data = require("util");
|
|
44
|
+
_util = function() {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
39
49
|
const _TerminalReporter = require("./TerminalReporter");
|
|
40
50
|
const _externals = require("./externals");
|
|
41
51
|
const _env = require("../../../utils/env");
|
|
@@ -259,21 +269,32 @@ function isNodeStdLibraryModule(moduleName) {
|
|
|
259
269
|
return /^node:/.test(moduleName) || _externals.NODE_STDLIB_MODULES.includes(moduleName);
|
|
260
270
|
}
|
|
261
271
|
/** If the code frame can be found then append it to the existing message. */ function maybeAppendCodeFrame(message, rawMessage) {
|
|
262
|
-
const codeFrame = stripMetroInfo(rawMessage);
|
|
272
|
+
const codeFrame = extractCodeFrame(stripMetroInfo(rawMessage));
|
|
263
273
|
if (codeFrame) {
|
|
264
274
|
message += '\n' + codeFrame;
|
|
265
275
|
}
|
|
266
276
|
return message;
|
|
267
277
|
}
|
|
278
|
+
function extractCodeFrame(errorMessage) {
|
|
279
|
+
const codeFrameLine = /^(?:\s*(?:>?\s*\d+\s*\||\s*\|).*\n?)+/;
|
|
280
|
+
let wasPreviousLineCodeFrame = null;
|
|
281
|
+
return errorMessage.split('\n').filter((line)=>{
|
|
282
|
+
if (wasPreviousLineCodeFrame === false) return false;
|
|
283
|
+
const keep = codeFrameLine.test((0, _util().stripVTControlCharacters)(line));
|
|
284
|
+
if (keep && wasPreviousLineCodeFrame === null) wasPreviousLineCodeFrame = true;
|
|
285
|
+
else if (!keep && wasPreviousLineCodeFrame) wasPreviousLineCodeFrame = false;
|
|
286
|
+
return keep;
|
|
287
|
+
}).join('\n');
|
|
288
|
+
}
|
|
268
289
|
function stripMetroInfo(errorMessage) {
|
|
269
290
|
// Newer versions of Metro don't include the list.
|
|
270
291
|
if (!errorMessage.includes('4. Remove the cache')) {
|
|
271
|
-
return
|
|
292
|
+
return errorMessage;
|
|
272
293
|
}
|
|
273
294
|
const lines = errorMessage.split('\n');
|
|
274
295
|
const index = lines.findIndex((line)=>line.includes('4. Remove the cache'));
|
|
275
296
|
if (index === -1) {
|
|
276
|
-
return
|
|
297
|
+
return errorMessage;
|
|
277
298
|
}
|
|
278
299
|
return lines.slice(index + 1).join('\n');
|
|
279
300
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/MetroTerminalReporter.ts"],"sourcesContent":["import type { Terminal } from '@expo/metro/metro-core';\nimport chalk from 'chalk';\nimport path from 'path';\n\nimport { logWarning, TerminalReporter } from './TerminalReporter';\nimport {\n BuildPhase,\n BundleDetails,\n BundleProgress,\n SnippetError,\n TerminalReportableEvent,\n} from './TerminalReporter.types';\nimport { NODE_STDLIB_MODULES } from './externals';\nimport { env } from '../../../utils/env';\nimport { learnMore } from '../../../utils/link';\nimport {\n logLikeMetro,\n maybeSymbolicateAndFormatJSErrorStackLogAsync,\n parseErrorStringToObject,\n} from '../serverLogLikeMetro';\nimport { attachImportStackToRootMessage, nearestImportStack } from './metroErrorInterface';\n\nconst debug = require('debug')('expo:metro:logger') as typeof console.log;\n\nconst MAX_PROGRESS_BAR_CHAR_WIDTH = 16;\nconst DARK_BLOCK_CHAR = '\\u2593';\nconst LIGHT_BLOCK_CHAR = '\\u2591';\n/**\n * Extends the default Metro logger and adds some additional features.\n * Also removes the giant Metro logo from the output.\n */\nexport class MetroTerminalReporter extends TerminalReporter {\n constructor(\n public projectRoot: string,\n terminal: Terminal\n ) {\n super(terminal);\n }\n\n _log(event: TerminalReportableEvent): void {\n switch (event.type) {\n case 'unstable_server_log':\n if (typeof event.data?.[0] === 'string') {\n const message = event.data[0];\n if (message.match(/JavaScript logs have moved/)) {\n // Hide this very loud message from upstream React Native in favor of the note in the terminal UI:\n // The \"› Press j │ open debugger\"\n\n // logger?.info(\n // '\\u001B[1m\\u001B[7m💡 JavaScript logs have moved!\\u001B[22m They can now be ' +\n // 'viewed in React Native DevTools. Tip: Type \\u001B[1mj\\u001B[22m in ' +\n // 'the terminal to open (requires Google Chrome or Microsoft Edge).' +\n // '\\u001B[27m',\n // );\n return;\n }\n\n if (!env.EXPO_DEBUG) {\n // In the context of developing an iOS app or website, the MetroInspectorProxy \"connection\" logs are very confusing.\n // Here we'll hide them behind EXPO_DEBUG or DEBUG=expo:*. In the future we can reformat them to clearly indicate that the \"Connection\" is regarding the debugger.\n // These logs are also confusing because they can say \"connection established\" even when the debugger is not in a usable state. Really they belong in a UI or behind some sort of debug logging.\n if (message.match(/Connection (closed|established|failed|terminated)/i)) {\n // Skip logging.\n return;\n }\n }\n }\n break;\n case 'client_log': {\n if (this.shouldFilterClientLog(event)) {\n return;\n }\n const { level } = event;\n\n if (!level) {\n break;\n }\n\n const mode = event.mode === 'NOBRIDGE' || event.mode === 'BRIDGE' ? '' : (event.mode ?? '');\n // @ts-expect-error\n if (level === 'warn' || level === 'error') {\n let hasStack = false;\n const parsed = event.data.map((msg) => {\n // Quick check to see if an unsymbolicated stack is being logged.\n if (msg.includes('.bundle//&platform=')) {\n const stack = parseErrorStringToObject(msg);\n if (stack) {\n hasStack = true;\n }\n return stack;\n }\n return msg;\n });\n\n if (hasStack) {\n (async () => {\n const symbolicating = parsed.map((p) => {\n if (typeof p === 'string') return p;\n return maybeSymbolicateAndFormatJSErrorStackLogAsync(this.projectRoot, level, p);\n });\n\n let usefulStackCount = 0;\n const fallbackIndices: number[] = [];\n const symbolicated = (await Promise.allSettled(symbolicating)).map((s, index) => {\n if (s.status === 'rejected') {\n debug('Error formatting stack', parsed[index], s.reason);\n return parsed[index];\n } else if (typeof s.value === 'string') {\n return s.value;\n } else {\n if (!s.value.isFallback) {\n usefulStackCount++;\n } else {\n fallbackIndices.push(index);\n }\n return s.value.stack;\n }\n });\n\n // Using EXPO_DEBUG we can print all stack\n const filtered =\n usefulStackCount && !env.EXPO_DEBUG\n ? symbolicated.filter((_, index) => !fallbackIndices.includes(index))\n : symbolicated;\n\n logLikeMetro(this.terminal.log.bind(this.terminal), level, mode, ...filtered);\n })();\n return;\n }\n }\n\n // Overwrite the Metro terminal logging so we can improve the warnings, symbolicate stacks, and inject extra info.\n logLikeMetro(this.terminal.log.bind(this.terminal), level, mode, ...event.data);\n return;\n }\n }\n return super._log(event);\n }\n\n // Used for testing\n _getElapsedTime(startTime: bigint): bigint {\n return process.hrtime.bigint() - startTime;\n }\n /**\n * Extends the bundle progress to include the current platform that we're bundling.\n *\n * @returns `iOS path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)`\n */\n _getBundleStatusMessage(progress: BundleProgress, phase: BuildPhase): string {\n const env = getEnvironmentForBuildDetails(progress.bundleDetails);\n const platform = env || getPlatformTagForBuildDetails(progress.bundleDetails);\n const inProgress = phase === 'in_progress';\n\n let localPath: string;\n\n if (\n typeof progress.bundleDetails?.customTransformOptions?.dom === 'string' &&\n progress.bundleDetails.customTransformOptions.dom.includes(path.sep)\n ) {\n // Because we use a generated entry file for DOM components, we need to adjust the logging path so it\n // shows a unique path for each component.\n // Here, we take the relative import path and remove all the starting slashes.\n localPath = progress.bundleDetails.customTransformOptions.dom.replace(/^(\\.?\\.[\\\\/])+/, '');\n } else {\n const inputFile = progress.bundleDetails.entryFile;\n\n localPath = path.isAbsolute(inputFile)\n ? path.relative(this.projectRoot, inputFile)\n : inputFile;\n }\n\n if (!inProgress) {\n const status = phase === 'done' ? `Bundled ` : `Bundling failed `;\n const color = phase === 'done' ? chalk.green : chalk.red;\n\n const startTime = this._bundleTimers.get(progress.bundleDetails.buildID!);\n\n let time: string = '';\n\n if (startTime != null) {\n const elapsed: bigint = this._getElapsedTime(startTime);\n const micro = Number(elapsed) / 1000;\n const converted = Number(elapsed) / 1e6;\n // If the milliseconds are < 0.5 then it will display as 0, so we display in microseconds.\n if (converted <= 0.5) {\n const tenthFractionOfMicro = ((micro * 10) / 1000).toFixed(0);\n // Format as microseconds to nearest tenth\n time = chalk.cyan.bold(`0.${tenthFractionOfMicro}ms`);\n } else {\n time = chalk.dim(converted.toFixed(0) + 'ms');\n }\n }\n\n // iOS Bundled 150ms\n const plural = progress.totalFileCount === 1 ? '' : 's';\n return (\n color(platform + status) +\n time +\n chalk.reset.dim(` ${localPath} (${progress.totalFileCount} module${plural})`)\n );\n }\n\n const filledBar = Math.floor(progress.ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);\n\n const _progress = inProgress\n ? chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +\n chalk.bgWhite.white(LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar)) +\n chalk.bold(` ${(100 * progress.ratio).toFixed(1).padStart(4)}% `) +\n chalk.dim(\n `(${progress.transformedFileCount\n .toString()\n .padStart(progress.totalFileCount.toString().length)}/${progress.totalFileCount})`\n )\n : '';\n\n return (\n platform +\n chalk.reset.dim(`${path.dirname(localPath)}${path.sep}`) +\n chalk.bold(path.basename(localPath)) +\n ' ' +\n _progress\n );\n }\n\n _logInitializing(port: number, hasReducedPerformance: boolean): void {\n // Don't print a giant logo...\n this.terminal.log(chalk.dim('Starting Metro Bundler'));\n }\n\n shouldFilterClientLog(event: { type: 'client_log'; data: unknown[] }): boolean {\n return isAppRegistryStartupMessage(event.data);\n }\n\n shouldFilterBundleEvent(event: TerminalReportableEvent): boolean {\n return 'bundleDetails' in event && event.bundleDetails?.bundleType === 'map';\n }\n\n /** Print the cache clear message. */\n transformCacheReset(): void {\n logWarning(\n this.terminal,\n chalk`Bundler cache is empty, rebuilding {dim (this may take a minute)}`\n );\n }\n\n /** One of the first logs that will be printed */\n dependencyGraphLoading(hasReducedPerformance: boolean): void {\n // this.terminal.log('Dependency graph is loading...');\n if (hasReducedPerformance) {\n // Extends https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/lib/TerminalReporter.js#L283-L290\n this.terminal.log(\n chalk.red(\n [\n 'Metro is operating with reduced performance.',\n 'Fix the problem above and restart Metro.',\n ].join('\\n')\n )\n );\n }\n }\n\n _logBundlingError(error: SnippetError): void {\n const moduleResolutionError = formatUsingNodeStandardLibraryError(this.projectRoot, error);\n if (moduleResolutionError) {\n let message = maybeAppendCodeFrame(moduleResolutionError, error.message);\n message += '\\n\\n' + nearestImportStack(error);\n return this.terminal.log(message);\n }\n\n attachImportStackToRootMessage(error);\n return super._logBundlingError(error);\n }\n}\n\n/**\n * Formats an error where the user is attempting to import a module from the Node.js standard library.\n * Exposed for testing.\n *\n * @param error\n * @returns error message or null if not a module resolution error\n */\nexport function formatUsingNodeStandardLibraryError(\n projectRoot: string,\n error: SnippetError\n): string | null {\n if (!error.message) {\n return null;\n }\n const { targetModuleName, originModulePath } = error;\n if (!targetModuleName || !originModulePath) {\n return null;\n }\n const relativePath = path.relative(projectRoot, originModulePath);\n\n const DOCS_PAGE_URL =\n 'https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries';\n\n if (isNodeStdLibraryModule(targetModuleName)) {\n if (originModulePath.includes('node_modules')) {\n return [\n `The package at \"${chalk.bold(\n relativePath\n )}\" attempted to import the Node standard library module \"${chalk.bold(\n targetModuleName\n )}\".`,\n `It failed because the native React runtime does not include the Node standard library.`,\n learnMore(DOCS_PAGE_URL),\n ].join('\\n');\n } else {\n return [\n `You attempted to import the Node standard library module \"${chalk.bold(\n targetModuleName\n )}\" from \"${chalk.bold(relativePath)}\".`,\n `It failed because the native React runtime does not include the Node standard library.`,\n learnMore(DOCS_PAGE_URL),\n ].join('\\n');\n }\n }\n return `Unable to resolve \"${targetModuleName}\" from \"${relativePath}\"`;\n}\n\nexport function isNodeStdLibraryModule(moduleName: string): boolean {\n return /^node:/.test(moduleName) || NODE_STDLIB_MODULES.includes(moduleName);\n}\n\n/** If the code frame can be found then append it to the existing message. */\nfunction maybeAppendCodeFrame(message: string, rawMessage: string): string {\n const codeFrame = stripMetroInfo(rawMessage);\n if (codeFrame) {\n message += '\\n' + codeFrame;\n }\n return message;\n}\n\n/**\n * Remove the Metro cache clearing steps if they exist.\n * In future versions we won't need this.\n * Returns the remaining code frame logs.\n */\nexport function stripMetroInfo(errorMessage: string): string | null {\n // Newer versions of Metro don't include the list.\n if (!errorMessage.includes('4. Remove the cache')) {\n return null;\n }\n const lines = errorMessage.split('\\n');\n const index = lines.findIndex((line) => line.includes('4. Remove the cache'));\n if (index === -1) {\n return null;\n }\n return lines.slice(index + 1).join('\\n');\n}\n\n/** @returns if the message matches the initial startup log */\nfunction isAppRegistryStartupMessage(body: any[]): boolean {\n return (\n body.length === 1 &&\n (/^Running application \"main\" with appParams:/.test(body[0]) ||\n /^Running \"main\" with \\{/.test(body[0]))\n );\n}\n\n/** @returns platform specific tag for a `BundleDetails` object */\nfunction getPlatformTagForBuildDetails(bundleDetails?: BundleDetails | null): string {\n const platform = bundleDetails?.platform ?? null;\n if (platform) {\n const formatted = { ios: 'iOS', android: 'Android', web: 'Web' }[platform] || platform;\n return `${chalk.bold(formatted)} `;\n }\n\n return '';\n}\n/** @returns platform specific tag for a `BundleDetails` object */\nfunction getEnvironmentForBuildDetails(bundleDetails?: BundleDetails | null): string {\n // Expo CLI will pass `customTransformOptions.environment = 'node'` when bundling for the server.\n const env = bundleDetails?.customTransformOptions?.environment ?? null;\n if (env === 'node') {\n return chalk.bold('λ') + ' ';\n } else if (env === 'react-server') {\n return chalk.bold(`RSC(${getPlatformTagForBuildDetails(bundleDetails).trim()})`) + ' ';\n }\n\n if (\n bundleDetails?.customTransformOptions?.dom &&\n typeof bundleDetails?.customTransformOptions?.dom === 'string'\n ) {\n return chalk.bold(`DOM`) + ' ';\n }\n\n return '';\n}\n"],"names":["MetroTerminalReporter","formatUsingNodeStandardLibraryError","isNodeStdLibraryModule","stripMetroInfo","debug","require","MAX_PROGRESS_BAR_CHAR_WIDTH","DARK_BLOCK_CHAR","LIGHT_BLOCK_CHAR","TerminalReporter","constructor","projectRoot","terminal","_log","event","type","data","message","match","env","EXPO_DEBUG","shouldFilterClientLog","level","mode","hasStack","parsed","map","msg","includes","stack","parseErrorStringToObject","symbolicating","p","maybeSymbolicateAndFormatJSErrorStackLogAsync","usefulStackCount","fallbackIndices","symbolicated","Promise","allSettled","s","index","status","reason","value","isFallback","push","filtered","filter","_","logLikeMetro","log","bind","_getElapsedTime","startTime","process","hrtime","bigint","_getBundleStatusMessage","progress","phase","getEnvironmentForBuildDetails","bundleDetails","platform","getPlatformTagForBuildDetails","inProgress","localPath","customTransformOptions","dom","path","sep","replace","inputFile","entryFile","isAbsolute","relative","color","chalk","green","red","_bundleTimers","get","buildID","time","elapsed","micro","Number","converted","tenthFractionOfMicro","toFixed","cyan","bold","dim","plural","totalFileCount","reset","filledBar","Math","floor","ratio","_progress","bgGreen","repeat","bgWhite","white","padStart","transformedFileCount","toString","length","dirname","basename","_logInitializing","port","hasReducedPerformance","isAppRegistryStartupMessage","shouldFilterBundleEvent","bundleType","transformCacheReset","logWarning","dependencyGraphLoading","join","_logBundlingError","error","moduleResolutionError","maybeAppendCodeFrame","nearestImportStack","attachImportStackToRootMessage","targetModuleName","originModulePath","relativePath","DOCS_PAGE_URL","learnMore","moduleName","test","NODE_STDLIB_MODULES","rawMessage","codeFrame","errorMessage","lines","split","findIndex","line","slice","body","formatted","ios","android","web","environment","trim"],"mapp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AAuCsF,WAAW,KAAI;IAClE,IAAIhI,QAAQ,QAAQ;QAClB,OAAOyD,gBAAK,CAACc,IAAI,CAAC,OAAO;IAC3B,OAAO,IAAIvE,QAAQ,gBAAgB;QACjC,OAAOyD,gBAAK,CAACc,IAAI,CAAC,CAAC,IAAI,EAAE3B,8BAA8BF,eAAeuF,IAAI,GAAG,CAAC,CAAC,IAAI;IACrF;IAEA,IACEvF,CAAAA,kCAAAA,yCAAAA,cAAeK,sBAAsB,qBAArCL,uCAAuCM,GAAG,KAC1C,QAAON,kCAAAA,yCAAAA,cAAeK,sBAAsB,qBAArCL,uCAAuCM,GAAG,MAAK,UACtD;QACA,OAAOS,gBAAK,CAACc,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI;IAC7B;IAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/MetroTerminalReporter.ts"],"sourcesContent":["import type { Terminal } from '@expo/metro/metro-core';\nimport chalk from 'chalk';\nimport path from 'path';\nimport { stripVTControlCharacters } from 'util';\n\nimport { logWarning, TerminalReporter } from './TerminalReporter';\nimport {\n BuildPhase,\n BundleDetails,\n BundleProgress,\n SnippetError,\n TerminalReportableEvent,\n} from './TerminalReporter.types';\nimport { NODE_STDLIB_MODULES } from './externals';\nimport { env } from '../../../utils/env';\nimport { learnMore } from '../../../utils/link';\nimport {\n logLikeMetro,\n maybeSymbolicateAndFormatJSErrorStackLogAsync,\n parseErrorStringToObject,\n} from '../serverLogLikeMetro';\nimport { attachImportStackToRootMessage, nearestImportStack } from './metroErrorInterface';\n\nconst debug = require('debug')('expo:metro:logger') as typeof console.log;\n\nconst MAX_PROGRESS_BAR_CHAR_WIDTH = 16;\nconst DARK_BLOCK_CHAR = '\\u2593';\nconst LIGHT_BLOCK_CHAR = '\\u2591';\n/**\n * Extends the default Metro logger and adds some additional features.\n * Also removes the giant Metro logo from the output.\n */\nexport class MetroTerminalReporter extends TerminalReporter {\n constructor(\n public projectRoot: string,\n terminal: Terminal\n ) {\n super(terminal);\n }\n\n _log(event: TerminalReportableEvent): void {\n switch (event.type) {\n case 'unstable_server_log':\n if (typeof event.data?.[0] === 'string') {\n const message = event.data[0];\n if (message.match(/JavaScript logs have moved/)) {\n // Hide this very loud message from upstream React Native in favor of the note in the terminal UI:\n // The \"› Press j │ open debugger\"\n\n // logger?.info(\n // '\\u001B[1m\\u001B[7m💡 JavaScript logs have moved!\\u001B[22m They can now be ' +\n // 'viewed in React Native DevTools. Tip: Type \\u001B[1mj\\u001B[22m in ' +\n // 'the terminal to open (requires Google Chrome or Microsoft Edge).' +\n // '\\u001B[27m',\n // );\n return;\n }\n\n if (!env.EXPO_DEBUG) {\n // In the context of developing an iOS app or website, the MetroInspectorProxy \"connection\" logs are very confusing.\n // Here we'll hide them behind EXPO_DEBUG or DEBUG=expo:*. In the future we can reformat them to clearly indicate that the \"Connection\" is regarding the debugger.\n // These logs are also confusing because they can say \"connection established\" even when the debugger is not in a usable state. Really they belong in a UI or behind some sort of debug logging.\n if (message.match(/Connection (closed|established|failed|terminated)/i)) {\n // Skip logging.\n return;\n }\n }\n }\n break;\n case 'client_log': {\n if (this.shouldFilterClientLog(event)) {\n return;\n }\n const { level } = event;\n\n if (!level) {\n break;\n }\n\n const mode = event.mode === 'NOBRIDGE' || event.mode === 'BRIDGE' ? '' : (event.mode ?? '');\n // @ts-expect-error\n if (level === 'warn' || level === 'error') {\n let hasStack = false;\n const parsed = event.data.map((msg) => {\n // Quick check to see if an unsymbolicated stack is being logged.\n if (msg.includes('.bundle//&platform=')) {\n const stack = parseErrorStringToObject(msg);\n if (stack) {\n hasStack = true;\n }\n return stack;\n }\n return msg;\n });\n\n if (hasStack) {\n (async () => {\n const symbolicating = parsed.map((p) => {\n if (typeof p === 'string') return p;\n return maybeSymbolicateAndFormatJSErrorStackLogAsync(this.projectRoot, level, p);\n });\n\n let usefulStackCount = 0;\n const fallbackIndices: number[] = [];\n const symbolicated = (await Promise.allSettled(symbolicating)).map((s, index) => {\n if (s.status === 'rejected') {\n debug('Error formatting stack', parsed[index], s.reason);\n return parsed[index];\n } else if (typeof s.value === 'string') {\n return s.value;\n } else {\n if (!s.value.isFallback) {\n usefulStackCount++;\n } else {\n fallbackIndices.push(index);\n }\n return s.value.stack;\n }\n });\n\n // Using EXPO_DEBUG we can print all stack\n const filtered =\n usefulStackCount && !env.EXPO_DEBUG\n ? symbolicated.filter((_, index) => !fallbackIndices.includes(index))\n : symbolicated;\n\n logLikeMetro(this.terminal.log.bind(this.terminal), level, mode, ...filtered);\n })();\n return;\n }\n }\n\n // Overwrite the Metro terminal logging so we can improve the warnings, symbolicate stacks, and inject extra info.\n logLikeMetro(this.terminal.log.bind(this.terminal), level, mode, ...event.data);\n return;\n }\n }\n return super._log(event);\n }\n\n // Used for testing\n _getElapsedTime(startTime: bigint): bigint {\n return process.hrtime.bigint() - startTime;\n }\n /**\n * Extends the bundle progress to include the current platform that we're bundling.\n *\n * @returns `iOS path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)`\n */\n _getBundleStatusMessage(progress: BundleProgress, phase: BuildPhase): string {\n const env = getEnvironmentForBuildDetails(progress.bundleDetails);\n const platform = env || getPlatformTagForBuildDetails(progress.bundleDetails);\n const inProgress = phase === 'in_progress';\n\n let localPath: string;\n\n if (\n typeof progress.bundleDetails?.customTransformOptions?.dom === 'string' &&\n progress.bundleDetails.customTransformOptions.dom.includes(path.sep)\n ) {\n // Because we use a generated entry file for DOM components, we need to adjust the logging path so it\n // shows a unique path for each component.\n // Here, we take the relative import path and remove all the starting slashes.\n localPath = progress.bundleDetails.customTransformOptions.dom.replace(/^(\\.?\\.[\\\\/])+/, '');\n } else {\n const inputFile = progress.bundleDetails.entryFile;\n\n localPath = path.isAbsolute(inputFile)\n ? path.relative(this.projectRoot, inputFile)\n : inputFile;\n }\n\n if (!inProgress) {\n const status = phase === 'done' ? `Bundled ` : `Bundling failed `;\n const color = phase === 'done' ? chalk.green : chalk.red;\n\n const startTime = this._bundleTimers.get(progress.bundleDetails.buildID!);\n\n let time: string = '';\n\n if (startTime != null) {\n const elapsed: bigint = this._getElapsedTime(startTime);\n const micro = Number(elapsed) / 1000;\n const converted = Number(elapsed) / 1e6;\n // If the milliseconds are < 0.5 then it will display as 0, so we display in microseconds.\n if (converted <= 0.5) {\n const tenthFractionOfMicro = ((micro * 10) / 1000).toFixed(0);\n // Format as microseconds to nearest tenth\n time = chalk.cyan.bold(`0.${tenthFractionOfMicro}ms`);\n } else {\n time = chalk.dim(converted.toFixed(0) + 'ms');\n }\n }\n\n // iOS Bundled 150ms\n const plural = progress.totalFileCount === 1 ? '' : 's';\n return (\n color(platform + status) +\n time +\n chalk.reset.dim(` ${localPath} (${progress.totalFileCount} module${plural})`)\n );\n }\n\n const filledBar = Math.floor(progress.ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);\n\n const _progress = inProgress\n ? chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +\n chalk.bgWhite.white(LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar)) +\n chalk.bold(` ${(100 * progress.ratio).toFixed(1).padStart(4)}% `) +\n chalk.dim(\n `(${progress.transformedFileCount\n .toString()\n .padStart(progress.totalFileCount.toString().length)}/${progress.totalFileCount})`\n )\n : '';\n\n return (\n platform +\n chalk.reset.dim(`${path.dirname(localPath)}${path.sep}`) +\n chalk.bold(path.basename(localPath)) +\n ' ' +\n _progress\n );\n }\n\n _logInitializing(port: number, hasReducedPerformance: boolean): void {\n // Don't print a giant logo...\n this.terminal.log(chalk.dim('Starting Metro Bundler'));\n }\n\n shouldFilterClientLog(event: { type: 'client_log'; data: unknown[] }): boolean {\n return isAppRegistryStartupMessage(event.data);\n }\n\n shouldFilterBundleEvent(event: TerminalReportableEvent): boolean {\n return 'bundleDetails' in event && event.bundleDetails?.bundleType === 'map';\n }\n\n /** Print the cache clear message. */\n transformCacheReset(): void {\n logWarning(\n this.terminal,\n chalk`Bundler cache is empty, rebuilding {dim (this may take a minute)}`\n );\n }\n\n /** One of the first logs that will be printed */\n dependencyGraphLoading(hasReducedPerformance: boolean): void {\n // this.terminal.log('Dependency graph is loading...');\n if (hasReducedPerformance) {\n // Extends https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/lib/TerminalReporter.js#L283-L290\n this.terminal.log(\n chalk.red(\n [\n 'Metro is operating with reduced performance.',\n 'Fix the problem above and restart Metro.',\n ].join('\\n')\n )\n );\n }\n }\n\n _logBundlingError(error: SnippetError): void {\n const moduleResolutionError = formatUsingNodeStandardLibraryError(this.projectRoot, error);\n if (moduleResolutionError) {\n let message = maybeAppendCodeFrame(moduleResolutionError, error.message);\n message += '\\n\\n' + nearestImportStack(error);\n return this.terminal.log(message);\n }\n\n attachImportStackToRootMessage(error);\n return super._logBundlingError(error);\n }\n}\n\n/**\n * Formats an error where the user is attempting to import a module from the Node.js standard library.\n * Exposed for testing.\n *\n * @param error\n * @returns error message or null if not a module resolution error\n */\nexport function formatUsingNodeStandardLibraryError(\n projectRoot: string,\n error: SnippetError\n): string | null {\n if (!error.message) {\n return null;\n }\n const { targetModuleName, originModulePath } = error;\n if (!targetModuleName || !originModulePath) {\n return null;\n }\n const relativePath = path.relative(projectRoot, originModulePath);\n\n const DOCS_PAGE_URL =\n 'https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries';\n\n if (isNodeStdLibraryModule(targetModuleName)) {\n if (originModulePath.includes('node_modules')) {\n return [\n `The package at \"${chalk.bold(\n relativePath\n )}\" attempted to import the Node standard library module \"${chalk.bold(\n targetModuleName\n )}\".`,\n `It failed because the native React runtime does not include the Node standard library.`,\n learnMore(DOCS_PAGE_URL),\n ].join('\\n');\n } else {\n return [\n `You attempted to import the Node standard library module \"${chalk.bold(\n targetModuleName\n )}\" from \"${chalk.bold(relativePath)}\".`,\n `It failed because the native React runtime does not include the Node standard library.`,\n learnMore(DOCS_PAGE_URL),\n ].join('\\n');\n }\n }\n return `Unable to resolve \"${targetModuleName}\" from \"${relativePath}\"`;\n}\n\nexport function isNodeStdLibraryModule(moduleName: string): boolean {\n return /^node:/.test(moduleName) || NODE_STDLIB_MODULES.includes(moduleName);\n}\n\n/** If the code frame can be found then append it to the existing message. */\nfunction maybeAppendCodeFrame(message: string, rawMessage: string): string {\n const codeFrame = extractCodeFrame(stripMetroInfo(rawMessage));\n if (codeFrame) {\n message += '\\n' + codeFrame;\n }\n return message;\n}\n\n/** Extract fist code frame presented in the error message */\nexport function extractCodeFrame(errorMessage: string): string {\n const codeFrameLine = /^(?:\\s*(?:>?\\s*\\d+\\s*\\||\\s*\\|).*\\n?)+/;\n let wasPreviousLineCodeFrame: boolean | null = null;\n return errorMessage\n .split('\\n')\n .filter((line) => {\n if (wasPreviousLineCodeFrame === false) return false;\n const keep = codeFrameLine.test(stripVTControlCharacters(line));\n if (keep && wasPreviousLineCodeFrame === null) wasPreviousLineCodeFrame = true;\n else if (!keep && wasPreviousLineCodeFrame) wasPreviousLineCodeFrame = false;\n return keep;\n })\n .join('\\n');\n}\n\n/**\n * Remove the Metro cache clearing steps if they exist.\n * In future versions we won't need this.\n * Returns the remaining code frame logs.\n */\nexport function stripMetroInfo(errorMessage: string): string {\n // Newer versions of Metro don't include the list.\n if (!errorMessage.includes('4. Remove the cache')) {\n return errorMessage;\n }\n const lines = errorMessage.split('\\n');\n const index = lines.findIndex((line) => line.includes('4. Remove the cache'));\n if (index === -1) {\n return errorMessage;\n }\n return lines.slice(index + 1).join('\\n');\n}\n\n/** @returns if the message matches the initial startup log */\nfunction isAppRegistryStartupMessage(body: any[]): boolean {\n return (\n body.length === 1 &&\n (/^Running application \"main\" with appParams:/.test(body[0]) ||\n /^Running \"main\" with \\{/.test(body[0]))\n );\n}\n\n/** @returns platform specific tag for a `BundleDetails` object */\nfunction getPlatformTagForBuildDetails(bundleDetails?: BundleDetails | null): string {\n const platform = bundleDetails?.platform ?? null;\n if (platform) {\n const formatted = { ios: 'iOS', android: 'Android', web: 'Web' }[platform] || platform;\n return `${chalk.bold(formatted)} `;\n }\n\n return '';\n}\n/** @returns platform specific tag for a `BundleDetails` object */\nfunction getEnvironmentForBuildDetails(bundleDetails?: BundleDetails | null): string {\n // Expo CLI will pass `customTransformOptions.environment = 'node'` when bundling for the server.\n const env = bundleDetails?.customTransformOptions?.environment ?? null;\n if (env === 'node') {\n return chalk.bold('λ') + ' ';\n } else if (env === 'react-server') {\n return chalk.bold(`RSC(${getPlatformTagForBuildDetails(bundleDetails).trim()})`) + ' ';\n }\n\n if (\n bundleDetails?.customTransformOptions?.dom &&\n typeof bundleDetails?.customTransformOptions?.dom === 'string'\n ) {\n return chalk.bold(`DOM`) + ' ';\n }\n\n return '';\n}\n"],"names":["MetroTerminalReporter","extractCodeFrame","formatUsingNodeStandardLibraryError","isNodeStdLibraryModule","stripMetroInfo","debug","require","MAX_PROGRESS_BAR_CHAR_WIDTH","DARK_BLOCK_CHAR","LIGHT_BLOCK_CHAR","TerminalReporter","constructor","projectRoot","terminal","_log","event","type","data","message","match","env","EXPO_DEBUG","shouldFilterClientLog","level","mode","hasStack","parsed","map","msg","includes","stack","parseErrorStringToObject","symbolicating","p","maybeSymbolicateAndFormatJSErrorStackLogAsync","usefulStackCount","fallbackIndices","symbolicated","Promise","allSettled","s","index","status","reason","value","isFallback","push","filtered","filter","_","logLikeMetro","log","bind","_getElapsedTime","startTime","process","hrtime","bigint","_getBundleStatusMessage","progress","phase","getEnvironmentForBuildDetails","bundleDetails","platform","getPlatformTagForBuildDetails","inProgress","localPath","customTransformOptions","dom","path","sep","replace","inputFile","entryFile","isAbsolute","relative","color","chalk","green","red","_bundleTimers","get","buildID","time","elapsed","micro","Number","converted","tenthFractionOfMicro","toFixed","cyan","bold","dim","plural","totalFileCount","reset","filledBar","Math","floor","ratio","_progress","bgGreen","repeat","bgWhite","white","padStart","transformedFileCount","toString","length","dirname","basename","_logInitializing","port","hasReducedPerformance","isAppRegistryStartupMessage","shouldFilterBundleEvent","bundleType","transformCacheReset","logWarning","dependencyGraphLoading","join","_logBundlingError","error","moduleResolutionError","maybeAppendCodeFrame","nearestImportStack","attachImportStackToRootMessage","targetModuleName","originModulePath","relativePath","DOCS_PAGE_URL","learnMore","moduleName","test","NODE_STDLIB_MODULES","rawMessage","codeFrame","errorMessage","codeFrameLine","wasPreviousLineCodeFrame","split","line","keep","stripVTControlCharacters","lines","findIndex","slice","body","formatted","ios","android","web","environment","trim"],"mappings":";;;;;;;;;;;IAgCaA,qBAAqB;eAArBA;;IAgTGC,gBAAgB;eAAhBA;;IAtDAC,mCAAmC;eAAnCA;;IAwCAC,sBAAsB;eAAtBA;;IAkCAC,cAAc;eAAdA;;;;gEAnWE;;;;;;;gEACD;;;;;;;yBACwB;;;;;;kCAEI;2BAQT;qBAChB;sBACM;oCAKnB;qCAC4D;;;;;;AAEnE,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,MAAMC,8BAA8B;AACpC,MAAMC,kBAAkB;AACxB,MAAMC,mBAAmB;AAKlB,MAAMT,8BAA8BU,kCAAgB;IACzDC,YACE,AAAOC,WAAmB,EAC1BC,QAAkB,CAClB;QACA,KAAK,CAACA,gBAHCD,cAAAA;IAIT;IAEAE,KAAKC,KAA8B,EAAQ;QACzC,OAAQA,MAAMC,IAAI;YAChB,KAAK;oBACQD;gBAAX,IAAI,SAAOA,cAAAA,MAAME,IAAI,qBAAVF,WAAY,CAAC,EAAE,MAAK,UAAU;oBACvC,MAAMG,UAAUH,MAAME,IAAI,CAAC,EAAE;oBAC7B,IAAIC,QAAQC,KAAK,CAAC,+BAA+B;wBAC/C,kGAAkG;wBAClG,kCAAkC;wBAElC,gBAAgB;wBAChB,oFAAoF;wBACpF,8EAA8E;wBAC9E,2EAA2E;wBAC3E,oBAAoB;wBACpB,KAAK;wBACL;oBACF;oBAEA,IAAI,CAACC,QAAG,CAACC,UAAU,EAAE;wBACnB,oHAAoH;wBACpH,kKAAkK;wBAClK,gMAAgM;wBAChM,IAAIH,Q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iddleware(projectRoot, options) {
|
|
|
177
177
|
basedir: options.appDir
|
|
178
178
|
});
|
|
179
179
|
try {
|
|
180
|
+
var _middlewareModule_unstable_settings;
|
|
180
181
|
debug(`Bundling middleware at: ${resolvedFunctionPath}`);
|
|
181
|
-
|
|
182
|
+
const middlewareModule = await options.bundleApiRoute(resolvedFunctionPath);
|
|
183
|
+
if ((_middlewareModule_unstable_settings = middlewareModule.unstable_settings) == null ? void 0 : _middlewareModule_unstable_settings.matcher) {
|
|
184
|
+
var _middlewareModule_unstable_settings1;
|
|
185
|
+
(0, _router.warnInvalidMiddlewareMatcherSettings)((_middlewareModule_unstable_settings1 = middlewareModule.unstable_settings) == null ? void 0 : _middlewareModule_unstable_settings1.matcher);
|
|
186
|
+
}
|
|
187
|
+
return middlewareModule;
|
|
182
188
|
} catch (error) {
|
|
183
189
|
return new Response('Failed to load middleware: ' + resolvedFunctionPath + '\n\n' + error.message, {
|
|
184
190
|
status: 500,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/createServerRouteMiddleware.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 */\n\nimport type { ProjectConfig } from '@expo/config';\nimport resolve from 'resolve';\nimport resolveFrom from 'resolve-from';\nimport { promisify } from 'util';\n\nimport { fetchManifest } from './fetchRouterManifest';\nimport { getErrorOverlayHtmlAsync, logMetroError } from './metroErrorInterface';\nimport { warnInvalidWebOutput, warnInvalidMiddlewareOutput } from './router';\nimport { CommandError } from '../../../utils/errors';\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\nconst resolveAsync = promisify(resolve) as any as (\n id: string,\n opts: resolve.AsyncOpts\n) => Promise<string | null>;\n\nexport function createRouteHandlerMiddleware(\n projectRoot: string,\n options: {\n appDir: string;\n routerRoot: string;\n getStaticPageAsync: (pathname: string) => Promise<{ content: string }>;\n bundleApiRoute: (\n functionFilePath: string\n ) => Promise<null | Record<string, Function> | Response>;\n config: ProjectConfig;\n } & import('expo-router/build/routes-manifest').Options\n) {\n if (!resolveFrom.silent(projectRoot, 'expo-router')) {\n throw new CommandError(\n `static and server rendering requires the expo-router package to be installed in your project. Either install the expo-router package or change 'web.output' to 'static' in your app.json.`\n );\n }\n\n const { createRequestHandler } =\n require('@expo/server/adapter/http') as typeof import('@expo/server/adapter/http');\n\n return createRequestHandler(\n { build: '' },\n {\n async getRoutesManifest() {\n const manifest = await fetchManifest<RegExp>(projectRoot, options);\n debug('manifest', manifest);\n // NOTE: no app dir if null\n // TODO: Redirect to 404 page\n return (\n manifest ?? {\n // Support the onboarding screen if there's no manifest\n htmlRoutes: [\n {\n file: 'index.js',\n page: '/index',\n routeKeys: {},\n namedRegex: /^\\/(?:index)?\\/?$/i,\n },\n ],\n apiRoutes: [],\n notFoundRoutes: [],\n redirects: [],\n rewrites: [],\n }\n );\n },\n async getHtml(request) {\n try {\n const { content } = await options.getStaticPageAsync(request.url);\n return content;\n } catch (error: any) {\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n\n try {\n return new Response(\n await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot: options.routerRoot,\n }),\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n } catch (staticError: any) {\n debug('Failed to render static error overlay:', staticError);\n // Fallback error for when Expo Router is misconfigured in the project.\n return new Response(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>',\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n }\n },\n async handleRouteError(error) {\n const { ExpoError } = require('@expo/server') as typeof import('@expo/server');\n\n if (ExpoError.isExpoError(error)) {\n // TODO(@krystofwoldrich): Can we show code snippet of the handler?\n // NOTE(@krystofwoldrich): Removing stack since to avoid confusion. The error is not in the server code.\n delete error.stack;\n }\n\n const htmlServerError = await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot: options.routerRoot!,\n });\n\n return new Response(htmlServerError, {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n },\n async getApiRoute(route) {\n const { exp } = options.config;\n if (exp.web?.output !== 'server') {\n warnInvalidWebOutput();\n }\n\n const resolvedFunctionPath = await resolveAsync(route.file, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n })!;\n\n try {\n debug(`Bundling API route at: ${resolvedFunctionPath}`);\n return await options.bundleApiRoute(resolvedFunctionPath!);\n } catch (error: any) {\n return new Response(\n 'Failed to load API Route: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n async getMiddleware(route) {\n const { exp } = options.config;\n\n if (!options.unstable_useServerMiddleware) {\n return {\n default: () => {\n throw new CommandError(\n 'Server middleware is not enabled. Add unstable_useServerMiddleware: true to your `expo-router` plugin config.'\n );\n },\n };\n }\n\n if (exp.web?.output !== 'server') {\n warnInvalidMiddlewareOutput();\n return {\n default: () => {\n console.warn(\n 'Server middleware is only supported when web.output is set to \"server\" in your app config'\n );\n },\n };\n }\n\n const resolvedFunctionPath = await resolveAsync(route.file, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n })!;\n\n try {\n debug(`Bundling middleware at: ${resolvedFunctionPath}`);\n return await options.bundleApiRoute(resolvedFunctionPath!);\n } catch (error: any) {\n return new Response(\n 'Failed to load middleware: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n }\n );\n}\n"],"names":["createRouteHandlerMiddleware","debug","require","resolveAsync","promisify","resolve","projectRoot","options","resolveFrom","silent","CommandError","createRequestHandler","build","getRoutesManifest","manifest","fetchManifest","htmlRoutes","file","page","routeKeys","namedRegex","apiRoutes","notFoundRoutes","redirects","rewrites","getHtml","request","content","getStaticPageAsync","url","error","Response","getErrorOverlayHtmlAsync","routerRoot","status","headers","staticError","message","handleRouteError","ExpoError","isExpoError","stack","htmlServerError","getApiRoute","route","exp","config","web","output","warnInvalidWebOutput","resolvedFunctionPath","extensions","basedir","appDir","bundleApiRoute","getMiddleware","unstable_useServerMiddleware","default","warnInvalidMiddlewareOutput","console","warn"],"mappings":"AAAA;;;;;CAKC;;;;+BAmBeA;;;eAAAA;;;;gEAhBI;;;;;;;gEACI;;;;;;;yBACE;;;;;;qCAEI;qCAC0B;wBACU;wBACrC;;;;;;AAE7B,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,MAAMC,eAAeC,IAAAA,iBAAS,EAACC,kBAAO;AAK/B,SAASL,6BACdM,WAAmB,EACnBC,OAQuD;IAEvD,IAAI,CAACC,sBAAW,CAACC,MAAM,CAACH,aAAa,gBAAgB;QACnD,MAAM,IAAII,oBAAY,CACpB,CAAC,yLAAyL,CAAC;IAE/L;IAEA,MAAM,EAAEC,oBAAoB,EAAE,GAC5BT,QAAQ;IAEV,OAAOS,qBACL;QAAEC,OAAO;IAAG,GACZ;QACE,MAAMC;YACJ,MAAMC,WAAW,MAAMC,IAAAA,kCAAa,EAAST,aAAaC;YAC1DN,MAAM,YAAYa;YAClB,2BAA2B;YAC3B,6BAA6B;YAC7B,OACEA,YAAY;gBACV,uDAAuD;gBACvDE,YAAY;oBACV;wBACEC,MAAM;wBACNC,MAAM;wBACNC,WAAW,CAAC;wBACZC,YAAY;oBACd;iBACD;gBACDC,WAAW,EAAE;gBACbC,gBAAgB,EAAE;gBAClBC,WAAW,EAAE;gBACbC,UAAU,EAAE;YACd;QAEJ;QACA,MAAMC,SAAQC,OAAO;YACnB,IAAI;gBACF,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAMpB,QAAQqB,kBAAkB,CAACF,QAAQG,GAAG;gBAChE,OAAOF;YACT,EAAE,OAAOG,OAAY;gBACnB,iGAAiG;gB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J;YACtC,EAAE,OAAOpB,OAAY;gBACnB,OAAO,IAAIC,SACT,+BAA+BmB,uBAAuB,SAASpB,MAAMO,OAAO,EAC5E;oBACEH,QAAQ;oBACRC,SAAS;wBACP,gBAAgB;oBAClB;gBACF;YAEJ;QACF;QACA,MAAMoB,eAAcX,KAAK;gBAanBC;YAZJ,MAAM,EAAEA,GAAG,EAAE,GAAGtC,QAAQuC,MAAM;YAE9B,IAAI,CAACvC,QAAQiD,4BAA4B,EAAE;gBACzC,OAAO;oBACLC,SAAS;wBACP,MAAM,IAAI/C,oBAAY,CACpB;oBAEJ;gBACF;YACF;YAEA,IAAImC,EAAAA,WAAAA,IAAIE,GAAG,qBAAPF,SAASG,MAAM,MAAK,UAAU;gBAChCU,IAAAA,mCAA2B;gBAC3B,OAAO;oBACLD,SAAS;wBACPE,QAAQC,IAAI,CACV;oBAEJ;gBACF;YACF;YAEA,MAAMV,uBAAuB,MAAM/C,aAAayC,MAAM3B,IAAI,EAAE;gBAC1DkC,YAAY;oBAAC;oBAAO;oBAAQ;oBAAO;iBAAO;gBAC1CC,SAAS7C,QAAQ8C,MAAM;YACzB;YAEA,IAAI;gBACFpD,MAAM,CAAC,wBAAwB,EAAEiD,sBAAsB;gBACvD,OAAO,MAAM3C,QAAQ+C,cAAc,CAACJ;YACtC,EAAE,OAAOpB,OAAY;gBACnB,OAAO,IAAIC,SACT,gCAAgCmB,uBAAuB,SAASpB,MAAMO,OAAO,EAC7E;oBACEH,QAAQ;oBACRC,SAAS;wBACP,gBAAgB;oBAClB;gBACF;YAEJ;QACF;IACF;AAEJ"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/createServerRouteMiddleware.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 */\n\nimport type { ProjectConfig } from '@expo/config';\nimport { MiddlewareModule } from '@expo/server/build/types';\nimport resolve from 'resolve';\nimport resolveFrom from 'resolve-from';\nimport { promisify } from 'util';\n\nimport { fetchManifest } from './fetchRouterManifest';\nimport { getErrorOverlayHtmlAsync, logMetroError } from './metroErrorInterface';\nimport {\n warnInvalidWebOutput,\n warnInvalidMiddlewareOutput,\n warnInvalidMiddlewareMatcherSettings,\n} from './router';\nimport { CommandError } from '../../../utils/errors';\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\nconst resolveAsync = promisify(resolve) as any as (\n id: string,\n opts: resolve.AsyncOpts\n) => Promise<string | null>;\n\nexport function createRouteHandlerMiddleware(\n projectRoot: string,\n options: {\n appDir: string;\n routerRoot: string;\n getStaticPageAsync: (pathname: string) => Promise<{ content: string }>;\n bundleApiRoute: (\n functionFilePath: string\n ) => Promise<null | Record<string, Function> | Response>;\n config: ProjectConfig;\n } & import('expo-router/build/routes-manifest').Options\n) {\n if (!resolveFrom.silent(projectRoot, 'expo-router')) {\n throw new CommandError(\n `static and server rendering requires the expo-router package to be installed in your project. Either install the expo-router package or change 'web.output' to 'static' in your app.json.`\n );\n }\n\n const { createRequestHandler } =\n require('@expo/server/adapter/http') as typeof import('@expo/server/adapter/http');\n\n return createRequestHandler(\n { build: '' },\n {\n async getRoutesManifest() {\n const manifest = await fetchManifest<RegExp>(projectRoot, options);\n debug('manifest', manifest);\n // NOTE: no app dir if null\n // TODO: Redirect to 404 page\n return (\n manifest ?? {\n // Support the onboarding screen if there's no manifest\n htmlRoutes: [\n {\n file: 'index.js',\n page: '/index',\n routeKeys: {},\n namedRegex: /^\\/(?:index)?\\/?$/i,\n },\n ],\n apiRoutes: [],\n notFoundRoutes: [],\n redirects: [],\n rewrites: [],\n }\n );\n },\n async getHtml(request) {\n try {\n const { content } = await options.getStaticPageAsync(request.url);\n return content;\n } catch (error: any) {\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n\n try {\n return new Response(\n await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot: options.routerRoot,\n }),\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n } catch (staticError: any) {\n debug('Failed to render static error overlay:', staticError);\n // Fallback error for when Expo Router is misconfigured in the project.\n return new Response(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>',\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n }\n },\n async handleRouteError(error) {\n const { ExpoError } = require('@expo/server') as typeof import('@expo/server');\n\n if (ExpoError.isExpoError(error)) {\n // TODO(@krystofwoldrich): Can we show code snippet of the handler?\n // NOTE(@krystofwoldrich): Removing stack since to avoid confusion. The error is not in the server code.\n delete error.stack;\n }\n\n const htmlServerError = await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot: options.routerRoot!,\n });\n\n return new Response(htmlServerError, {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n },\n async getApiRoute(route) {\n const { exp } = options.config;\n if (exp.web?.output !== 'server') {\n warnInvalidWebOutput();\n }\n\n const resolvedFunctionPath = await resolveAsync(route.file, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n })!;\n\n try {\n debug(`Bundling API route at: ${resolvedFunctionPath}`);\n return await options.bundleApiRoute(resolvedFunctionPath!);\n } catch (error: any) {\n return new Response(\n 'Failed to load API Route: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n async getMiddleware(route) {\n const { exp } = options.config;\n\n if (!options.unstable_useServerMiddleware) {\n return {\n default: () => {\n throw new CommandError(\n 'Server middleware is not enabled. Add unstable_useServerMiddleware: true to your `expo-router` plugin config.'\n );\n },\n };\n }\n\n if (exp.web?.output !== 'server') {\n warnInvalidMiddlewareOutput();\n return {\n default: () => {\n console.warn(\n 'Server middleware is only supported when web.output is set to \"server\" in your app config'\n );\n },\n };\n }\n\n const resolvedFunctionPath = await resolveAsync(route.file, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n })!;\n\n try {\n debug(`Bundling middleware at: ${resolvedFunctionPath}`);\n const middlewareModule = (await options.bundleApiRoute(\n resolvedFunctionPath!\n )) as unknown as MiddlewareModule;\n\n if (middlewareModule.unstable_settings?.matcher) {\n warnInvalidMiddlewareMatcherSettings(middlewareModule.unstable_settings?.matcher);\n }\n\n return middlewareModule;\n } catch (error: any) {\n return new Response(\n 'Failed to load middleware: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n }\n );\n}\n"],"names":["createRouteHandlerMiddleware","debug","require","resolveAsync","promisify","resolve","projectRoot","options","resolveFrom","silent","CommandError","createRequestHandler","build","getRoutesManifest","manifest","fetchManifest","htmlRoutes","file","page","routeKeys","namedRegex","apiRoutes","notFoundRoutes","redirects","rewrites","getHtml","request","content","getStaticPageAsync","url","error","Response","getErrorOverlayHtmlAsync","routerRoot","status","headers","staticError","message","handleRouteError","ExpoError","isExpoError","stack","htmlServerError","getApiRoute","route","exp","config","web","output","warnInvalidWebOutput","resolvedFunctionPath","extensions","basedir","appDir","bundleApiRoute","getMiddleware","unstable_useServerMiddleware","default","warnInvalidMiddlewareOutput","console","warn","middlewareModule","unstable_settings","matcher","warnInvalidMiddlewareMatcherSettings"],"mappings":"AAAA;;;;;CAKC;;;;+BAwBeA;;;eAAAA;;;;gEApBI;;;;;;;gEACI;;;;;;;yBACE;;;;;;qCAEI;qCAC0B;wBAKjD;wBACsB;;;;;;AAE7B,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,MAAMC,eAAeC,IAAAA,iBAAS,EAACC,kBAAO;AAK/B,SAASL,6BACdM,WAAmB,EACnBC,OAQuD;IAEvD,IAAI,CAACC,sBAAW,CAACC,MAAM,CAACH,aAAa,gBAAgB;QACnD,MAAM,IAAII,oBAAY,CACpB,CAAC,yLAAyL,CAA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kC,YAAY;oBAAC;oBAAO;oBAAQ;oBAAO;iBAAO;gBAC1CC,SAAS7C,QAAQ8C,MAAM;YACzB;YAEA,IAAI;oBAMEQ;gBALJ5D,MAAM,CAAC,wBAAwB,EAAEiD,sBAAsB;gBACvD,MAAMW,mBAAoB,MAAMtD,QAAQ+C,cAAc,CACpDJ;gBAGF,KAAIW,sCAAAA,iBAAiBC,iBAAiB,qBAAlCD,oCAAoCE,OAAO,EAAE;wBACVF;oBAArCG,IAAAA,4CAAoC,GAACH,uCAAAA,iBAAiBC,iBAAiB,qBAAlCD,qCAAoCE,OAAO;gBAClF;gBAEA,OAAOF;YACT,EAAE,OAAO/B,OAAY;gBACnB,OAAO,IAAIC,SACT,gCAAgCmB,uBAAuB,SAASpB,MAAMO,OAAO,EAC7E;oBACEH,QAAQ;oBACRC,SAAS;wBACP,gBAAgB;oBAClB;gBACF;YAEJ;QACF;IACF;AAEJ"}
|
|
@@ -36,6 +36,9 @@ _export(exports, {
|
|
|
36
36
|
isApiRouteConvention: function() {
|
|
37
37
|
return isApiRouteConvention;
|
|
38
38
|
},
|
|
39
|
+
warnInvalidMiddlewareMatcherSettings: function() {
|
|
40
|
+
return warnInvalidMiddlewareMatcherSettings;
|
|
41
|
+
},
|
|
39
42
|
warnInvalidMiddlewareOutput: function() {
|
|
40
43
|
return warnInvalidMiddlewareOutput;
|
|
41
44
|
},
|
|
@@ -174,5 +177,42 @@ function warnInvalidMiddlewareOutput() {
|
|
|
174
177
|
}
|
|
175
178
|
hasWarnedAboutMiddlewareOutput = true;
|
|
176
179
|
}
|
|
180
|
+
function warnInvalidMiddlewareMatcherSettings(matcher) {
|
|
181
|
+
const validMethods = [
|
|
182
|
+
'GET',
|
|
183
|
+
'POST',
|
|
184
|
+
'PUT',
|
|
185
|
+
'PATCH',
|
|
186
|
+
'DELETE',
|
|
187
|
+
'OPTIONS',
|
|
188
|
+
'HEAD'
|
|
189
|
+
];
|
|
190
|
+
// Ensure methods are valid HTTP methods
|
|
191
|
+
if (matcher.methods) {
|
|
192
|
+
if (!Array.isArray(matcher.methods)) {
|
|
193
|
+
_log.Log.error(_chalk().default.red`Middleware matcher methods must be an array of valid HTTP methods. Supported methods are: ${validMethods.join(', ')}`);
|
|
194
|
+
} else {
|
|
195
|
+
for (const method of matcher.methods){
|
|
196
|
+
if (!validMethods.includes(method)) {
|
|
197
|
+
_log.Log.error(_chalk().default.red`Invalid middleware HTTP method: ${method}. Supported methods are: ${validMethods.join(', ')}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Ensure patterns are either a string or RegExp
|
|
203
|
+
if (matcher.patterns) {
|
|
204
|
+
const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [
|
|
205
|
+
matcher.patterns
|
|
206
|
+
];
|
|
207
|
+
for (const pattern of patterns){
|
|
208
|
+
if (typeof pattern !== 'string' && !(pattern instanceof RegExp)) {
|
|
209
|
+
_log.Log.error(_chalk().default.red`Middleware matcher patterns must be strings or regular expressions. Received: ${String(pattern)}`);
|
|
210
|
+
}
|
|
211
|
+
if (typeof pattern === 'string' && !pattern.startsWith('/')) {
|
|
212
|
+
_log.Log.error(_chalk().default.red`String patterns in middleware matcher must start with '/'. Received: ${pattern}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
177
217
|
|
|
178
218
|
//# sourceMappingURL=router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/router.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { Log } from '../../../log';\nimport { directoryExistsSync } from '../../../utils/dir';\nimport { toPosixPath } from '../../../utils/filePath';\nimport { learnMore } from '../../../utils/link';\n\nconst debug = require('debug')('expo:start:server:metro:router') as typeof console.log;\n\n/**\n * Get the relative path for requiring the `/app` folder relative to the `expo-router/entry` file.\n * This mechanism does require the server to restart after the `expo-router` package is installed.\n */\nexport function getAppRouterRelativeEntryPath(\n projectRoot: string,\n routerDirectory: string = getRouterDirectory(projectRoot)\n): string | undefined {\n // Auto pick App entry\n const routerEntry =\n resolveFrom.silent(projectRoot, 'expo-router/entry') ?? getFallbackEntryRoot(projectRoot);\n if (!routerEntry) {\n return undefined;\n }\n // It doesn't matter if the app folder exists.\n const appFolder = path.join(projectRoot, routerDirectory);\n const appRoot = path.relative(path.dirname(routerEntry), appFolder);\n debug('expo-router entry', routerEntry, appFolder, appRoot);\n return appRoot;\n}\n\n/** If the `expo-router` package is not installed, then use the `expo` package to determine where the node modules are relative to the project. */\nfunction getFallbackEntryRoot(projectRoot: string): string {\n const expoRoot = resolveFrom.silent(projectRoot, 'expo/package.json');\n if (expoRoot) {\n return path.join(path.dirname(path.dirname(expoRoot)), 'expo-router/entry');\n }\n return path.join(projectRoot, 'node_modules/expo-router/entry');\n}\n\nexport function getRouterDirectoryModuleIdWithManifest(\n projectRoot: string,\n exp: ExpoConfig\n): string {\n return toPosixPath(exp.extra?.router?.root ?? getRouterDirectory(projectRoot));\n}\n\nlet hasWarnedAboutSrcDir = false;\nconst logSrcDir = () => {\n if (hasWarnedAboutSrcDir) return;\n hasWarnedAboutSrcDir = true;\n Log.log(chalk.gray('Using src/app as the root directory for Expo Router.'));\n};\n\nexport function getRouterDirectory(projectRoot: string): string {\n // more specific directories first\n if (directoryExistsSync(path.join(projectRoot, 'src', 'app'))) {\n logSrcDir();\n return path.join('src', 'app');\n }\n\n debug('Using app as the root directory for Expo Router.');\n return 'app';\n}\n\nexport function isApiRouteConvention(name: string): boolean {\n return /\\+api\\.[tj]sx?$/.test(name);\n}\n\nexport function getApiRoutesForDirectory(cwd: string) {\n return globSync('**/*+api.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n}\n\n/**\n * Gets the +middleware file for a given directory. In\n * @param cwd\n */\nexport function getMiddlewareForDirectory(cwd: string): string | null {\n const files = globSync('+middleware.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n\n if (files.length === 0) return null;\n\n if (files.length > 1) {\n // In development, throw an error if there are multiple root-level middleware files\n if (process.env.NODE_ENV !== 'production') {\n const relativePaths = files.map((f) => './' + path.relative(cwd, f)).sort();\n throw new Error(\n `Only one middleware file is allowed. Keep one of the conflicting files: ${relativePaths.map((p) => `\"${p}\"`).join(' or ')}`\n );\n }\n }\n\n return files[0];\n}\n\n// Used to emulate a context module, but way faster. TODO: May need to adjust the extensions to stay in sync with Metro.\nexport function getRoutePaths(cwd: string) {\n return globSync('**/*.@(ts|tsx|js|jsx)', {\n cwd,\n dot: true,\n }).map((p) => './' + normalizePaths(p));\n}\n\nfunction normalizePaths(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\nlet hasWarnedAboutApiRouteOutput = false;\nlet hasWarnedAboutMiddlewareOutput = false;\n\nexport function hasWarnedAboutApiRoutes() {\n return hasWarnedAboutApiRouteOutput;\n}\n\nexport function hasWarnedAboutMiddleware() {\n return hasWarnedAboutMiddlewareOutput;\n}\n\nexport function warnInvalidWebOutput() {\n if (!hasWarnedAboutApiRouteOutput) {\n Log.warn(\n chalk.yellow`Using API routes requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutApiRouteOutput = true;\n}\n\nexport function warnInvalidMiddlewareOutput() {\n if (!hasWarnedAboutMiddlewareOutput) {\n Log.warn(\n chalk.yellow`Using middleware requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutMiddlewareOutput = true;\n}\n"],"names":["getApiRoutesForDirectory","getAppRouterRelativeEntryPath","getMiddlewareForDirectory","getRoutePaths","getRouterDirectory","getRouterDirectoryModuleIdWithManifest","hasWarnedAboutApiRoutes","hasWarnedAboutMiddleware","isApiRouteConvention","warnInvalidMiddlewareOutput","warnInvalidWebOutput","debug","require","projectRoot","routerDirectory","routerEntry","resolveFrom","silent","getFallbackEntryRoot","undefined","appFolder","path","join","appRoot","relative","dirname","expoRoot","exp","toPosixPath","extra","router","root","hasWarnedAboutSrcDir","logSrcDir","Log","log","chalk","gray","directoryExistsSync","name","test","cwd","globSync","absolute","dot","files","length","process","env","NODE_ENV","relativePaths","map","f","sort","Error","p","normalizePaths","replace","hasWarnedAboutApiRouteOutput","hasWarnedAboutMiddlewareOutput","warn","yellow","learnMore"],"mappings":";;;;;;;;;;;IAwEgBA,wBAAwB;eAAxBA;;IAvDAC,6BAA6B;eAA7BA;;IAmEAC,yBAAyB;eAAzBA;;IAuBAC,aAAa;eAAbA;;IAlDAC,kBAAkB;eAAlBA;;IAdAC,sCAAsC;eAAtCA;;IA8EAC,uBAAuB;eAAvBA;;IAIAC,wBAAwB;eAAxBA;;IAzDAC,oBAAoB;eAApBA;;IAyEAC,2BAA2B;eAA3BA;;IAZAC,oBAAoB;eAApBA;;;;gEAhIE;;;;;;;yBACe;;;;;;;gEAChB;;;;;;;gEACO;;;;;;qBAEJ;qBACgB;0BACR;sBACF;;;;;;AAE1B,MAAMC,QAAQC,QAAQ,SAAS;AAMxB,SAASX,8BACdY,WAAmB,EACnBC,kBAA0BV,mBAAmBS,YAAY;IAEzD,sBAAsB;IACtB,MAAME,cACJC,sBAAW,CAACC,MAAM,CAACJ,aAAa,wBAAwBK,qBAAqBL;IAC/E,IAAI,CAACE,aAAa;QAChB,OAAOI;IACT;IACA,8CAA8C;IAC9C,MAAMC,YAAYC,eAAI,CAACC,IAAI,CAACT,aAAaC;IACzC,MAAMS,UAAUF,eAAI,CAACG,QAAQ,CAACH,eAAI,CAACI,OAAO,CAACV,cAAcK;IACzDT,MAAM,qBAAqBI,aAAaK,WAAWG;IACnD,OAAOA;AACT;AAEA,gJAAgJ,GAChJ,SA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AK,cAAc;YACzC,MAAMC,gBAAgBL,MAAMM,GAAG,CAAC,CAACC,IAAM,OAAO/B,eAAI,CAACG,QAAQ,CAACiB,KAAKW,IAAIC,IAAI;YACzE,MAAM,IAAIC,MACR,CAAC,wEAAwE,EAAEJ,cAAcC,GAAG,CAAC,CAACI,IAAM,CAAC,CAAC,EAAEA,EAAE,CAAC,CAAC,EAAEjC,IAAI,CAAC,SAAS;QAEhI;IACF;IAEA,OAAOuB,KAAK,CAAC,EAAE;AACjB;AAGO,SAAS1C,cAAcsC,GAAW;IACvC,OAAOC,IAAAA,YAAQ,EAAC,yBAAyB;QACvCD;QACAG,KAAK;IACP,GAAGO,GAAG,CAAC,CAACI,IAAM,OAAOC,eAAeD;AACtC;AAEA,SAASC,eAAeD,CAAS;IAC/B,OAAOA,EAAEE,OAAO,CAAC,OAAO;AAC1B;AAEA,IAAIC,+BAA+B;AACnC,IAAIC,iCAAiC;AAE9B,SAASrD;IACd,OAAOoD;AACT;AAEO,SAASnD;IACd,OAAOoD;AACT;AAEO,SAASjD;IACd,IAAI,CAACgD,8BAA8B;QACjCxB,QAAG,CAAC0B,IAAI,CACNxB,gBAAK,CAACyB,MAAM,CAAC,6GAA6G,EAAEC,IAAAA,eAAS,EACnI,sDACA,CAAC;IAEP;IAEAJ,+BAA+B;AACjC;AAEO,SAASjD;IACd,IAAI,CAACkD,gCAAgC;QACnCzB,QAAG,CAAC0B,IAAI,CACNxB,gBAAK,CAACyB,MAAM,CAAC,6GAA6G,EAAEC,IAAAA,eAAS,EACnI,sDACA,CAAC;IAEP;IAEAH,iCAAiC;AACnC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/router.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport type { MiddlewareMatcher } from '@expo/server/build/types';\nimport chalk from 'chalk';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { Log } from '../../../log';\nimport { directoryExistsSync } from '../../../utils/dir';\nimport { toPosixPath } from '../../../utils/filePath';\nimport { learnMore } from '../../../utils/link';\n\nconst debug = require('debug')('expo:start:server:metro:router') as typeof console.log;\n\n/**\n * Get the relative path for requiring the `/app` folder relative to the `expo-router/entry` file.\n * This mechanism does require the server to restart after the `expo-router` package is installed.\n */\nexport function getAppRouterRelativeEntryPath(\n projectRoot: string,\n routerDirectory: string = getRouterDirectory(projectRoot)\n): string | undefined {\n // Auto pick App entry\n const routerEntry =\n resolveFrom.silent(projectRoot, 'expo-router/entry') ?? getFallbackEntryRoot(projectRoot);\n if (!routerEntry) {\n return undefined;\n }\n // It doesn't matter if the app folder exists.\n const appFolder = path.join(projectRoot, routerDirectory);\n const appRoot = path.relative(path.dirname(routerEntry), appFolder);\n debug('expo-router entry', routerEntry, appFolder, appRoot);\n return appRoot;\n}\n\n/** If the `expo-router` package is not installed, then use the `expo` package to determine where the node modules are relative to the project. */\nfunction getFallbackEntryRoot(projectRoot: string): string {\n const expoRoot = resolveFrom.silent(projectRoot, 'expo/package.json');\n if (expoRoot) {\n return path.join(path.dirname(path.dirname(expoRoot)), 'expo-router/entry');\n }\n return path.join(projectRoot, 'node_modules/expo-router/entry');\n}\n\nexport function getRouterDirectoryModuleIdWithManifest(\n projectRoot: string,\n exp: ExpoConfig\n): string {\n return toPosixPath(exp.extra?.router?.root ?? getRouterDirectory(projectRoot));\n}\n\nlet hasWarnedAboutSrcDir = false;\nconst logSrcDir = () => {\n if (hasWarnedAboutSrcDir) return;\n hasWarnedAboutSrcDir = true;\n Log.log(chalk.gray('Using src/app as the root directory for Expo Router.'));\n};\n\nexport function getRouterDirectory(projectRoot: string): string {\n // more specific directories first\n if (directoryExistsSync(path.join(projectRoot, 'src', 'app'))) {\n logSrcDir();\n return path.join('src', 'app');\n }\n\n debug('Using app as the root directory for Expo Router.');\n return 'app';\n}\n\nexport function isApiRouteConvention(name: string): boolean {\n return /\\+api\\.[tj]sx?$/.test(name);\n}\n\nexport function getApiRoutesForDirectory(cwd: string) {\n return globSync('**/*+api.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n}\n\n/**\n * Gets the +middleware file for a given directory. In\n * @param cwd\n */\nexport function getMiddlewareForDirectory(cwd: string): string | null {\n const files = globSync('+middleware.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n\n if (files.length === 0) return null;\n\n if (files.length > 1) {\n // In development, throw an error if there are multiple root-level middleware files\n if (process.env.NODE_ENV !== 'production') {\n const relativePaths = files.map((f) => './' + path.relative(cwd, f)).sort();\n throw new Error(\n `Only one middleware file is allowed. Keep one of the conflicting files: ${relativePaths.map((p) => `\"${p}\"`).join(' or ')}`\n );\n }\n }\n\n return files[0];\n}\n\n// Used to emulate a context module, but way faster. TODO: May need to adjust the extensions to stay in sync with Metro.\nexport function getRoutePaths(cwd: string) {\n return globSync('**/*.@(ts|tsx|js|jsx)', {\n cwd,\n dot: true,\n }).map((p) => './' + normalizePaths(p));\n}\n\nfunction normalizePaths(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\nlet hasWarnedAboutApiRouteOutput = false;\nlet hasWarnedAboutMiddlewareOutput = false;\n\nexport function hasWarnedAboutApiRoutes() {\n return hasWarnedAboutApiRouteOutput;\n}\n\nexport function hasWarnedAboutMiddleware() {\n return hasWarnedAboutMiddlewareOutput;\n}\n\nexport function warnInvalidWebOutput() {\n if (!hasWarnedAboutApiRouteOutput) {\n Log.warn(\n chalk.yellow`Using API routes requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutApiRouteOutput = true;\n}\n\nexport function warnInvalidMiddlewareOutput() {\n if (!hasWarnedAboutMiddlewareOutput) {\n Log.warn(\n chalk.yellow`Using middleware requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutMiddlewareOutput = true;\n}\n\nexport function warnInvalidMiddlewareMatcherSettings(matcher: MiddlewareMatcher) {\n const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];\n\n // Ensure methods are valid HTTP methods\n if (matcher.methods) {\n if (!Array.isArray(matcher.methods)) {\n Log.error(\n chalk.red`Middleware matcher methods must be an array of valid HTTP methods. Supported methods are: ${validMethods.join(', ')}`\n );\n } else {\n for (const method of matcher.methods) {\n if (!validMethods.includes(method)) {\n Log.error(\n chalk.red`Invalid middleware HTTP method: ${method}. Supported methods are: ${validMethods.join(', ')}`\n );\n }\n }\n }\n }\n\n // Ensure patterns are either a string or RegExp\n if (matcher.patterns) {\n const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [matcher.patterns];\n for (const pattern of patterns) {\n if (typeof pattern !== 'string' && !(pattern instanceof RegExp)) {\n Log.error(\n chalk.red`Middleware matcher patterns must be strings or regular expressions. Received: ${String(\n pattern\n )}`\n );\n }\n\n if (typeof pattern === 'string' && !pattern.startsWith('/')) {\n Log.error(\n chalk.red`String patterns in middleware matcher must start with '/'. Received: ${pattern}`\n );\n }\n }\n }\n}\n"],"names":["getApiRoutesForDirectory","getAppRouterRelativeEntryPath","getMiddlewareForDirectory","getRoutePaths","getRouterDirectory","getRouterDirectoryModuleIdWithManifest","hasWarnedAboutApiRoutes","hasWarnedAboutMiddleware","isApiRouteConvention","warnInvalidMiddlewareMatcherSettings","warnInvalidMiddlewareOutput","warnInvalidWebOutput","debug","require","projectRoot","routerDirectory","routerEntry","resolveFrom","silent","getFallbackEntryRoot","undefined","appFolder","path","join","appRoot","relative","dirname","expoRoot","exp","toPosixPath","extra","router","root","hasWarnedAboutSrcDir","logSrcDir","Log","log","chalk","gray","directoryExistsSync","name","test","cwd","globSync","absolute","dot","files","length","process","env","NODE_ENV","relativePaths","map","f","sort","Error","p","normalizePaths","replace","hasWarnedAboutApiRouteOutput","hasWarnedAboutMiddlewareOutput","warn","yellow","learnMore","matcher","validMethods","methods","Array","isArray","error","red","method","includes","patterns","pattern","RegExp","String","startsWith"],"mappings":";;;;;;;;;;;IAyEgBA,wBAAwB;eAAxBA;;IAvDAC,6BAA6B;eAA7BA;;IAmEAC,yBAAyB;eAAzBA;;IAuBAC,aAAa;eAAbA;;IAlDAC,kBAAkB;eAAlBA;;IAdAC,sCAAsC;eAAtCA;;IA8EAC,uBAAuB;eAAvBA;;IAIAC,wBAAwB;eAAxBA;;IAzDAC,oBAAoB;eAApBA;;IAqFAC,oCAAoC;eAApCA;;IAZAC,2BAA2B;eAA3BA;;IAZAC,oBAAoB;eAApBA;;;;gEAhIE;;;;;;;yBACe;;;;;;;gEAChB;;;;;;;gEACO;;;;;;qBAEJ;qBACgB;0BACR;sBACF;;;;;;AAE1B,MAAMC,QAAQC,QAAQ,SAAS;AAMxB,SAASZ,8BACda,WAAmB,EACnBC,kBAA0BX,mBAAmBU,YAAY;IAEzD,sBAAsB;IACtB,MAAME,cACJC,sBAAW,CAACC,MAAM,CAACJ,aAAa,wBAAwBK,qBAAqBL;IAC/E,IAAI,CAACE,aAAa;QAChB,OAAOI;IACT;IACA,8CAA8C;IAC9C,MAAMC,YAAYC,eAAI,CAACC,IAAI,CAACT,aAAaC;IACzC,MAAMS,UAAUF,eAAI,CAACG,QAAQ,CAACH,eAAI,CAACI,OAAO,CAACV,cAAcK;IACzDT,MAAM,qBAAqBI,aAAaK,WAAWG;IACnD,OAAOA;AACT;AAEA,gJAAgJ,GAChJ,SAASL,qBAAqBL,WAAmB;IAC/C,MAAMa,WAAWV,sBAAW,CAACC,MAAM,CAACJ,aAAa;IACjD,IAAIa,UAAU;QACZ,OAAOL,eAAI,CAACC,IAAI,CAACD,eAAI,CAACI,OAAO,CAACJ,eAAI,CAACI,OAAO,CAACC,YAAY;IACzD;IACA,OAAOL,eAAI,CAACC,IAAI,CAACT,aAAa;AAChC;AAEO,SAAST,uCACdS,WAAmB,EACnBc,GAAe;QAEIA,mBAAAA;IA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AC,MAAM,CAAC;gBAE3G;YACF;QACF;IACF;IAEA,gDAAgD;IAChD,IAAIyC,QAAQS,QAAQ,EAAE;QACpB,MAAMA,WAAWN,MAAMC,OAAO,CAACJ,QAAQS,QAAQ,IAAIT,QAAQS,QAAQ,GAAG;YAACT,QAAQS,QAAQ;SAAC;QACxF,KAAK,MAAMC,WAAWD,SAAU;YAC9B,IAAI,OAAOC,YAAY,YAAY,CAAEA,CAAAA,mBAAmBC,MAAK,GAAI;gBAC/DxC,QAAG,CAACkC,KAAK,CACPhC,gBAAK,CAACiC,GAAG,CAAC,8EAA8E,EAAEM,OACxFF,SACA,CAAC;YAEP;YAEA,IAAI,OAAOA,YAAY,YAAY,CAACA,QAAQG,UAAU,CAAC,MAAM;gBAC3D1C,QAAG,CAACkC,KAAK,CACPhC,gBAAK,CAACiC,GAAG,CAAC,qEAAqE,EAAEI,QAAQ,CAAC;YAE9F;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/build-cache-providers/index.ts"],"sourcesContent":["import { ExpoConfig, BuildCacheProviderPlugin, BuildCacheProvider, RunOptions } from '@expo/config';\nimport fs from 'fs';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { moduleNameIsDirectFileReference, moduleNameIsPackageReference } from './helpers';\nimport * as Log from '../../log';\nimport { ensureDependenciesAsync } from '../../start/doctor/dependencies/ensureDependenciesAsync';\nimport { CommandError } from '../errors';\n\nconst debug = require('debug')('expo:run:build-cache-provider') as typeof console.log;\n\nexport const resolveBuildCacheProvider = async (\n provider: Required<Required<ExpoConfig>['experiments']>['buildCacheProvider'] | undefined,\n projectRoot: string\n): Promise<BuildCacheProvider | undefined> => {\n if (!provider) {\n return;\n }\n\n if (provider === 'eas') {\n try {\n await ensureDependenciesAsync(projectRoot, {\n isProjectMutable: true,\n installMessage:\n 'eas-build-cache-provider package is required to use the EAS build cache.\\n',\n warningMessage: 'Unable to to use the EAS remote build cache.',\n requiredPackages: [\n {\n pkg: 'eas-build-cache-provider',\n file: 'eas-build-cache-provider/package.json',\n dev: true,\n },\n ],\n });\n\n // We need to manually load dependencies installed on the fly\n const plugin = await manuallyLoadDependency(projectRoot, 'eas-build-cache-provider');\n\n return {\n plugin: plugin.default ?? plugin,\n options: {},\n };\n } catch (error: any) {\n if (error instanceof CommandError) {\n Log.warn(error.message);\n } else {\n throw error;\n }\n return undefined;\n }\n }\n\n if (typeof provider === 'object' && typeof provider.plugin === 'string') {\n const plugin = resolvePluginFunction(projectRoot, provider.plugin);\n\n return { plugin, options: provider.options };\n }\n\n throw new Error('Invalid build cache provider');\n};\n\nexport async function resolveBuildCache({\n projectRoot,\n platform,\n provider,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n runOptions: RunOptions;\n}): Promise<string | null> {\n const fingerprintHash = await calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n });\n if (!fingerprintHash) {\n return null;\n }\n\n if ('resolveRemoteBuildCache' in provider.plugin) {\n Log.warn('The resolveRemoteBuildCache function is deprecated. Use resolveBuildCache instead.');\n return await provider.plugin.resolveRemoteBuildCache(\n { fingerprintHash, platform, runOptions, projectRoot },\n provider.options\n );\n }\n return await provider.plugin.resolveBuildCache(\n { fingerprintHash, platform, runOptions, projectRoot },\n provider.options\n );\n}\n\nexport async function uploadBuildCache({\n projectRoot,\n platform,\n provider,\n buildPath,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n buildPath: string;\n runOptions: RunOptions;\n}): Promise<void> {\n const fingerprintHash = await calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n });\n if (!fingerprintHash) {\n debug('No fingerprint hash found, skipping upload');\n return;\n }\n\n if ('uploadRemoteBuildCache' in provider.plugin) {\n Log.warn('The uploadRemoteBuildCache function is deprecated. Use uploadBuildCache instead.');\n await provider.plugin.uploadRemoteBuildCache(\n {\n projectRoot,\n platform,\n fingerprintHash,\n buildPath,\n runOptions,\n },\n provider.options\n );\n } else {\n await provider.plugin.uploadBuildCache(\n {\n projectRoot,\n platform,\n fingerprintHash,\n buildPath,\n runOptions,\n },\n provider.options\n );\n }\n}\n\nasync function calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n runOptions: RunOptions;\n}): Promise<string | null> {\n if (provider.plugin.calculateFingerprintHash) {\n return await provider.plugin.calculateFingerprintHash(\n { projectRoot, platform, runOptions },\n provider.options\n );\n }\n\n const Fingerprint = importFingerprintForDev(projectRoot);\n if (!Fingerprint) {\n debug('@expo/fingerprint is not installed in the project, unable to calculate fingerprint');\n return null;\n }\n const fingerprint = await Fingerprint.createFingerprintAsync(projectRoot);\n\n return fingerprint.hash;\n}\n\nfunction importFingerprintForDev(projectRoot: string): null | typeof import('@expo/fingerprint') {\n try {\n return require(require.resolve('@expo/fingerprint', { paths: [projectRoot] }));\n } catch (error: any) {\n if ('code' in error && error.code === 'MODULE_NOT_FOUND') {\n return null;\n }\n throw error;\n }\n}\n\n/**\n * Resolve the provider plugin from a node module or package.\n * If the module or package does not include a provider plugin, this function throws.\n * The resolution is done in following order:\n * 1. Is the reference a relative file path or an import specifier with file path? e.g. `./file.js`, `pkg/file.js` or `@org/pkg/file.js`?\n * - Resolve the provider plugin as-is\n * 2. Does the module have a valid provider plugin in the `main` field?\n * - Resolve the `main` entry point as provider plugin\n */\nfunction resolvePluginFilePathForModule(projectRoot: string, pluginReference: string) {\n if (moduleNameIsDirectFileReference(pluginReference)) {\n // Only resolve `./file.js`, `package/file.js`, `@org/package/file.js`\n const pluginScriptFile = resolveFrom.silent(projectRoot, pluginReference);\n if (pluginScriptFile) {\n return pluginScriptFile;\n }\n } else if (moduleNameIsPackageReference(pluginReference)) {\n // Try to resole the `main` entry as config plugin\n return resolveFrom(projectRoot, pluginReference);\n }\n\n throw new Error(\n `Failed to resolve provider plugin for module \"${pluginReference}\" relative to \"${projectRoot}\". Do you have node modules installed?`\n );\n}\n\n// Resolve the module function and assert type\nexport function resolvePluginFunction(\n projectRoot: string,\n pluginReference: string\n): BuildCacheProviderPlugin {\n const pluginFile = resolvePluginFilePathForModule(projectRoot, pluginReference);\n\n try {\n let plugin = require(pluginFile);\n if (plugin?.default != null) {\n plugin = plugin.default;\n }\n\n if (\n typeof plugin !== 'object' ||\n (typeof plugin.resolveRemoteBuildCache !== 'function' &&\n typeof plugin.resolveBuildCache !== 'function') ||\n (typeof plugin.uploadRemoteBuildCache !== 'function' &&\n typeof plugin.uploadBuildCache !== 'function')\n ) {\n throw new Error(`\n The provider plugin \"${pluginReference}\" must export an object containing\n the resolveBuildCache and uploadBuildCache functions.\n `);\n }\n return plugin;\n } catch (error) {\n if (error instanceof SyntaxError) {\n // Add error linking to the docs of how create a valid provider plugin\n }\n throw error;\n }\n}\n\nasync function manuallyLoadDependency(projectRoot: string, packageName: string) {\n const possiblePaths = [\n path.join(projectRoot, 'node_modules'),\n ...(require.resolve.paths(packageName) ?? []),\n ];\n const nodeModulesFolder = possiblePaths?.find((p) => {\n const packagePath = path.join(p, packageName);\n return fs.existsSync(packagePath);\n });\n if (!nodeModulesFolder) {\n throw new Error(`Package ${packageName} not found in ${possiblePaths}`);\n }\n\n const { main } = await import(path.join(nodeModulesFolder, packageName, 'package.json'));\n return import(path.join(nodeModulesFolder, packageName, main));\n}\n"],"names":["resolveBuildCache","resolveBuildCacheProvider","resolvePluginFunction","uploadBuildCache","debug","require","provider","projectRoot","ensureDependenciesAsync","isProjectMutable","installMessage","warningMessage","requiredPackages","pkg","file","dev","plugin","manuallyLoadDependency","default","options","error","CommandError","Log","warn","message","undefined","Error","platform","runOptions","fingerprintHash","calculateFingerprintHashAsync","resolveRemoteBuildCache","buildPath","uploadRemoteBuildCache","calculateFingerprintHash","Fingerprint","importFingerprintForDev","fingerprint","createFingerprintAsync","hash","resolve","paths","code","resolvePluginFilePathForModule","pluginReference","moduleNameIsDirectFileReference","pluginScriptFile","resolveFrom","silent","moduleNameIsPackageReference","pluginFile","SyntaxError","packageName","possiblePaths","path","join","nodeModulesFolder","find","p","packagePath","fs","existsSync","main"],"mappings":";;;;;;;;;;;IA8DsBA,iBAAiB;eAAjBA;;IAlDTC,yBAAyB;eAAzBA;;IAwMGC,qBAAqB;eAArBA;;IApHMC,gBAAgB;eAAhBA;;;;gEA/FP;;;;;;;gEACE;;;;;;;gEACO;;;;;;yBAEsD;6DACzD;yCACmB;wBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,MAAMC,QAAQC,QAAQ,SAAS;AAExB,MAAMJ,4BAA4B,OACvCK,UACAC;IAEA,IAAI,CAACD,UAAU;QACb;IACF;IAEA,IAAIA,aAAa,OAAO;QACtB,IAAI;YACF,MAAME,IAAAA,gDAAuB,EAACD,aAAa;gBACzCE,kBAAkB;gBAClBC,gBACE;gBACFC,gBAAgB;gBAChBC,kBAAkB;oBAChB;wBACEC,KAAK;wBACLC,MAAM;wBACNC,KAAK;oBACP;iBACD;YACH;YAEA,6DAA6D;YAC7D,MAAMC,SAAS,MAAMC,uBAAuBV,aAAa;YAEzD,OAAO;gBACLS,QAAQA,OAAOE,OAAO,IAAIF;gBAC1BG,SAAS,CAAC;YACZ;QACF,EAAE,OAAOC,OAAY;YACnB,IAAIA,iBAAiBC,oBAAY,EAAE;gBACjCC,KAAIC,IAAI,CAACH,MAAMI,OAAO;YACxB,OAAO;gBACL,MAAMJ;YACR;YACA,OAAOK;QACT;IACF;IAEA,IAAI,OAAOnB,aAAa,YAAY,OAAOA,SAASU,MAAM,KAAK,UAAU;QACvE,MAAMA,SAASd,sBAAsBK,aAAaD,SAASU,MAAM;QAEjE,OAAO;YAAEA;YAAQG,SAASb,SAASa,OAAO;QAAC;IAC7C;IAEA,MAAM,IAAIO,MAAM;AAClB;AAEO,eAAe1B,kBAAkB,EACtCO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rC;YACA,MAAM,IAAIuB,MAAM,CAAC;6BACM,EAAEkB,gBAAgB;;MAEzC,CAAC;QACH;QACA,OAAO5B;IACT,EAAE,OAAOI,OAAO;QACd,IAAIA,iBAAiB+B,aAAa;QAChC,sEAAsE;QACxE;QACA,MAAM/B;IACR;AACF;AAEA,eAAeH,uBAAuBV,WAAmB,EAAE6C,WAAmB;IAC5E,MAAMC,gBAAgB;QACpBC,eAAI,CAACC,IAAI,CAAChD,aAAa;WACnBF,QAAQmC,OAAO,CAACC,KAAK,CAACW,gBAAgB,EAAE;KAC7C;IACD,MAAMI,oBAAoBH,iCAAAA,cAAeI,IAAI,CAAC,CAACC;QAC7C,MAAMC,cAAcL,eAAI,CAACC,IAAI,CAACG,GAAGN;QACjC,OAAOQ,aAAE,CAACC,UAAU,CAACF;IACvB;IACA,IAAI,CAACH,mBAAmB;QACtB,MAAM,IAAI9B,MAAM,CAAC,QAAQ,EAAE0B,YAAY,cAAc,EAAEC,eAAe;IACxE;IAEA,MAAM,EAAES,IAAI,EAAE,GAAG,MAAM,gBAAOR,eAAI,CAACC,IAAI,CAACC,mBAAmBJ,aAAa,mEAAjD;IACvB,OAAO,gBAAOE,eAAI,CAACC,IAAI,CAACC,mBAAmBJ,aAAaU,yDAAjD;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/build-cache-providers/index.ts"],"sourcesContent":["import { ExpoConfig, BuildCacheProviderPlugin, BuildCacheProvider, RunOptions } from '@expo/config';\nimport fs from 'fs';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { moduleNameIsDirectFileReference, moduleNameIsPackageReference } from './helpers';\nimport * as Log from '../../log';\nimport { ensureDependenciesAsync } from '../../start/doctor/dependencies/ensureDependenciesAsync';\nimport { CommandError } from '../errors';\n\nconst debug = require('debug')('expo:run:build-cache-provider') as typeof console.log;\n\nexport const resolveBuildCacheProvider = async (\n provider: Required<ExpoConfig>['buildCacheProvider'] | undefined,\n projectRoot: string\n): Promise<BuildCacheProvider | undefined> => {\n if (!provider) {\n return;\n }\n\n if (provider === 'eas') {\n try {\n await ensureDependenciesAsync(projectRoot, {\n isProjectMutable: true,\n installMessage:\n 'eas-build-cache-provider package is required to use the EAS build cache.\\n',\n warningMessage: 'Unable to to use the EAS remote build cache.',\n requiredPackages: [\n {\n pkg: 'eas-build-cache-provider',\n file: 'eas-build-cache-provider/package.json',\n dev: true,\n },\n ],\n });\n\n // We need to manually load dependencies installed on the fly\n const plugin = await manuallyLoadDependency(projectRoot, 'eas-build-cache-provider');\n\n return {\n plugin: plugin.default ?? plugin,\n options: {},\n };\n } catch (error: any) {\n if (error instanceof CommandError) {\n Log.warn(error.message);\n } else {\n throw error;\n }\n return undefined;\n }\n }\n\n if (typeof provider === 'object' && typeof provider.plugin === 'string') {\n const plugin = resolvePluginFunction(projectRoot, provider.plugin);\n\n return { plugin, options: provider.options };\n }\n\n throw new Error('Invalid build cache provider');\n};\n\nexport async function resolveBuildCache({\n projectRoot,\n platform,\n provider,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n runOptions: RunOptions;\n}): Promise<string | null> {\n const fingerprintHash = await calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n });\n if (!fingerprintHash) {\n return null;\n }\n\n if ('resolveRemoteBuildCache' in provider.plugin) {\n Log.warn('The resolveRemoteBuildCache function is deprecated. Use resolveBuildCache instead.');\n return await provider.plugin.resolveRemoteBuildCache(\n { fingerprintHash, platform, runOptions, projectRoot },\n provider.options\n );\n }\n return await provider.plugin.resolveBuildCache(\n { fingerprintHash, platform, runOptions, projectRoot },\n provider.options\n );\n}\n\nexport async function uploadBuildCache({\n projectRoot,\n platform,\n provider,\n buildPath,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n buildPath: string;\n runOptions: RunOptions;\n}): Promise<void> {\n const fingerprintHash = await calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n });\n if (!fingerprintHash) {\n debug('No fingerprint hash found, skipping upload');\n return;\n }\n\n if ('uploadRemoteBuildCache' in provider.plugin) {\n Log.warn('The uploadRemoteBuildCache function is deprecated. Use uploadBuildCache instead.');\n await provider.plugin.uploadRemoteBuildCache(\n {\n projectRoot,\n platform,\n fingerprintHash,\n buildPath,\n runOptions,\n },\n provider.options\n );\n } else {\n await provider.plugin.uploadBuildCache(\n {\n projectRoot,\n platform,\n fingerprintHash,\n buildPath,\n runOptions,\n },\n provider.options\n );\n }\n}\n\nasync function calculateFingerprintHashAsync({\n projectRoot,\n platform,\n provider,\n runOptions,\n}: {\n projectRoot: string;\n platform: 'android' | 'ios';\n provider: BuildCacheProvider;\n runOptions: RunOptions;\n}): Promise<string | null> {\n if (provider.plugin.calculateFingerprintHash) {\n return await provider.plugin.calculateFingerprintHash(\n { projectRoot, platform, runOptions },\n provider.options\n );\n }\n\n const Fingerprint = importFingerprintForDev(projectRoot);\n if (!Fingerprint) {\n debug('@expo/fingerprint is not installed in the project, unable to calculate fingerprint');\n return null;\n }\n const fingerprint = await Fingerprint.createFingerprintAsync(projectRoot);\n\n return fingerprint.hash;\n}\n\nfunction importFingerprintForDev(projectRoot: string): null | typeof import('@expo/fingerprint') {\n try {\n return require(require.resolve('@expo/fingerprint', { paths: [projectRoot] }));\n } catch (error: any) {\n if ('code' in error && error.code === 'MODULE_NOT_FOUND') {\n return null;\n }\n throw error;\n }\n}\n\n/**\n * Resolve the provider plugin from a node module or package.\n * If the module or package does not include a provider plugin, this function throws.\n * The resolution is done in following order:\n * 1. Is the reference a relative file path or an import specifier with file path? e.g. `./file.js`, `pkg/file.js` or `@org/pkg/file.js`?\n * - Resolve the provider plugin as-is\n * 2. Does the module have a valid provider plugin in the `main` field?\n * - Resolve the `main` entry point as provider plugin\n */\nfunction resolvePluginFilePathForModule(projectRoot: string, pluginReference: string) {\n if (moduleNameIsDirectFileReference(pluginReference)) {\n // Only resolve `./file.js`, `package/file.js`, `@org/package/file.js`\n const pluginScriptFile = resolveFrom.silent(projectRoot, pluginReference);\n if (pluginScriptFile) {\n return pluginScriptFile;\n }\n } else if (moduleNameIsPackageReference(pluginReference)) {\n // Try to resole the `main` entry as config plugin\n return resolveFrom(projectRoot, pluginReference);\n }\n\n throw new Error(\n `Failed to resolve provider plugin for module \"${pluginReference}\" relative to \"${projectRoot}\". Do you have node modules installed?`\n );\n}\n\n// Resolve the module function and assert type\nexport function resolvePluginFunction(\n projectRoot: string,\n pluginReference: string\n): BuildCacheProviderPlugin {\n const pluginFile = resolvePluginFilePathForModule(projectRoot, pluginReference);\n\n try {\n let plugin = require(pluginFile);\n if (plugin?.default != null) {\n plugin = plugin.default;\n }\n\n if (\n typeof plugin !== 'object' ||\n (typeof plugin.resolveRemoteBuildCache !== 'function' &&\n typeof plugin.resolveBuildCache !== 'function') ||\n (typeof plugin.uploadRemoteBuildCache !== 'function' &&\n typeof plugin.uploadBuildCache !== 'function')\n ) {\n throw new Error(`\n The provider plugin \"${pluginReference}\" must export an object containing\n the resolveBuildCache and uploadBuildCache functions.\n `);\n }\n return plugin;\n } catch (error) {\n if (error instanceof SyntaxError) {\n // Add error linking to the docs of how create a valid provider plugin\n }\n throw error;\n }\n}\n\nasync function manuallyLoadDependency(projectRoot: string, packageName: string) {\n const possiblePaths = [\n path.join(projectRoot, 'node_modules'),\n ...(require.resolve.paths(packageName) ?? []),\n ];\n const nodeModulesFolder = possiblePaths?.find((p) => {\n const packagePath = path.join(p, packageName);\n return fs.existsSync(packagePath);\n });\n if (!nodeModulesFolder) {\n throw new Error(`Package ${packageName} not found in ${possiblePaths}`);\n }\n\n const { main } = await import(path.join(nodeModulesFolder, packageName, 'package.json'));\n return import(path.join(nodeModulesFolder, packageName, main));\n}\n"],"names":["resolveBuildCache","resolveBuildCacheProvider","resolvePluginFunction","uploadBuildCache","debug","require","provider","projectRoot","ensureDependenciesAsync","isProjectMutable","installMessage","warningMessage","requiredPackages","pkg","file","dev","plugin","manuallyLoadDependency","default","options","error","CommandError","Log","warn","message","undefined","Error","platform","runOptions","fingerprintHash","calculateFingerprintHashAsync","resolveRemoteBuildCache","buildPath","uploadRemoteBuildCache","calculateFingerprintHash","Fingerprint","importFingerprintForDev","fingerprint","createFingerprintAsync","hash","resolve","paths","code","resolvePluginFilePathForModule","pluginReference","moduleNameIsDirectFileReference","pluginScriptFile","resolveFrom","silent","moduleNameIsPackageReference","pluginFile","SyntaxError","packageName","possiblePaths","path","join","nodeModulesFolder","find","p","packagePath","fs","existsSync","main"],"mappings":";;;;;;;;;;;IA8DsBA,iBAAiB;eAAjBA;;IAlDTC,yBAAyB;eAAzBA;;IAwMGC,qBAAqB;eAArBA;;IApHMC,gBAAgB;eAAhBA;;;;gEA/FP;;;;;;;gEACE;;;;;;;gEACO;;;;;;yBAEsD;6DACzD;yCACmB;wBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,MAAMC,QAAQC,QAAQ,SAAS;AAExB,MAAMJ,4BAA4B,OACvCK,UACAC;IAEA,IAAI,CAACD,UAAU;QACb;IACF;IAEA,IAAIA,aAAa,OAAO;QACtB,IAAI;YACF,MAAME,IAAAA,gDAAuB,EAACD,aAAa;gBACzCE,kBAAkB;gBAClBC,gBACE;gBACFC,gBAAgB;gBAChBC,kBAAkB;oBAChB;wBACEC,KAAK;wBACLC,MAAM;wBACNC,KAAK;oBACP;iBACD;YACH;YAEA,6DAA6D;YAC7D,MAAMC,SAAS,MAAMC,uBAAuBV,aAAa;YAEzD,OAAO;gBACLS,QAAQA,OAAOE,OAAO,IAAIF;gBAC1BG,SAAS,CAAC;YACZ;QACF,EAAE,OAAOC,OAAY;YACnB,IAAIA,iBAAiBC,oBAAY,EAAE;gBACjCC,KAAIC,IAAI,CAACH,MAAMI,OAAO;YACxB,OAAO;gBACL,MAAMJ;YACR;YACA,OAAOK;QACT;IACF;IAEA,IAAI,OAAOnB,aAAa,YAAY,OAAOA,SAASU,MAAM,KA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QACzB;QAEA,IACE,OAAOF,WAAW,YACjB,OAAOA,OAAOe,uBAAuB,KAAK,cACzC,OAAOf,OAAOhB,iBAAiB,KAAK,cACrC,OAAOgB,OAAOiB,sBAAsB,KAAK,cACxC,OAAOjB,OAAOb,gBAAgB,KAAK,YACrC;YACA,MAAM,IAAIuB,MAAM,CAAC;6BACM,EAAEkB,gBAAgB;;MAEzC,CAAC;QACH;QACA,OAAO5B;IACT,EAAE,OAAOI,OAAO;QACd,IAAIA,iBAAiB+B,aAAa;QAChC,sEAAsE;QACxE;QACA,MAAM/B;IACR;AACF;AAEA,eAAeH,uBAAuBV,WAAmB,EAAE6C,WAAmB;IAC5E,MAAMC,gBAAgB;QACpBC,eAAI,CAACC,IAAI,CAAChD,aAAa;WACnBF,QAAQmC,OAAO,CAACC,KAAK,CAACW,gBAAgB,EAAE;KAC7C;IACD,MAAMI,oBAAoBH,iCAAAA,cAAeI,IAAI,CAAC,CAACC;QAC7C,MAAMC,cAAcL,eAAI,CAACC,IAAI,CAACG,GAAGN;QACjC,OAAOQ,aAAE,CAACC,UAAU,CAACF;IACvB;IACA,IAAI,CAACH,mBAAmB;QACtB,MAAM,IAAI9B,MAAM,CAAC,QAAQ,EAAE0B,YAAY,cAAc,EAAEC,eAAe;IACxE;IAEA,MAAM,EAAES,IAAI,EAAE,GAAG,MAAM,gBAAOR,eAAI,CAACC,IAAI,CAACC,mBAAmBJ,aAAa,mEAAjD;IACvB,OAAO,gBAAOE,eAAI,CAACC,IAAI,CAACC,mBAAmBJ,aAAaU,yDAAjD;AACT"}
|
|
@@ -33,7 +33,7 @@ class FetchClient {
|
|
|
33
33
|
this.headers = {
|
|
34
34
|
accept: 'application/json',
|
|
35
35
|
'content-type': 'application/json',
|
|
36
|
-
'user-agent': `expo-cli/${"0.26.
|
|
36
|
+
'user-agent': `expo-cli/${"0.26.8"}`,
|
|
37
37
|
authorization: 'Basic ' + _nodebuffer().Buffer.from(`${target}:`).toString('base64')
|
|
38
38
|
};
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/cli",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.8",
|
|
4
4
|
"description": "The Expo CLI",
|
|
5
5
|
"main": "build/bin/cli",
|
|
6
6
|
"bin": {
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@0no-co/graphql.web": "^1.0.8",
|
|
44
44
|
"@expo/code-signing-certificates": "^0.0.5",
|
|
45
|
-
"@expo/config": "~12.0.
|
|
46
|
-
"@expo/config-plugins": "~11.0.
|
|
45
|
+
"@expo/config": "~12.0.7",
|
|
46
|
+
"@expo/config-plugins": "~11.0.7",
|
|
47
47
|
"@expo/devcert": "^1.1.2",
|
|
48
|
-
"@expo/env": "~2.0.
|
|
49
|
-
"@expo/image-utils": "^0.8.
|
|
50
|
-
"@expo/json-file": "^10.0.
|
|
48
|
+
"@expo/env": "~2.0.6",
|
|
49
|
+
"@expo/image-utils": "^0.8.6",
|
|
50
|
+
"@expo/json-file": "^10.0.6",
|
|
51
51
|
"@expo/metro": "~0.1.1",
|
|
52
|
-
"@expo/metro-config": "~0.21.
|
|
53
|
-
"@expo/osascript": "^2.3.
|
|
54
|
-
"@expo/package-manager": "^1.9.
|
|
55
|
-
"@expo/plist": "^0.4.
|
|
56
|
-
"@expo/prebuild-config": "^10.0.
|
|
57
|
-
"@expo/schema-utils": "^0.1.
|
|
58
|
-
"@expo/server": "^0.7.
|
|
52
|
+
"@expo/metro-config": "~0.21.9",
|
|
53
|
+
"@expo/osascript": "^2.3.6",
|
|
54
|
+
"@expo/package-manager": "^1.9.6",
|
|
55
|
+
"@expo/plist": "^0.4.6",
|
|
56
|
+
"@expo/prebuild-config": "^10.0.8",
|
|
57
|
+
"@expo/schema-utils": "^0.1.6",
|
|
58
|
+
"@expo/server": "^0.7.3",
|
|
59
59
|
"@expo/spawn-async": "^1.7.2",
|
|
60
60
|
"@expo/ws-tunnel": "^1.0.1",
|
|
61
61
|
"@expo/xcpretty": "^4.3.0",
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"tree-kill": "^1.2.2",
|
|
168
168
|
"tsd": "^0.28.1"
|
|
169
169
|
},
|
|
170
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "f97e6d1cae0cb14d5eed1b08fad6d12a7144af3a"
|
|
171
171
|
}
|