@expo/cli 0.10.6 → 0.10.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.
Files changed (39) hide show
  1. package/build/bin/cli +2 -2
  2. package/build/src/prebuild/updatePackageJson.js +1 -1
  3. package/build/src/prebuild/updatePackageJson.js.map +1 -1
  4. package/build/src/start/server/metro/inspector-proxy/device.js +21 -2
  5. package/build/src/start/server/metro/inspector-proxy/device.js.map +1 -1
  6. package/build/src/start/server/metro/inspector-proxy/handlers/DebuggerScriptSource.js.map +1 -1
  7. package/build/src/start/server/metro/inspector-proxy/handlers/NetworkResponse.js.map +1 -1
  8. package/build/src/start/server/metro/inspector-proxy/handlers/PageReload.js.map +1 -1
  9. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.js +22 -0
  10. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.js.map +1 -0
  11. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerScriptParsed.js +55 -0
  12. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerScriptParsed.js.map +1 -0
  13. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerSetBreakpointByUrl.js +17 -0
  14. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerSetBreakpointByUrl.js.map +1 -0
  15. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeGetProperties.js +39 -0
  16. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeGetProperties.js.map +1 -0
  17. package/build/src/start/server/metro/inspector-proxy/handlers/types.js.map +1 -1
  18. package/build/src/start/server/metro/inspector-proxy/proxy.js +14 -6
  19. package/build/src/start/server/metro/inspector-proxy/proxy.js.map +1 -1
  20. package/build/src/start/server/metro/runServer-fork.js +4 -5
  21. package/build/src/start/server/metro/runServer-fork.js.map +1 -1
  22. package/build/src/start/server/metro/withMetroMultiPlatform.js +2 -1
  23. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
  24. package/build/src/start/server/middleware/ClassicManifestMiddleware.js +1 -1
  25. package/build/src/start/server/middleware/HistoryFallbackMiddleware.js +0 -29
  26. package/build/src/start/server/middleware/HistoryFallbackMiddleware.js.map +1 -1
  27. package/build/src/start/server/middleware/server.types.js.map +1 -1
  28. package/build/src/start/server/type-generation/__typetests__/fixtures/basic.js +38 -0
  29. package/build/src/start/server/type-generation/__typetests__/fixtures/basic.js.map +1 -0
  30. package/build/src/start/server/type-generation/__typetests__/generateFixtures.js +38 -0
  31. package/build/src/start/server/type-generation/__typetests__/generateFixtures.js.map +1 -0
  32. package/build/src/start/server/type-generation/__typetests__/route.test.js +165 -0
  33. package/build/src/start/server/type-generation/__typetests__/route.test.js.map +1 -0
  34. package/build/src/start/server/type-generation/routes.js +175 -62
  35. package/build/src/start/server/type-generation/routes.js.map +1 -1
  36. package/build/src/utils/analytics/rudderstackClient.js +2 -2
  37. package/package.json +11 -9
  38. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeCompat.js +0 -63
  39. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeCompat.js.map +0 -1
package/build/bin/cli CHANGED
@@ -132,7 +132,7 @@ const args = (0, _arg).default({
132
132
  });
133
133
  if (args["--version"]) {
134
134
  // Version is added in the build script.
135
- console.log("0.10.6");
135
+ console.log("0.10.8");
136
136
  process.exit(0);
137
137
  }
138
138
  if (args["--non-interactive"]) {
@@ -262,7 +262,7 @@ commands[command]().then((exec)=>{
262
262
  logEventAsync("action", {
263
263
  action: `expo ${command}`,
264
264
  source: "expo/cli",
265
- source_version: "0.10.6"
265
+ source_version: "0.10.8"
266
266
  });
267
267
  });
268
268
 
@@ -206,7 +206,7 @@ function createFileHash(contents) {
206
206
  */ function versionRangesIntersect(rangeA, rangeB) {
207
207
  try {
208
208
  return (0, _semver).intersects(rangeA, rangeB);
209
- } finally{
209
+ } catch {
210
210
  return false;
211
211
  }
212
212
  }
@@ -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 /** Indicates that new values were added to the `dependencies` object in the `package.json`. */\n hasNewDependencies: boolean;\n /** Indicates that new values were added to the `devDependencies` object in the `package.json`. */\n hasNewDevDependencies: boolean;\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 pkg,\n skipDependencyUpdate,\n }: {\n templateDirectory: string;\n pkg: PackageJSONConfig;\n skipDependencyUpdate?: string[];\n }\n): Promise<DependenciesModificationResults> {\n const updatingPackageJsonStep = logNewSection(\n 'Updating your package.json scripts, dependencies, and main file'\n );\n\n const templatePkg = getPackageJson(templateDirectory);\n\n const results = modifyPackageJson(projectRoot, {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n });\n\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 updatingPackageJsonStep.succeed(\n 'Updated package.json and added index.js entry point for iOS and Android'\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` and `devDependencies`.\n * 3. Update `package.json` `main`.\n *\n * @param projectRoot The root directory of the project.\n * @param props.templatePkg Template project package.json as JSON.\n * @param props.pkg Current package.json as JSON.\n * @param props.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 skipDependencyUpdate?: string[];\n }\n) {\n updatePkgScripts({ pkg });\n\n // TODO: Move to `npx expo-doctor`\n return updatePkgDependencies(projectRoot, {\n pkg,\n templatePkg,\n skipDependencyUpdate,\n });\n}\n\n/**\n * Update package.json dependencies by combining the dependencies in the project we are ejecting\n * with the dependencies in the template project. Does the same for devDependencies.\n *\n * - The template may have some dependencies beyond react/react-native/react-native-unimodules,\n * for example RNGH and Reanimated. We should prefer the version that is already being used\n * in the project for those, but swap the react/react-native/react-native-unimodules versions\n * with the ones in the template.\n * - The same applies to expo-updates -- since some native project configuration may depend on the\n * version, we should always use the version of expo-updates in the template.\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 if (!pkg.devDependencies) {\n pkg.devDependencies = {};\n }\n const { dependencies, devDependencies } = templatePkg;\n const defaultDependencies = createDependenciesMap(dependencies);\n const defaultDevDependencies = createDependenciesMap(devDependencies);\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 = ['expo', 'expo-splash-screen', 'react', 'react-native'].filter(\n (depKey) => !!defaultDependencies[depKey]\n );\n\n const symlinkedPackages: string[] = [];\n const nonRecommendedPackages: string[] = [];\n\n for (const dependenciesKey of requiredDependencies) {\n // If the local package.json defined the dependency that we want to overwrite...\n if (pkg.dependencies?.[dependenciesKey]) {\n // Then ensure it isn't symlinked (i.e. the user has a custom version in their yarn workspace).\n if (isModuleSymlinked(projectRoot, { moduleId: dependenciesKey, isSilent: true })) {\n // If the package is in the project's package.json and it's symlinked, then skip overwriting it.\n symlinkedPackages.push(dependenciesKey);\n continue;\n }\n\n // Do not modify manually skipped dependencies\n if (skipDependencyUpdate.includes(dependenciesKey)) {\n continue;\n }\n\n // Warn users for outdated dependencies when prebuilding\n const hasRecommendedVersion = versionRangesIntersect(\n pkg.dependencies[dependenciesKey],\n String(defaultDependencies[dependenciesKey])\n );\n if (!hasRecommendedVersion) {\n nonRecommendedPackages.push(`${dependenciesKey}@${defaultDependencies[dependenciesKey]}`);\n }\n }\n }\n\n if (symlinkedPackages.length) {\n Log.log(\n `\\u203A Using symlinked ${symlinkedPackages\n .map((pkg) => chalk.bold(pkg))\n .join(', ')} instead of recommended version(s).`\n );\n }\n\n if (nonRecommendedPackages.length) {\n Log.warn(\n `\\u203A Using current versions instead of recommended ${nonRecommendedPackages\n .map((pkg) => chalk.bold(pkg))\n .join(', ')}.`\n );\n }\n\n const combinedDevDependencies: DependenciesMap = createDependenciesMap({\n ...defaultDevDependencies,\n ...pkg.devDependencies,\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 const hasNewDevDependencies =\n hashForDependencyMap(pkg.devDependencies) !== hashForDependencyMap(combinedDevDependencies);\n // Save the dependencies\n if (hasNewDependencies) {\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 if (hasNewDevDependencies) {\n // Same as with dependencies\n pkg.devDependencies = Object.assign(pkg.devDependencies ?? {}, combinedDevDependencies);\n }\n\n return {\n hasNewDependencies,\n hasNewDevDependencies,\n };\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 * Update package.json scripts - `npm start` should default to `expo\n * start --dev-client` rather than `expo start` after ejecting, for example.\n */\nfunction updatePkgScripts({ pkg }: { pkg: PackageJSONConfig }) {\n if (!pkg.scripts) {\n pkg.scripts = {};\n }\n if (!pkg.scripts.android?.includes('run')) {\n pkg.scripts.android = 'expo run:android';\n }\n if (!pkg.scripts.ios?.includes('run')) {\n pkg.scripts.ios = 'expo run:ios';\n }\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 } finally {\n return false;\n }\n}\n"],"names":["updatePackageJSONAsync","updatePkgDependencies","createDependenciesMap","hashForDependencyMap","createFileHash","Log","projectRoot","templateDirectory","pkg","skipDependencyUpdate","updatingPackageJsonStep","logNewSection","templatePkg","getPackageJson","results","modifyPackageJson","fs","promises","writeFile","path","resolve","JSON","stringify","succeed","updatePkgScripts","devDependencies","dependencies","defaultDependencies","defaultDevDependencies","combinedDependencies","requiredDependencies","filter","depKey","symlinkedPackages","nonRecommendedPackages","dependenciesKey","isModuleSymlinked","moduleId","isSilent","push","includes","hasRecommendedVersion","versionRangesIntersect","String","length","log","map","chalk","bold","join","warn","combinedDevDependencies","hasNewDependencies","hasNewDevDependencies","Object","assign","Error","outputMap","key","keys","value","scripts","android","ios","normalizeDependencyMap","deps","dependency","sort","depsList","depsString","contents","crypto","createHash","update","digest","rangeA","rangeB","semverIntersects"],"mappings":"AAAA;;;;QAqBsBA,sBAAsB,GAAtBA,sBAAsB;QAsF5BC,qBAAqB,GAArBA,qBAAqB;QA0GrBC,qBAAqB,GAArBA,qBAAqB;QA8CrBC,oBAAoB,GAApBA,oBAAoB;QAMpBC,cAAc,GAAdA,cAAc;AAzQoB,IAAA,OAAc,WAAd,cAAc,CAAA;AAC9C,IAAA,MAAO,kCAAP,OAAO,EAAA;AACN,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACZ,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AAC8C,IAAA,OAAQ,WAAR,QAAQ,CAAA;AAEjEC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACmB,IAAA,kBAA4B,WAA5B,4BAA4B,CAAA;AAChC,IAAA,IAAc,WAAd,cAAc,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYrC,eAAeL,sBAAsB,CAC1CM,WAAmB,EACnB,EACEC,iBAAiB,CAAA,EACjBC,GAAG,CAAA,EACHC,oBAAoB,CAAA,EAKrB,EACyC;IAC1C,MAAMC,uBAAuB,GAAGC,CAAAA,GAAAA,IAAa,AAE5C,CAAA,cAF4C,CAC3C,iEAAiE,CAClE,AAAC;IAEF,MAAMC,WAAW,GAAGC,CAAAA,GAAAA,OAAc,AAAmB,CAAA,eAAnB,CAACN,iBAAiB,CAAC,AAAC;IAEtD,MAAMO,OAAO,GAAGC,iBAAiB,C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{"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 /** Indicates that new values were added to the `dependencies` object in the `package.json`. */\n hasNewDependencies: boolean;\n /** Indicates that new values were added to the `devDependencies` object in the `package.json`. */\n hasNewDevDependencies: boolean;\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 pkg,\n skipDependencyUpdate,\n }: {\n templateDirectory: string;\n pkg: PackageJSONConfig;\n skipDependencyUpdate?: string[];\n }\n): Promise<DependenciesModificationResults> {\n const updatingPackageJsonStep = logNewSection(\n 'Updating your package.json scripts, dependencies, and main file'\n );\n\n const templatePkg = getPackageJson(templateDirectory);\n\n const results = modifyPackageJson(projectRoot, {\n templatePkg,\n pkg,\n skipDependencyUpdate,\n });\n\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 updatingPackageJsonStep.succeed(\n 'Updated package.json and added index.js entry point for iOS and Android'\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` and `devDependencies`.\n * 3. Update `package.json` `main`.\n *\n * @param projectRoot The root directory of the project.\n * @param props.templatePkg Template project package.json as JSON.\n * @param props.pkg Current package.json as JSON.\n * @param props.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 skipDependencyUpdate?: string[];\n }\n) {\n updatePkgScripts({ pkg });\n\n // TODO: Move to `npx expo-doctor`\n return updatePkgDependencies(projectRoot, {\n pkg,\n templatePkg,\n skipDependencyUpdate,\n });\n}\n\n/**\n * Update package.json dependencies by combining the dependencies in the project we are ejecting\n * with the dependencies in the template project. Does the same for devDependencies.\n *\n * - The template may have some dependencies beyond react/react-native/react-native-unimodules,\n * for example RNGH and Reanimated. We should prefer the version that is already being used\n * in the project for those, but swap the react/react-native/react-native-unimodules versions\n * with the ones in the template.\n * - The same applies to expo-updates -- since some native project configuration may depend on the\n * version, we should always use the version of expo-updates in the template.\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 if (!pkg.devDependencies) {\n pkg.devDependencies = {};\n }\n const { dependencies, devDependencies } = templatePkg;\n const defaultDependencies = createDependenciesMap(dependencies);\n const defaultDevDependencies = createDependenciesMap(devDependencies);\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 = ['expo', 'expo-splash-screen', 'react', 'react-native'].filter(\n (depKey) => !!defaultDependencies[depKey]\n );\n\n const symlinkedPackages: string[] = [];\n const nonRecommendedPackages: string[] = [];\n\n for (const dependenciesKey of requiredDependencies) {\n // If the local package.json defined the dependency that we want to overwrite...\n if (pkg.dependencies?.[dependenciesKey]) {\n // Then ensure it isn't symlinked (i.e. the user has a custom version in their yarn workspace).\n if (isModuleSymlinked(projectRoot, { moduleId: dependenciesKey, isSilent: true })) {\n // If the package is in the project's package.json and it's symlinked, then skip overwriting it.\n symlinkedPackages.push(dependenciesKey);\n continue;\n }\n\n // Do not modify manually skipped dependencies\n if (skipDependencyUpdate.includes(dependenciesKey)) {\n continue;\n }\n\n // Warn users for outdated dependencies when prebuilding\n const hasRecommendedVersion = versionRangesIntersect(\n pkg.dependencies[dependenciesKey],\n String(defaultDependencies[dependenciesKey])\n );\n if (!hasRecommendedVersion) {\n nonRecommendedPackages.push(`${dependenciesKey}@${defaultDependencies[dependenciesKey]}`);\n }\n }\n }\n\n if (symlinkedPackages.length) {\n Log.log(\n `\\u203A Using symlinked ${symlinkedPackages\n .map((pkg) => chalk.bold(pkg))\n .join(', ')} instead of recommended version(s).`\n );\n }\n\n if (nonRecommendedPackages.length) {\n Log.warn(\n `\\u203A Using current versions instead of recommended ${nonRecommendedPackages\n .map((pkg) => chalk.bold(pkg))\n .join(', ')}.`\n );\n }\n\n const combinedDevDependencies: DependenciesMap = createDependenciesMap({\n ...defaultDevDependencies,\n ...pkg.devDependencies,\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 const hasNewDevDependencies =\n hashForDependencyMap(pkg.devDependencies) !== hashForDependencyMap(combinedDevDependencies);\n // Save the dependencies\n if (hasNewDependencies) {\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 if (hasNewDevDependencies) {\n // Same as with dependencies\n pkg.devDependencies = Object.assign(pkg.devDependencies ?? {}, combinedDevDependencies);\n }\n\n return {\n hasNewDependencies,\n hasNewDevDependencies,\n };\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 * Update package.json scripts - `npm start` should default to `expo\n * start --dev-client` rather than `expo start` after ejecting, for example.\n */\nfunction updatePkgScripts({ pkg }: { pkg: PackageJSONConfig }) {\n if (!pkg.scripts) {\n pkg.scripts = {};\n }\n if (!pkg.scripts.android?.includes('run')) {\n pkg.scripts.android = 'expo run:android';\n }\n if (!pkg.scripts.ios?.includes('run')) {\n pkg.scripts.ios = 'expo run:ios';\n }\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":["updatePackageJSONAsync","updatePkgDependencies","createDependenciesMap","hashForDependencyMap","createFileHash","Log","projectRoot","templateDirectory","pkg","skipDependencyUpdate","updatingPackageJsonStep","logNewSection","templatePkg","getPackageJson","results","modifyPackageJson","fs","promises","writeFile","path","resolve","JSON","stringify","succeed","updatePkgScripts","devDependencies","dependencies","defaultDependencies","defaultDevDependencies","combinedDependencies","requiredDependencies","filter","depKey","symlinkedPackages","nonRecommendedPackages","dependenciesKey","isModuleSymlinked","moduleId","isSilent","push","includes","hasRecommendedVersion","versionRangesIntersect","String","length","log","map","chalk","bold","join","warn","combinedDevDependencies","hasNewDependencies","hasNewDevDependencies","Object","assign","Error","outputMap","key","keys","value","scripts","android","ios","normalizeDependencyMap","deps","dependency","sort","depsList","depsString","contents","crypto","createHash","update","digest","rangeA","rangeB","semverIntersects"],"mappings":"AAAA;;;;QAqBsBA,sBAAsB,GAAtBA,sBAAsB;QAsF5BC,qBAAqB,GAArBA,qBAAqB;QA0GrBC,qBAAqB,GAArBA,qBAAqB;QA8CrBC,oBAAoB,GAApBA,oBAAoB;QAMpBC,cAAc,GAAdA,cAAc;AAzQoB,IAAA,OAAc,WAAd,cAAc,CAAA;AAC9C,IAAA,MAAO,kCAAP,OAAO,EAAA;AACN,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACZ,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AAC8C,IAAA,OAAQ,WAAR,QAAQ,CAAA;AAEjEC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACmB,IAAA,kBAA4B,WAA5B,4BAA4B,CAAA;AAChC,IAAA,IAAc,WAAd,cAAc,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYrC,eAAeL,sBAAsB,CAC1CM,WAAmB,EACnB,EACEC,iBAAiB,CAAA,EACjBC,GAAG,CAAA,EACHC,oBAAoB,CAAA,EAKrB,EACyC;IAC1C,MAAMC,uBAAuB,GAAGC,CAAAA,GAAAA,IAAa,AAE5C,CAAA,cAF4C,CAC3C,iEAAiE,CAClE,AAAC;IAEF,MAAMC,WAAW,GAAGC,CAAAA,GAAAA,OAAc,AAAmB,CAAA,eAAnB,CAACN,iBAAiB,CAAC,AAAC;IAEtD,MAAMO,OAAO,GAAGC,iBAAiB,CAACT,WAAW,EAA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10 @@ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
7
7
  var _debuggerScriptSource = require("./handlers/DebuggerScriptSource");
8
8
  var _networkResponse = require("./handlers/NetworkResponse");
9
9
  var _pageReload = require("./handlers/PageReload");
10
- var _vscodeCompat = require("./handlers/VscodeCompat");
10
+ var _vscodeDebuggerGetPossibleBreakpoints = require("./handlers/VscodeDebuggerGetPossibleBreakpoints");
11
+ var _vscodeDebuggerScriptParsed = require("./handlers/VscodeDebuggerScriptParsed");
12
+ var _vscodeDebuggerSetBreakpointByUrl = require("./handlers/VscodeDebuggerSetBreakpointByUrl");
13
+ var _vscodeRuntimeGetProperties = require("./handlers/VscodeRuntimeGetProperties");
11
14
  function _interopRequireDefault(obj) {
12
15
  return obj && obj.__esModule ? obj : {
13
16
  default: obj
@@ -15,11 +18,17 @@ function _interopRequireDefault(obj) {
15
18
  }
16
19
  function createInspectorDeviceClass(metroBundler, MetroDeviceClass) {
17
20
  return class ExpoInspectorDevice extends MetroDeviceClass {
21
+ /** Stores information about currently connected debugger (if any). */ _debuggerConnection = null;
18
22
  /** All handlers that should be used to intercept or reply to CDP events */ handlers = [
23
+ // Generic handlers
19
24
  new _networkResponse.NetworkResponseHandler(),
20
25
  new _debuggerScriptSource.DebuggerScriptSourceHandler(this),
21
26
  new _pageReload.PageReloadHandler(metroBundler),
22
- new _vscodeCompat.VscodeCompatHandler(),
27
+ // Vscode-specific handlers
28
+ new _vscodeDebuggerGetPossibleBreakpoints.VscodeDebuggerGetPossibleBreakpointsHandler(),
29
+ new _vscodeDebuggerScriptParsed.VscodeDebuggerScriptParsedHandler(this),
30
+ new _vscodeDebuggerSetBreakpointByUrl.VscodeDebuggerSetBreakpointByUrlHandler(),
31
+ new _vscodeRuntimeGetProperties.VscodeRuntimeGetPropertiesHandler(),
23
32
  ];
24
33
  onDeviceMessage(message, info) {
25
34
  var ref;
@@ -52,6 +61,16 @@ function createInspectorDeviceClass(metroBundler, MetroDeviceClass) {
52
61
  newDevice.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId);
53
62
  }
54
63
  }
64
+ /**
65
+ * Handle a new debugger connection to this device.
66
+ * This adds the `debuggerType` property to the `DebuggerInfo` object.
67
+ * With that information, we can enable or disable debugger-specific handlers.
68
+ */ handleDebuggerConnectionWithType(socket, pageId, debuggerType) {
69
+ this.handleDebuggerConnection(socket, pageId);
70
+ if (this._debuggerConnection) {
71
+ this._debuggerConnection.debuggerType = debuggerType;
72
+ }
73
+ }
55
74
  /** Hook into the message life cycle to answer more complex CDP messages */ async _processMessageFromDevice(message, info) {
56
75
  if (!this.onDeviceMessage(message, info)) {
57
76
  await super._processMessageFromDevice(message, info);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/start/server/metro/inspector-proxy/device.ts"],"sourcesContent":["import type { DebuggerInfo, Device as MetroDevice } from 'metro-inspector-proxy';\nimport fetch from 'node-fetch';\nimport type WS from 'ws';\n\nimport { MetroBundlerDevServer } from '../MetroBundlerDevServer';\nimport { DebuggerScriptSourceHandler } from './handlers/DebuggerScriptSource';\nimport { NetworkResponseHandler } from './handlers/NetworkResponse';\nimport { PageReloadHandler } from './handlers/PageReload';\nimport { VscodeCompatHandler } from './handlers/VscodeCompat';\nimport { DeviceRequest, InspectorHandler, DebuggerRequest } from './handlers/types';\n\nexport function createInspectorDeviceClass(\n metroBundler: MetroBundlerDevServer,\n MetroDeviceClass: typeof MetroDevice\n) {\n return class ExpoInspectorDevice extends MetroDeviceClass implements InspectorHandler {\n /** All handlers that should be used to intercept or reply to CDP events */\n public handlers: InspectorHandler[] = [\n new NetworkResponseHandler(),\n new DebuggerScriptSourceHandler(this),\n new PageReloadHandler(metroBundler),\n new VscodeCompatHandler(),\n ];\n\n onDeviceMessage(message: any, info: DebuggerInfo): boolean {\n return this.handlers.some((handler) => handler.onDeviceMessage?.(message, info) ?? false);\n }\n\n onDebuggerMessage(message: any, info: DebuggerInfo): boolean {\n return this.handlers.some((handler) => handler.onDebuggerMessage?.(message, info) ?? false);\n }\n\n /**\n * Handle a new device connection with the same device identifier.\n * When the app and device name matches, we can reuse the debugger connection.\n * Else, we have to shut the debugger connection down.\n */\n handleDuplicateDeviceConnection(newDevice: InstanceType<typeof MetroDeviceClass>) {\n if (this._app !== newDevice._app || this._name !== newDevice._name) {\n this._deviceSocket.close();\n this._debuggerConnection?.socket.close();\n return;\n }\n\n const oldDebugger = this._debuggerConnection;\n this._debuggerConnection = null;\n\n if (oldDebugger) {\n oldDebugger.socket.removeAllListeners();\n this._deviceSocket.close();\n newDevice.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId);\n }\n }\n\n /** Hook into the message life cycle to answer more complex CDP messages */\n async _processMessageFromDevice(message: DeviceRequest<any>, info: DebuggerInfo) {\n if (!this.onDeviceMessage(message, info)) {\n await super._processMessageFromDevice(message, info);\n }\n }\n\n /** Hook into the message life cycle to answer more complex CDP messages */\n _interceptMessageFromDebugger(\n request: DebuggerRequest,\n info: DebuggerInfo,\n socket: WS\n ): boolean {\n // Note, `socket` is the exact same as `info.socket`\n if (this.onDebuggerMessage(request, info)) {\n return true;\n }\n\n return super._interceptMessageFromDebugger(request, info, socket);\n }\n\n /**\n * Overwrite the default text fetcher, to load sourcemaps from sources other than `localhost`.\n * @todo Cedric: remove the custom `DebuggerScriptSource` handler when switching over to `metro@>=0.75.1`\n * @see https://github.com/facebook/metro/blob/77f445f1bcd2264ad06174dbf8d542bc75834d29/packages/metro-inspector-proxy/src/Device.js#L573-L588\n * @since metro-inspector-proxy@0.75.1\n */\n async _fetchText(url: URL): Promise<string> {\n const LENGTH_LIMIT_BYTES = 350_000_000; // 350mb\n\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Received status ${response.status} while fetching: ${url}`);\n }\n\n const contentLength = response.headers.get('Content-Length');\n if (contentLength && Number(contentLength) > LENGTH_LIMIT_BYTES) {\n throw new Error('Expected file size is too large (more than 350mb)');\n }\n\n const text = await response.text();\n if (Buffer.byteLength(text, 'utf8') > LENGTH_LIMIT_BYTES) {\n throw new Error('File size is too large (more than 350mb)');\n }\n\n return text;\n }\n };\n}\n"],"names":["createInspectorDeviceClass","metroBundler","MetroDeviceClass","ExpoInspectorDevice","handlers","NetworkResponseHandler","DebuggerScriptSourceHandler","PageReloadHandler","VscodeCompatHandler","onDeviceMessage","message","info","handler","some","onDebuggerMessage","handleDuplicateDeviceConnection","newDevice","_app","_name","_deviceSocket","close","_debuggerConnection","socket","oldDebugger","removeAllListeners","handleDebuggerConnection","pageId","_processMessageFromDevice","_interceptMessageFromDebugger","request","_fetchText","url","LENGTH_LIMIT_BYTES","response","fetch","ok","Error","status","contentLength","headers","get","Number","text","Buffer","byteLength"],"mappings":"AAAA;;;;QAWgBA,0BAA0B,GAA1BA,0BAA0B;AAVxB,IAAA,UAAY,kCAAZ,YAAY,EAAA;AAIc,IAAA,qBAAiC,WAAjC,iCAAiC,CAAA;AACtC,IAAA,gBAA4B,WAA5B,4BAA4B,CAAA;AACjC,IAAA,WAAuB,WAAvB,uBAAuB,CAAA;AACrB,IAAA,aAAyB,WAAzB,yBAAyB,CAAA;;;;;;AAGtD,SAASA,0BAA0B,CACxCC,YAAmC,EACnCC,gBAAoC,EACpC;IACA,OAAO,MAAMC,mBAAmB,SAASD,gBAAgB;QACvD,2EAA2E,CAC3E,AAAOE,QAAQ,GAAuB;YACpC,IAAIC,gBAAsB,uBAAA,EAAE;YAC5B,IAAIC,qBAA2B,4BAAA,CAAC,IAAI,CAAC;YACrC,IAAIC,WAAiB,kBAAA,CAACN,YAAY,CAAC;YACnC,IAAIO,aAAmB,oBAAA,EAAE;SAC1B,CAAC;QAEFC,eAAe,CAACC,OAAY,EAAEC,IAAkB,EAAW;gBAClBC,GAAwC;YAA/E,OAAO,IAAI,CAACR,QAAQ,CAACS,IAAI,CAAC,CAACD,OAAO;gBAAKA,OAAAA,CAAAA,GAAwC,GAAxCA,OAAO,CAACH,eAAe,QAAiB,GAAxCG,KAAAA,CAAwC,GAAxCA,OAAO,CAACH,eAAe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AC;SACb;KACF,CAAC;CACH"}
1
+ {"version":3,"sources":["../../../../../../src/start/server/metro/inspector-proxy/device.ts"],"sourcesContent":["import type { DebuggerInfo, Device as MetroDevice } from 'metro-inspector-proxy';\nimport fetch from 'node-fetch';\nimport type WS from 'ws';\n\nimport { MetroBundlerDevServer } from '../MetroBundlerDevServer';\nimport { DebuggerScriptSourceHandler } from './handlers/DebuggerScriptSource';\nimport { NetworkResponseHandler } from './handlers/NetworkResponse';\nimport { PageReloadHandler } from './handlers/PageReload';\nimport { VscodeDebuggerGetPossibleBreakpointsHandler } from './handlers/VscodeDebuggerGetPossibleBreakpoints';\nimport { VscodeDebuggerScriptParsedHandler } from './handlers/VscodeDebuggerScriptParsed';\nimport { VscodeDebuggerSetBreakpointByUrlHandler } from './handlers/VscodeDebuggerSetBreakpointByUrl';\nimport { VscodeRuntimeGetPropertiesHandler } from './handlers/VscodeRuntimeGetProperties';\nimport { DeviceRequest, InspectorHandler, DebuggerRequest } from './handlers/types';\n\n/** Export the supported debugger types this inspector proxy can handle */\nexport type DebuggerType = 'vscode' | 'generic';\n\n/** The debugger information being tracked by this device class */\nexport type ExpoDebuggerInfo = DebuggerInfo & { debuggerType?: DebuggerType };\n\nexport function createInspectorDeviceClass(\n metroBundler: MetroBundlerDevServer,\n MetroDeviceClass: typeof MetroDevice\n) {\n return class ExpoInspectorDevice extends MetroDeviceClass implements InspectorHandler {\n /** Stores information about currently connected debugger (if any). */\n _debuggerConnection: ExpoDebuggerInfo | null = null;\n\n /** All handlers that should be used to intercept or reply to CDP events */\n public handlers: InspectorHandler[] = [\n // Generic handlers\n new NetworkResponseHandler(),\n new DebuggerScriptSourceHandler(this),\n new PageReloadHandler(metroBundler),\n // Vscode-specific handlers\n new VscodeDebuggerGetPossibleBreakpointsHandler(),\n new VscodeDebuggerScriptParsedHandler(this),\n new VscodeDebuggerSetBreakpointByUrlHandler(),\n new VscodeRuntimeGetPropertiesHandler(),\n ];\n\n onDeviceMessage(message: any, info: DebuggerInfo): boolean {\n return this.handlers.some((handler) => handler.onDeviceMessage?.(message, info) ?? false);\n }\n\n onDebuggerMessage(message: any, info: DebuggerInfo): boolean {\n return this.handlers.some((handler) => handler.onDebuggerMessage?.(message, info) ?? false);\n }\n\n /**\n * Handle a new device connection with the same device identifier.\n * When the app and device name matches, we can reuse the debugger connection.\n * Else, we have to shut the debugger connection down.\n */\n handleDuplicateDeviceConnection(newDevice: InstanceType<typeof MetroDeviceClass>) {\n if (this._app !== newDevice._app || this._name !== newDevice._name) {\n this._deviceSocket.close();\n this._debuggerConnection?.socket.close();\n return;\n }\n\n const oldDebugger = this._debuggerConnection;\n this._debuggerConnection = null;\n\n if (oldDebugger) {\n oldDebugger.socket.removeAllListeners();\n this._deviceSocket.close();\n newDevice.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId);\n }\n }\n\n /**\n * Handle a new debugger connection to this device.\n * This adds the `debuggerType` property to the `DebuggerInfo` object.\n * With that information, we can enable or disable debugger-specific handlers.\n */\n handleDebuggerConnectionWithType(socket: WS, pageId: string, debuggerType: DebuggerType): void {\n this.handleDebuggerConnection(socket, pageId);\n\n if (this._debuggerConnection) {\n this._debuggerConnection.debuggerType = debuggerType;\n }\n }\n\n /** Hook into the message life cycle to answer more complex CDP messages */\n async _processMessageFromDevice(message: DeviceRequest<any>, info: DebuggerInfo) {\n if (!this.onDeviceMessage(message, info)) {\n await super._processMessageFromDevice(message, info);\n }\n }\n\n /** Hook into the message life cycle to answer more complex CDP messages */\n _interceptMessageFromDebugger(\n request: DebuggerRequest,\n info: DebuggerInfo,\n socket: WS\n ): boolean {\n // Note, `socket` is the exact same as `info.socket`\n if (this.onDebuggerMessage(request, info)) {\n return true;\n }\n\n return super._interceptMessageFromDebugger(request, info, socket);\n }\n\n /**\n * Overwrite the default text fetcher, to load sourcemaps from sources other than `localhost`.\n * @todo Cedric: remove the custom `DebuggerScriptSource` handler when switching over to `metro@>=0.75.1`\n * @see https://github.com/facebook/metro/blob/77f445f1bcd2264ad06174dbf8d542bc75834d29/packages/metro-inspector-proxy/src/Device.js#L573-L588\n * @since metro-inspector-proxy@0.75.1\n */\n async _fetchText(url: URL): Promise<string> {\n const LENGTH_LIMIT_BYTES = 350_000_000; // 350mb\n\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Received status ${response.status} while fetching: ${url}`);\n }\n\n const contentLength = response.headers.get('Content-Length');\n if (contentLength && Number(contentLength) > LENGTH_LIMIT_BYTES) {\n throw new Error('Expected file size is too large (more than 350mb)');\n }\n\n const text = await response.text();\n if (Buffer.byteLength(text, 'utf8') > LENGTH_LIMIT_BYTES) {\n throw new Error('File size is too large (more than 350mb)');\n }\n\n return text;\n }\n };\n}\n"],"names":["createInspectorDeviceClass","metroBundler","MetroDeviceClass","ExpoInspectorDevice","_debuggerConnection","handlers","NetworkResponseHandler","DebuggerScriptSourceHandler","PageReloadHandler","VscodeDebuggerGetPossibleBreakpointsHandler","VscodeDebuggerScriptParsedHandler","VscodeDebuggerSetBreakpointByUrlHandler","VscodeRuntimeGetPropertiesHandler","onDeviceMessage","message","info","handler","some","onDebuggerMessage","handleDuplicateDeviceConnection","newDevice","_app","_name","_deviceSocket","close","socket","oldDebugger","removeAllListeners","handleDebuggerConnection","pageId","handleDebuggerConnectionWithType","debuggerType","_processMessageFromDevice","_interceptMessageFromDebugger","request","_fetchText","url","LENGTH_LIMIT_BYTES","response","fetch","ok","Error","status","contentLength","headers","get","Number","text","Buffer","byteLength"],"mappings":"AAAA;;;;QAoBgBA,0BAA0B,GAA1BA,0BAA0B;AAnBxB,IAAA,UAAY,kCAAZ,YAAY,EAAA;AAIc,IAAA,qBAAiC,WAAjC,iCAAiC,CAAA;AACtC,IAAA,gBAA4B,WAA5B,4BAA4B,CAAA;AACjC,IAAA,WAAuB,WAAvB,uBAAuB,CAAA;AACG,IAAA,qCAAiD,WAAjD,iDAAiD,CAAA;AAC3D,IAAA,2BAAuC,WAAvC,uCAAuC,CAAA;AACjC,IAAA,iCAA6C,WAA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AA6B,CAC3BC,OAAwB,EACxBnB,IAAkB,EAClBU,MAAU,EACD;YACT,oDAAoD;YACpD,IAAI,IAAI,CAACP,iBAAiB,CAACgB,OAAO,EAAEnB,IAAI,CAAC,EAAE;gBACzC,OAAO,IAAI,CAAC;aACb;YAED,OAAO,KAAK,CAACkB,6BAA6B,CAACC,OAAO,EAAEnB,IAAI,EAAEU,MAAM,CAAC,CAAC;SACnE;QAED;;;;;OAKG,CACH,MAAMU,UAAU,CAACC,GAAQ,EAAmB;YAC1C,MAAMC,kBAAkB,GAAG,SAAW,AAAC,EAAC,QAAQ;YAEhD,MAAMC,QAAQ,GAAG,MAAMC,CAAAA,GAAAA,UAAK,AAAK,CAAA,QAAL,CAACH,GAAG,CAAC,AAAC;YAClC,IAAI,CAACE,QAAQ,CAACE,EAAE,EAAE;gBAChB,MAAM,IAAIC,KAAK,CAAC,CAAC,gBAAgB,EAAEH,QAAQ,CAACI,MAAM,CAAC,iBAAiB,EAAEN,GAAG,CAAC,CAAC,CAAC,CAAC;aAC9E;YAED,MAAMO,aAAa,GAAGL,QAAQ,CAACM,OAAO,CAACC,GAAG,CAAC,gBAAgB,CAAC,AAAC;YAC7D,IAAIF,aAAa,IAAIG,MAAM,CAACH,aAAa,CAAC,GAAGN,kBAAkB,EAAE;gBAC/D,MAAM,IAAII,KAAK,CAAC,mDAAmD,CAAC,CAAC;aACtE;YAED,MAAMM,IAAI,GAAG,MAAMT,QAAQ,CAACS,IAAI,EAAE,AAAC;YACnC,IAAIC,MAAM,CAACC,UAAU,CAACF,IAAI,EAAE,MAAM,CAAC,GAAGV,kBAAkB,EAAE;gBACxD,MAAM,IAAII,KAAK,CAAC,0CAA0C,CAAC,CAAC;aAC7D;YAED,OAAOM,IAAI,CAAC;SACb;KACF,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/DebuggerScriptSource.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\nimport fs from 'fs';\nimport type { DebuggerInfo, Device as MetroDevice } from 'metro-inspector-proxy';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport type WS from 'ws';\n\nimport { CdpMessage, DebuggerRequest, DebuggerResponse, InspectorHandler } from './types';\n\n// TODO(cedric): remove this custom handler when fully switching over to `metro@>=0.75.1`\nexport class DebuggerScriptSourceHandler implements InspectorHandler {\n constructor(private readonly device: MetroDevice) {}\n\n onDebuggerMessage(\n message: DebuggerRequest<DebuggerGetScriptSource>,\n { socket }: Pick<DebuggerInfo, 'socket'>\n ) {\n // See: https://github.com/facebook/metro/blob/65d801cb60c06c1b17f428ca79491db73c53ef87/packages/metro-inspector-proxy/src/Device.js#L488-L544\n if (message.method === 'Debugger.getScriptSource') {\n const { scriptId } = message.params;\n const pathOrUrl = this.device._scriptIdToSourcePathMapping.get(scriptId);\n\n // Unkown scriptId provided, can't reply\n if (!pathOrUrl) {\n return false;\n }\n\n // Fetch the source from URL, if the path is a bundle URL\n if (isUrl(pathOrUrl)) {\n fetch(pathOrUrl)\n .then((response) =>\n response.ok\n ? response.text()\n : respond(socket, message, {\n error: `Received status ${response.status} while fetching: ${pathOrUrl}`,\n })\n )\n .then((scriptSource) => {\n if (scriptSource !== null) {\n respond(socket, message, { scriptSource });\n }\n });\n\n return true;\n }\n\n // Fetch the source from file directly, using the project root as starting directory\n try {\n const relativePath = path.resolve(this.device._projectRoot, pathOrUrl);\n respond(socket, message, { scriptSource: fs.readFileSync(relativePath, 'utf8') });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n respond(socket, message, {\n error: `Failed to load \"${pathOrUrl}\": ${errorMessage}`,\n });\n }\n\n return true;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-getScriptSource */\nexport type DebuggerGetScriptSource = CdpMessage<\n 'Debugger.getScriptSource',\n Protocol.Debugger.GetScriptSourceRequest,\n Protocol.Debugger.GetScriptSourceResponse\n>;\n\nfunction respond<T extends CdpMessage>(\n socket: WS,\n request: DebuggerRequest<T>,\n response: DebuggerResponse<T>['result'] | { error: string }\n) {\n if ('error' in response) {\n socket.send(JSON.stringify({ id: request.id, error: { message: response.error } }));\n } else {\n socket.send(JSON.stringify({ id: request.id, result: response }));\n }\n\n return null;\n}\n\nfunction isUrl(pathOrUrl: string) {\n try {\n const url = new URL(pathOrUrl);\n return ['http', 'https'].some((protocol) => url.protocol.toLowerCase().startsWith(protocol));\n } catch {\n return false;\n }\n}\n"],"names":["DebuggerScriptSourceHandler","constructor","device","onDebuggerMessage","message","socket","method","scriptId","params","pathOrUrl","_scriptIdToSourcePathMapping","get","isUrl","fetch","then","response","ok","text","respond","error","status","scriptSource","relativePath","path","resolve","_projectRoot","fs","readFileSync","errorMessage","Error","String","request","send","JSON","stringify","id","result","url","URL","some","protocol","toLowerCase","startsWith"],"mappings":"AAAA;;;;AACe,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAED,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;;;;;;AAMhB,MAAMA,2BAA2B;IACtCC,YAA6BC,MAAmB,CAAE;aAArBA,MAAmB,GAAnBA,MAAmB;KAAI;IAEpDC,iBAAiB,CACfC,OAAiD,EACjD,EAAEC,MAAM,CAAA,EAAgC,EACxC;QACA,8IAA8I;QAC9I,IAAID,OAAO,CAACE,MAAM,KAAK,0BAA0B,EAAE;YACjD,MAAM,EAAEC,QAAQ,CAAA,EAAE,GAAGH,OAAO,CAACI,MAAM,AAAC;YACpC,MAAMC,SAAS,GAAG,IAAI,CAACP,MAAM,CAACQ,4BAA4B,CAACC,GAAG,CAACJ,QAAQ,CAAC,AAAC;YAEzE,wCAAwC;YACxC,IAAI,CAACE,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,yDAAyD;YACzD,IAAIG,KAAK,CAACH,SAAS,CAAC,EAAE;gBACpBI,CAAAA,GAAAA,UAAK,AAAW,CAAA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,EAC3D;IACA,IAAI,OAAO,IAAIA,QAAQ,EAAE;QACvBV,MAAM,CAAC2B,IAAI,CAACC,IAAI,CAACC,SAAS,CAAC;YAAEC,EAAE,EAAEJ,OAAO,CAACI,EAAE;YAAEhB,KAAK,EAAE;gBAAEf,OAAO,EAAEW,QAAQ,CAACI,KAAK;aAAE;SAAE,CAAC,CAAC,CAAC;KACrF,MAAM;QACLd,MAAM,CAAC2B,IAAI,CAACC,IAAI,CAACC,SAAS,CAAC;YAAEC,EAAE,EAAEJ,OAAO,CAACI,EAAE;YAAEC,MAAM,EAAErB,QAAQ;SAAE,CAAC,CAAC,CAAC;KACnE;IAED,OAAO,IAAI,CAAC;CACb;AAED,SAASH,KAAK,CAACH,SAAiB,EAAE;IAChC,IAAI;QACF,MAAM4B,GAAG,GAAG,IAAIC,GAAG,CAAC7B,SAAS,CAAC,AAAC;QAC/B,OAAO;YAAC,MAAM;YAAE,OAAO;SAAC,CAAC8B,IAAI,CAAC,CAACC,QAAQ,GAAKH,GAAG,CAACG,QAAQ,CAACC,WAAW,EAAE,CAACC,UAAU,CAACF,QAAQ,CAAC;QAAA,CAAC,CAAC;KAC9F,CAAC,OAAM;QACN,OAAO,KAAK,CAAC;KACd;CACF"}
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/DebuggerScriptSource.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\nimport fs from 'fs';\nimport type { Device as MetroDevice } from 'metro-inspector-proxy';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport type WS from 'ws';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DebuggerRequest, DebuggerResponse, InspectorHandler } from './types';\n\n// TODO(cedric): remove this custom handler when fully switching over to `metro@>=0.75.1`\nexport class DebuggerScriptSourceHandler implements InspectorHandler {\n constructor(private readonly device: MetroDevice) {}\n\n onDebuggerMessage(\n message: DebuggerRequest<DebuggerGetScriptSource>,\n { socket }: ExpoDebuggerInfo\n ) {\n // See: https://github.com/facebook/metro/blob/65d801cb60c06c1b17f428ca79491db73c53ef87/packages/metro-inspector-proxy/src/Device.js#L488-L544\n if (message.method === 'Debugger.getScriptSource') {\n const { scriptId } = message.params;\n const pathOrUrl = this.device._scriptIdToSourcePathMapping.get(scriptId);\n\n // Unkown scriptId provided, can't reply\n if (!pathOrUrl) {\n return false;\n }\n\n // Fetch the source from URL, if the path is a bundle URL\n if (isUrl(pathOrUrl)) {\n fetch(pathOrUrl)\n .then((response) =>\n response.ok\n ? response.text()\n : respond(socket, message, {\n error: `Received status ${response.status} while fetching: ${pathOrUrl}`,\n })\n )\n .then((scriptSource) => {\n if (scriptSource !== null) {\n respond(socket, message, { scriptSource });\n }\n });\n\n return true;\n }\n\n // Fetch the source from file directly, using the project root as starting directory\n try {\n const relativePath = path.resolve(this.device._projectRoot, pathOrUrl);\n respond(socket, message, { scriptSource: fs.readFileSync(relativePath, 'utf8') });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n respond(socket, message, {\n error: `Failed to load \"${pathOrUrl}\": ${errorMessage}`,\n });\n }\n\n return true;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-getScriptSource */\nexport type DebuggerGetScriptSource = CdpMessage<\n 'Debugger.getScriptSource',\n Protocol.Debugger.GetScriptSourceRequest,\n Protocol.Debugger.GetScriptSourceResponse\n>;\n\nfunction respond<T extends CdpMessage>(\n socket: WS,\n request: DebuggerRequest<T>,\n response: DebuggerResponse<T>['result'] | { error: string }\n) {\n if ('error' in response) {\n socket.send(JSON.stringify({ id: request.id, error: { message: response.error } }));\n } else {\n socket.send(JSON.stringify({ id: request.id, result: response }));\n }\n\n return null;\n}\n\nfunction isUrl(pathOrUrl: string) {\n try {\n const url = new URL(pathOrUrl);\n return ['http', 'https'].some((protocol) => url.protocol.toLowerCase().startsWith(protocol));\n } catch {\n return false;\n }\n}\n"],"names":["DebuggerScriptSourceHandler","constructor","device","onDebuggerMessage","message","socket","method","scriptId","params","pathOrUrl","_scriptIdToSourcePathMapping","get","isUrl","fetch","then","response","ok","text","respond","error","status","scriptSource","relativePath","path","resolve","_projectRoot","fs","readFileSync","errorMessage","Error","String","request","send","JSON","stringify","id","result","url","URL","some","protocol","toLowerCase","startsWith"],"mappings":"AAAA;;;;AACe,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAED,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;;;;;;AAOhB,MAAMA,2BAA2B;IACtCC,YAA6BC,MAAmB,CAAE;aAArBA,MAAmB,GAAnBA,MAAmB;KAAI;IAEpDC,iBAAiB,CACfC,OAAiD,EACjD,EAAEC,MAAM,CAAA,EAAoB,EAC5B;QACA,8IAA8I;QAC9I,IAAID,OAAO,CAACE,MAAM,KAAK,0BAA0B,EAAE;YACjD,MAAM,EAAEC,QAAQ,CAAA,EAAE,GAAGH,OAAO,CAACI,MAAM,AAAC;YACpC,MAAMC,SAAS,GAAG,IAAI,CAACP,MAAM,CAACQ,4BAA4B,CAACC,GAAG,CAACJ,QAAQ,CAAC,AAAC;YAEzE,wCAAwC;YACxC,IAAI,CAACE,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,yDAAyD;YACzD,IAAIG,KAAK,CAACH,SAAS,CAAC,EAAE;gBACpBI,CAAAA,GAAAA,UAAK,AAAW,CAAA,QAAX,CAACJ,SAAS,CAAC,CACbK,IAAI,CAAC,CAACC,QAAQ,GACbA,QAAQ,CAACC,EAAE,GACPD,QAAQ,CAACE,IAAI,EAAE,GACfC,OAAO,CAACb,MAAM,EAAED,OAAO,EAAE;wBACvBe,KAAK,EAAE,CAAC,gBAAgB,EAAEJ,QAAQ,CAACK,MAAM,CAAC,iBAAiB,EAAEX,SAAS,CAAC,CAAC;qBACzE,CAAC;gBAAA,CACP,CACAK,IAAI,CAAC,CAACO,YAAY,GAAK;oBACtB,IAAIA,YAAY,KAAK,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EC,MAAM,EAAErB,QAAQ;SAAE,CAAC,CAAC,CAAC;KACnE;IAED,OAAO,IAAI,CAAC;CACb;AAED,SAASH,KAAK,CAACH,SAAiB,EAAE;IAChC,IAAI;QACF,MAAM4B,GAAG,GAAG,IAAIC,GAAG,CAAC7B,SAAS,CAAC,AAAC;QAC/B,OAAO;YAAC,MAAM;YAAE,OAAO;SAAC,CAAC8B,IAAI,CAAC,CAACC,QAAQ,GAAKH,GAAG,CAACG,QAAQ,CAACC,WAAW,EAAE,CAACC,UAAU,CAACF,QAAQ,CAAC;QAAA,CAAC,CAAC;KAC9F,CAAC,OAAM;QACN,OAAO,KAAK,CAAC;KACd;CACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/NetworkResponse.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\nimport type { DebuggerInfo } from 'metro-inspector-proxy';\n\nimport {\n CdpMessage,\n InspectorHandler,\n DeviceRequest,\n DebuggerRequest,\n DebuggerResponse,\n DeviceResponse,\n} from './types';\n\nexport class NetworkResponseHandler implements InspectorHandler {\n /** All known responses, mapped by request id */\n storage = new Map<string, DebuggerResponse<NetworkGetResponseBody>['result']>();\n\n onDeviceMessage(message: DeviceRequest<NetworkReceivedResponseBody>) {\n if (message.method === 'Expo(Network.receivedResponseBody)') {\n const { requestId, ...requestInfo } = message.params;\n this.storage.set(requestId, requestInfo);\n return true;\n }\n\n return false;\n }\n\n onDebuggerMessage(\n message: DebuggerRequest<NetworkGetResponseBody>,\n { socket }: Pick<DebuggerInfo, 'socket'>\n ) {\n if (\n message.method === 'Network.getResponseBody' &&\n this.storage.has(message.params.requestId)\n ) {\n const response: DeviceResponse<NetworkGetResponseBody> = {\n id: message.id,\n result: this.storage.get(message.params.requestId)!,\n };\n\n socket.send(JSON.stringify(response));\n return true;\n }\n\n return false;\n }\n}\n\n/** Custom message to transfer the response body data to the proxy */\nexport type NetworkReceivedResponseBody = CdpMessage<\n 'Expo(Network.receivedResponseBody)',\n Protocol.Network.GetResponseBodyRequest & Protocol.Network.GetResponseBodyResponse,\n never\n>;\n\n/** @see https://chromedevtools.github.io/devtools-protocol/1-2/Network/#method-getResponseBody */\nexport type NetworkGetResponseBody = CdpMessage<\n 'Network.getResponseBody',\n Protocol.Network.GetResponseBodyRequest,\n Protocol.Network.GetResponseBodyResponse\n>;\n"],"names":["NetworkResponseHandler","storage","Map","onDeviceMessage","message","method","requestId","requestInfo","params","set","onDebuggerMessage","socket","has","response","id","result","get","send","JSON","stringify"],"mappings":"AAAA;;;;AAYO,MAAMA,sBAAsB;IACjC,gDAAgD,CAChDC,OAAO,GAAG,IAAIC,GAAG,EAA8D,CAAC;IAEhFC,eAAe,CAACC,OAAmD,EAAE;QACnE,IAAIA,OAAO,CAACC,MAAM,KAAK,oCAAoC,EAAE;YAC3D,MAAM,EAAEC,SAAS,CAAA,EAAE,GAAGC,WAAW,EAAE,GAAGH,OAAO,CAACI,MAAM,AAAC;YACrD,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACH,SAAS,EAAEC,WAAW,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;IAEDG,iBAAiB,CACfN,OAAgD,EAChD,EAAEO,MAAM,CAAA,EAAgC,EACxC;QACA,IACEP,OAAO,CAACC,MAAM,KAAK,yBAAyB,IAC5C,IAAI,CAACJ,OAAO,CAACW,GAAG,CAACR,OAAO,CAACI,MAAM,CAACF,SAAS,CAAC,EAC1C;YACA,MAAMO,QAAQ,GAA2C;gBACvDC,EAAE,EAAEV,OAAO,CAACU,EAAE;gBACdC,MAAM,EAAE,IAAI,CAACd,OAAO,CAACe,GAAG,CAACZ,OAAO,CAACI,MAAM,CAACF,SAAS,CAAC;aACnD,AAAC;YAEFK,MAAM,CAACM,IAAI,CAACC,IAAI,CAACC,SAAS,CAACN,QAAQ,CAAC,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAjCYb,sBAAsB,GAAtBA,sBAAsB"}
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/NetworkResponse.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport {\n CdpMessage,\n InspectorHandler,\n DeviceRequest,\n DebuggerRequest,\n DebuggerResponse,\n DeviceResponse,\n} from './types';\n\nexport class NetworkResponseHandler implements InspectorHandler {\n /** All known responses, mapped by request id */\n storage = new Map<string, DebuggerResponse<NetworkGetResponseBody>['result']>();\n\n onDeviceMessage(message: DeviceRequest<NetworkReceivedResponseBody>) {\n if (message.method === 'Expo(Network.receivedResponseBody)') {\n const { requestId, ...requestInfo } = message.params;\n this.storage.set(requestId, requestInfo);\n return true;\n }\n\n return false;\n }\n\n onDebuggerMessage(\n message: DebuggerRequest<NetworkGetResponseBody>,\n { socket }: ExpoDebuggerInfo\n ) {\n if (\n message.method === 'Network.getResponseBody' &&\n this.storage.has(message.params.requestId)\n ) {\n const response: DeviceResponse<NetworkGetResponseBody> = {\n id: message.id,\n result: this.storage.get(message.params.requestId)!,\n };\n\n socket.send(JSON.stringify(response));\n return true;\n }\n\n return false;\n }\n}\n\n/** Custom message to transfer the response body data to the proxy */\nexport type NetworkReceivedResponseBody = CdpMessage<\n 'Expo(Network.receivedResponseBody)',\n Protocol.Network.GetResponseBodyRequest & Protocol.Network.GetResponseBodyResponse,\n never\n>;\n\n/** @see https://chromedevtools.github.io/devtools-protocol/1-2/Network/#method-getResponseBody */\nexport type NetworkGetResponseBody = CdpMessage<\n 'Network.getResponseBody',\n Protocol.Network.GetResponseBodyRequest,\n Protocol.Network.GetResponseBodyResponse\n>;\n"],"names":["NetworkResponseHandler","storage","Map","onDeviceMessage","message","method","requestId","requestInfo","params","set","onDebuggerMessage","socket","has","response","id","result","get","send","JSON","stringify"],"mappings":"AAAA;;;;AAYO,MAAMA,sBAAsB;IACjC,gDAAgD,CAChDC,OAAO,GAAG,IAAIC,GAAG,EAA8D,CAAC;IAEhFC,eAAe,CAACC,OAAmD,EAAE;QACnE,IAAIA,OAAO,CAACC,MAAM,KAAK,oCAAoC,EAAE;YAC3D,MAAM,EAAEC,SAAS,CAAA,EAAE,GAAGC,WAAW,EAAE,GAAGH,OAAO,CAACI,MAAM,AAAC;YACrD,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACH,SAAS,EAAEC,WAAW,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;IAEDG,iBAAiB,CACfN,OAAgD,EAChD,EAAEO,MAAM,CAAA,EAAoB,EAC5B;QACA,IACEP,OAAO,CAACC,MAAM,KAAK,yBAAyB,IAC5C,IAAI,CAACJ,OAAO,CAACW,GAAG,CAACR,OAAO,CAACI,MAAM,CAACF,SAAS,CAAC,EAC1C;YACA,MAAMO,QAAQ,GAA2C;gBACvDC,EAAE,EAAEV,OAAO,CAACU,EAAE;gBACdC,MAAM,EAAE,IAAI,CAACd,OAAO,CAACe,GAAG,CAACZ,OAAO,CAACI,MAAM,CAACF,SAAS,CAAC;aACnD,AAAC;YAEFK,MAAM,CAACM,IAAI,CAACC,IAAI,CAACC,SAAS,CAACN,QAAQ,CAAC,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAjCYb,sBAAsB,GAAtBA,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/PageReload.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\nimport { DebuggerInfo } from 'metro-inspector-proxy';\n\nimport { MetroBundlerDevServer } from '../../MetroBundlerDevServer';\nimport { CdpMessage, DebuggerRequest, InspectorHandler } from './types';\n\nexport class PageReloadHandler implements InspectorHandler {\n constructor(private readonly metroBundler: MetroBundlerDevServer) {}\n\n onDebuggerMessage(\n message: DebuggerRequest<PageReload>,\n { socket }: Pick<DebuggerInfo, 'socket'>\n ) {\n if (message.method === 'Page.reload') {\n this.metroBundler.broadcastMessage('reload');\n socket.send(JSON.stringify({ id: message.id }));\n return true;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/1-2/Page/#method-reload */\nexport type PageReload = CdpMessage<'Page.reload', Protocol.Page.ReloadRequest, never>;\n"],"names":["PageReloadHandler","constructor","metroBundler","onDebuggerMessage","message","socket","method","broadcastMessage","send","JSON","stringify","id"],"mappings":"AAAA;;;;AAMO,MAAMA,iBAAiB;IAC5BC,YAA6BC,YAAmC,CAAE;aAArCA,YAAmC,GAAnCA,YAAmC;KAAI;IAEpEC,iBAAiB,CACfC,OAAoC,EACpC,EAAEC,MAAM,CAAA,EAAgC,EACxC;QACA,IAAID,OAAO,CAACE,MAAM,KAAK,aAAa,EAAE;YACpC,IAAI,CAACJ,YAAY,CAACK,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAC7CF,MAAM,CAACG,IAAI,CAACC,IAAI,CAACC,SAAS,CAAC;gBAAEC,EAAE,EAAEP,OAAO,CAACO,EAAE;aAAE,CAAC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAfYX,iBAAiB,GAAjBA,iBAAiB"}
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/PageReload.ts"],"sourcesContent":["import type { Protocol } from 'devtools-protocol';\n\nimport { MetroBundlerDevServer } from '../../MetroBundlerDevServer';\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DebuggerRequest, InspectorHandler } from './types';\n\nexport class PageReloadHandler implements InspectorHandler {\n constructor(private readonly metroBundler: MetroBundlerDevServer) {}\n\n onDebuggerMessage(message: DebuggerRequest<PageReload>, { socket }: ExpoDebuggerInfo) {\n if (message.method === 'Page.reload') {\n this.metroBundler.broadcastMessage('reload');\n socket.send(JSON.stringify({ id: message.id }));\n return true;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/1-2/Page/#method-reload */\nexport type PageReload = CdpMessage<'Page.reload', Protocol.Page.ReloadRequest, never>;\n"],"names":["PageReloadHandler","constructor","metroBundler","onDebuggerMessage","message","socket","method","broadcastMessage","send","JSON","stringify","id"],"mappings":"AAAA;;;;AAMO,MAAMA,iBAAiB;IAC5BC,YAA6BC,YAAmC,CAAE;aAArCA,YAAmC,GAAnCA,YAAmC;KAAI;IAEpEC,iBAAiB,CAACC,OAAoC,EAAE,EAAEC,MAAM,CAAA,EAAoB,EAAE;QACpF,IAAID,OAAO,CAACE,MAAM,KAAK,aAAa,EAAE;YACpC,IAAI,CAACJ,YAAY,CAACK,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAC7CF,MAAM,CAACG,IAAI,CAACC,IAAI,CAACC,SAAS,CAAC;gBAAEC,EAAE,EAAEP,OAAO,CAACO,EAAE;aAAE,CAAC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAZYX,iBAAiB,GAAjBA,iBAAiB"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ class VscodeDebuggerGetPossibleBreakpointsHandler {
6
+ onDebuggerMessage(message, { socket , debuggerType }) {
7
+ if (debuggerType === "vscode" && message.method === "Debugger.getPossibleBreakpoints") {
8
+ const response = {
9
+ id: message.id,
10
+ result: {
11
+ locations: []
12
+ }
13
+ };
14
+ socket.send(JSON.stringify(response));
15
+ return true;
16
+ }
17
+ return false;
18
+ }
19
+ }
20
+ exports.VscodeDebuggerGetPossibleBreakpointsHandler = VscodeDebuggerGetPossibleBreakpointsHandler;
21
+
22
+ //# sourceMappingURL=VscodeDebuggerGetPossibleBreakpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.ts"],"sourcesContent":["import Protocol from 'devtools-protocol';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DebuggerRequest, DeviceResponse, InspectorHandler } from './types';\n\n/**\n * Hermes doesn't seem to handle this request, but `locations` have to be returned.\n * Respond with an empty location to make it \"spec compliant\" with Chrome DevTools.\n */\nexport class VscodeDebuggerGetPossibleBreakpointsHandler implements InspectorHandler {\n onDebuggerMessage(\n message: DebuggerRequest<DebuggerGetPossibleBreakpoints>,\n { socket, debuggerType }: ExpoDebuggerInfo\n ): boolean {\n if (debuggerType === 'vscode' && message.method === 'Debugger.getPossibleBreakpoints') {\n const response: DeviceResponse<DebuggerGetPossibleBreakpoints> = {\n id: message.id,\n result: { locations: [] },\n };\n socket.send(JSON.stringify(response));\n return true;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-getPossibleBreakpoints */\nexport type DebuggerGetPossibleBreakpoints = CdpMessage<\n 'Debugger.getPossibleBreakpoints',\n Protocol.Debugger.GetPossibleBreakpointsRequest,\n Protocol.Debugger.GetPossibleBreakpointsResponse\n>;\n"],"names":["VscodeDebuggerGetPossibleBreakpointsHandler","onDebuggerMessage","message","socket","debuggerType","method","response","id","result","locations","send","JSON","stringify"],"mappings":"AAAA;;;;AASO,MAAMA,2CAA2C;IACtDC,iBAAiB,CACfC,OAAwD,EACxD,EAAEC,MAAM,CAAA,EAAEC,YAAY,CAAA,EAAoB,EACjC;QACT,IAAIA,YAAY,KAAK,QAAQ,IAAIF,OAAO,CAACG,MAAM,KAAK,iCAAiC,EAAE;YACrF,MAAMC,QAAQ,GAAmD;gBAC/DC,EAAE,EAAEL,OAAO,CAACK,EAAE;gBACdC,MAAM,EAAE;oBAAEC,SAAS,EAAE,EAAE;iBAAE;aAC1B,AAAC;YACFN,MAAM,CAACO,IAAI,CAACC,IAAI,CAACC,SAAS,CAACN,QAAQ,CAAC,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAhBYN,2CAA2C,GAA3CA,2CAA2C"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ /** Android's stock emulator and other emulators such as genymotion use a standard localhost alias. */ const EMULATOR_LOCALHOST_ADDRESSES = [
6
+ "10.0.2.2",
7
+ "10.0.3.2"
8
+ ];
9
+ /** Prefix for script URLs that are alphanumeric IDs. */ const FILE_PREFIX = "file://";
10
+ class VscodeDebuggerScriptParsedHandler {
11
+ constructor(device){
12
+ this.device = device;
13
+ }
14
+ onDeviceMessage(message, debuggerInfo) {
15
+ if (debuggerInfo.debuggerType !== "vscode" || message.method !== "Debugger.scriptParsed") {
16
+ return false;
17
+ }
18
+ // See: https://github.com/facebook/metro/blob/f43caa371a813b257cb0b42028079645a1e85e0e/packages/metro-inspector-proxy/src/Device.js#L401-L410
19
+ if (message.params.sourceMapURL) {
20
+ for(let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i){
21
+ const address = EMULATOR_LOCALHOST_ADDRESSES[i];
22
+ if (message.params.sourceMapURL.indexOf(address) >= 0) {
23
+ message.params.sourceMapURL = message.params.sourceMapURL.replace(address, "localhost");
24
+ debuggerInfo.originalSourceURLAddress = address;
25
+ }
26
+ }
27
+ }
28
+ // See: https://github.com/facebook/metro/blob/f43caa371a813b257cb0b42028079645a1e85e0e/packages/metro-inspector-proxy/src/Device.js#L431-L453
29
+ if (message.params.url) {
30
+ for(let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i){
31
+ const address = EMULATOR_LOCALHOST_ADDRESSES[i];
32
+ if (message.params.url.indexOf(address) >= 0) {
33
+ message.params.url = message.params.url.replace(address, "localhost");
34
+ debuggerInfo.originalSourceURLAddress = address;
35
+ }
36
+ }
37
+ // Chrome doesn't download source maps if URL param is not a valid
38
+ // URL. Some frameworks pass alphanumeric script ID instead of URL which causes
39
+ // Chrome to not download source maps. In this case we want to prepend script ID
40
+ // with 'file://' prefix.
41
+ if (message.params.url.match(/^[0-9a-z]+$/)) {
42
+ message.params.url = FILE_PREFIX + message.params.url;
43
+ debuggerInfo.prependedFilePrefix = true;
44
+ }
45
+ if (message.params.scriptId != null) {
46
+ this.device._scriptIdToSourcePathMapping.set(message.params.scriptId, message.params.url);
47
+ }
48
+ }
49
+ // Block `metro-inspector-proxy`'s default source map inlining
50
+ return true;
51
+ }
52
+ }
53
+ exports.VscodeDebuggerScriptParsedHandler = VscodeDebuggerScriptParsedHandler;
54
+
55
+ //# sourceMappingURL=VscodeDebuggerScriptParsed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerScriptParsed.ts"],"sourcesContent":["import Protocol from 'devtools-protocol';\nimport { Device as MetroDevice } from 'metro-inspector-proxy';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DeviceRequest, InspectorHandler } from './types';\n\n/** Android's stock emulator and other emulators such as genymotion use a standard localhost alias. */\nconst EMULATOR_LOCALHOST_ADDRESSES: Readonly<string[]> = ['10.0.2.2', '10.0.3.2'];\n/** Prefix for script URLs that are alphanumeric IDs. */\nconst FILE_PREFIX = 'file://';\n\n/**\n * Some debug clients does not support fetching source maps by URL.\n * By default, the `metro-inspector-proxy` inlines the source map as base64 string.\n * Unfortunately, that causes a multi-second delay in VS Code (±5s).\n * This handler disables inlining the source maps for VS Code only.\n */\nexport class VscodeDebuggerScriptParsedHandler implements InspectorHandler {\n constructor(private readonly device: MetroDevice) {}\n\n onDeviceMessage(message: DeviceRequest<DebuggerScriptParsed>, debuggerInfo: ExpoDebuggerInfo) {\n if (debuggerInfo.debuggerType !== 'vscode' || message.method !== 'Debugger.scriptParsed') {\n return false;\n }\n\n // See: https://github.com/facebook/metro/blob/f43caa371a813b257cb0b42028079645a1e85e0e/packages/metro-inspector-proxy/src/Device.js#L401-L410\n if (message.params.sourceMapURL) {\n for (let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i) {\n const address = EMULATOR_LOCALHOST_ADDRESSES[i];\n if (message.params.sourceMapURL.indexOf(address) >= 0) {\n message.params.sourceMapURL = message.params.sourceMapURL.replace(address, 'localhost');\n debuggerInfo.originalSourceURLAddress = address;\n }\n }\n }\n\n // See: https://github.com/facebook/metro/blob/f43caa371a813b257cb0b42028079645a1e85e0e/packages/metro-inspector-proxy/src/Device.js#L431-L453\n if (message.params.url) {\n for (let i = 0; i < EMULATOR_LOCALHOST_ADDRESSES.length; ++i) {\n const address = EMULATOR_LOCALHOST_ADDRESSES[i];\n if (message.params.url.indexOf(address) >= 0) {\n message.params.url = message.params.url.replace(address, 'localhost');\n debuggerInfo.originalSourceURLAddress = address;\n }\n }\n\n // Chrome doesn't download source maps if URL param is not a valid\n // URL. Some frameworks pass alphanumeric script ID instead of URL which causes\n // Chrome to not download source maps. In this case we want to prepend script ID\n // with 'file://' prefix.\n if (message.params.url.match(/^[0-9a-z]+$/)) {\n message.params.url = FILE_PREFIX + message.params.url;\n debuggerInfo.prependedFilePrefix = true;\n }\n\n if (message.params.scriptId != null) {\n this.device._scriptIdToSourcePathMapping.set(message.params.scriptId, message.params.url);\n }\n }\n\n // Block `metro-inspector-proxy`'s default source map inlining\n return true;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#event-scriptParsed */\nexport type DebuggerScriptParsed = CdpMessage<\n 'Debugger.scriptParsed',\n Protocol.Debugger.ScriptParsedEvent,\n never\n>;\n"],"names":["EMULATOR_LOCALHOST_ADDRESSES","FILE_PREFIX","VscodeDebuggerScriptParsedHandler","constructor","device","onDeviceMessage","message","debuggerInfo","debuggerType","method","params","sourceMapURL","i","length","address","indexOf","replace","originalSourceURLAddress","url","match","prependedFilePrefix","scriptId","_scriptIdToSourcePathMapping","set"],"mappings":"AAAA;;;;AAMA,sGAAsG,CACtG,MAAMA,4BAA4B,GAAuB;IAAC,UAAU;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,CAACQ,GAAG,CAACF,OAAO,CAACF,OAAO,EAAE,WAAW,CAAC,CAAC;oBACtEP,YAAY,CAACU,wBAAwB,GAAGH,OAAO,CAAC;iBACjD;aACF;YAED,kEAAkE;YAClE,+EAA+E;YAC/E,gFAAgF;YAChF,yBAAyB;YACzB,IAAIR,OAAO,CAACI,MAAM,CAACQ,GAAG,CAACC,KAAK,eAAe,EAAE;gBAC3Cb,OAAO,CAACI,MAAM,CAACQ,GAAG,GAAGjB,WAAW,GAAGK,OAAO,CAACI,MAAM,CAACQ,GAAG,CAAC;gBACtDX,YAAY,CAACa,mBAAmB,GAAG,IAAI,CAAC;aACzC;YAED,IAAId,OAAO,CAACI,MAAM,CAACW,QAAQ,IAAI,IAAI,EAAE;gBACnC,IAAI,CAACjB,MAAM,CAACkB,4BAA4B,CAACC,GAAG,CAACjB,OAAO,CAACI,MAAM,CAACW,QAAQ,EAAEf,OAAO,CAACI,MAAM,CAACQ,GAAG,CAAC,CAAC;aAC3F;SACF;QAED,8DAA8D;QAC9D,OAAO,IAAI,CAAC;KACb;CACF;QA9CYhB,iCAAiC,GAAjCA,iCAAiC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ class VscodeDebuggerSetBreakpointByUrlHandler {
6
+ onDebuggerMessage(message, { debuggerType }) {
7
+ if (debuggerType === "vscode" && message.method === "Debugger.setBreakpointByUrl" && message.params.urlRegex) {
8
+ // Explicitly force the breakpoint to be unbounded
9
+ message.params.url = "file://__invalid_url__";
10
+ delete message.params.urlRegex;
11
+ }
12
+ return false;
13
+ }
14
+ }
15
+ exports.VscodeDebuggerSetBreakpointByUrlHandler = VscodeDebuggerSetBreakpointByUrlHandler;
16
+
17
+ //# sourceMappingURL=VscodeDebuggerSetBreakpointByUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerSetBreakpointByUrl.ts"],"sourcesContent":["import Protocol from 'devtools-protocol';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DebuggerRequest, InspectorHandler } from './types';\n\n/**\n * Hermes and vscode have trouble setting breakpoints by `urlRegex` through `Debugger.setBreakpointByUrl`.\n * Vscode adds `file://` to a URL containing `http://`, which confuses Hermes and sets it to the wrong location.\n * Hermes needs to create the breakpoint to get the proper ID, but it must be unbounded.\n * Once the sourcemap is loaded, vscode will rebind the unbounded breakpoint to the correct location (using `Debugger.setBreakpoint`).\n */\nexport class VscodeDebuggerSetBreakpointByUrlHandler implements InspectorHandler {\n onDebuggerMessage(\n message: DebuggerRequest<DebuggerSetBreakpointByUrl>,\n { debuggerType }: ExpoDebuggerInfo\n ): boolean {\n if (\n debuggerType === 'vscode' &&\n message.method === 'Debugger.setBreakpointByUrl' &&\n message.params.urlRegex\n ) {\n // Explicitly force the breakpoint to be unbounded\n message.params.url = 'file://__invalid_url__';\n delete message.params.urlRegex;\n }\n\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#method-setBreakpointByUrl */\nexport type DebuggerSetBreakpointByUrl = CdpMessage<\n 'Debugger.setBreakpointByUrl',\n Protocol.Debugger.SetBreakpointByUrlRequest,\n Protocol.Debugger.SetBreakpointByUrlResponse\n>;\n"],"names":["VscodeDebuggerSetBreakpointByUrlHandler","onDebuggerMessage","message","debuggerType","method","params","urlRegex","url"],"mappings":"AAAA;;;;AAWO,MAAMA,uCAAuC;IAClDC,iBAAiB,CACfC,OAAoD,EACpD,EAAEC,YAAY,CAAA,EAAoB,EACzB;QACT,IACEA,YAAY,KAAK,QAAQ,IACzBD,OAAO,CAACE,MAAM,KAAK,6BAA6B,IAChDF,OAAO,CAACG,MAAM,CAACC,QAAQ,EACvB;YACA,kDAAkD;YAClDJ,OAAO,CAACG,MAAM,CAACE,GAAG,GAAG,wBAAwB,CAAC;YAC9C,OAAOL,OAAO,CAACG,MAAM,CAACC,QAAQ,CAAC;SAChC;QAED,OAAO,KAAK,CAAC;KACd;CACF;QAjBYN,uCAAuC,GAAvCA,uCAAuC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ class VscodeRuntimeGetPropertiesHandler {
6
+ /** Keep track of `Runtime.getProperties` responses to intercept, by request id */ interceptGetProperties = new Set();
7
+ onDebuggerMessage(message, { debuggerType }) {
8
+ if (debuggerType === "vscode" && message.method === "Runtime.getProperties") {
9
+ this.interceptGetProperties.add(message.id);
10
+ }
11
+ // Do not block propagation of this message
12
+ return false;
13
+ }
14
+ onDeviceMessage(message, { debuggerType }) {
15
+ if (debuggerType === "vscode" && "id" in message && this.interceptGetProperties.has(message.id)) {
16
+ this.interceptGetProperties.delete(message.id);
17
+ var _result;
18
+ for (const item of (_result = message.result.result) != null ? _result : []){
19
+ var ref;
20
+ // Force-fully format the properties description to be an empty string
21
+ if (item.value) {
22
+ var _description;
23
+ item.value.description = (_description = item.value.description) != null ? _description : "";
24
+ }
25
+ // Avoid passing the `objectId` for symbol types.
26
+ // When collapsing in vscode, it will fetch information about the symbol using the `objectId`.
27
+ // The `Runtime.getProperties` request of the symbol hard-crashes Hermes.
28
+ if (((ref = item.value) == null ? void 0 : ref.type) === "symbol" && item.value.objectId) {
29
+ delete item.value.objectId;
30
+ }
31
+ }
32
+ }
33
+ // Do not block propagation of this message
34
+ return false;
35
+ }
36
+ }
37
+ exports.VscodeRuntimeGetPropertiesHandler = VscodeRuntimeGetPropertiesHandler;
38
+
39
+ //# sourceMappingURL=VscodeRuntimeGetProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeGetProperties.ts"],"sourcesContent":["import Protocol from 'devtools-protocol';\n\nimport { ExpoDebuggerInfo } from '../device';\nimport { CdpMessage, DebuggerRequest, DeviceResponse, InspectorHandler } from './types';\n\n/**\n * Vscode doesn't seem to work nicely with missing `description` fields on `RemoteObject` instances.\n * It also tries to invoke `Runtime.callFunctionOn` on `Symbol` types, which crashes Hermes.\n * This handler tries to compensate for these two separate issues.\n *\n * @see https://github.com/facebook/hermes/issues/114\n * @see https://github.com/microsoft/vscode-js-debug/issues/1583\n */\nexport class VscodeRuntimeGetPropertiesHandler implements InspectorHandler {\n /** Keep track of `Runtime.getProperties` responses to intercept, by request id */\n interceptGetProperties = new Set<number>();\n\n onDebuggerMessage(\n message: DebuggerRequest<RuntimeGetProperties>,\n { debuggerType }: ExpoDebuggerInfo\n ): boolean {\n if (debuggerType === 'vscode' && message.method === 'Runtime.getProperties') {\n this.interceptGetProperties.add(message.id);\n }\n\n // Do not block propagation of this message\n return false;\n }\n\n onDeviceMessage(\n message: DeviceResponse<RuntimeGetProperties>,\n { debuggerType }: ExpoDebuggerInfo\n ) {\n if (\n debuggerType === 'vscode' &&\n 'id' in message &&\n this.interceptGetProperties.has(message.id)\n ) {\n this.interceptGetProperties.delete(message.id);\n\n for (const item of message.result.result ?? []) {\n // Force-fully format the properties description to be an empty string\n if (item.value) {\n item.value.description = item.value.description ?? '';\n }\n\n // Avoid passing the `objectId` for symbol types.\n // When collapsing in vscode, it will fetch information about the symbol using the `objectId`.\n // The `Runtime.getProperties` request of the symbol hard-crashes Hermes.\n if (item.value?.type === 'symbol' && item.value.objectId) {\n delete item.value.objectId;\n }\n }\n }\n\n // Do not block propagation of this message\n return false;\n }\n}\n\n/** @see https://chromedevtools.github.io/devtools-protocol/v8/Runtime/#method-getProperties */\nexport type RuntimeGetProperties = CdpMessage<\n 'Runtime.getProperties',\n Protocol.Runtime.GetPropertiesRequest,\n Protocol.Runtime.GetPropertiesResponse\n>;\n"],"names":["VscodeRuntimeGetPropertiesHandler","interceptGetProperties","Set","onDebuggerMessage","message","debuggerType","method","add","id","onDeviceMessage","has","delete","item","result","value","description","type","objectId"],"mappings":"AAAA;;;;AAaO,MAAMA,iCAAiC;IAC5C,kFAAkF,CAClFC,sBAAsB,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QAED,2CAA2C;QAC3C,OAAO,KAAK,CAAC;KACd;CACF;QA7CYjB,iCAAiC,GAAjCA,iCAAiC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/types.ts"],"sourcesContent":["import { DebuggerInfo } from 'metro-inspector-proxy';\n\nexport interface InspectorHandler {\n /**\n * Intercept a message coming from the device, modify or respond to it through `this._sendMessageToDevice`.\n * Return `true` if the message was handled, this will stop the message propagation.\n */\n onDeviceMessage?(message: DeviceRequest | DeviceResponse, info: DebuggerInfo): boolean;\n\n /**\n * Intercept a message coming from the debugger, modify or respond to it through `socket.send`.\n * Return `true` if the message was handled, this will stop the message propagation.\n */\n onDebuggerMessage?(message: DebuggerRequest, info: DebuggerInfo): boolean;\n}\n\n/**\n * The outline of a basic Chrome DevTools Protocol request, either from device or debugger.\n * Both the request and response parameters could be optional, use `never` to enforce these fields.\n */\nexport type CdpMessage<\n Method extends string = string,\n Request extends object = object,\n Response extends object = object\n> = {\n id: number;\n method: Method;\n params: Request;\n result: Response;\n};\n\nexport type DeviceRequest<M extends CdpMessage = CdpMessage> = Pick<M, 'method' | 'params'>;\nexport type DeviceResponse<M extends CdpMessage = CdpMessage> = Pick<M, 'id' | 'result'>;\n\nexport type DebuggerRequest<M extends CdpMessage = CdpMessage> = Pick<\n M,\n 'id' | 'method' | 'params'\n>;\nexport type DebuggerResponse<M extends CdpMessage = CdpMessage> = Pick<M, 'result'>;\n"],"names":[],"mappings":"AAAA"}
1
+ {"version":3,"sources":["../../../../../../../src/start/server/metro/inspector-proxy/handlers/types.ts"],"sourcesContent":["import { ExpoDebuggerInfo } from '../device';\n\nexport interface InspectorHandler {\n /**\n * Intercept a message coming from the device, modify or respond to it through `this._sendMessageToDevice`.\n * Return `true` if the message was handled, this will stop the message propagation.\n */\n onDeviceMessage?(message: DeviceRequest | DeviceResponse, info: ExpoDebuggerInfo): boolean;\n\n /**\n * Intercept a message coming from the debugger, modify or respond to it through `socket.send`.\n * Return `true` if the message was handled, this will stop the message propagation.\n */\n onDebuggerMessage?(message: DebuggerRequest, info: ExpoDebuggerInfo): boolean;\n}\n\n/**\n * The outline of a basic Chrome DevTools Protocol request, either from device or debugger.\n * Both the request and response parameters could be optional, use `never` to enforce these fields.\n */\nexport type CdpMessage<\n Method extends string = string,\n Request extends object = object,\n Response extends object = object\n> = {\n id: number;\n method: Method;\n params: Request;\n result: Response;\n};\n\nexport type DeviceRequest<M extends CdpMessage = CdpMessage> = Pick<M, 'method' | 'params'>;\nexport type DeviceResponse<M extends CdpMessage = CdpMessage> = Pick<M, 'id' | 'result'>;\n\nexport type DebuggerRequest<M extends CdpMessage = CdpMessage> = Pick<\n M,\n 'id' | 'method' | 'params'\n>;\nexport type DebuggerResponse<M extends CdpMessage = CdpMessage> = Pick<M, 'result'>;\n"],"names":[],"mappings":"AAAA"}
@@ -62,7 +62,7 @@ class ExpoInspectorProxy {
62
62
  wss.on("connection", (socket, request)=>{
63
63
  try {
64
64
  const fallbackDeviceId = String(this.metroProxy._deviceCounter++);
65
- const { deviceId: newDeviceId , deviceName , appName } = getNewDeviceInfo(request.url);
65
+ const { deviceId: newDeviceId , deviceName , appName } = getDeviceInfo(request.url);
66
66
  const deviceId = newDeviceId != null ? newDeviceId : fallbackDeviceId;
67
67
  const oldDevice = this.devices.get(deviceId);
68
68
  const newDevice = new this.DeviceClass(deviceId, deviceName, appName, socket, this.metroProxy._projectRoot);
@@ -104,7 +104,7 @@ class ExpoInspectorProxy {
104
104
  // See: https://github.com/facebook/metro/blob/eeb211fdcfdcb9e7f8a51721bd0f48bc7d0d211f/packages/metro-inspector-proxy/src/InspectorProxy.js#L193
105
105
  wss.on("connection", (socket, request)=>{
106
106
  try {
107
- const { deviceId , pageId } = getExistingDeviceInfo(request.url);
107
+ const { deviceId , pageId , debuggerType } = getDebuggerInfo(request.url);
108
108
  if (!deviceId || !pageId) {
109
109
  // TODO(cedric): change these errors to proper error types
110
110
  throw new Error(`Missing "device" and/or "page" IDs in query parameters`);
@@ -115,7 +115,13 @@ class ExpoInspectorProxy {
115
115
  throw new Error(`Device with ID "${deviceId}" not found.`);
116
116
  }
117
117
  debug("New debugger connected: device=%s, app=%s", device._name, device._app);
118
- device.handleDebuggerConnection(socket, pageId);
118
+ // @ts-expect-error The `handleDebuggerConnectionWithType` is part of our device implementation, not Metro's device
119
+ if (debuggerType && typeof device.handleDebuggerConnectionWithType === "function") {
120
+ // @ts-expect-error The `handleDebuggerConnectionWithType` is part of our device implementation, not Metro's device
121
+ device.handleDebuggerConnectionWithType(socket, pageId, debuggerType);
122
+ } else {
123
+ device.handleDebuggerConnection(socket, pageId);
124
+ }
119
125
  socket.on("close", ()=>{
120
126
  debug("Debugger disconnected: device=%s, app=%s", device._name, device._app);
121
127
  });
@@ -139,7 +145,7 @@ exports.ExpoInspectorProxy = ExpoInspectorProxy;
139
145
  function asString(value = "") {
140
146
  return Array.isArray(value) ? value.join() : value;
141
147
  }
142
- function getNewDeviceInfo(url) {
148
+ function getDeviceInfo(url) {
143
149
  const { query } = (0, _url).parse(url != null ? url : "", true);
144
150
  return {
145
151
  deviceId: asString(query.device) || undefined,
@@ -147,11 +153,13 @@ function getNewDeviceInfo(url) {
147
153
  appName: asString(query.app) || "Unknown app name"
148
154
  };
149
155
  }
150
- function getExistingDeviceInfo(url) {
156
+ function getDebuggerInfo(url) {
151
157
  const { query } = (0, _url).parse(url != null ? url : "", true);
158
+ var ref;
152
159
  return {
153
160
  deviceId: asString(query.device),
154
- pageId: asString(query.page)
161
+ pageId: asString(query.page),
162
+ debuggerType: (ref = asString(query.type)) != null ? ref : undefined
155
163
  };
156
164
  }
157
165