@expo/cli 0.13.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bin/cli +30 -27
- package/build/bin/cli.map +1 -1
- package/build/src/api/getVersions.js.map +1 -1
- package/build/src/api/rest/cache/response.js.map +1 -1
- package/build/src/api/rest/client.js +2 -2
- package/build/src/api/rest/client.js.map +1 -1
- package/build/src/config/configAsync.js +1 -1
- package/build/src/config/configAsync.js.map +1 -1
- package/build/src/config/index.js +2 -2
- package/build/src/config/index.js.map +1 -1
- package/build/src/customize/generate.js +1 -1
- package/build/src/customize/generate.js.map +1 -1
- package/build/src/customize/typescript.js +6 -4
- package/build/src/customize/typescript.js.map +1 -1
- package/build/src/export/createMetadataJson.js +3 -2
- package/build/src/export/createMetadataJson.js.map +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +44 -17
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/embed/index.js +4 -4
- package/build/src/export/embed/index.js.map +1 -1
- package/build/src/export/embed/resolveOptions.js +3 -3
- package/build/src/export/embed/resolveOptions.js.map +1 -1
- package/build/src/export/exportApp.js +74 -83
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/exportAssets.js +81 -21
- package/build/src/export/exportAssets.js.map +1 -1
- package/build/src/export/exportHermes.js +24 -14
- package/build/src/export/exportHermes.js.map +1 -1
- package/build/src/export/exportStaticAsync.js +109 -58
- package/build/src/export/exportStaticAsync.js.map +1 -1
- package/build/src/export/favicon.js +2 -2
- package/build/src/export/favicon.js.map +1 -1
- package/build/src/export/fork-bundleAsync.js +56 -23
- package/build/src/export/fork-bundleAsync.js.map +1 -1
- package/build/src/export/index.js +11 -9
- package/build/src/export/index.js.map +1 -1
- package/build/src/export/metroAssetLocalPath.js +101 -0
- package/build/src/export/metroAssetLocalPath.js.map +1 -0
- package/build/src/export/persistMetroAssets.js +94 -21
- package/build/src/export/persistMetroAssets.js.map +1 -1
- package/build/src/export/resolveOptions.js +1 -1
- package/build/src/export/resolveOptions.js.map +1 -1
- package/build/src/export/saveAssets.js +9 -48
- package/build/src/export/saveAssets.js.map +1 -1
- package/build/src/export/web/exportWebAsync.js +1 -1
- package/build/src/export/web/exportWebAsync.js.map +1 -1
- package/build/src/export/web/index.js +2 -2
- package/build/src/export/web/index.js.map +1 -1
- package/build/src/export/writeContents.js +6 -3
- package/build/src/export/writeContents.js.map +1 -1
- package/build/src/install/applyPlugins.js +52 -0
- package/build/src/install/applyPlugins.js.map +1 -0
- package/build/src/install/checkPackages.js +2 -2
- package/build/src/install/checkPackages.js.map +1 -1
- package/build/src/install/fixPackages.js +84 -0
- package/build/src/install/fixPackages.js.map +1 -0
- package/build/src/install/installAsync.js +32 -61
- package/build/src/install/installAsync.js.map +1 -1
- package/build/src/install/installExpoPackage.js +79 -0
- package/build/src/install/installExpoPackage.js.map +1 -0
- package/build/src/login/index.js +1 -1
- package/build/src/login/index.js.map +1 -1
- package/build/src/logout/index.js +1 -1
- package/build/src/logout/index.js.map +1 -1
- package/build/src/prebuild/clearNativeFolder.js +1 -1
- package/build/src/prebuild/clearNativeFolder.js.map +1 -1
- package/build/src/prebuild/configureProjectAsync.js +3 -3
- package/build/src/prebuild/configureProjectAsync.js.map +1 -1
- package/build/src/prebuild/copyTemplateFiles.js +21 -30
- package/build/src/prebuild/copyTemplateFiles.js.map +1 -1
- package/build/src/prebuild/index.js +3 -3
- package/build/src/prebuild/index.js.map +1 -1
- package/build/src/prebuild/prebuildAsync.js +39 -17
- package/build/src/prebuild/prebuildAsync.js.map +1 -1
- package/build/src/prebuild/resolveOptions.js +2 -2
- package/build/src/prebuild/resolveOptions.js.map +1 -1
- package/build/src/prebuild/updateFromTemplate.js +6 -6
- package/build/src/prebuild/updateFromTemplate.js.map +1 -1
- package/build/src/prebuild/updatePackageJson.js +49 -36
- package/build/src/prebuild/updatePackageJson.js.map +1 -1
- package/build/src/prebuild/validateTemplatePlatforms.js +2 -2
- package/build/src/prebuild/validateTemplatePlatforms.js.map +1 -1
- package/build/src/register/index.js +1 -1
- package/build/src/register/index.js.map +1 -1
- package/build/src/run/android/index.js +2 -2
- package/build/src/run/android/index.js.map +1 -1
- package/build/src/run/ios/appleDevice/AppleDevice.js +35 -2
- package/build/src/run/ios/appleDevice/AppleDevice.js.map +1 -1
- package/build/src/run/ios/index.js +2 -2
- package/build/src/run/ios/index.js.map +1 -1
- package/build/src/start/doctor/dependencies/getVersionedPackages.js +12 -4
- package/build/src/start/doctor/dependencies/getVersionedPackages.js.map +1 -1
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js +20 -3
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js.map +1 -1
- package/build/src/start/index.js +3 -3
- package/build/src/start/index.js.map +1 -1
- package/build/src/start/interface/interactiveActions.js +30 -11
- package/build/src/start/interface/interactiveActions.js.map +1 -1
- package/build/src/start/server/BundlerDevServer.js +14 -10
- package/build/src/start/server/BundlerDevServer.js.map +1 -1
- package/build/src/start/server/DevServerManager.js +6 -1
- package/build/src/start/server/DevServerManager.js.map +1 -1
- package/build/src/start/server/DevToolsPluginManager.js +63 -0
- package/build/src/start/server/DevToolsPluginManager.js.map +1 -0
- package/build/src/start/server/getStaticRenderFunctions.js +21 -20
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +67 -64
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/bundleApiRoutes.js +4 -19
- package/build/src/start/server/metro/bundleApiRoutes.js.map +1 -1
- package/build/src/start/server/metro/createExpoMetroResolver.js +187 -0
- package/build/src/start/server/metro/createExpoMetroResolver.js.map +1 -0
- package/build/src/start/server/metro/createJResolver.js +149 -0
- package/build/src/start/server/metro/createJResolver.js.map +1 -0
- package/build/src/start/server/metro/createServerRouteMiddleware.js +13 -1
- package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -1
- package/build/src/start/server/metro/externals.js +25 -3
- package/build/src/start/server/metro/externals.js.map +1 -1
- package/build/src/start/server/metro/fetchRouterManifest.js.map +1 -1
- package/build/src/start/server/metro/formatFileCandidates.js +72 -0
- package/build/src/start/server/metro/formatFileCandidates.js.map +1 -0
- package/build/src/start/server/metro/inspector-proxy/device.js +3 -1
- package/build/src/start/server/metro/inspector-proxy/device.js.map +1 -1
- package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.js +3 -4
- package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.js.map +1 -1
- package/build/src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeCallFunctionOn.js +24 -0
- package/build/src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeCallFunctionOn.js.map +1 -0
- package/build/src/start/server/metro/inspector-proxy/handlers/utils.js +11 -0
- package/build/src/start/server/metro/inspector-proxy/handlers/utils.js.map +1 -0
- package/build/src/start/server/metro/inspector-proxy/index.js +10 -7
- package/build/src/start/server/metro/inspector-proxy/index.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +37 -16
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +3 -2
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/router.js +6 -3
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/start/server/metro/runServer-fork.js +19 -10
- package/build/src/start/server/metro/runServer-fork.js.map +1 -1
- package/build/src/start/server/metro/serializeHtml.js +43 -0
- package/build/src/start/server/metro/serializeHtml.js.map +1 -0
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js +1 -2
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +268 -191
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/metro/withMetroResolvers.js +114 -40
- package/build/src/start/server/metro/withMetroResolvers.js.map +1 -1
- package/build/src/start/server/middleware/DevToolsPluginMiddleware.js +61 -0
- package/build/src/start/server/middleware/DevToolsPluginMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/ExpoMiddleware.js +2 -2
- package/build/src/start/server/middleware/ExpoMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js +45 -68
- package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/inspector/JsInspector.js +1 -1
- package/build/src/start/server/middleware/inspector/JsInspector.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js +30 -26
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js +7 -7
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js +5 -2
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js +3 -2
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js.map +1 -1
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js +8 -7
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js.map +1 -1
- package/build/src/start/server/middleware/metroOptions.js +123 -0
- package/build/src/start/server/middleware/metroOptions.js.map +1 -0
- package/build/src/start/server/middleware/resolveAssets.js.map +1 -1
- package/build/src/start/server/type-generation/__typetests__/fixtures/basic.js.map +1 -1
- package/build/src/start/server/type-generation/expo-env.js +1 -1
- package/build/src/start/server/type-generation/expo-env.js.map +1 -1
- package/build/src/start/server/type-generation/routes.js +1 -0
- package/build/src/start/server/type-generation/routes.js.map +1 -1
- package/build/src/utils/analytics/getMetroDebugProperties.js +1 -2
- package/build/src/utils/analytics/getMetroDebugProperties.js.map +1 -1
- package/build/src/utils/analytics/getMetroProperties.js +1 -2
- package/build/src/utils/analytics/getMetroProperties.js.map +1 -1
- package/build/src/utils/analytics/rudderstackClient.js +2 -2
- package/build/src/utils/args.js +4 -2
- package/build/src/utils/args.js.map +1 -1
- package/build/src/utils/cocoapods.js +2 -1
- package/build/src/utils/cocoapods.js.map +1 -1
- package/build/src/utils/dir.js +18 -8
- package/build/src/utils/dir.js.map +1 -1
- package/build/src/utils/env.js +6 -0
- package/build/src/utils/env.js.map +1 -1
- package/build/src/utils/getOrPromptApplicationId.js +2 -4
- package/build/src/utils/getOrPromptApplicationId.js.map +1 -1
- package/build/src/utils/prompts.js +1 -28
- package/build/src/utils/prompts.js.map +1 -1
- package/build/src/whoami/index.js +1 -1
- package/build/src/whoami/index.js.map +1 -1
- package/package.json +16 -16
- package/static/shims/react-native-web/dist/cjs/exports/AppRegistry/AppContainer.js +13 -0
- package/static/shims/react-native-web/dist/cjs/exports/BackHandler/index.js +10 -0
- package/static/shims/react-native-web/dist/exports/AppRegistry/AppContainer.js +12 -0
- package/static/shims/react-native-web/dist/exports/BackHandler/index.js +7 -0
- package/build/src/export/createBundles.js +0 -37
- package/build/src/export/createBundles.js.map +0 -1
- package/build/src/start/server/metro/resolveFromProject.js +0 -90
- package/build/src/start/server/metro/resolveFromProject.js.map +0 -1
- package/build/src/start/server/middleware/resolveEntryPoint.js +0 -42
- package/build/src/start/server/middleware/resolveEntryPoint.js.map +0 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.createFastResolver = createFastResolver;
|
|
6
|
+
var _path = _interopRequireDefault(require("path"));
|
|
7
|
+
var _createJResolver = _interopRequireDefault(require("./createJResolver"));
|
|
8
|
+
var _externals = require("./externals");
|
|
9
|
+
var _formatFileCandidates = require("./formatFileCandidates");
|
|
10
|
+
function _interopRequireDefault(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
class FailedToResolvePathError extends Error {
|
|
16
|
+
}
|
|
17
|
+
class ShimModuleError extends Error {
|
|
18
|
+
}
|
|
19
|
+
function createFastResolver({ preserveSymlinks , blockList }) {
|
|
20
|
+
const cachedExtensions = new Map();
|
|
21
|
+
function getAdjustedExtensions({ metroSourceExtensions , platform , isNative }) {
|
|
22
|
+
const key = JSON.stringify({
|
|
23
|
+
metroSourceExtensions,
|
|
24
|
+
platform,
|
|
25
|
+
isNative
|
|
26
|
+
});
|
|
27
|
+
if (cachedExtensions.has(key)) {
|
|
28
|
+
return cachedExtensions.get(key);
|
|
29
|
+
}
|
|
30
|
+
let output = metroSourceExtensions;
|
|
31
|
+
if (platform) {
|
|
32
|
+
const nextOutput = [];
|
|
33
|
+
output.forEach((ext)=>{
|
|
34
|
+
nextOutput.push(`${platform}.${ext}`);
|
|
35
|
+
if (isNative) {
|
|
36
|
+
nextOutput.push(`native.${ext}`);
|
|
37
|
+
}
|
|
38
|
+
nextOutput.push(ext);
|
|
39
|
+
});
|
|
40
|
+
output = nextOutput;
|
|
41
|
+
}
|
|
42
|
+
output = Array.from(new Set(output));
|
|
43
|
+
// resolve expects these to start with a dot.
|
|
44
|
+
output = output.map((ext)=>`.${ext}`
|
|
45
|
+
);
|
|
46
|
+
cachedExtensions.set(key, output);
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
function fastResolve(context, moduleName, platform) {
|
|
50
|
+
var ref2;
|
|
51
|
+
const environment = (ref2 = context.customResolverOptions) == null ? void 0 : ref2.environment;
|
|
52
|
+
const isServer = environment === "node";
|
|
53
|
+
const extensions = getAdjustedExtensions({
|
|
54
|
+
metroSourceExtensions: context.sourceExts,
|
|
55
|
+
platform,
|
|
56
|
+
isNative: context.preferNativePlatform
|
|
57
|
+
});
|
|
58
|
+
let fp;
|
|
59
|
+
try {
|
|
60
|
+
var _platform;
|
|
61
|
+
const conditions = context.unstable_enablePackageExports ? [
|
|
62
|
+
...new Set([
|
|
63
|
+
"default",
|
|
64
|
+
...context.unstable_conditionNames,
|
|
65
|
+
...platform != null ? (_platform = context.unstable_conditionsByPlatform[platform]) != null ? _platform : [] : [],
|
|
66
|
+
]),
|
|
67
|
+
] : [];
|
|
68
|
+
fp = (0, _createJResolver).default(moduleName, {
|
|
69
|
+
blockList,
|
|
70
|
+
enablePackageExports: context.unstable_enablePackageExports,
|
|
71
|
+
basedir: _path.default.dirname(context.originModulePath),
|
|
72
|
+
paths: context.nodeModulesPaths,
|
|
73
|
+
extensions,
|
|
74
|
+
conditions,
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
realpathSync: context.unstable_getRealPath,
|
|
77
|
+
packageFilter (pkg) {
|
|
78
|
+
// set the pkg.main to the first available field in context.mainFields
|
|
79
|
+
for (const field of context.mainFields){
|
|
80
|
+
if (pkg[field] && // object-inspect uses browser: {} in package.json
|
|
81
|
+
typeof pkg[field] === "string") {
|
|
82
|
+
return {
|
|
83
|
+
...pkg,
|
|
84
|
+
main: pkg[field]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return pkg;
|
|
89
|
+
},
|
|
90
|
+
// Used to ensure files trace to packages instead of node_modules in expo/expo. This is how Metro works and
|
|
91
|
+
// the app doesn't finish without it.
|
|
92
|
+
preserveSymlinks,
|
|
93
|
+
readPackageSync (readFileSync, pkgFile) {
|
|
94
|
+
var ref;
|
|
95
|
+
return (ref = context.getPackage(pkgFile)) != null ? ref : JSON.parse(// @ts-expect-error
|
|
96
|
+
readFileSync(pkgfile));
|
|
97
|
+
},
|
|
98
|
+
includeCoreModules: isServer,
|
|
99
|
+
pathFilter: // Disable `browser` field for server environments.
|
|
100
|
+
isServer ? undefined : (pkg, _resolvedPath, relativePathIn)=>{
|
|
101
|
+
let relativePath = relativePathIn;
|
|
102
|
+
if (relativePath[0] !== ".") {
|
|
103
|
+
relativePath = `./${relativePath}`;
|
|
104
|
+
}
|
|
105
|
+
const replacements = pkg.browser;
|
|
106
|
+
if (replacements === undefined) {
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
var _relativePath;
|
|
110
|
+
// TODO: Probably use a better extension matching system here.
|
|
111
|
+
// This was added for `uuid/v4` -> `./lib/rng` -> `./lib/rng-browser.js`
|
|
112
|
+
const mappedPath = (_relativePath = replacements[relativePath]) != null ? _relativePath : replacements[relativePath + ".js"];
|
|
113
|
+
if (mappedPath === false) {
|
|
114
|
+
throw new ShimModuleError();
|
|
115
|
+
}
|
|
116
|
+
return mappedPath;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof ShimModuleError) {
|
|
121
|
+
return {
|
|
122
|
+
type: "empty"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if ("code" in error && error.code === "MODULE_NOT_FOUND") {
|
|
126
|
+
if ((0, _externals).isNodeExternal(moduleName)) {
|
|
127
|
+
// In this case, mock the file to use an empty module.
|
|
128
|
+
return {
|
|
129
|
+
type: "empty"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// TODO: Add improved error handling.
|
|
133
|
+
throw new FailedToResolvePathError("The module could not be resolved because no file or module matched the pattern:\n" + ` ${(0, _formatFileCandidates).formatFileCandidates({
|
|
134
|
+
type: "sourceFile",
|
|
135
|
+
filePathPrefix: moduleName,
|
|
136
|
+
candidateExts: extensions
|
|
137
|
+
}, true)}\n\n`);
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
if (context.sourceExts.some((ext)=>fp.endsWith(ext)
|
|
142
|
+
)) {
|
|
143
|
+
return {
|
|
144
|
+
type: "sourceFile",
|
|
145
|
+
filePath: fp
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if ((0, _externals).isNodeExternal(fp)) {
|
|
149
|
+
if (isServer) {
|
|
150
|
+
return {
|
|
151
|
+
type: "sourceFile",
|
|
152
|
+
filePath: fp
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// NOTE: This shouldn't happen, the module should throw.
|
|
156
|
+
// Mock non-server built-in modules to empty.
|
|
157
|
+
return {
|
|
158
|
+
type: "empty"
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// NOTE: platform extensions may not be supported on assets.
|
|
162
|
+
if (platform === "web") {
|
|
163
|
+
// Skip multi-resolution on web/server bundles. Only consideration here is that
|
|
164
|
+
// we may still need it in case the only image is a multi-resolution image.
|
|
165
|
+
return {
|
|
166
|
+
type: "assetFiles",
|
|
167
|
+
filePaths: [
|
|
168
|
+
fp
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const dirPath = _path.default.dirname(fp);
|
|
173
|
+
const extension = _path.default.extname(fp);
|
|
174
|
+
const basename = _path.default.basename(fp, extension);
|
|
175
|
+
var ref1;
|
|
176
|
+
return {
|
|
177
|
+
type: "assetFiles",
|
|
178
|
+
// Support multi-resolution asset extensions...
|
|
179
|
+
filePaths: (ref1 = context.resolveAsset(dirPath, basename, extension)) != null ? ref1 : [
|
|
180
|
+
fp
|
|
181
|
+
]
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return fastResolve;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=createExpoMetroResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/createExpoMetroResolver.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { Resolution, ResolutionContext } from 'metro-resolver';\nimport path from 'path';\n\nimport jestResolver from './createJResolver';\nimport { isNodeExternal } from './externals';\nimport { formatFileCandidates } from './formatFileCandidates';\n\nclass FailedToResolvePathError extends Error {}\n\nclass ShimModuleError extends Error {}\n\nexport function createFastResolver({\n preserveSymlinks,\n blockList,\n}: {\n preserveSymlinks: boolean;\n blockList: RegExp[];\n}) {\n const cachedExtensions: Map<string, readonly string[]> = new Map();\n\n function getAdjustedExtensions({\n metroSourceExtensions,\n platform,\n isNative,\n }: {\n metroSourceExtensions: readonly string[];\n platform: string | null;\n isNative: boolean;\n }): readonly string[] {\n const key = JSON.stringify({ metroSourceExtensions, platform, isNative });\n if (cachedExtensions.has(key)) {\n return cachedExtensions.get(key)!;\n }\n\n let output = metroSourceExtensions;\n if (platform) {\n const nextOutput: string[] = [];\n\n output.forEach((ext) => {\n nextOutput.push(`${platform}.${ext}`);\n if (isNative) {\n nextOutput.push(`native.${ext}`);\n }\n nextOutput.push(ext);\n });\n\n output = nextOutput;\n }\n\n output = Array.from(new Set<string>(output));\n\n // resolve expects these to start with a dot.\n output = output.map((ext) => `.${ext}`);\n\n cachedExtensions.set(key, output);\n\n return output;\n }\n\n function fastResolve(\n context: Pick<\n ResolutionContext,\n | 'unstable_enablePackageExports'\n | 'customResolverOptions'\n | 'sourceExts'\n | 'preferNativePlatform'\n | 'originModulePath'\n | 'getPackage'\n | 'nodeModulesPaths'\n | 'mainFields'\n | 'resolveAsset'\n | 'unstable_conditionNames'\n | 'unstable_conditionsByPlatform'\n >,\n moduleName: string,\n platform: string | null\n ): Resolution {\n const environment = context.customResolverOptions?.environment;\n const isServer = environment === 'node';\n\n const extensions = getAdjustedExtensions({\n metroSourceExtensions: context.sourceExts,\n platform,\n isNative: context.preferNativePlatform,\n }) as string[];\n\n let fp: string;\n\n try {\n const conditions = context.unstable_enablePackageExports\n ? [\n ...new Set([\n 'default',\n ...context.unstable_conditionNames,\n ...(platform != null ? context.unstable_conditionsByPlatform[platform] ?? [] : []),\n ]),\n ]\n : [];\n\n fp = jestResolver(moduleName, {\n blockList,\n enablePackageExports: context.unstable_enablePackageExports,\n basedir: path.dirname(context.originModulePath),\n paths: context.nodeModulesPaths as string[],\n extensions,\n conditions,\n // @ts-ignore\n realpathSync: context.unstable_getRealPath,\n packageFilter(pkg) {\n // set the pkg.main to the first available field in context.mainFields\n for (const field of context.mainFields) {\n if (\n pkg[field] &&\n // object-inspect uses browser: {} in package.json\n typeof pkg[field] === 'string'\n ) {\n return {\n ...pkg,\n main: pkg[field],\n };\n }\n }\n return pkg;\n },\n // Used to ensure files trace to packages instead of node_modules in expo/expo. This is how Metro works and\n // the app doesn't finish without it.\n preserveSymlinks,\n readPackageSync(readFileSync, pkgFile) {\n return (\n context.getPackage(pkgFile) ??\n JSON.parse(\n // @ts-expect-error\n readFileSync(pkgfile)\n )\n );\n },\n includeCoreModules: isServer,\n\n pathFilter:\n // Disable `browser` field for server environments.\n isServer\n ? undefined\n : // Enable `browser` field support\n (pkg: any, _resolvedPath: string, relativePathIn: string): string => {\n let relativePath = relativePathIn;\n if (relativePath[0] !== '.') {\n relativePath = `./${relativePath}`;\n }\n\n const replacements = pkg.browser;\n if (replacements === undefined) {\n return '';\n }\n\n // TODO: Probably use a better extension matching system here.\n // This was added for `uuid/v4` -> `./lib/rng` -> `./lib/rng-browser.js`\n const mappedPath = replacements[relativePath] ?? replacements[relativePath + '.js'];\n if (mappedPath === false) {\n throw new ShimModuleError();\n }\n return mappedPath;\n },\n });\n } catch (error: any) {\n if (error instanceof ShimModuleError) {\n return {\n type: 'empty',\n };\n }\n\n if ('code' in error && error.code === 'MODULE_NOT_FOUND') {\n if (isNodeExternal(moduleName)) {\n // In this case, mock the file to use an empty module.\n return {\n type: 'empty',\n };\n }\n\n // TODO: Add improved error handling.\n throw new FailedToResolvePathError(\n 'The module could not be resolved because no file or module matched the pattern:\\n' +\n ` ${formatFileCandidates(\n {\n type: 'sourceFile',\n filePathPrefix: moduleName,\n candidateExts: extensions,\n },\n true\n )}\\n\\n`\n );\n }\n throw error;\n }\n\n if (context.sourceExts.some((ext) => fp.endsWith(ext))) {\n return {\n type: 'sourceFile',\n filePath: fp,\n };\n }\n\n if (isNodeExternal(fp)) {\n if (isServer) {\n return {\n type: 'sourceFile',\n filePath: fp,\n };\n }\n // NOTE: This shouldn't happen, the module should throw.\n // Mock non-server built-in modules to empty.\n return {\n type: 'empty',\n };\n }\n\n // NOTE: platform extensions may not be supported on assets.\n\n if (platform === 'web') {\n // Skip multi-resolution on web/server bundles. Only consideration here is that\n // we may still need it in case the only image is a multi-resolution image.\n return {\n type: 'assetFiles',\n filePaths: [fp],\n };\n }\n\n const dirPath = path.dirname(fp);\n const extension = path.extname(fp);\n const basename = path.basename(fp, extension);\n return {\n type: 'assetFiles',\n // Support multi-resolution asset extensions...\n filePaths: context.resolveAsset(dirPath, basename, extension) ?? [fp],\n };\n }\n\n return fastResolve;\n}\n"],"names":["createFastResolver","FailedToResolvePathError","Error","ShimModuleError","preserveSymlinks","blockList","cachedExtensions","Map","getAdjustedExtensions","metroSourceExtensions","platform","isNative","key","JSON","stringify","has","get","output","nextOutput","forEach","ext","push","Array","from","Set","map","set","fastResolve","context","moduleName","environment","customResolverOptions","isServer","extensions","sourceExts","preferNativePlatform","fp","conditions","unstable_enablePackageExports","unstable_conditionNames","unstable_conditionsByPlatform","jestResolver","enablePackageExports","basedir","path","dirname","originModulePath","paths","nodeModulesPaths","realpathSync","unstable_getRealPath","packageFilter","pkg","field","mainFields","main","readPackageSync","readFileSync","pkgFile","getPackage","parse","pkgfile","includeCoreModules","pathFilter","undefined","_resolvedPath","relativePathIn","relativePath","replacements","browser","mappedPath","error","type","code","isNodeExternal","formatFileCandidates","filePathPrefix","candidateExts","some","endsWith","filePath","filePaths","dirPath","extension","extname","basename","resolveAsset"],"mappings":"AAMA;;;;QAWgBA,kBAAkB,GAAlBA,kBAAkB;AAVjB,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEE,IAAA,gBAAmB,kCAAnB,mBAAmB,EAAA;AACb,IAAA,UAAa,WAAb,aAAa,CAAA;AACP,IAAA,qBAAwB,WAAxB,wBAAwB,CAAA;;;;;;AAE7D,MAAMC,wBAAwB,SAASC,KAAK;CAAG;AAE/C,MAAMC,eAAe,SAASD,KAAK;CAAG;AAE/B,SAASF,kBAAkB,CAAC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ACLoC,IAAI,EAAE,OAAO;aACd,CAAC;SACH;QAED,4DAA4D;QAE5D,IAAI9D,QAAQ,KAAK,KAAK,EAAE;YACtB,+EAA+E;YAC/E,2EAA2E;YAC3E,OAAO;gBACL8D,IAAI,EAAE,YAAY;gBAClBS,SAAS,EAAE;oBAAC7C,EAAE;iBAAC;aAChB,CAAC;SACH;QAED,MAAM8C,OAAO,GAAGtC,KAAI,QAAA,CAACC,OAAO,CAACT,EAAE,CAAC,AAAC;QACjC,MAAM+C,SAAS,GAAGvC,KAAI,QAAA,CAACwC,OAAO,CAAChD,EAAE,CAAC,AAAC;QACnC,MAAMiD,QAAQ,GAAGzC,KAAI,QAAA,CAACyC,QAAQ,CAACjD,EAAE,EAAE+C,SAAS,CAAC,AAAC;YAIjCvD,IAAkD;QAH/D,OAAO;YACL4C,IAAI,EAAE,YAAY;YAClB,+CAA+C;YAC/CS,SAAS,EAAErD,CAAAA,IAAkD,GAAlDA,OAAO,CAAC0D,YAAY,CAACJ,OAAO,EAAEG,QAAQ,EAAEF,SAAS,CAAC,YAAlDvD,IAAkD,GAAI;gBAACQ,EAAE;aAAC;SACtE,CAAC;KACH;IAED,OAAOT,WAAW,CAAC;CACpB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
7
|
+
var _path = require("path");
|
|
8
|
+
var _resolve = require("resolve");
|
|
9
|
+
var resolve = _interopRequireWildcard(require("resolve.exports"));
|
|
10
|
+
var _dir = require("../../../utils/dir");
|
|
11
|
+
function _interopRequireDefault(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : {
|
|
13
|
+
default: obj
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function _interopRequireWildcard(obj) {
|
|
17
|
+
if (obj && obj.__esModule) {
|
|
18
|
+
return obj;
|
|
19
|
+
} else {
|
|
20
|
+
var newObj = {};
|
|
21
|
+
if (obj != null) {
|
|
22
|
+
for(var key in obj){
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
24
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
25
|
+
if (desc.get || desc.set) {
|
|
26
|
+
Object.defineProperty(newObj, key, desc);
|
|
27
|
+
} else {
|
|
28
|
+
newObj[key] = obj[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
newObj.default = obj;
|
|
34
|
+
return newObj;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const defaultResolver = (path, { enablePackageExports , blockList =[] , ...options })=>{
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
const resolveOptions = {
|
|
40
|
+
...options,
|
|
41
|
+
isDirectory (file) {
|
|
42
|
+
if (blockList.some((regex)=>regex.test(file)
|
|
43
|
+
)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return (0, _dir).directoryExistsSync(file);
|
|
47
|
+
},
|
|
48
|
+
isFile (file) {
|
|
49
|
+
if (blockList.some((regex)=>regex.test(file)
|
|
50
|
+
)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return (0, _dir).fileExistsSync(file);
|
|
54
|
+
},
|
|
55
|
+
preserveSymlinks: enablePackageExports ? false : options.preserveSymlinks,
|
|
56
|
+
defaultResolver
|
|
57
|
+
};
|
|
58
|
+
// resolveSync dereferences symlinks to ensure we don't create a separate
|
|
59
|
+
// module instance depending on how it was referenced.
|
|
60
|
+
const result = (0, _resolve).sync(enablePackageExports ? getPathInModule(path, resolveOptions) : path, resolveOptions);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
var _default = defaultResolver;
|
|
64
|
+
exports.default = _default;
|
|
65
|
+
/*
|
|
66
|
+
* helper functions
|
|
67
|
+
*/ function getPathInModule(path, options) {
|
|
68
|
+
if (shouldIgnoreRequestForExports(path)) {
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
const segments = path.split("/");
|
|
72
|
+
let moduleName = segments.shift();
|
|
73
|
+
if (moduleName) {
|
|
74
|
+
if (moduleName.startsWith("@")) {
|
|
75
|
+
moduleName = `${moduleName}/${segments.shift()}`;
|
|
76
|
+
}
|
|
77
|
+
// Disable package exports for babel/runtime for https://github.com/facebook/metro/issues/984/
|
|
78
|
+
if (moduleName === "@babel/runtime") {
|
|
79
|
+
return path;
|
|
80
|
+
}
|
|
81
|
+
// self-reference
|
|
82
|
+
const closestPackageJson = findClosestPackageJson(options.basedir, options);
|
|
83
|
+
if (closestPackageJson) {
|
|
84
|
+
const pkg = options.readPackageSync(options.readFileSync, closestPackageJson);
|
|
85
|
+
(0, _assert).default(pkg, "package.json should be read by `readPackageSync`");
|
|
86
|
+
if (pkg.name === moduleName) {
|
|
87
|
+
const resolved = resolve.exports(pkg, segments.join("/") || ".", createResolveOptions(options.conditions));
|
|
88
|
+
if (resolved) {
|
|
89
|
+
return (0, _path).resolve((0, _path).dirname(closestPackageJson), resolved[0]);
|
|
90
|
+
}
|
|
91
|
+
if (pkg.exports) {
|
|
92
|
+
throw new Error("`exports` exists, but no results - this is a bug in Expo CLI's Metro resolver. Please report an issue");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let packageJsonPath = "";
|
|
97
|
+
try {
|
|
98
|
+
packageJsonPath = (0, _resolve).sync(`${moduleName}/package.json`, options);
|
|
99
|
+
} catch {
|
|
100
|
+
// ignore if package.json cannot be found
|
|
101
|
+
}
|
|
102
|
+
if (packageJsonPath && options.isFile(packageJsonPath)) {
|
|
103
|
+
const pkg = options.readPackageSync(options.readFileSync, packageJsonPath);
|
|
104
|
+
(0, _assert).default(pkg, "package.json should be read by `readPackageSync`");
|
|
105
|
+
const resolved = resolve.exports(pkg, segments.join("/") || ".", createResolveOptions(options.conditions));
|
|
106
|
+
if (resolved) {
|
|
107
|
+
return (0, _path).resolve((0, _path).dirname(packageJsonPath), resolved[0]);
|
|
108
|
+
}
|
|
109
|
+
if (pkg.exports) {
|
|
110
|
+
throw new Error("`exports` exists, but no results - this is a bug in Expo CLI's Metro resolver. Please report an issue");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return path;
|
|
115
|
+
}
|
|
116
|
+
function createResolveOptions(conditions) {
|
|
117
|
+
return conditions ? {
|
|
118
|
+
conditions,
|
|
119
|
+
unsafe: true
|
|
120
|
+
} : {
|
|
121
|
+
browser: false,
|
|
122
|
+
require: true
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// if it's a relative import or an absolute path, imports/exports are ignored
|
|
126
|
+
const shouldIgnoreRequestForExports = (path)=>path.startsWith(".") || (0, _path).isAbsolute(path)
|
|
127
|
+
;
|
|
128
|
+
// adapted from
|
|
129
|
+
// https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js
|
|
130
|
+
function findClosestPackageJson(start, options) {
|
|
131
|
+
let dir = (0, _path).resolve(".", start);
|
|
132
|
+
if (!options.isDirectory(dir)) {
|
|
133
|
+
dir = (0, _path).dirname(dir);
|
|
134
|
+
}
|
|
135
|
+
while(true){
|
|
136
|
+
const pkgJsonFile = (0, _path).resolve(dir, "./package.json");
|
|
137
|
+
const hasPackageJson = options.isFile(pkgJsonFile);
|
|
138
|
+
if (hasPackageJson) {
|
|
139
|
+
return pkgJsonFile;
|
|
140
|
+
}
|
|
141
|
+
const prevDir = dir;
|
|
142
|
+
dir = (0, _path).dirname(dir);
|
|
143
|
+
if (prevDir === dir) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=createJResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/createJResolver.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Fork of the jest resolver but with additional settings for Metro and pnp removed.\n * https://github.com/jestjs/jest/blob/d1a2ed7fea4bdc19836274cd810c8360e3ab62f3/packages/jest-resolve/src/defaultResolver.ts#L1\n */\nimport type { JSONObject as PackageJSON } from '@expo/json-file';\nimport assert from 'assert';\nimport { dirname, isAbsolute, resolve as pathResolve } from 'path';\nimport { sync as resolveSync, SyncOpts as UpstreamResolveOptions } from 'resolve';\nimport * as resolve from 'resolve.exports';\n\nimport { directoryExistsSync, fileExistsSync } from '../../../utils/dir';\n\n/**\n * Allows transforming parsed `package.json` contents.\n *\n * @param pkg - Parsed `package.json` contents.\n * @param file - Path to `package.json` file.\n * @param dir - Directory that contains the `package.json`.\n *\n * @returns Transformed `package.json` contents.\n */\nexport type PackageFilter = (pkg: PackageJSON, file: string, dir: string) => PackageJSON;\n\n/**\n * Allows transforming a path within a package.\n *\n * @param pkg - Parsed `package.json` contents.\n * @param path - Path being resolved.\n * @param relativePath - Path relative from the `package.json` location.\n *\n * @returns Relative path that will be joined from the `package.json` location.\n */\nexport type PathFilter = (pkg: PackageJSON, path: string, relativePath: string) => string;\n\nexport type ResolverOptions = {\n /** Directory to begin resolving from. */\n basedir: string;\n /** List of export conditions. */\n conditions?: string[];\n /** Instance of default resolver. */\n defaultResolver: typeof defaultResolver;\n /** List of file extensions to search in order. */\n extensions?: string[];\n /**\n * List of directory names to be looked up for modules recursively.\n *\n * @defaultValue\n * The default is `['node_modules']`.\n */\n moduleDirectory?: string[];\n /**\n * List of `require.paths` to use if nothing is found in `node_modules`.\n *\n * @defaultValue\n * The default is `undefined`.\n */\n paths?: string[];\n /** Allows transforming parsed `package.json` contents. */\n packageFilter?: PackageFilter;\n /** Allows transforms a path within a package. */\n pathFilter?: PathFilter;\n /** Current root directory. */\n rootDir?: string;\n\n enablePackageExports?: boolean;\n\n blockList: RegExp[];\n} & Pick<\n UpstreamResolveOptions,\n 'readPackageSync' | 'moduleDirectory' | 'extensions' | 'preserveSymlinks' | 'includeCoreModules'\n>;\n\ntype UpstreamResolveOptionsWithConditions = UpstreamResolveOptions & ResolverOptions;\n\nexport type SyncResolver = (path: string, options: ResolverOptions) => string;\nexport type AsyncResolver = (path: string, options: ResolverOptions) => Promise<string>;\n\nexport type Resolver = SyncResolver | AsyncResolver;\n\nconst defaultResolver: SyncResolver = (\n path,\n { enablePackageExports, blockList = [], ...options }\n) => {\n // @ts-expect-error\n const resolveOptions: UpstreamResolveOptionsWithConditions = {\n ...options,\n\n isDirectory(file) {\n if (blockList.some((regex) => regex.test(file))) {\n return false;\n }\n return directoryExistsSync(file);\n },\n isFile(file) {\n if (blockList.some((regex) => regex.test(file))) {\n return false;\n }\n return fileExistsSync(file);\n },\n preserveSymlinks: enablePackageExports ? false : options.preserveSymlinks,\n defaultResolver,\n };\n\n // resolveSync dereferences symlinks to ensure we don't create a separate\n // module instance depending on how it was referenced.\n const result = resolveSync(\n enablePackageExports ? getPathInModule(path, resolveOptions) : path,\n resolveOptions\n );\n\n return result;\n};\n\nexport default defaultResolver;\n\n/*\n * helper functions\n */\n\nfunction getPathInModule(path: string, options: UpstreamResolveOptionsWithConditions): string {\n if (shouldIgnoreRequestForExports(path)) {\n return path;\n }\n\n const segments = path.split('/');\n\n let moduleName = segments.shift();\n\n if (moduleName) {\n if (moduleName.startsWith('@')) {\n moduleName = `${moduleName}/${segments.shift()}`;\n }\n\n // Disable package exports for babel/runtime for https://github.com/facebook/metro/issues/984/\n if (moduleName === '@babel/runtime') {\n return path;\n }\n\n // self-reference\n const closestPackageJson = findClosestPackageJson(options.basedir, options);\n if (closestPackageJson) {\n const pkg = options.readPackageSync!(options.readFileSync!, closestPackageJson);\n assert(pkg, 'package.json should be read by `readPackageSync`');\n\n if (pkg.name === moduleName) {\n const resolved = resolve.exports(\n pkg,\n (segments.join('/') || '.') as resolve.Exports.Entry,\n createResolveOptions(options.conditions)\n );\n\n if (resolved) {\n return pathResolve(dirname(closestPackageJson), resolved[0]);\n }\n\n if (pkg.exports) {\n throw new Error(\n \"`exports` exists, but no results - this is a bug in Expo CLI's Metro resolver. Please report an issue\"\n );\n }\n }\n }\n\n let packageJsonPath = '';\n\n try {\n packageJsonPath = resolveSync(`${moduleName}/package.json`, options);\n } catch {\n // ignore if package.json cannot be found\n }\n\n if (packageJsonPath && options.isFile!(packageJsonPath)) {\n const pkg = options.readPackageSync!(options.readFileSync!, packageJsonPath);\n assert(pkg, 'package.json should be read by `readPackageSync`');\n\n const resolved = resolve.exports(\n pkg,\n (segments.join('/') || '.') as resolve.Exports.Entry,\n createResolveOptions(options.conditions)\n );\n\n if (resolved) {\n return pathResolve(dirname(packageJsonPath), resolved[0]);\n }\n\n if (pkg.exports) {\n throw new Error(\n \"`exports` exists, but no results - this is a bug in Expo CLI's Metro resolver. Please report an issue\"\n );\n }\n }\n }\n\n return path;\n}\n\nfunction createResolveOptions(conditions: string[] | undefined): resolve.Options {\n return conditions\n ? { conditions, unsafe: true }\n : // no conditions were passed - let's assume this is Jest internal and it should be `require`\n { browser: false, require: true };\n}\n\n// if it's a relative import or an absolute path, imports/exports are ignored\nconst shouldIgnoreRequestForExports = (path: string) => path.startsWith('.') || isAbsolute(path);\n\n// adapted from\n// https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js\nfunction findClosestPackageJson(\n start: string,\n options: UpstreamResolveOptions\n): string | undefined {\n let dir = pathResolve('.', start);\n if (!options.isDirectory!(dir)) {\n dir = dirname(dir);\n }\n\n while (true) {\n const pkgJsonFile = pathResolve(dir, './package.json');\n const hasPackageJson = options.isFile!(pkgJsonFile);\n\n if (hasPackageJson) {\n return pkgJsonFile;\n }\n\n const prevDir = dir;\n dir = dirname(dir);\n\n if (prevDir === dir) {\n return undefined;\n }\n }\n}\n"],"names":["resolve","defaultResolver","path","enablePackageExports","blockList","options","resolveOptions","isDirectory","file","some","regex","test","directoryExistsSync","isFile","fileExistsSync","preserveSymlinks","result","resolveSync","getPathInModule","shouldIgnoreRequestForExports","segments","split","moduleName","shift","startsWith","closestPackageJson","findClosestPackageJson","basedir","pkg","readPackageSync","readFileSync","assert","name","resolved","exports","join","createResolveOptions","conditions","pathResolve","dirname","Error","packageJsonPath","unsafe","browser","require","isAbsolute","start","dir","pkgJsonFile","hasPackageJson","prevDir","undefined"],"mappings":"AAUA;;;;;AACmB,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACiC,IAAA,KAAM,WAAN,MAAM,CAAA;AACM,IAAA,QAAS,WAAT,SAAS,CAAA;AACrEA,IAAAA,OAAO,mCAAM,iBAAiB,EAAvB;AAEiC,IAAA,IAAoB,WAApB,oBAAoB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqExE,MAAMC,eAAe,GAAiB,CACpCC,IAAI,EACJ,EAAEC,oBAAoB,CAAA,EAAEC,SAAS,EAAG,EAAE,CAAA,EAAE,GAAGC,OAAO,EAAE,GACjD;IACH,mBAAmB;IACnB,MAAMC,cAAc,GAAyC;QAC3D,GAAGD,OAAO;QAEVE,WAAW,EAACC,IAAI,EAAE;YAChB,IAAIJ,SAAS,CAACK,IAAI,CAAC,CAACC,KAAK,GAAKA,KAAK,CAACC,IAAI,CAACH,IAAI,CAAC;YAAA,CAAC,EAAE;gBAC/C,OAAO,KAAK,CAAC;aACd;YACD,OAAOI,CAAAA,GAAAA,IAAmB,AAAM,CAAA,oBAAN,CAACJ,IAAI,CAAC,CAAC;SAClC;QACDK,MAAM,EAACL,IAAI,EAAE;YACX,IAAIJ,SAAS,CAACK,IAAI,CAAC,CAACC,KAAK,GAAKA,KAAK,CAACC,IAAI,CAACH,IAAI,CAAC;YAAA,CAAC,EAAE;gBAC/C,OAAO,KAAK,CAAC;aACd;YACD,OAAOM,CAAAA,GAAAA,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AAC,AAAC;QAEpD,IAAIC,cAAc,EAAE;YAClB,OAAOD,WAAW,CAAC;SACpB;QAED,MAAME,OAAO,GAAGH,GAAG,AAAC;QACpBA,GAAG,GAAGR,CAAAA,GAAAA,KAAO,AAAK,CAAA,QAAL,CAACQ,GAAG,CAAC,CAAC;QAEnB,IAAIG,OAAO,KAAKH,GAAG,EAAE;YACnB,OAAOI,SAAS,CAAC;SAClB;KACF;CACF"}
|
|
@@ -29,7 +29,19 @@ function createRouteHandlerMiddleware(projectRoot, options) {
|
|
|
29
29
|
debug("manifest", manifest);
|
|
30
30
|
// NOTE: no app dir if null
|
|
31
31
|
// TODO: Redirect to 404 page
|
|
32
|
-
return manifest
|
|
32
|
+
return manifest != null ? manifest : {
|
|
33
|
+
// Support the onboarding screen if there's no manifest
|
|
34
|
+
htmlRoutes: [
|
|
35
|
+
{
|
|
36
|
+
file: "index.js",
|
|
37
|
+
page: "/index",
|
|
38
|
+
routeKeys: {},
|
|
39
|
+
namedRegex: /^\/(?:index)?\/?$/i
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
apiRoutes: [],
|
|
43
|
+
notFoundRoutes: []
|
|
44
|
+
};
|
|
33
45
|
},
|
|
34
46
|
async getHtml (request) {
|
|
35
47
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/createServerRouteMiddleware.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { ExpoResponse } from '@expo/server';\nimport { createRequestHandler } from '@expo/server/build/vendor/http';\nimport requireString from 'require-from-string';\nimport resolve from 'resolve';\nimport { promisify } from 'util';\n\nimport { ForwardHtmlError } from './MetroBundlerDevServer';\nimport { bundleApiRoute } from './bundleApiRoutes';\nimport { fetchManifest } from './fetchRouterManifest';\nimport { getErrorOverlayHtmlAsync, logMetroError, logMetroErrorAsync } from './metroErrorInterface';\nimport { Log } from '../../../log';\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\nconst resolveAsync = promisify(resolve) as any as (\n id: string,\n opts: resolve.AsyncOpts\n) => Promise<string | null>;\n\nexport function createRouteHandlerMiddleware(\n projectRoot: string,\n options: {\n mode?: string;\n appDir: string;\n port?: number;\n getWebBundleUrl: () => string;\n getStaticPageAsync: (pathname: string) => Promise<{ content: string }>;\n }\n) {\n return createRequestHandler(\n { build: '' },\n {\n async getRoutesManifest() {\n const manifest = await fetchManifest<RegExp>(projectRoot, options);\n debug('manifest', manifest);\n // NOTE: no app dir if null\n // TODO: Redirect to 404 page\n return manifest;\n },\n async getHtml(request) {\n try {\n const { content } = await options.getStaticPageAsync(request.url);\n return content;\n } catch (error: any) {\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n if (error instanceof ForwardHtmlError) {\n return new ExpoResponse(error.html, {\n status: error.statusCode,\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n }\n\n try {\n return new ExpoResponse(\n await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n }),\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n } catch (staticError: any) {\n // Fallback error for when Expo Router is misconfigured in the project.\n return new ExpoResponse(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>',\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n }\n },\n logApiRouteExecutionError(error) {\n logMetroError(projectRoot, { error });\n },\n async getApiRoute(route) {\n const resolvedFunctionPath = await resolveAsync(route.page, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n });\n\n const middlewareContents = await bundleApiRoute(\n projectRoot,\n resolvedFunctionPath!,\n options\n );\n if (!middlewareContents) {\n // TODO: Error handling\n return null;\n }\n\n try {\n debug(`Bundling middleware at: ${resolvedFunctionPath}`);\n return requireString(middlewareContents);\n } catch (error: any) {\n if (error instanceof Error) {\n await logMetroErrorAsync({ projectRoot, error });\n } else {\n Log.error('Failed to load middleware: ' + error);\n }\n return new ExpoResponse(\n 'Failed to load middleware: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n }\n );\n}\n"],"names":["createRouteHandlerMiddleware","debug","require","resolveAsync","promisify","resolve","projectRoot","options","createRequestHandler","build","getRoutesManifest","manifest","fetchManifest","getHtml","request","content","getStaticPageAsync","url","error","ForwardHtmlError","ExpoResponse","html","status","statusCode","headers","getErrorOverlayHtmlAsync","staticError","message","logApiRouteExecutionError","logMetroError","getApiRoute","route","resolvedFunctionPath","
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/createServerRouteMiddleware.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { ExpoResponse } from '@expo/server';\nimport { createRequestHandler } from '@expo/server/build/vendor/http';\nimport requireString from 'require-from-string';\nimport resolve from 'resolve';\nimport { promisify } from 'util';\n\nimport { ForwardHtmlError } from './MetroBundlerDevServer';\nimport { bundleApiRoute } from './bundleApiRoutes';\nimport { fetchManifest } from './fetchRouterManifest';\nimport { getErrorOverlayHtmlAsync, logMetroError, logMetroErrorAsync } from './metroErrorInterface';\nimport { Log } from '../../../log';\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\nconst resolveAsync = promisify(resolve) as any as (\n id: string,\n opts: resolve.AsyncOpts\n) => Promise<string | null>;\n\nexport function createRouteHandlerMiddleware(\n projectRoot: string,\n options: {\n mode?: string;\n appDir: string;\n port?: number;\n baseUrl: string;\n getWebBundleUrl: () => string;\n getStaticPageAsync: (pathname: string) => Promise<{ content: string }>;\n }\n) {\n return createRequestHandler(\n { build: '' },\n {\n async getRoutesManifest() {\n const manifest = await fetchManifest<RegExp>(projectRoot, options);\n debug('manifest', manifest);\n // NOTE: no app dir if null\n // TODO: Redirect to 404 page\n return (\n manifest ?? {\n // Support the onboarding screen if there's no manifest\n htmlRoutes: [\n {\n file: 'index.js',\n page: '/index',\n routeKeys: {},\n namedRegex: /^\\/(?:index)?\\/?$/i,\n },\n ],\n apiRoutes: [],\n notFoundRoutes: [],\n }\n );\n },\n async getHtml(request) {\n try {\n const { content } = await options.getStaticPageAsync(request.url);\n return content;\n } catch (error: any) {\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n if (error instanceof ForwardHtmlError) {\n return new ExpoResponse(error.html, {\n status: error.statusCode,\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n }\n\n try {\n return new ExpoResponse(\n await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n }),\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n } catch (staticError: any) {\n // Fallback error for when Expo Router is misconfigured in the project.\n return new ExpoResponse(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>',\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n }\n },\n logApiRouteExecutionError(error) {\n logMetroError(projectRoot, { error });\n },\n async getApiRoute(route) {\n const resolvedFunctionPath = await resolveAsync(route.page, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n });\n\n const middlewareContents = await bundleApiRoute(\n projectRoot,\n resolvedFunctionPath!,\n options\n );\n if (!middlewareContents) {\n // TODO: Error handling\n return null;\n }\n\n try {\n debug(`Bundling middleware at: ${resolvedFunctionPath}`);\n return requireString(middlewareContents);\n } catch (error: any) {\n if (error instanceof Error) {\n await logMetroErrorAsync({ projectRoot, error });\n } else {\n Log.error('Failed to load middleware: ' + error);\n }\n return new ExpoResponse(\n 'Failed to load middleware: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n }\n );\n}\n"],"names":["createRouteHandlerMiddleware","debug","require","resolveAsync","promisify","resolve","projectRoot","options","createRequestHandler","build","getRoutesManifest","manifest","fetchManifest","htmlRoutes","file","page","routeKeys","namedRegex","apiRoutes","notFoundRoutes","getHtml","request","content","getStaticPageAsync","url","error","ForwardHtmlError","ExpoResponse","html","status","statusCode","headers","getErrorOverlayHtmlAsync","staticError","message","logApiRouteExecutionError","logMetroError","getApiRoute","route","resolvedFunctionPath","extensions","basedir","appDir","middlewareContents","bundleApiRoute","requireString","Error","logMetroErrorAsync","Log"],"mappings":"AAMA;;;;QAmBgBA,4BAA4B,GAA5BA,4BAA4B;AAnBf,IAAA,OAAc,WAAd,cAAc,CAAA;AACN,IAAA,KAAgC,WAAhC,gCAAgC,CAAA;AAC3C,IAAA,kBAAqB,kCAArB,qBAAqB,EAAA;AAC3B,IAAA,QAAS,kCAAT,SAAS,EAAA;AACH,IAAA,KAAM,WAAN,MAAM,CAAA;AAEC,IAAA,sBAAyB,WAAzB,yBAAyB,CAAA;AAC3B,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;AACpB,IAAA,oBAAuB,WAAvB,uBAAuB,CAAA;AACuB,IAAA,oBAAuB,WAAvB,uBAAuB,CAAA;AAC/E,IAAA,IAAc,WAAd,cAAc,CAAA;;;;;;AAElC,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,AAAsB,AAAC;AAEhF,MAAMC,YAAY,GAAGC,CAAAA,GAAAA,KAAS,AAAS,CAAA,UAAT,CAACC,QAAO,QAAA,CAAC,AAGZ,AAAC;AAErB,SAASL,4BAA4B,CAC1CM,WAAmB,EACnBC,OAOC,EACD;IACA,OAAOC,CAAAA,GAAAA,KAAoB,AA8G1B,CAAA,qBA9G0B,CACzB;QAAEC,KAAK,EAAE,EAAE;KAAE,EACb;QACE,MAAMC,iBAAiB,IAAG;YAC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CAAC,6BAA6B,GAAGA,KAAK,CAAC,CAAC;iBAClD;gBACD,OAAO,IAAIE,OAAY,aAAA,CACrB,6BAA6B,GAAGY,oBAAoB,GAAG,MAAM,GAAGd,KAAK,CAACS,OAAO,EAC7E;oBACEL,MAAM,EAAE,GAAG;oBACXE,OAAO,EAAE;wBACP,cAAc,EAAE,WAAW;qBAC5B;iBACF,CACF,CAAC;aACH;SACF;KACF,CACF,CAAC;CACH"}
|
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.getNodeExternalModuleId = getNodeExternalModuleId;
|
|
6
|
+
exports.setupShimFiles = setupShimFiles;
|
|
6
7
|
exports.setupNodeExternals = setupNodeExternals;
|
|
7
8
|
exports.isNodeExternal = isNodeExternal;
|
|
8
|
-
exports.METRO_EXTERNALS_FOLDER = exports.EXTERNAL_REQUIRE_NATIVE_POLYFILL = exports.EXTERNAL_REQUIRE_POLYFILL = exports.NODE_STDLIB_MODULES = void 0;
|
|
9
|
+
exports.METRO_SHIMS_FOLDER = exports.METRO_EXTERNALS_FOLDER = exports.EXTERNAL_REQUIRE_NATIVE_POLYFILL = exports.EXTERNAL_REQUIRE_POLYFILL = exports.NODE_STDLIB_MODULES = void 0;
|
|
9
10
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
11
|
var _module = require("module");
|
|
11
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _dir = require("../../../utils/dir");
|
|
12
14
|
function _interopRequireDefault(obj) {
|
|
13
15
|
return obj && obj.__esModule ? obj : {
|
|
14
16
|
default: obj
|
|
@@ -29,9 +31,22 @@ const EXTERNAL_REQUIRE_NATIVE_POLYFILL = ".expo/metro/polyfill.native.js";
|
|
|
29
31
|
exports.EXTERNAL_REQUIRE_NATIVE_POLYFILL = EXTERNAL_REQUIRE_NATIVE_POLYFILL;
|
|
30
32
|
const METRO_EXTERNALS_FOLDER = ".expo/metro/externals";
|
|
31
33
|
exports.METRO_EXTERNALS_FOLDER = METRO_EXTERNALS_FOLDER;
|
|
34
|
+
const METRO_SHIMS_FOLDER = ".expo/metro/shims";
|
|
35
|
+
exports.METRO_SHIMS_FOLDER = METRO_SHIMS_FOLDER;
|
|
32
36
|
function getNodeExternalModuleId(fromModule, moduleId) {
|
|
33
37
|
return _path.default.relative(_path.default.dirname(fromModule), _path.default.join(METRO_EXTERNALS_FOLDER, moduleId, "index.js"));
|
|
34
38
|
}
|
|
39
|
+
async function setupShimFiles(projectRoot) {
|
|
40
|
+
await _fs.default.promises.mkdir(_path.default.join(projectRoot, METRO_SHIMS_FOLDER), {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
// Copy the shims to the project folder in case we're running in a monorepo.
|
|
44
|
+
const shimsFolder = _path.default.join(require.resolve("@expo/cli/package.json"), "../static/shims");
|
|
45
|
+
await (0, _dir).copyAsync(shimsFolder, _path.default.join(projectRoot, METRO_SHIMS_FOLDER), {
|
|
46
|
+
overwrite: false,
|
|
47
|
+
recursive: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
35
50
|
async function setupNodeExternals(projectRoot) {
|
|
36
51
|
await tapExternalRequirePolyfill(projectRoot);
|
|
37
52
|
await tapNodeShims(projectRoot);
|
|
@@ -40,8 +55,15 @@ async function tapExternalRequirePolyfill(projectRoot) {
|
|
|
40
55
|
await _fs.default.promises.mkdir(_path.default.join(projectRoot, _path.default.dirname(EXTERNAL_REQUIRE_POLYFILL)), {
|
|
41
56
|
recursive: true
|
|
42
57
|
});
|
|
43
|
-
await
|
|
44
|
-
await
|
|
58
|
+
await writeIfDifferentAsync(_path.default.join(projectRoot, EXTERNAL_REQUIRE_POLYFILL), 'global.$$require_external = typeof window === "undefined" ? require : () => null;');
|
|
59
|
+
await writeIfDifferentAsync(_path.default.join(projectRoot, EXTERNAL_REQUIRE_NATIVE_POLYFILL), "global.$$require_external = (moduleId) => {throw new Error(`Node.js standard library module ${moduleId} is not available in this JavaScript environment`);}");
|
|
60
|
+
}
|
|
61
|
+
async function writeIfDifferentAsync(filePath, contents) {
|
|
62
|
+
if (_fs.default.existsSync(filePath)) {
|
|
63
|
+
const current = await _fs.default.promises.readFile(filePath, "utf8");
|
|
64
|
+
if (current === contents) return;
|
|
65
|
+
}
|
|
66
|
+
await _fs.default.promises.writeFile(filePath, contents);
|
|
45
67
|
}
|
|
46
68
|
function isNodeExternal(moduleName) {
|
|
47
69
|
const moduleId = moduleName.replace(/^node:/, "");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/externals.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport { builtinModules } from 'module';\nimport path from 'path';\n\n// A list of the Node.js standard library modules that are currently\n// available,\nexport const NODE_STDLIB_MODULES: string[] = [\n 'fs/promises',\n ...(\n builtinModules ||\n // @ts-expect-error\n (process.binding ? Object.keys(process.binding('natives')) : []) ||\n []\n ).filter((x) => !/^_|^(internal|v8|node-inspect)\\/|\\//.test(x) && !['sys'].includes(x)),\n].sort();\n\nexport const EXTERNAL_REQUIRE_POLYFILL = '.expo/metro/polyfill.js';\nexport const EXTERNAL_REQUIRE_NATIVE_POLYFILL = '.expo/metro/polyfill.native.js';\nexport const METRO_EXTERNALS_FOLDER = '.expo/metro/externals';\n\nexport function getNodeExternalModuleId(fromModule: string, moduleId: string) {\n return path.relative(\n path.dirname(fromModule),\n path.join(METRO_EXTERNALS_FOLDER, moduleId, 'index.js')\n );\n}\n\nexport async function setupNodeExternals(projectRoot: string) {\n await tapExternalRequirePolyfill(projectRoot);\n await tapNodeShims(projectRoot);\n}\n\nasync function tapExternalRequirePolyfill(projectRoot: string) {\n await fs.promises.mkdir(path.join(projectRoot, path.dirname(EXTERNAL_REQUIRE_POLYFILL)), {\n recursive: true,\n });\n await
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/externals.ts"],"sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport { builtinModules } from 'module';\nimport path from 'path';\n\nimport { copyAsync } from '../../../utils/dir';\n\n// A list of the Node.js standard library modules that are currently\n// available,\nexport const NODE_STDLIB_MODULES: string[] = [\n 'fs/promises',\n ...(\n builtinModules ||\n // @ts-expect-error\n (process.binding ? Object.keys(process.binding('natives')) : []) ||\n []\n ).filter((x) => !/^_|^(internal|v8|node-inspect)\\/|\\//.test(x) && !['sys'].includes(x)),\n].sort();\n\nexport const EXTERNAL_REQUIRE_POLYFILL = '.expo/metro/polyfill.js';\nexport const EXTERNAL_REQUIRE_NATIVE_POLYFILL = '.expo/metro/polyfill.native.js';\nexport const METRO_EXTERNALS_FOLDER = '.expo/metro/externals';\nexport const METRO_SHIMS_FOLDER = '.expo/metro/shims';\n\nexport function getNodeExternalModuleId(fromModule: string, moduleId: string) {\n return path.relative(\n path.dirname(fromModule),\n path.join(METRO_EXTERNALS_FOLDER, moduleId, 'index.js')\n );\n}\n\nexport async function setupShimFiles(projectRoot: string) {\n await fs.promises.mkdir(path.join(projectRoot, METRO_SHIMS_FOLDER), { recursive: true });\n // Copy the shims to the project folder in case we're running in a monorepo.\n const shimsFolder = path.join(require.resolve('@expo/cli/package.json'), '../static/shims');\n\n await copyAsync(shimsFolder, path.join(projectRoot, METRO_SHIMS_FOLDER), {\n overwrite: false,\n recursive: true,\n });\n}\n\nexport async function setupNodeExternals(projectRoot: string) {\n await tapExternalRequirePolyfill(projectRoot);\n await tapNodeShims(projectRoot);\n}\n\nasync function tapExternalRequirePolyfill(projectRoot: string) {\n await fs.promises.mkdir(path.join(projectRoot, path.dirname(EXTERNAL_REQUIRE_POLYFILL)), {\n recursive: true,\n });\n await writeIfDifferentAsync(\n path.join(projectRoot, EXTERNAL_REQUIRE_POLYFILL),\n 'global.$$require_external = typeof window === \"undefined\" ? require : () => null;'\n );\n await writeIfDifferentAsync(\n path.join(projectRoot, EXTERNAL_REQUIRE_NATIVE_POLYFILL),\n 'global.$$require_external = (moduleId) => {throw new Error(`Node.js standard library module ${moduleId} is not available in this JavaScript environment`);}'\n );\n}\n\nasync function writeIfDifferentAsync(filePath: string, contents: string): Promise<void> {\n if (fs.existsSync(filePath)) {\n const current = await fs.promises.readFile(filePath, 'utf8');\n if (current === contents) return;\n }\n\n await fs.promises.writeFile(filePath, contents);\n}\n\nexport function isNodeExternal(moduleName: string): string | null {\n const moduleId = moduleName.replace(/^node:/, '');\n if (NODE_STDLIB_MODULES.includes(moduleId)) {\n return moduleId;\n }\n return null;\n}\n\nfunction tapNodeShimContents(moduleId: string): string {\n return `module.exports = $$require_external('node:${moduleId}');`;\n}\n\n// Ensure Node.js shims which require using `$$require_external` are available inside the project.\nasync function tapNodeShims(projectRoot: string) {\n const externals: Record<string, string> = {};\n for (const moduleId of NODE_STDLIB_MODULES) {\n const shimDir = path.join(projectRoot, METRO_EXTERNALS_FOLDER, moduleId);\n const shimPath = path.join(shimDir, 'index.js');\n externals[moduleId] = shimPath;\n\n if (!fs.existsSync(shimPath)) {\n await fs.promises.mkdir(shimDir, { recursive: true });\n await fs.promises.writeFile(shimPath, tapNodeShimContents(moduleId));\n }\n }\n}\n"],"names":["getNodeExternalModuleId","setupShimFiles","setupNodeExternals","isNodeExternal","NODE_STDLIB_MODULES","builtinModules","process","binding","Object","keys","filter","x","test","includes","sort","EXTERNAL_REQUIRE_POLYFILL","EXTERNAL_REQUIRE_NATIVE_POLYFILL","METRO_EXTERNALS_FOLDER","METRO_SHIMS_FOLDER","fromModule","moduleId","path","relative","dirname","join","projectRoot","fs","promises","mkdir","recursive","shimsFolder","require","resolve","copyAsync","overwrite","tapExternalRequirePolyfill","tapNodeShims","writeIfDifferentAsync","filePath","contents","existsSync","current","readFile","writeFile","moduleName","replace","tapNodeShimContents","externals","shimDir","shimPath"],"mappings":"AAMA;;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E;gBAAEnB,SAAS,EAAE,IAAI;aAAE,CAAC,CAAC;YACtD,MAAMH,GAAE,QAAA,CAACC,QAAQ,CAACgB,SAAS,CAACM,QAAQ,EAAEH,mBAAmB,CAAC1B,QAAQ,CAAC,CAAC,CAAC;SACtE;KACF;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/fetchRouterManifest.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport resolveFrom from 'resolve-from';\n\nimport { getRoutePaths } from './router';\n\nexport type ExpoRouterServerManifestV1Route<TRegex = string> = {\n page: string;\n routeKeys: Record<string, string>;\n namedRegex: TRegex;\n generated?: boolean;\n};\n\nexport type ExpoRouterServerManifestV1<TRegex = string> = {\n apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n};\n\nfunction getExpoRouteManifestBuilderAsync(projectRoot: string) {\n return require(resolveFrom(projectRoot, 'expo-router/build/routes-manifest'))\n .createRoutesManifest as typeof import('expo-router/build/routes-manifest').createRoutesManifest;\n}\n\n// TODO: Simplify this now that we use Node.js directly, no need for the Metro bundler caching layer.\nexport async function fetchManifest<TRegex = string>(\n projectRoot: string,\n options: { asJson?: boolean; appDir: string }\n): Promise<ExpoRouterServerManifestV1<TRegex> | null> {\n const getManifest = getExpoRouteManifestBuilderAsync(projectRoot);\n const paths = getRoutePaths(options.appDir);\n // Get the serialized manifest\n const jsonManifest = getManifest(paths);\n\n if (!jsonManifest) {\n return null;\n }\n\n if (!jsonManifest.htmlRoutes || !jsonManifest.apiRoutes) {\n throw new Error('Routes manifest is malformed: ' + JSON.stringify(jsonManifest, null, 2));\n }\n\n if (!options.asJson) {\n // @ts-expect-error\n return inflateManifest(jsonManifest);\n }\n // @ts-expect-error\n return jsonManifest;\n}\n\n// Convert the serialized manifest to a usable format\nexport function inflateManifest(\n json: ExpoRouterServerManifestV1<string>\n): ExpoRouterServerManifestV1<RegExp> {\n return {\n ...json,\n htmlRoutes: json.htmlRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n apiRoutes: json.apiRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n notFoundRoutes: json.notFoundRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n };\n}\n"],"names":["fetchManifest","inflateManifest","getExpoRouteManifestBuilderAsync","projectRoot","require","resolveFrom","createRoutesManifest","options","getManifest","paths","getRoutePaths","appDir","jsonManifest","htmlRoutes","apiRoutes","Error","JSON","stringify","asJson","json","map","value","namedRegex","RegExp","notFoundRoutes"],"mappings":"AAMA;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/fetchRouterManifest.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport resolveFrom from 'resolve-from';\n\nimport { getRoutePaths } from './router';\n\nexport type ExpoRouterServerManifestV1Route<TRegex = string> = {\n file: string;\n page: string;\n routeKeys: Record<string, string>;\n namedRegex: TRegex;\n generated?: boolean;\n};\n\nexport type ExpoRouterServerManifestV1<TRegex = string> = {\n apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n};\n\nfunction getExpoRouteManifestBuilderAsync(projectRoot: string) {\n return require(resolveFrom(projectRoot, 'expo-router/build/routes-manifest'))\n .createRoutesManifest as typeof import('expo-router/build/routes-manifest').createRoutesManifest;\n}\n\n// TODO: Simplify this now that we use Node.js directly, no need for the Metro bundler caching layer.\nexport async function fetchManifest<TRegex = string>(\n projectRoot: string,\n options: { asJson?: boolean; appDir: string }\n): Promise<ExpoRouterServerManifestV1<TRegex> | null> {\n const getManifest = getExpoRouteManifestBuilderAsync(projectRoot);\n const paths = getRoutePaths(options.appDir);\n // Get the serialized manifest\n const jsonManifest = getManifest(paths);\n\n if (!jsonManifest) {\n return null;\n }\n\n if (!jsonManifest.htmlRoutes || !jsonManifest.apiRoutes) {\n throw new Error('Routes manifest is malformed: ' + JSON.stringify(jsonManifest, null, 2));\n }\n\n if (!options.asJson) {\n // @ts-expect-error\n return inflateManifest(jsonManifest);\n }\n // @ts-expect-error\n return jsonManifest;\n}\n\n// Convert the serialized manifest to a usable format\nexport function inflateManifest(\n json: ExpoRouterServerManifestV1<string>\n): ExpoRouterServerManifestV1<RegExp> {\n return {\n ...json,\n htmlRoutes: json.htmlRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n apiRoutes: json.apiRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n notFoundRoutes: json.notFoundRoutes?.map((value) => {\n return {\n ...value,\n namedRegex: new RegExp(value.namedRegex),\n };\n }),\n };\n}\n"],"names":["fetchManifest","inflateManifest","getExpoRouteManifestBuilderAsync","projectRoot","require","resolveFrom","createRoutesManifest","options","getManifest","paths","getRoutePaths","appDir","jsonManifest","htmlRoutes","apiRoutes","Error","JSON","stringify","asJson","json","map","value","namedRegex","RegExp","notFoundRoutes"],"mappings":"AAMA;;;;QAwBsBA,aAAa,GAAbA,aAAa;QA0BnBC,eAAe,GAAfA,eAAe;AAlDP,IAAA,YAAc,kCAAd,cAAc,EAAA;AAER,IAAA,OAAU,WAAV,UAAU,CAAA;;;;;;AAgBxC,SAASC,gCAAgC,CAACC,WAAmB,EAAE;IAC7D,OAAOC,OAAO,CAACC,CAAAA,GAAAA,YAAW,AAAkD,CAAA,QAAlD,CAACF,WAAW,EAAE,mCAAmC,CAAC,CAAC,CAC1EG,oBAAo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