This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-02 02:24:13 +03:00

1 line
8.7 KiB
Plaintext

{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/paths/paths.ts"],"names":[],"mappings":";;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,gEAAuC;AAEvC,sCAAsC;AAEtC,6CAAoD;AAEpD,wIAAwI;AACxI,SAAgB,WAAW,CAAC,SAAiB,EAAE,UAAmB;IAChE,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,QAAQ,IAAI,CAAC,UAAU,EAAE;QAC3B,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KAClD;SAAM,IAAI,CAAC,QAAQ,IAAI,UAAU,EAAE;QAClC,OAAO,GAAG,SAAS,GAAG,CAAC;KACxB;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AATD,kCASC;AAED,SAAgB,sBAAsB;IACpC,OAAO,kBAAE,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACxC,CAAC;AAFD,wDAEC;AAED,SAAgB,aAAa,CAC3B,WAAmB,EACnB,UAAoB,EACpB,SAAmB,EACnB,aAA6B;IAE7B,MAAM,UAAU,GAAG,iCAAoB,CAAC,SAAS,CAAC,CAAC;IACnD,OAAO,2BAA2B,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AACzF,CAAC;AARD,sCAQC;AAED,qDAAqD;AACrD,SAAgB,2BAA2B,CACzC,WAAmB,EACnB,UAAoB,EACpB,UAAoB,EACpB,aAA6B;IAE7B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,kBAAS,CAAC,WAAW,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAA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import resolveFrom from 'resolve-from';\n\nimport { getConfig } from '../Config';\nimport { ProjectConfig } from '../Config.types';\nimport { getManagedExtensions } from './extensions';\n\n// https://github.com/facebook/create-react-app/blob/9750738cce89a967cc71f28390daf5d4311b193c/packages/react-scripts/config/paths.js#L22\nexport function ensureSlash(inputPath: string, needsSlash: boolean): string {\n const hasSlash = inputPath.endsWith('/');\n if (hasSlash && !needsSlash) {\n return inputPath.substr(0, inputPath.length - 1);\n } else if (!hasSlash && needsSlash) {\n return `${inputPath}/`;\n } else {\n return inputPath;\n }\n}\n\nexport function getPossibleProjectRoot(): string {\n return fs.realpathSync(process.cwd());\n}\n\nexport function getEntryPoint(\n projectRoot: string,\n entryFiles: string[],\n platforms: string[],\n projectConfig?: ProjectConfig\n): string | null {\n const extensions = getManagedExtensions(platforms);\n return getEntryPointWithExtensions(projectRoot, entryFiles, extensions, projectConfig);\n}\n\n// Used to resolve the main entry file for a project.\nexport function getEntryPointWithExtensions(\n projectRoot: string,\n entryFiles: string[],\n extensions: string[],\n projectConfig?: ProjectConfig\n): string {\n const { exp, pkg } = projectConfig ?? getConfig(projectRoot, { skipSDKVersionRequirement: true });\n\n // This will first look in the `app.json`s `expo.entryPoint` field for a potential main file.\n // We check the Expo config first in case you want your project to start differently with Expo then in a standalone environment.\n if (exp && exp.entryPoint && typeof exp.entryPoint === 'string') {\n // If the field exists then we want to test it against every one of the supplied extensions\n // to ensure the bundler resolves the same way.\n let entry = getFileWithExtensions(projectRoot, exp.entryPoint, extensions);\n if (!entry) {\n // Allow for paths like: `{ \"main\": \"expo/AppEntry\" }`\n entry = resolveFromSilentWithExtensions(projectRoot, exp.entryPoint, extensions);\n\n // If it doesn't resolve then just return the entryPoint as-is. This makes\n // it possible for people who have an unconventional setup (eg: multiple\n // apps in monorepo with metro at root) to customize entry point without\n // us imposing our assumptions.\n if (!entry) {\n return exp.entryPoint;\n }\n }\n return entry;\n } else if (pkg) {\n // If the config doesn't define a custom entry then we want to look at the `package.json`s `main` field, and try again.\n const { main } = pkg;\n if (main && typeof main === 'string') {\n // Testing the main field against all of the provided extensions - for legacy reasons we can't use node module resolution as the package.json allows you to pass in a file without a relative path and expect it as a relative path.\n let entry = getFileWithExtensions(projectRoot, main, extensions);\n if (!entry) {\n // Allow for paths like: `{ \"main\": \"expo/AppEntry\" }`\n entry = resolveFromSilentWithExtensions(projectRoot, main, extensions);\n if (!entry)\n throw new Error(\n `Cannot resolve entry file: The \\`main\\` field defined in your \\`package.json\\` points to a non-existent path.`\n );\n }\n return entry;\n }\n }\n\n // Now we will start looking for a default entry point using the provided `entryFiles` argument.\n // This will add support for create-react-app (src/index.js) and react-native-cli (index.js) which don't define a main.\n for (const fileName of entryFiles) {\n const entry = resolveFromSilentWithExtensions(projectRoot, fileName, extensions);\n if (entry) return entry;\n }\n\n try {\n // If none of the default files exist then we will attempt to use the main Expo entry point.\n // This requires `expo` to be installed in the project to work as it will use `node_module/expo/AppEntry.js`\n // Doing this enables us to create a bare minimum Expo project.\n\n // TODO(Bacon): We may want to do a check against `./App` and `expo` in the `package.json` `dependencies` as we can more accurately ensure that the project is expo-min without needing the modules installed.\n return resolveFrom(projectRoot, 'expo/AppEntry');\n } catch {\n throw new Error(\n `The project entry file could not be resolved. Please either define it in the \\`package.json\\` (main), \\`app.json\\` (expo.entryPoint), create an \\`index.js\\`, or install the \\`expo\\` package.`\n );\n }\n}\n\n// Resolve from but with the ability to resolve like a bundler\nexport function resolveFromSilentWithExtensions(\n fromDirectory: string,\n moduleId: string,\n extensions: string[]\n): string | null {\n for (const extension of extensions) {\n const modulePath = resolveFrom.silent(fromDirectory, `${moduleId}.${extension}`);\n if (modulePath && modulePath.endsWith(extension)) {\n return modulePath;\n }\n }\n return resolveFrom.silent(fromDirectory, moduleId) || null;\n}\n\n// Statically attempt to resolve a module but with the ability to resolve like a bundler.\n// This won't use node module resolution.\nexport function getFileWithExtensions(\n fromDirectory: string,\n moduleId: string,\n extensions: string[]\n): string | null {\n const modulePath = path.join(fromDirectory, moduleId);\n if (fs.existsSync(modulePath)) {\n return modulePath;\n }\n for (const extension of extensions) {\n const modulePath = path.join(fromDirectory, `${moduleId}.${extension}`);\n if (fs.existsSync(modulePath)) {\n return modulePath;\n }\n }\n return null;\n}\n"]}