1 line
18 KiB
Plaintext
1 line
18 KiB
Plaintext
{"version":3,"sources":["UrlUtils.js"],"names":["async","projectRoot","opts","requestHostname","constructUrlAsync","constructBundleUrlAsync","constructManifestUrlAsync","let","baseUrl","await","urlType","constructLogUrlAsync","entryPoint","ext","bundleUrl","hostType","mainModulePath","guessMainModulePath","queryParams","constructBundleQueryParamsAsync","dev","minify","constructUrlWithExtensionAsync","constructPublishUrlAsync","constructSourceMapUrlAsync","constructAssetsUrlAsync","constructDebuggerHostAsync","encodeURIComponent","hasOwnProperty","strict","exp","pkg","ProjectUtils","readConfigJsonAsync","sdkPkg","dependencies","nodeModulesPath","path","join","resolve","pluginModule","supportsAssetPlugins","Versions","gteSdkVersion","isPackager","urlRandomnessSchema","Config","offline","joi","string","optional","allow","schema","object","keys","any","valid","lanType","boolean","urlRandomness","joiValidateAsync","e","ErrorCode","INVALID_OPTIONS","toString","defaultOpts","ProjectSettings","getPackagerOptsAsync","Object","assign","packagerInfo","readPackagerInfoAsync","protocol","detach","scheme","hostname","port","proxyURL","process","env","EXPO_PACKAGER_PROXY_URL","EXPO_MANIFEST_PROXY_URL","parsedProxyURL","url","parse","packagerPort","expoServerPort","EXPO_PACKAGER_HOSTNAME","REACT_NATIVE_PACKAGER_HOSTNAME","ip","address","os","ngrokUrl","packagerNgrokUrl","expoServerNgrokUrl","pnu","url_","Error","randomIdentifier","sevenDigitIdentifier","randomIdentifierForUser","someRandomness","domainify","getPlatformSpecificBundleUrl","promisify","validate","replace","length","alphabet","result","i","j","Math","floor","random","c","substr","username","s","toLowerCase","platform","includes","Exp","ENTRY_POINT_PLATFORM_TEMPLATE_STRING"],"mappings":";;;;;;;;+BAqBOA,WACLC,WADKD,EAELE,IAFKF,EAGLG,eAHKH,EAIL;AACA,WAAOI,kBAAkBH,WAAlBG,EAA+BF,IAA/BE,EAAqC,IAArCA,EAA2CD,eAA3CC,CAAP;AACF,G;;kBANsBC,uB;;;;;;gCAQfL,WACLC,WADKD,EAELE,IAFKF,E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GAA5B,EAAiC;AAC/BvG,QAAIwG,IAAIC,KAAKC,KAALD,CAAWA,KAAKE,MAALF,KAAgBJ,SAASD,MAApCK,CAARzG;AACAA,QAAI4G,IAAIP,SAASQ,MAATR,CAAgBG,CAAhBH,EAAmB,CAAnBA,CAARrG;AACAsG,cAAUM,CAAVN;AACF;AACA,SAAOA,MAAP;AACF;;AAEO,SAASV,oBAAT,GAAgC;AACrC,SAAQ,GAAED,iBAAiB,CAAjBA,CAAoB,IAAGA,iBAAiB,CAAjBA,CAAoB,EAArD;AACF;;AAEO,SAASE,uBAAT,CAAiCiB,QAAjC,EAAmD;AACxD,SAAQ,GAAEA,QAAS,IAAGnB,iBAAiB,CAAjBA,CAAoB,IAAGA,iBAAiB,CAAjBA,CAAoB,EAAjE;AACF;;AAEO,SAASG,cAAT,GAA0B;AAC/B,SAAO,CAACH,iBAAiB,CAAjBA,CAAD,EAAsBA,iBAAiB,CAAjBA,CAAtB,EAA2C5D,IAA3C,CAAgD,GAAhD,CAAP;AACF;;AAEO,SAASgE,SAAT,CAAmBgB,CAAnB,EAA8B;AACnC,SAAOA,EACJC,WADID,GAEJZ,OAFIY,CAEI,aAFJA,EAEmB,GAFnBA,EAGJZ,OAHIY,CAGI,KAHJA,EAGW,EAHXA,EAIJZ,OAJIY,CAII,KAJJA,EAIW,EAJXA,CAAP;AAKF;;AAEO,SAASf,4BAAT,CAAsCpB,GAAtC,EAAmDqC,QAAnD,EAAqE;AAC1E,MAAIrC,IAAIsC,QAAJtC,CAAauC,sBAAIC,oCAAjBxC,CAAJ,EAA4D;AAC1D,WAAOA,IAAIuB,OAAJvB,CAAYuC,sBAAIC,oCAAhBxC,EAAsDqC,QAAtDrC,CAAP;AACF,GAFA,MAEO;AACL,WAAOA,GAAP;AACF;AACF","file":"../UrlUtils.js","sourcesContent":["/**\n * @flow\n */\n\nimport joi from 'joi';\nimport os from 'os';\nimport path from 'path';\nimport url from 'url';\nimport promisify from 'util.promisify';\n\nimport ip from './ip';\nimport Config from './Config';\nimport ErrorCode from './ErrorCode';\nimport * as Exp from './Exp';\nimport * as ProjectSettings from './ProjectSettings';\nimport * as ProjectUtils from './project/ProjectUtils';\nimport * as Versions from './Versions';\nimport XDLError from './XDLError';\n\nconst joiValidateAsync = promisify(joi.validate);\n\nexport async function constructBundleUrlAsync(\n projectRoot: string,\n opts: any,\n requestHostname?: string\n) {\n return constructUrlAsync(projectRoot, opts, true, requestHostname);\n}\n\nexport async function constructManifestUrlAsync(\n projectRoot: string,\n opts: any,\n requestHostname?: string\n) {\n return constructUrlAsync(projectRoot, opts, false, requestHostname);\n}\n\nexport async function constructLogUrlAsync(projectRoot: string, requestHostname?: string) {\n let baseUrl = await constructUrlAsync(projectRoot, { urlType: 'http' }, false, requestHostname);\n return `${baseUrl}/logs`;\n}\n\nexport async function constructUrlWithExtensionAsync(\n projectRoot: string,\n entryPoint: string,\n ext: string,\n requestHostname?: string\n) {\n let bundleUrl = await constructBundleUrlAsync(\n projectRoot,\n {\n hostType: 'localhost',\n urlType: 'http',\n },\n requestHostname\n );\n\n let mainModulePath = guessMainModulePath(entryPoint);\n bundleUrl += `/${mainModulePath}.${ext}`;\n\n let queryParams = await constructBundleQueryParamsAsync(\n projectRoot,\n {\n dev: false,\n minify: true,\n },\n requestHostname\n );\n return `${bundleUrl}?${queryParams}`;\n}\n\nexport async function constructPublishUrlAsync(\n projectRoot: string,\n entryPoint: string,\n requestHostname?: string\n) {\n return await constructUrlWithExtensionAsync(projectRoot, entryPoint, 'bundle', requestHostname);\n}\n\nexport async function constructSourceMapUrlAsync(\n projectRoot: string,\n entryPoint: string,\n requestHostname?: string\n) {\n return await constructUrlWithExtensionAsync(projectRoot, entryPoint, 'map', requestHostname);\n}\n\nexport async function constructAssetsUrlAsync(\n projectRoot: string,\n entryPoint: string,\n requestHostname?: string\n) {\n return await constructUrlWithExtensionAsync(projectRoot, entryPoint, 'assets', requestHostname);\n}\n\nexport async function constructDebuggerHostAsync(projectRoot: string, requestHostname?: string) {\n return constructUrlAsync(\n projectRoot,\n {\n urlType: 'no-protocol',\n },\n true,\n requestHostname\n );\n}\n\nexport async function constructBundleQueryParamsAsync(projectRoot: string, opts: any) {\n let queryParams = `dev=${encodeURIComponent(!!opts.dev)}`;\n\n if (opts.hasOwnProperty('strict')) {\n queryParams += `&strict=${encodeURIComponent(!!opts.strict)}`;\n }\n\n if (opts.hasOwnProperty('minify')) {\n queryParams += `&minify=${encodeURIComponent(!!opts.minify)}`;\n }\n\n queryParams += '&hot=false';\n\n let { exp, pkg } = await ProjectUtils.readConfigJsonAsync(projectRoot);\n\n // Be backwards compatible for users who haven't migrated from `exponent`\n // to the `expo` sdk package.\n let sdkPkg = pkg.dependencies['expo'] ? 'expo' : 'exponent';\n // Use an absolute path here so that we can not worry about symlinks/relative requires\n let nodeModulesPath = exp.nodeModulesPath\n ? path.join(path.resolve(projectRoot, exp.nodeModulesPath), 'node_modules')\n : path.join(projectRoot, 'node_modules');\n let pluginModule = path.join(nodeModulesPath, sdkPkg, 'tools', 'hashAssetFiles');\n queryParams += `&assetPlugin=${pluginModule}`;\n\n // Only sdk-10.1.0+ supports the assetPlugin parameter. We use only the\n // major version in the sdkVersion field, so check for 11.0.0 to be sure.\n let supportsAssetPlugins = Versions.gteSdkVersion(exp, '11.0.0');\n if (!supportsAssetPlugins) {\n queryParams += '&includeAssetFileHashes=true';\n }\n\n return queryParams;\n}\n\nexport async function constructUrlAsync(\n projectRoot: string,\n opts: any,\n isPackager: boolean,\n requestHostname?: string\n) {\n if (opts) {\n // the randomness is only important if we're online and can build a tunnel\n let urlRandomnessSchema;\n if (Config.offline) {\n urlRandomnessSchema = joi\n .string()\n .optional()\n .allow(null);\n } else {\n urlRandomnessSchema = joi.string();\n }\n\n let schema = joi.object().keys({\n urlType: joi.any().valid('exp', 'http', 'redirect', 'no-protocol'),\n lanType: joi.any().valid('ip', 'hostname'),\n hostType: joi.any().valid('localhost', 'lan', 'tunnel'),\n dev: joi.boolean(),\n strict: joi.boolean(),\n minify: joi.boolean(),\n urlRandomness: urlRandomnessSchema,\n });\n\n try {\n await joiValidateAsync(opts, schema);\n } catch (e) {\n throw new XDLError(ErrorCode.INVALID_OPTIONS, e.toString());\n }\n }\n\n let defaultOpts = await ProjectSettings.getPackagerOptsAsync(projectRoot);\n if (!opts) {\n opts = defaultOpts;\n } else {\n opts = Object.assign({}, defaultOpts, opts);\n }\n\n let packagerInfo = await ProjectSettings.readPackagerInfoAsync(projectRoot);\n\n let protocol;\n if (opts.urlType === 'http') {\n protocol = 'http';\n } else if (opts.urlType === 'no-protocol') {\n protocol = null;\n } else {\n protocol = 'exp';\n\n let { exp } = await ProjectUtils.readConfigJsonAsync(projectRoot);\n if (exp.detach && exp.detach.scheme) {\n protocol = exp.detach.scheme;\n }\n }\n\n let hostname;\n let port;\n\n const proxyURL = isPackager\n ? process.env.EXPO_PACKAGER_PROXY_URL\n : process.env.EXPO_MANIFEST_PROXY_URL;\n if (proxyURL) {\n const parsedProxyURL = url.parse(proxyURL);\n hostname = parsedProxyURL.hostname;\n port = parsedProxyURL.port;\n if (parsedProxyURL.protocol === 'https:') {\n if (protocol === 'http') {\n protocol = 'https';\n }\n if (!port) {\n port = '443';\n }\n }\n } else if (opts.hostType === 'localhost' || requestHostname === 'localhost') {\n hostname = 'localhost';\n port = isPackager ? packagerInfo.packagerPort : packagerInfo.expoServerPort;\n } else if (opts.hostType === 'lan' || Config.offline) {\n if (process.env.EXPO_PACKAGER_HOSTNAME) {\n hostname = process.env.EXPO_PACKAGER_HOSTNAME;\n } else if (process.env.REACT_NATIVE_PACKAGER_HOSTNAME) {\n hostname = process.env.REACT_NATIVE_PACKAGER_HOSTNAME;\n } else if (opts.lanType === 'ip') {\n if (requestHostname) {\n hostname = requestHostname;\n } else {\n hostname = ip.address();\n }\n } else {\n // Some old versions of OSX work with hostname but not local ip address.\n hostname = os.hostname();\n }\n port = isPackager ? packagerInfo.packagerPort : packagerInfo.expoServerPort;\n } else {\n let ngrokUrl = isPackager ? packagerInfo.packagerNgrokUrl : packagerInfo.expoServerNgrokUrl;\n if (!ngrokUrl) {\n // use localhost\n hostname = 'localhost';\n port = isPackager ? packagerInfo.packagerPort : packagerInfo.expoServerPort;\n\n // TODO report a warning when this is for a currently served project, suppress for status checks\n } else {\n let pnu = url.parse(ngrokUrl);\n hostname = pnu.hostname;\n port = pnu.port;\n }\n }\n\n let url_ = '';\n if (protocol) {\n url_ += `${protocol}://`;\n }\n\n if (!hostname) {\n throw new Error('Hostname cannot be inferred.');\n }\n\n url_ += hostname;\n\n if (port) {\n url_ += `:${port}`;\n } else {\n // Android HMR breaks without this :|\n url_ += ':80';\n }\n\n if (opts.urlType === 'redirect') {\n return `https://exp.host/--/to-exp/${encodeURIComponent(url_)}`;\n }\n\n return url_;\n}\n\nexport function guessMainModulePath(entryPoint: string) {\n return entryPoint.replace(/\\.js$/, '');\n}\n\nexport function randomIdentifier(length: number = 6) {\n let alphabet = '23456789qwertyuipasdfghjkzxcvbnm';\n let result = '';\n for (let i = 0; i < length; i++) {\n let j = Math.floor(Math.random() * alphabet.length);\n let c = alphabet.substr(j, 1);\n result += c;\n }\n return result;\n}\n\nexport function sevenDigitIdentifier() {\n return `${randomIdentifier(3)}-${randomIdentifier(4)}`;\n}\n\nexport function randomIdentifierForUser(username: string) {\n return `${username}-${randomIdentifier(3)}-${randomIdentifier(2)}`;\n}\n\nexport function someRandomness() {\n return [randomIdentifier(2), randomIdentifier(3)].join('-');\n}\n\nexport function domainify(s: string) {\n return s\n .toLowerCase()\n .replace(/[^a-z0-9-]/g, '-')\n .replace(/^-+/, '')\n .replace(/-+$/, '');\n}\n\nexport function getPlatformSpecificBundleUrl(url: string, platform: string) {\n if (url.includes(Exp.ENTRY_POINT_PLATFORM_TEMPLATE_STRING)) {\n return url.replace(Exp.ENTRY_POINT_PLATFORM_TEMPLATE_STRING, platform);\n } else {\n return url;\n }\n}\n"],"sourceRoot":"/xdl/src"} |