@expo/cli 0.0.0 → 0.1.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/README.md +106 -0
- package/build/bin/cli +125 -0
- package/build/bin/cli.map +1 -0
- package/build/src/api/endpoint.js +17 -0
- package/build/src/api/endpoint.js.map +1 -0
- package/build/src/api/getExpoGoIntermediateCertificate.js +21 -0
- package/build/src/api/getExpoGoIntermediateCertificate.js.map +1 -0
- package/build/src/api/getExpoSchema.js +69 -0
- package/build/src/api/getExpoSchema.js.map +1 -0
- package/build/src/api/getNativeModuleVersions.js +31 -0
- package/build/src/api/getNativeModuleVersions.js.map +1 -0
- package/build/src/api/getProject.js +19 -0
- package/build/src/api/getProject.js.map +1 -0
- package/build/src/api/getProjectDevelopmentCertificate.js +24 -0
- package/build/src/api/getProjectDevelopmentCertificate.js.map +1 -0
- package/build/src/api/getVersions.js +37 -0
- package/build/src/api/getVersions.js.map +1 -0
- package/build/src/api/graphql/client.js +104 -0
- package/build/src/api/graphql/client.js.map +1 -0
- package/build/src/api/graphql/generated.js +113 -0
- package/build/src/api/graphql/generated.js.map +1 -0
- package/build/src/api/graphql/queries/UserQuery.js +43 -0
- package/build/src/api/graphql/queries/UserQuery.js.map +1 -0
- package/build/src/api/rest/cache/FileSystemCache.js +79 -0
- package/build/src/api/rest/cache/FileSystemCache.js.map +1 -0
- package/build/src/api/rest/cache/response.js +31 -0
- package/build/src/api/rest/cache/response.js.map +1 -0
- package/build/src/api/rest/cache/wrapFetchWithCache.js +156 -0
- package/build/src/api/rest/cache/wrapFetchWithCache.js.map +1 -0
- package/build/src/api/rest/client.js +94 -0
- package/build/src/api/rest/client.js.map +1 -0
- package/build/src/api/rest/client.types.js +6 -0
- package/build/src/api/rest/client.types.js.map +1 -0
- package/build/src/api/rest/wrapFetchWithBaseUrl.js +20 -0
- package/build/src/api/rest/wrapFetchWithBaseUrl.js.map +1 -0
- package/build/src/api/rest/wrapFetchWithOffline.js +39 -0
- package/build/src/api/rest/wrapFetchWithOffline.js.map +1 -0
- package/build/src/api/rest/wrapFetchWithProgress.js +59 -0
- package/build/src/api/rest/wrapFetchWithProgress.js.map +1 -0
- package/build/src/api/settings.js +11 -0
- package/build/src/api/settings.js.map +1 -0
- package/build/src/api/signManifest.js +38 -0
- package/build/src/api/signManifest.js.map +1 -0
- package/build/src/api/updateDevelopmentSession.js +74 -0
- package/build/src/api/updateDevelopmentSession.js.map +1 -0
- package/build/src/api/user/UserSettings.js +71 -0
- package/build/src/api/user/UserSettings.js.map +1 -0
- package/build/src/api/user/actions.js +97 -0
- package/build/src/api/user/actions.js.map +1 -0
- package/build/src/api/user/otp.js +139 -0
- package/build/src/api/user/otp.js.map +1 -0
- package/build/src/api/user/user.js +114 -0
- package/build/src/api/user/user.js.map +1 -0
- package/build/src/config/configAsync.js +118 -0
- package/build/src/config/configAsync.js.map +1 -0
- package/build/src/config/index.js +85 -0
- package/build/src/config/index.js.map +1 -0
- package/build/src/install/checkPackages.js +74 -0
- package/build/src/install/checkPackages.js.map +1 -0
- package/build/src/install/index.js +76 -0
- package/build/src/install/index.js.map +1 -0
- package/build/src/install/installAsync.js +103 -0
- package/build/src/install/installAsync.js.map +1 -0
- package/build/src/install/resolveOptions.js +99 -0
- package/build/src/install/resolveOptions.js.map +1 -0
- package/build/src/install/utils/autoAddConfigPlugins.js +87 -0
- package/build/src/install/utils/autoAddConfigPlugins.js.map +1 -0
- package/build/src/log.js +74 -0
- package/build/src/log.js.map +1 -0
- package/build/src/login/index.js +76 -0
- package/build/src/login/index.js.map +1 -0
- package/build/src/logout/index.js +63 -0
- package/build/src/logout/index.js.map +1 -0
- package/build/src/prebuild/clearNativeFolder.js +137 -0
- package/build/src/prebuild/clearNativeFolder.js.map +1 -0
- package/build/src/prebuild/configureProjectAsync.js +68 -0
- package/build/src/prebuild/configureProjectAsync.js.map +1 -0
- package/build/src/prebuild/copyTemplateFiles.js +124 -0
- package/build/src/prebuild/copyTemplateFiles.js.map +1 -0
- package/build/src/prebuild/ensureConfigAsync.js +86 -0
- package/build/src/prebuild/ensureConfigAsync.js.map +1 -0
- package/build/src/prebuild/index.js +101 -0
- package/build/src/prebuild/index.js.map +1 -0
- package/build/src/prebuild/prebuildAsync.js +112 -0
- package/build/src/prebuild/prebuildAsync.js.map +1 -0
- package/build/src/prebuild/resolveOptions.js +97 -0
- package/build/src/prebuild/resolveOptions.js.map +1 -0
- package/build/src/prebuild/resolveTemplate.js +157 -0
- package/build/src/prebuild/resolveTemplate.js.map +1 -0
- package/build/src/prebuild/updateFromTemplate.js +102 -0
- package/build/src/prebuild/updateFromTemplate.js.map +1 -0
- package/build/src/prebuild/updatePackageJson.js +236 -0
- package/build/src/prebuild/updatePackageJson.js.map +1 -0
- package/build/src/prebuild/writeMetroConfig.js +89 -0
- package/build/src/prebuild/writeMetroConfig.js.map +1 -0
- package/build/src/register/index.js +63 -0
- package/build/src/register/index.js.map +1 -0
- package/build/src/register/registerAsync.js +37 -0
- package/build/src/register/registerAsync.js.map +1 -0
- package/build/src/start/doctor/Prerequisite.js +47 -0
- package/build/src/start/doctor/Prerequisite.js.map +1 -0
- package/build/src/start/doctor/apple/SimulatorAppPrerequisite.js +68 -0
- package/build/src/start/doctor/apple/SimulatorAppPrerequisite.js.map +1 -0
- package/build/src/start/doctor/apple/XcodePrerequisite.js +115 -0
- package/build/src/start/doctor/apple/XcodePrerequisite.js.map +1 -0
- package/build/src/start/doctor/apple/XcrunPrerequisite.js +65 -0
- package/build/src/start/doctor/apple/XcrunPrerequisite.js.map +1 -0
- package/build/src/start/doctor/dependencies/bundledNativeModules.js +64 -0
- package/build/src/start/doctor/dependencies/bundledNativeModules.js.map +1 -0
- package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js +131 -0
- package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js.map +1 -0
- package/build/src/start/doctor/dependencies/getMissingPackages.js +95 -0
- package/build/src/start/doctor/dependencies/getMissingPackages.js.map +1 -0
- package/build/src/start/doctor/dependencies/getVersionedPackages.js +119 -0
- package/build/src/start/doctor/dependencies/getVersionedPackages.js.map +1 -0
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js +147 -0
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js.map +1 -0
- package/build/src/start/doctor/ngrok/ExternalModule.js +164 -0
- package/build/src/start/doctor/ngrok/ExternalModule.js.map +1 -0
- package/build/src/start/doctor/ngrok/NgrokResolver.js +17 -0
- package/build/src/start/doctor/ngrok/NgrokResolver.js.map +1 -0
- package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js +142 -0
- package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js.map +1 -0
- package/build/src/start/doctor/typescript/updateTSConfig.js +92 -0
- package/build/src/start/doctor/typescript/updateTSConfig.js.map +1 -0
- package/build/src/start/doctor/web/WebSupportProjectPrerequisite.js +112 -0
- package/build/src/start/doctor/web/WebSupportProjectPrerequisite.js.map +1 -0
- package/build/src/start/index.js +126 -0
- package/build/src/start/index.js.map +1 -0
- package/build/src/start/interface/KeyPressHandler.js +99 -0
- package/build/src/start/interface/KeyPressHandler.js.map +1 -0
- package/build/src/start/interface/commandsTable.js +175 -0
- package/build/src/start/interface/commandsTable.js.map +1 -0
- package/build/src/start/interface/interactiveActions.js +134 -0
- package/build/src/start/interface/interactiveActions.js.map +1 -0
- package/build/src/start/interface/startInterface.js +217 -0
- package/build/src/start/interface/startInterface.js.map +1 -0
- package/build/src/start/platforms/AppIdResolver.js +44 -0
- package/build/src/start/platforms/AppIdResolver.js.map +1 -0
- package/build/src/start/platforms/DeviceManager.js +43 -0
- package/build/src/start/platforms/DeviceManager.js.map +1 -0
- package/build/src/start/platforms/ExpoGoInstaller.js +108 -0
- package/build/src/start/platforms/ExpoGoInstaller.js.map +1 -0
- package/build/src/start/platforms/PlatformManager.js +96 -0
- package/build/src/start/platforms/PlatformManager.js.map +1 -0
- package/build/src/start/platforms/android/ADBServer.js +127 -0
- package/build/src/start/platforms/android/ADBServer.js.map +1 -0
- package/build/src/start/platforms/android/AndroidAppIdResolver.js +40 -0
- package/build/src/start/platforms/android/AndroidAppIdResolver.js.map +1 -0
- package/build/src/start/platforms/android/AndroidDeviceManager.js +171 -0
- package/build/src/start/platforms/android/AndroidDeviceManager.js.map +1 -0
- package/build/src/start/platforms/android/AndroidPlatformManager.js +35 -0
- package/build/src/start/platforms/android/AndroidPlatformManager.js.map +1 -0
- package/build/src/start/platforms/android/activateWindow.js +78 -0
- package/build/src/start/platforms/android/activateWindow.js.map +1 -0
- package/build/src/start/platforms/android/adb.js +230 -0
- package/build/src/start/platforms/android/adb.js.map +1 -0
- package/build/src/start/platforms/android/adbReverse.js +84 -0
- package/build/src/start/platforms/android/adbReverse.js.map +1 -0
- package/build/src/start/platforms/android/emulator.js +118 -0
- package/build/src/start/platforms/android/emulator.js.map +1 -0
- package/build/src/start/platforms/android/getDevices.js +36 -0
- package/build/src/start/platforms/android/getDevices.js.map +1 -0
- package/build/src/start/platforms/android/promptAndroidDevice.js +60 -0
- package/build/src/start/platforms/android/promptAndroidDevice.js.map +1 -0
- package/build/src/start/platforms/ios/AppleAppIdResolver.js +46 -0
- package/build/src/start/platforms/ios/AppleAppIdResolver.js.map +1 -0
- package/build/src/start/platforms/ios/AppleDeviceManager.js +201 -0
- package/build/src/start/platforms/ios/AppleDeviceManager.js.map +1 -0
- package/build/src/start/platforms/ios/ApplePlatformManager.js +31 -0
- package/build/src/start/platforms/ios/ApplePlatformManager.js.map +1 -0
- package/build/src/start/platforms/ios/assertSystemRequirements.js +16 -0
- package/build/src/start/platforms/ios/assertSystemRequirements.js.map +1 -0
- package/build/src/start/platforms/ios/ensureSimulatorAppRunning.js +85 -0
- package/build/src/start/platforms/ios/ensureSimulatorAppRunning.js.map +1 -0
- package/build/src/start/platforms/ios/getBestSimulator.js +101 -0
- package/build/src/start/platforms/ios/getBestSimulator.js.map +1 -0
- package/build/src/start/platforms/ios/promptAppleDevice.js +60 -0
- package/build/src/start/platforms/ios/promptAppleDevice.js.map +1 -0
- package/build/src/start/platforms/ios/simctl.js +229 -0
- package/build/src/start/platforms/ios/simctl.js.map +1 -0
- package/build/src/start/platforms/ios/xcrun.js +67 -0
- package/build/src/start/platforms/ios/xcrun.js.map +1 -0
- package/build/src/start/project/devices.js +77 -0
- package/build/src/start/project/devices.js.map +1 -0
- package/build/src/start/project/dotExpo.js +74 -0
- package/build/src/start/project/dotExpo.js.map +1 -0
- package/build/src/start/project/settings.js +13 -0
- package/build/src/start/project/settings.js.map +1 -0
- package/build/src/start/resolveOptions.js +156 -0
- package/build/src/start/resolveOptions.js.map +1 -0
- package/build/src/start/server/AsyncNgrok.js +173 -0
- package/build/src/start/server/AsyncNgrok.js.map +1 -0
- package/build/src/start/server/BundlerDevServer.js +252 -0
- package/build/src/start/server/BundlerDevServer.js.map +1 -0
- package/build/src/start/server/DevServerManager.js +142 -0
- package/build/src/start/server/DevServerManager.js.map +1 -0
- package/build/src/start/server/DevelopmentSession.js +104 -0
- package/build/src/start/server/DevelopmentSession.js.map +1 -0
- package/build/src/start/server/UrlCreator.js +158 -0
- package/build/src/start/server/UrlCreator.js.map +1 -0
- package/build/src/start/server/metro/MetroBundlerDevServer.js +100 -0
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -0
- package/build/src/start/server/metro/MetroTerminalReporter.js +178 -0
- package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -0
- package/build/src/start/server/metro/TerminalReporter.js +87 -0
- package/build/src/start/server/metro/TerminalReporter.js.map +1 -0
- package/build/src/start/server/metro/TerminalReporter.types.js +6 -0
- package/build/src/start/server/metro/TerminalReporter.types.js.map +1 -0
- package/build/src/start/server/metro/instantiateMetro.js +53 -0
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -0
- package/build/src/start/server/metro/resolveFromProject.js +38 -0
- package/build/src/start/server/metro/resolveFromProject.js.map +1 -0
- package/build/src/start/server/middleware/ClassicManifestMiddleware.js +145 -0
- package/build/src/start/server/middleware/ClassicManifestMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js +185 -0
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/ExpoMiddleware.js +78 -0
- package/build/src/start/server/middleware/ExpoMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js +70 -0
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/ManifestMiddleware.js +177 -0
- package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js +69 -0
- package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/createDevServerMiddleware.js +24 -0
- package/build/src/start/server/middleware/createDevServerMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/resolveAssets.js +107 -0
- package/build/src/start/server/middleware/resolveAssets.js.map +1 -0
- package/build/src/start/server/middleware/resolveEntryPoint.js +37 -0
- package/build/src/start/server/middleware/resolveEntryPoint.js.map +1 -0
- package/build/src/start/server/middleware/resolvePlatform.js +32 -0
- package/build/src/start/server/middleware/resolvePlatform.js.map +1 -0
- package/build/src/start/server/middleware/server.types.js +6 -0
- package/build/src/start/server/middleware/server.types.js.map +1 -0
- package/build/src/start/server/openPlatforms.js +30 -0
- package/build/src/start/server/openPlatforms.js.map +1 -0
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js +303 -0
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js.map +1 -0
- package/build/src/start/server/webpack/formatWebpackMessages.js +94 -0
- package/build/src/start/server/webpack/formatWebpackMessages.js.map +1 -0
- package/build/src/start/server/webpack/resolveFromProject.js +43 -0
- package/build/src/start/server/webpack/resolveFromProject.js.map +1 -0
- package/build/src/start/server/webpack/tls.js +72 -0
- package/build/src/start/server/webpack/tls.js.map +1 -0
- package/build/src/start/startAsync.js +150 -0
- package/build/src/start/startAsync.js.map +1 -0
- package/build/src/utils/FileNotifier.js +71 -0
- package/build/src/utils/FileNotifier.js.map +1 -0
- package/build/src/utils/analytics/getDevClientProperties.js +41 -0
- package/build/src/utils/analytics/getDevClientProperties.js.map +1 -0
- package/build/src/utils/analytics/rudderstackClient.js +106 -0
- package/build/src/utils/analytics/rudderstackClient.js.map +1 -0
- package/build/src/utils/ansi.js +17 -0
- package/build/src/utils/ansi.js.map +1 -0
- package/build/src/utils/args.js +63 -0
- package/build/src/utils/args.js.map +1 -0
- package/build/src/utils/array.js +27 -0
- package/build/src/utils/array.js.map +1 -0
- package/build/src/utils/cocoapods.js +143 -0
- package/build/src/utils/cocoapods.js.map +1 -0
- package/build/src/utils/codesigning.js +283 -0
- package/build/src/utils/codesigning.js.map +1 -0
- package/build/src/utils/createFileTransform.js +89 -0
- package/build/src/utils/createFileTransform.js.map +1 -0
- package/build/src/utils/delay.js +39 -0
- package/build/src/utils/delay.js.map +1 -0
- package/build/src/utils/dir.js +34 -0
- package/build/src/utils/dir.js.map +1 -0
- package/build/src/utils/downloadAppAsync.js +71 -0
- package/build/src/utils/downloadAppAsync.js.map +1 -0
- package/build/src/utils/downloadExpoGoAsync.js +93 -0
- package/build/src/utils/downloadExpoGoAsync.js.map +1 -0
- package/build/src/utils/editor.js +60 -0
- package/build/src/utils/editor.js.map +1 -0
- package/build/src/utils/env.js +59 -0
- package/build/src/utils/env.js.map +1 -0
- package/build/src/utils/errors.js +69 -0
- package/build/src/utils/errors.js.map +1 -0
- package/build/src/utils/exit.js +90 -0
- package/build/src/utils/exit.js.map +1 -0
- package/build/src/utils/findUp.js +33 -0
- package/build/src/utils/findUp.js.map +1 -0
- package/build/src/utils/fn.js +32 -0
- package/build/src/utils/fn.js.map +1 -0
- package/build/src/utils/getOrPromptApplicationId.js +183 -0
- package/build/src/utils/getOrPromptApplicationId.js.map +1 -0
- package/build/src/utils/getRunningProcess.js +92 -0
- package/build/src/utils/getRunningProcess.js.map +1 -0
- package/build/src/utils/git.js +88 -0
- package/build/src/utils/git.js.map +1 -0
- package/build/src/utils/glob.js +65 -0
- package/build/src/utils/glob.js.map +1 -0
- package/build/src/utils/ip.js +16 -0
- package/build/src/utils/ip.js.map +1 -0
- package/build/src/utils/isModuleSymlinked.js +37 -0
- package/build/src/utils/isModuleSymlinked.js.map +1 -0
- package/build/src/utils/link.js +31 -0
- package/build/src/utils/link.js.map +1 -0
- package/build/src/utils/mergeGitIgnorePaths.js +112 -0
- package/build/src/utils/mergeGitIgnorePaths.js.map +1 -0
- package/build/src/utils/modifyConfigAsync.js +68 -0
- package/build/src/utils/modifyConfigAsync.js.map +1 -0
- package/build/src/utils/modifyConfigPlugins.js +51 -0
- package/build/src/utils/modifyConfigPlugins.js.map +1 -0
- package/build/src/utils/nodeModules.js +118 -0
- package/build/src/utils/nodeModules.js.map +1 -0
- package/build/src/utils/npm.js +144 -0
- package/build/src/utils/npm.js.map +1 -0
- package/build/src/utils/obj.js +45 -0
- package/build/src/utils/obj.js.map +1 -0
- package/build/src/utils/ora.js +102 -0
- package/build/src/utils/ora.js.map +1 -0
- package/build/src/utils/port.js +130 -0
- package/build/src/utils/port.js.map +1 -0
- package/build/src/utils/profile.js +63 -0
- package/build/src/utils/profile.js.map +1 -0
- package/build/src/utils/progress.js +15 -0
- package/build/src/utils/progress.js.map +1 -0
- package/build/src/utils/prompts.js +127 -0
- package/build/src/utils/prompts.js.map +1 -0
- package/build/src/utils/scheme.js +106 -0
- package/build/src/utils/scheme.js.map +1 -0
- package/build/src/utils/tar.js +59 -0
- package/build/src/utils/tar.js.map +1 -0
- package/build/src/utils/url.js +67 -0
- package/build/src/utils/url.js.map +1 -0
- package/build/src/utils/validateApplicationId.js +90 -0
- package/build/src/utils/validateApplicationId.js.map +1 -0
- package/build/src/whoami/index.js +63 -0
- package/build/src/whoami/index.js.map +1 -0
- package/build/src/whoami/whoamiAsync.js +44 -0
- package/build/src/whoami/whoamiAsync.js.map +1 -0
- package/package.json +128 -4
- package/static/loading-page/index.html +270 -0
- package/index.js +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.mergeGitIgnorePaths = mergeGitIgnorePaths;
|
|
6
|
+
exports.removeGeneratedGitIgnoreContents = removeGeneratedGitIgnoreContents;
|
|
7
|
+
exports.mergeGitIgnoreContents = mergeGitIgnoreContents;
|
|
8
|
+
exports.createGeneratedHeaderComment = createGeneratedHeaderComment;
|
|
9
|
+
exports.getSanitizedGitIgnoreLines = getSanitizedGitIgnoreLines;
|
|
10
|
+
exports.createGitIgnoreHash = createGitIgnoreHash;
|
|
11
|
+
exports.generatedFooterComment = void 0;
|
|
12
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
13
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
|
+
function _interopRequireDefault(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function mergeGitIgnorePaths(targetGitIgnorePath, sourceGitIgnorePath) {
|
|
20
|
+
if (!_fs.default.existsSync(targetGitIgnorePath)) {
|
|
21
|
+
// No gitignore in the project already, no need to merge anything into anything. I guess they
|
|
22
|
+
// are not using git :O
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (!_fs.default.existsSync(sourceGitIgnorePath)) {
|
|
26
|
+
// Maybe we don't have a gitignore in the template project
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const targetGitIgnore = _fs.default.readFileSync(targetGitIgnorePath).toString();
|
|
30
|
+
const sourceGitIgnore = _fs.default.readFileSync(sourceGitIgnorePath).toString();
|
|
31
|
+
const merged = mergeGitIgnoreContents(targetGitIgnore, sourceGitIgnore);
|
|
32
|
+
// Only rewrite the file if it was modified.
|
|
33
|
+
if (merged.contents) {
|
|
34
|
+
_fs.default.writeFileSync(targetGitIgnorePath, merged.contents);
|
|
35
|
+
}
|
|
36
|
+
return merged;
|
|
37
|
+
}
|
|
38
|
+
const generatedHeaderPrefix = `# @generated expo-cli`;
|
|
39
|
+
const generatedFooterComment = `# @end expo-cli`;
|
|
40
|
+
exports.generatedFooterComment = generatedFooterComment;
|
|
41
|
+
/**
|
|
42
|
+
* Get line indexes for the generated section of a gitignore.
|
|
43
|
+
*
|
|
44
|
+
* @param gitIgnore
|
|
45
|
+
*/ function getGeneratedSectionIndexes(gitIgnore) {
|
|
46
|
+
const contents = gitIgnore.split("\n");
|
|
47
|
+
const start = contents.findIndex((line)=>line.startsWith(generatedHeaderPrefix)
|
|
48
|
+
);
|
|
49
|
+
const end = contents.findIndex((line)=>line.startsWith(generatedFooterComment)
|
|
50
|
+
);
|
|
51
|
+
return {
|
|
52
|
+
contents,
|
|
53
|
+
start,
|
|
54
|
+
end
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function removeGeneratedGitIgnoreContents(gitIgnore) {
|
|
58
|
+
const { contents , start , end } = getGeneratedSectionIndexes(gitIgnore);
|
|
59
|
+
if (start > -1 && end > -1 && start < end) {
|
|
60
|
+
contents.splice(start, end - start + 1);
|
|
61
|
+
// TODO: We could in theory check that the contents we're removing match the hash used in the header,
|
|
62
|
+
// this would ensure that we don't accidentally remove lines that someone added or removed from the generated section.
|
|
63
|
+
return contents.join("\n");
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function mergeGitIgnoreContents(targetGitIgnore, sourceGitIgnore) {
|
|
68
|
+
const header = createGeneratedHeaderComment(sourceGitIgnore);
|
|
69
|
+
if (!targetGitIgnore.includes(header)) {
|
|
70
|
+
// Ensure the old generated gitignore contents are removed.
|
|
71
|
+
const sanitizedTarget = removeGeneratedGitIgnoreContents(targetGitIgnore);
|
|
72
|
+
return {
|
|
73
|
+
contents: [
|
|
74
|
+
sanitizedTarget != null ? sanitizedTarget : targetGitIgnore,
|
|
75
|
+
header,
|
|
76
|
+
`# The following patterns were generated by expo-cli`,
|
|
77
|
+
``,
|
|
78
|
+
sourceGitIgnore,
|
|
79
|
+
generatedFooterComment,
|
|
80
|
+
].join("\n"),
|
|
81
|
+
didMerge: true,
|
|
82
|
+
didClear: !!sanitizedTarget
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
contents: targetGitIgnore,
|
|
87
|
+
didClear: false,
|
|
88
|
+
didMerge: false
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function createGeneratedHeaderComment(gitIgnore) {
|
|
92
|
+
const hashKey = createGitIgnoreHash(getSanitizedGitIgnoreLines(gitIgnore).join("\n"));
|
|
93
|
+
return `${generatedHeaderPrefix} ${hashKey}`;
|
|
94
|
+
}
|
|
95
|
+
function getSanitizedGitIgnoreLines(gitIgnore) {
|
|
96
|
+
// filter, trim, and sort the lines.
|
|
97
|
+
return gitIgnore.split("\n").filter((v)=>{
|
|
98
|
+
const line = v.trim();
|
|
99
|
+
// Strip comments
|
|
100
|
+
if (line.startsWith("#")) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return !!line;
|
|
104
|
+
}).sort();
|
|
105
|
+
}
|
|
106
|
+
function createGitIgnoreHash(gitIgnore) {
|
|
107
|
+
// this doesn't need to be secure, the shorter the better.
|
|
108
|
+
const hash = _crypto.default.createHash("sha1").update(gitIgnore).digest("hex");
|
|
109
|
+
return `sync-${hash}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=mergeGitIgnorePaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/mergeGitIgnorePaths.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\n\ntype MergeResults = {\n contents: string;\n didClear: boolean;\n didMerge: boolean;\n};\n/**\n * Merge two gitignore files together and add a generated header.\n *\n * @param targetGitIgnorePath\n * @param sourceGitIgnorePath\n *\n * @returns `null` if one of the gitignore files doesn't exist. Otherwise, returns the merged contents.\n */\nexport function mergeGitIgnorePaths(\n targetGitIgnorePath: string,\n sourceGitIgnorePath: string\n): null | MergeResults {\n if (!fs.existsSync(targetGitIgnorePath)) {\n // No gitignore in the project already, no need to merge anything into anything. I guess they\n // are not using git :O\n return null;\n }\n\n if (!fs.existsSync(sourceGitIgnorePath)) {\n // Maybe we don't have a gitignore in the template project\n return null;\n }\n\n const targetGitIgnore = fs.readFileSync(targetGitIgnorePath).toString();\n const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath).toString();\n const merged = mergeGitIgnoreContents(targetGitIgnore, sourceGitIgnore);\n // Only rewrite the file if it was modified.\n if (merged.contents) {\n fs.writeFileSync(targetGitIgnorePath, merged.contents);\n }\n\n return merged;\n}\n\nconst generatedHeaderPrefix = `# @generated expo-cli`;\nexport const generatedFooterComment = `# @end expo-cli`;\n\n/**\n * Get line indexes for the generated section of a gitignore.\n *\n * @param gitIgnore\n */\nfunction getGeneratedSectionIndexes(gitIgnore: string): {\n contents: string[];\n start: number;\n end: number;\n} {\n const contents = gitIgnore.split('\\n');\n const start = contents.findIndex((line) => line.startsWith(generatedHeaderPrefix));\n const end = contents.findIndex((line) => line.startsWith(generatedFooterComment));\n\n return { contents, start, end };\n}\n\n/**\n * Removes the generated section from a gitignore, returns null when nothing can be removed.\n * This sways heavily towards not removing lines unless it's certain that modifications were not made to the gitignore manually.\n *\n * @param gitIgnore\n */\nexport function removeGeneratedGitIgnoreContents(gitIgnore: string): string | null {\n const { contents, start, end } = getGeneratedSectionIndexes(gitIgnore);\n if (start > -1 && end > -1 && start < end) {\n contents.splice(start, end - start + 1);\n // TODO: We could in theory check that the contents we're removing match the hash used in the header,\n // this would ensure that we don't accidentally remove lines that someone added or removed from the generated section.\n return contents.join('\\n');\n }\n return null;\n}\n\n/**\n * Merge the contents of two gitignores together and add a generated header.\n *\n * @param targetGitIgnore contents of the existing gitignore\n * @param sourceGitIgnore contents of the extra gitignore\n */\nexport function mergeGitIgnoreContents(\n targetGitIgnore: string,\n sourceGitIgnore: string\n): MergeResults {\n const header = createGeneratedHeaderComment(sourceGitIgnore);\n if (!targetGitIgnore.includes(header)) {\n // Ensure the old generated gitignore contents are removed.\n const sanitizedTarget = removeGeneratedGitIgnoreContents(targetGitIgnore);\n return {\n contents: [\n sanitizedTarget ?? targetGitIgnore,\n header,\n `# The following patterns were generated by expo-cli`,\n ``,\n sourceGitIgnore,\n generatedFooterComment,\n ].join('\\n'),\n didMerge: true,\n didClear: !!sanitizedTarget,\n };\n }\n return { contents: targetGitIgnore, didClear: false, didMerge: false };\n}\n\nexport function createGeneratedHeaderComment(gitIgnore: string): string {\n const hashKey = createGitIgnoreHash(getSanitizedGitIgnoreLines(gitIgnore).join('\\n'));\n\n return `${generatedHeaderPrefix} ${hashKey}`;\n}\n\n/**\n * Normalize the contents of a gitignore to ensure that minor changes like new lines or sort order don't cause a regeneration.\n */\nexport function getSanitizedGitIgnoreLines(gitIgnore: string): string[] {\n // filter, trim, and sort the lines.\n return gitIgnore\n .split('\\n')\n .filter((v) => {\n const line = v.trim();\n // Strip comments\n if (line.startsWith('#')) {\n return false;\n }\n return !!line;\n })\n .sort();\n}\n\nexport function createGitIgnoreHash(gitIgnore: string): string {\n // this doesn't need to be secure, the shorter the better.\n const hash = crypto.createHash('sha1').update(gitIgnore).digest('hex');\n return `sync-${hash}`;\n}\n"],"names":["mergeGitIgnorePaths","removeGeneratedGitIgnoreContents","mergeGitIgnoreContents","createGeneratedHeaderComment","getSanitizedGitIgnoreLines","createGitIgnoreHash","targetGitIgnorePath","sourceGitIgnorePath","fs","existsSync","targetGitIgnore","readFileSync","toString","sourceGitIgnore","merged","contents","writeFileSync","generatedHeaderPrefix","generatedFooterComment","getGeneratedSectionIndexes","gitIgnore","split","start","findIndex","line","startsWith","end","splice","join","header","includes","sanitizedTarget","didMerge","didClear","hashKey","filter","v","trim","sort","hash","crypto","createHash","update","digest"],"mappings":"AAAA;;;;QA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Module", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.attemptModification = attemptModification;
|
|
6
|
+
exports.warnAboutConfigAndThrow = warnAboutConfigAndThrow;
|
|
7
|
+
var _config = require("@expo/config");
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
var Log = _interopRequireWildcard(require("../log"));
|
|
10
|
+
var _errors = require("./errors");
|
|
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
|
+
async function attemptModification(projectRoot, edits, exactEdits) {
|
|
38
|
+
const modification = await (0, _config).modifyConfigAsync(projectRoot, edits, {
|
|
39
|
+
skipSDKVersionRequirement: true
|
|
40
|
+
});
|
|
41
|
+
if (modification.type === "success") {
|
|
42
|
+
Log.log();
|
|
43
|
+
} else {
|
|
44
|
+
warnAboutConfigAndThrow(modification.type, modification.message, exactEdits);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function logNoConfig() {
|
|
48
|
+
Log.log(_chalk.default.yellow(`No Expo config was found. Please create an Expo config (${_chalk.default.bold`app.json`} or ${_chalk.default.bold`app.config.js`}) in your project root.`));
|
|
49
|
+
}
|
|
50
|
+
function warnAboutConfigAndThrow(type, message, edits) {
|
|
51
|
+
Log.log();
|
|
52
|
+
if (type === "warn") {
|
|
53
|
+
// The project is using a dynamic config, give the user a helpful log and bail out.
|
|
54
|
+
Log.log(_chalk.default.yellow(message));
|
|
55
|
+
} else {
|
|
56
|
+
logNoConfig();
|
|
57
|
+
}
|
|
58
|
+
notifyAboutManualConfigEdits(edits);
|
|
59
|
+
throw new _errors.SilentError();
|
|
60
|
+
}
|
|
61
|
+
function notifyAboutManualConfigEdits(edits) {
|
|
62
|
+
Log.log(_chalk.default.cyan(`Please add the following to your Expo config`));
|
|
63
|
+
Log.log();
|
|
64
|
+
Log.log(JSON.stringify(edits, null, 2));
|
|
65
|
+
Log.log();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=modifyConfigAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/modifyConfigAsync.ts"],"sourcesContent":["import { ExpoConfig, modifyConfigAsync } from '@expo/config';\nimport chalk from 'chalk';\n\nimport * as Log from '../log';\nimport { SilentError } from './errors';\n\n/** Wraps `[@expo/config] modifyConfigAsync()` and adds additional logging. */\nexport async function attemptModification(\n projectRoot: string,\n edits: Partial<ExpoConfig>,\n exactEdits: Partial<ExpoConfig>\n): Promise<void> {\n const modification = await modifyConfigAsync(projectRoot, edits, {\n skipSDKVersionRequirement: true,\n });\n if (modification.type === 'success') {\n Log.log();\n } else {\n warnAboutConfigAndThrow(modification.type, modification.message!, exactEdits);\n }\n}\n\nfunction logNoConfig() {\n Log.log(\n chalk.yellow(\n `No Expo config was found. Please create an Expo config (${chalk.bold`app.json`} or ${chalk.bold`app.config.js`}) in your project root.`\n )\n );\n}\n\nexport function warnAboutConfigAndThrow(type: string, message: string, edits: Partial<ExpoConfig>) {\n Log.log();\n if (type === 'warn') {\n // The project is using a dynamic config, give the user a helpful log and bail out.\n Log.log(chalk.yellow(message));\n } else {\n logNoConfig();\n }\n\n notifyAboutManualConfigEdits(edits);\n throw new SilentError();\n}\n\nfunction notifyAboutManualConfigEdits(edits: Partial<ExpoConfig>) {\n Log.log(chalk.cyan(`Please add the following to your Expo config`));\n Log.log();\n Log.log(JSON.stringify(edits, null, 2));\n Log.log();\n}\n"],"names":["attemptModification","warnAboutConfigAndThrow","Log","projectRoot","edits","exactEdits","modification","modifyConfigAsync","skipSDKVersionRequirement","type","log","message","logNoConfig","chalk","yellow","bold","notifyAboutManualConfigEdits","SilentError","cyan","JSON","stringify"],"mappings":"AAAA;;;;QAOsBA,mBAAmB,GAAnBA,mBAAmB;QAuBzBC,uBAAuB,GAAvBA,uBAAuB;AA9BO,IAAA,OAAc,WAAd,cAAc,CAAA;AAC1C,IAAA,MAAO,kCAAP,OAAO,EAAA;AAEbC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACa,IAAA,OAAU,WAAV,UAAU,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/B,eAAeF,mBAAmB,CACvCG,WAAmB,EACnBC,KAA0B,EAC1BC,UAA+B,EAChB;IACf,MAAMC,YAAY,GAAG,MAAMC,CAAAA,GAAAA,OAAiB,AAE1C,CAAA,kBAF0C,CAACJ,WAAW,EAAEC,KAAK,EAAE;QAC/DI,yBAAyB,EAAE,IAAI;KAChC,CAAC,AAAC;IACH,IAAIF,YAAY,CAACG,IAAI,KAAK,SAAS,EAAE;QACnCP,GAAG,CAACQ,GAAG,EAAE,CAAC;KACX,MAAM;QACLT,uBAAuB,CAACK,YAAY,CAACG,IAAI,EAAEH,YAAY,CAACK,OAAO,EAAGN,UAAU,CAAC,CAAC;KAC/E;CACF;AAED,SAASO,WAAW,GAAG;IACrBV,GAAG,CAACQ,GAAG,CACLG,MAAK,QAAA,CAACC,MAAM,CACV,CAAC,wDAAwD,EAAED,MAAK,QAAA,CAACE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAEF,MAAK,QAAA,CAACE,IAAI,CAAC,aAAa,CAAC,CAAC,uBAAuB,CAAC,CACzI,CACF,CAAC;CACH;AAEM,SAASd,uBAAuB,CAACQ,IAAY,EAAEE,OAAe,EAAEP,KAA0B,EAAE;IACjGF,GAAG,CAACQ,GAAG,EAAE,CAAC;IACV,IAAID,IAAI,KAAK,MAAM,EAAE;QACnB,mFAAmF;QACnFP,GAAG,CAACQ,GAAG,CAACG,MAAK,QAAA,CAACC,MAAM,CAACH,OAAO,CAAC,CAAC,CAAC;KAChC,MAAM;QACLC,WAAW,EAAE,CAAC;KACf;IAEDI,4BAA4B,CAACZ,KAAK,CAAC,CAAC;IACpC,MAAM,IAAIa,OAAW,YAAA,EAAE,CAAC;CACzB;AAED,SAASD,4BAA4B,CAACZ,KAA0B,EAAE;IAChEF,GAAG,CAACQ,GAAG,CAACG,MAAK,QAAA,CAACK,IAAI,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC,CAAC;IACpEhB,GAAG,CAACQ,GAAG,EAAE,CAAC;IACVR,GAAG,CAACQ,GAAG,CAACS,IAAI,CAACC,SAAS,CAAChB,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACxCF,GAAG,CAACQ,GAAG,EAAE,CAAC;CACX"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.attemptAddingPluginsAsync = attemptAddingPluginsAsync;
|
|
6
|
+
var _config = require("@expo/config");
|
|
7
|
+
var Log = _interopRequireWildcard(require("../log"));
|
|
8
|
+
var _modifyConfigAsync = require("./modifyConfigAsync");
|
|
9
|
+
function _interopRequireWildcard(obj) {
|
|
10
|
+
if (obj && obj.__esModule) {
|
|
11
|
+
return obj;
|
|
12
|
+
} else {
|
|
13
|
+
var newObj = {};
|
|
14
|
+
if (obj != null) {
|
|
15
|
+
for(var key in obj){
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
17
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
18
|
+
if (desc.get || desc.set) {
|
|
19
|
+
Object.defineProperty(newObj, key, desc);
|
|
20
|
+
} else {
|
|
21
|
+
newObj[key] = obj[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
newObj.default = obj;
|
|
27
|
+
return newObj;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function attemptAddingPluginsAsync(projectRoot, exp, plugins) {
|
|
31
|
+
if (!plugins.length) return;
|
|
32
|
+
const edits = {
|
|
33
|
+
plugins: [
|
|
34
|
+
...new Set((exp.plugins || []).concat(plugins))
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
const modification = await (0, _config).modifyConfigAsync(projectRoot, edits, {
|
|
38
|
+
skipSDKVersionRequirement: true,
|
|
39
|
+
skipPlugins: true
|
|
40
|
+
});
|
|
41
|
+
if (modification.type === "success") {
|
|
42
|
+
Log.log(`\u203A Added config plugin${plugins.length === 1 ? "" : "s"}: ${plugins.join(", ")}`);
|
|
43
|
+
} else {
|
|
44
|
+
const exactEdits = {
|
|
45
|
+
plugins
|
|
46
|
+
};
|
|
47
|
+
(0, _modifyConfigAsync).warnAboutConfigAndThrow(modification.type, modification.message, exactEdits);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=modifyConfigPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/modifyConfigPlugins.ts"],"sourcesContent":["import { ExpoConfig, modifyConfigAsync } from '@expo/config';\n\nimport * as Log from '../log';\nimport { warnAboutConfigAndThrow } from './modifyConfigAsync';\n\nexport async function attemptAddingPluginsAsync(\n projectRoot: string,\n exp: Pick<ExpoConfig, 'plugins'>,\n plugins: string[]\n): Promise<void> {\n if (!plugins.length) return;\n\n const edits = {\n plugins: [...new Set((exp.plugins || []).concat(plugins))],\n };\n const modification = await modifyConfigAsync(projectRoot, edits, {\n skipSDKVersionRequirement: true,\n skipPlugins: true,\n });\n if (modification.type === 'success') {\n Log.log(`\\u203A Added config plugin${plugins.length === 1 ? '' : 's'}: ${plugins.join(', ')}`);\n } else {\n const exactEdits = {\n plugins,\n };\n warnAboutConfigAndThrow(modification.type, modification.message!, exactEdits);\n }\n}\n"],"names":["attemptAddingPluginsAsync","Log","projectRoot","exp","plugins","length","edits","Set","concat","modification","modifyConfigAsync","skipSDKVersionRequirement","skipPlugins","type","log","join","exactEdits","warnAboutConfigAndThrow","message"],"mappings":"AAAA;;;;QAKsBA,yBAAyB,GAAzBA,yBAAyB;AALD,IAAA,OAAc,WAAd,cAAc,CAAA;AAEhDC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACyB,IAAA,kBAAqB,WAArB,qBAAqB,CAAA;;;;;;;;;;;;;;;;;;;;;;AAEtD,eAAeD,yBAAyB,CAC7CE,WAAmB,EACnBC,GAAgC,EAChCC,OAAiB,EACF;IACf,IAAI,CAACA,OAAO,CAACC,MAAM,EAAE,OAAO;IAE5B,MAAMC,KAAK,GAAG;QACZF,OAAO,EAAE;eAAI,IAAIG,GAAG,CAAC,CAACJ,GAAG,CAACC,OAAO,IAAI,EAAE,CAAC,CAACI,MAAM,CAACJ,OAAO,CAAC,CAAC;SAAC;KAC3D,AAAC;IACF,MAAMK,YAAY,GAAG,MAAMC,CAAAA,GAAAA,OAAiB,AAG1C,CAAA,kBAH0C,CAACR,WAAW,EAAEI,KAAK,EAAE;QAC/DK,yBAAyB,EAAE,IAAI;QAC/BC,WAAW,EAAE,IAAI;KAClB,CAAC,AAAC;IACH,IAAIH,YAAY,CAACI,IAAI,KAAK,SAAS,EAAE;QACnCZ,GAAG,CAACa,GAAG,CAAC,CAAC,0BAA0B,EAAEV,OAAO,CAACC,MAAM,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,EAAE,EAAED,OAAO,CAACW,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;KAChG,MAAM;QACL,MAAMC,UAAU,GAAG;YACjBZ,OAAO;SACR,AAAC;QACFa,CAAAA,GAAAA,kBAAuB,AAAsD,CAAA,wBAAtD,CAACR,YAAY,CAACI,IAAI,EAAEJ,YAAY,CAACS,OAAO,EAAGF,UAAU,CAAC,CAAC;KAC/E;CACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.resolvePackageManager = resolvePackageManager;
|
|
6
|
+
exports.installNodeDependenciesAsync = installNodeDependenciesAsync;
|
|
7
|
+
var PackageManager = _interopRequireWildcard(require("@expo/package-manager"));
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _semver = _interopRequireDefault(require("semver"));
|
|
13
|
+
var Log = _interopRequireWildcard(require("../log"));
|
|
14
|
+
var _env = require("./env");
|
|
15
|
+
var _errors = require("./errors");
|
|
16
|
+
var _ora = require("./ora");
|
|
17
|
+
function _interopRequireDefault(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _interopRequireWildcard(obj) {
|
|
23
|
+
if (obj && obj.__esModule) {
|
|
24
|
+
return obj;
|
|
25
|
+
} else {
|
|
26
|
+
var newObj = {};
|
|
27
|
+
if (obj != null) {
|
|
28
|
+
for(var key in obj){
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
30
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
31
|
+
if (desc.get || desc.set) {
|
|
32
|
+
Object.defineProperty(newObj, key, desc);
|
|
33
|
+
} else {
|
|
34
|
+
newObj[key] = obj[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
newObj.default = obj;
|
|
40
|
+
return newObj;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function resolvePackageManager(options) {
|
|
44
|
+
let packageManager = "npm";
|
|
45
|
+
if (options.yarn || !options.npm && PackageManager.shouldUseYarn()) {
|
|
46
|
+
packageManager = "yarn";
|
|
47
|
+
} else {
|
|
48
|
+
packageManager = "npm";
|
|
49
|
+
}
|
|
50
|
+
if (options.install) {
|
|
51
|
+
Log.log(packageManager === "yarn" ? `🧶 Using Yarn to install packages. ${_chalk.default.dim("Pass --npm to use npm instead.")}` : "\uD83D\uDCE6 Using npm to install packages.");
|
|
52
|
+
}
|
|
53
|
+
return packageManager;
|
|
54
|
+
}
|
|
55
|
+
async function installNodeDependenciesAsync(projectRoot, packageManager, flags = {}) {
|
|
56
|
+
var _silent;
|
|
57
|
+
// Default to silent unless debugging.
|
|
58
|
+
const isSilent = (_silent = flags.silent) != null ? _silent : !_env.env.EXPO_DEBUG;
|
|
59
|
+
if (flags.clean && packageManager !== "yarn") {
|
|
60
|
+
// This step can take a couple seconds, if the installation logs are enabled (with EXPO_DEBUG) then it
|
|
61
|
+
// ends up looking odd to see "Installing JavaScript dependencies" for ~5 seconds before the logs start showing up.
|
|
62
|
+
const cleanJsDepsStep = (0, _ora).logNewSection("Cleaning JavaScript dependencies");
|
|
63
|
+
const time = Date.now();
|
|
64
|
+
// nuke the node modules
|
|
65
|
+
// TODO: this is substantially slower, we should find a better alternative to ensuring the modules are installed.
|
|
66
|
+
await _fs.default.promises.rm("node_modules", {
|
|
67
|
+
recursive: true,
|
|
68
|
+
force: true
|
|
69
|
+
});
|
|
70
|
+
cleanJsDepsStep.succeed(`Cleaned JavaScript dependencies ${_chalk.default.gray(Date.now() - time + "ms")}`);
|
|
71
|
+
}
|
|
72
|
+
const installJsDepsStep = (0, _ora).logNewSection("Installing JavaScript dependencies");
|
|
73
|
+
try {
|
|
74
|
+
const time = Date.now();
|
|
75
|
+
await installNodeDependenciesInternalAsync(projectRoot, packageManager, {
|
|
76
|
+
silent: isSilent
|
|
77
|
+
});
|
|
78
|
+
installJsDepsStep.succeed(`Installed JavaScript dependencies ${_chalk.default.gray(Date.now() - time + "ms")}`);
|
|
79
|
+
} catch {
|
|
80
|
+
const message = `Something went wrong installing JavaScript dependencies, check your ${packageManager} logfile or run ${_chalk.default.bold(`${packageManager} install`)} again manually.`;
|
|
81
|
+
installJsDepsStep.fail(_chalk.default.red(message));
|
|
82
|
+
// TODO: actually show the error message from the package manager! :O
|
|
83
|
+
throw new _errors.SilentError(message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function installNodeDependenciesInternalAsync(projectRoot, packageManager, flags) {
|
|
87
|
+
const options = {
|
|
88
|
+
cwd: projectRoot,
|
|
89
|
+
silent: flags.silent
|
|
90
|
+
};
|
|
91
|
+
if (packageManager === "yarn") {
|
|
92
|
+
const yarn = new PackageManager.YarnPackageManager(options);
|
|
93
|
+
const version = await yarn.versionAsync();
|
|
94
|
+
const nodeLinker = await yarn.getConfigAsync("nodeLinker");
|
|
95
|
+
if (_semver.default.satisfies(version, ">=2.0.0-rc.24") && nodeLinker !== "node-modules") {
|
|
96
|
+
const yarnRc = _path.default.join(projectRoot, ".yarnrc.yml");
|
|
97
|
+
let yamlString = "";
|
|
98
|
+
try {
|
|
99
|
+
yamlString = _fs.default.readFileSync(yarnRc, "utf8");
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error.code !== "ENOENT") {
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const config = yamlString ? _jsYaml.default.safeLoad(yamlString) : {};
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
config.nodeLinker = "node-modules";
|
|
108
|
+
!flags.silent && Log.warn(`Yarn v${version} detected, enabling experimental Yarn v2 support using the node-modules plugin.`);
|
|
109
|
+
!flags.silent && Log.log(`Writing ${yarnRc}...`);
|
|
110
|
+
_fs.default.writeFileSync(yarnRc, _jsYaml.default.safeDump(config));
|
|
111
|
+
}
|
|
112
|
+
await yarn.installAsync();
|
|
113
|
+
} else {
|
|
114
|
+
await new PackageManager.NpmPackageManager(options).installAsync();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=nodeModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/nodeModules.ts"],"sourcesContent":["import * as PackageManager from '@expo/package-manager';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport yaml from 'js-yaml';\nimport path from 'path';\nimport semver from 'semver';\n\nimport * as Log from '../log';\nimport { env } from './env';\nimport { SilentError } from './errors';\nimport { logNewSection } from './ora';\n\nexport type PackageManagerName = 'npm' | 'yarn';\n\nexport function resolvePackageManager(options: {\n yarn?: boolean;\n npm?: boolean;\n install?: boolean;\n}): PackageManagerName {\n let packageManager: PackageManagerName = 'npm';\n if (options.yarn || (!options.npm && PackageManager.shouldUseYarn())) {\n packageManager = 'yarn';\n } else {\n packageManager = 'npm';\n }\n if (options.install) {\n Log.log(\n packageManager === 'yarn'\n ? `🧶 Using Yarn to install packages. ${chalk.dim('Pass --npm to use npm instead.')}`\n : '📦 Using npm to install packages.'\n );\n }\n\n return packageManager;\n}\n\nexport async function installNodeDependenciesAsync(\n projectRoot: string,\n packageManager: PackageManagerName,\n flags: { silent?: boolean; clean?: boolean } = {}\n) {\n // Default to silent unless debugging.\n const isSilent = flags.silent ?? !env.EXPO_DEBUG;\n if (flags.clean && packageManager !== 'yarn') {\n // This step can take a couple seconds, if the installation logs are enabled (with EXPO_DEBUG) then it\n // ends up looking odd to see \"Installing JavaScript dependencies\" for ~5 seconds before the logs start showing up.\n const cleanJsDepsStep = logNewSection('Cleaning JavaScript dependencies');\n const time = Date.now();\n // nuke the node modules\n // TODO: this is substantially slower, we should find a better alternative to ensuring the modules are installed.\n await fs.promises.rm('node_modules', { recursive: true, force: true });\n cleanJsDepsStep.succeed(\n `Cleaned JavaScript dependencies ${chalk.gray(Date.now() - time + 'ms')}`\n );\n }\n\n const installJsDepsStep = logNewSection('Installing JavaScript dependencies');\n try {\n const time = Date.now();\n await installNodeDependenciesInternalAsync(projectRoot, packageManager, { silent: isSilent });\n installJsDepsStep.succeed(\n `Installed JavaScript dependencies ${chalk.gray(Date.now() - time + 'ms')}`\n );\n } catch {\n const message = `Something went wrong installing JavaScript dependencies, check your ${packageManager} logfile or run ${chalk.bold(\n `${packageManager} install`\n )} again manually.`;\n installJsDepsStep.fail(chalk.red(message));\n // TODO: actually show the error message from the package manager! :O\n throw new SilentError(message);\n }\n}\n\nasync function installNodeDependenciesInternalAsync(\n projectRoot: string,\n packageManager: PackageManagerName,\n flags: { silent: boolean }\n) {\n const options = { cwd: projectRoot, silent: flags.silent };\n if (packageManager === 'yarn') {\n const yarn = new PackageManager.YarnPackageManager(options);\n const version = await yarn.versionAsync();\n const nodeLinker = await yarn.getConfigAsync('nodeLinker');\n if (semver.satisfies(version, '>=2.0.0-rc.24') && nodeLinker !== 'node-modules') {\n const yarnRc = path.join(projectRoot, '.yarnrc.yml');\n let yamlString = '';\n try {\n yamlString = fs.readFileSync(yarnRc, 'utf8');\n } catch (error: any) {\n if (error.code !== 'ENOENT') {\n throw error;\n }\n }\n const config = yamlString ? yaml.safeLoad(yamlString) : {};\n // @ts-ignore\n config.nodeLinker = 'node-modules';\n !flags.silent &&\n Log.warn(\n `Yarn v${version} detected, enabling experimental Yarn v2 support using the node-modules plugin.`\n );\n !flags.silent && Log.log(`Writing ${yarnRc}...`);\n fs.writeFileSync(yarnRc, yaml.safeDump(config));\n }\n await yarn.installAsync();\n } else {\n await new PackageManager.NpmPackageManager(options).installAsync();\n }\n}\n"],"names":["resolvePackageManager","installNodeDependenciesAsync","PackageManager","Log","options","packageManager","yarn","npm","shouldUseYarn","install","log","chalk","dim","projectRoot","flags","isSilent","silent","env","EXPO_DEBUG","clean","cleanJsDepsStep","logNewSection","time","Date","now","fs","promises","rm","recursive","force","succeed","gray","installJsDepsStep","installNodeDependenciesInternalAsync","message","bold","fail","red","SilentError","cwd","YarnPackageManager","version","versionAsync","nodeLinker","getConfigAsync","semver","satisfies","yarnRc","path","join","yamlString","readFileSync","error","code","config","yaml","safeLoad","warn","writeFileSync","safeDump","installAsync","NpmPackageManager"],"mappings":"AAAA;;;;QAcgBA,qBAAqB,GAArBA,qBAAqB;QAsBfC,4BAA4B,GAA5BA,4BAA4B;AApCtCC,IAAAA,cAAc,mCAAM,uBAAuB,EAA7B;AACR,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,OAAS,kCAAT,SAAS,EAAA;AACT,IAAA,KAAM,kCAAN,MAAM,EAAA;AACJ,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AAEfC,IAAAA,GAAG,mCAAM,QAAQ,EAAd;AACK,IAAA,IAAO,WAAP,OAAO,CAAA;AACC,IAAA,OAAU,WAAV,UAAU,CAAA;AACR,IAAA,IAAO,WAAP,OAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI9B,SAASH,qBAAqB,CAACI,OAIrC,EAAsB;IACrB,IAAIC,cAAc,GAAuB,KAAK,AAAC;IAC/C,IAAID,OAAO,CAACE,IAAI,IAAK,CAACF,OAAO,CAACG,GAAG,IAAIL,cAAc,CAACM,aAAa,EAAE,AAAC,EAAE;QACpEH,cAAc,GAAG,MAAM,CAAC;KACzB,MAAM;QACLA,cAAc,GAAG,KAAK,CAAC;KACxB;IACD,IAAID,OAAO,CAACK,OAAO,EAAE;QACnBN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AAE,AAAC;YACpB,IAAI;gBACFA,UAAU,GAAGzB,GAAE,QAAA,CAAC0B,YAAY,CAACJ,MAAM,EAAE,MAAM,CAAC,CAAC;aAC9C,CAAC,OAAOK,KAAK,EAAO;gBACnB,IAAIA,KAAK,CAACC,IAAI,KAAK,QAAQ,EAAE;oBAC3B,MAAMD,KAAK,CAAC;iBACb;aACF;YACD,MAAME,MAAM,GAAGJ,UAAU,GAAGK,OAAI,QAAA,CAACC,QAAQ,CAACN,UAAU,CAAC,GAAG,EAAE,AAAC;YAC3D,aAAa;YACbI,MAAM,CAACX,UAAU,GAAG,cAAc,CAAC;YACnC,CAAC7B,KAAK,CAACE,MAAM,IACXb,GAAG,CAACsD,IAAI,CACN,CAAC,MAAM,EAAEhB,OAAO,CAAC,+EAA+E,CAAC,CAClG,CAAC;YACJ,CAAC3B,KAAK,CAACE,MAAM,IAAIb,GAAG,CAACO,GAAG,CAAC,CAAC,QAAQ,EAAEqC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACjDtB,GAAE,QAAA,CAACiC,aAAa,CAACX,MAAM,EAAEQ,OAAI,QAAA,CAACI,QAAQ,CAACL,MAAM,CAAC,CAAC,CAAC;SACjD;QACD,MAAMhD,IAAI,CAACsD,YAAY,EAAE,CAAC;KAC3B,MAAM;QACL,MAAM,IAAI1D,cAAc,CAAC2D,iBAAiB,CAACzD,OAAO,CAAC,CAACwD,YAAY,EAAE,CAAC;KACpE;CACF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.sanitizeNpmPackageName = sanitizeNpmPackageName;
|
|
6
|
+
exports.npmViewAsync = npmViewAsync;
|
|
7
|
+
exports.getNpmUrlAsync = getNpmUrlAsync;
|
|
8
|
+
exports.downloadAndExtractNpmModuleAsync = downloadAndExtractNpmModuleAsync;
|
|
9
|
+
exports.extractLocalNpmTarballAsync = extractLocalNpmTarballAsync;
|
|
10
|
+
exports.extractNpmTarballFromUrlAsync = extractNpmTarballFromUrlAsync;
|
|
11
|
+
exports.extractNpmTarballAsync = extractNpmTarballAsync;
|
|
12
|
+
var _getUserState = require("@expo/config/build/getUserState");
|
|
13
|
+
var _spawnAsync = _interopRequireDefault(require("@expo/spawn-async"));
|
|
14
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
15
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
16
|
+
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
17
|
+
var _path = _interopRequireDefault(require("path"));
|
|
18
|
+
var _slugify = _interopRequireDefault(require("slugify"));
|
|
19
|
+
var _stream = require("stream");
|
|
20
|
+
var _tar = _interopRequireDefault(require("tar"));
|
|
21
|
+
var _util = require("util");
|
|
22
|
+
var _fileSystemCache = require("../api/rest/cache/FileSystemCache");
|
|
23
|
+
var _wrapFetchWithCache = require("../api/rest/cache/wrapFetchWithCache");
|
|
24
|
+
var Log = _interopRequireWildcard(require("../log"));
|
|
25
|
+
var _createFileTransform = require("./createFileTransform");
|
|
26
|
+
var _dir = require("./dir");
|
|
27
|
+
var _errors = require("./errors");
|
|
28
|
+
function _interopRequireDefault(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function _interopRequireWildcard(obj) {
|
|
34
|
+
if (obj && obj.__esModule) {
|
|
35
|
+
return obj;
|
|
36
|
+
} else {
|
|
37
|
+
var newObj = {};
|
|
38
|
+
if (obj != null) {
|
|
39
|
+
for(var key in obj){
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
41
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
42
|
+
if (desc.get || desc.set) {
|
|
43
|
+
Object.defineProperty(newObj, key, desc);
|
|
44
|
+
} else {
|
|
45
|
+
newObj[key] = obj[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
newObj.default = obj;
|
|
51
|
+
return newObj;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const cachedFetch = (0, _wrapFetchWithCache).wrapFetchWithCache(_nodeFetch.default, new _fileSystemCache.FileSystemCache({
|
|
55
|
+
cacheDirectory: getCacheFilePath()
|
|
56
|
+
}));
|
|
57
|
+
function sanitizeNpmPackageName(name) {
|
|
58
|
+
// https://github.com/npm/validate-npm-package-name/#naming-rules
|
|
59
|
+
return applyKnownNpmPackageNameRules(name) || applyKnownNpmPackageNameRules((0, _slugify).default(name)) || // If nothing is left use 'app' like we do in Xcode projects.
|
|
60
|
+
"app";
|
|
61
|
+
}
|
|
62
|
+
function applyKnownNpmPackageNameRules(name) {
|
|
63
|
+
// https://github.com/npm/validate-npm-package-name/#naming-rules
|
|
64
|
+
// package name cannot start with '.' or '_'.
|
|
65
|
+
while(/^(\.|_)/.test(name)){
|
|
66
|
+
name = name.substring(1);
|
|
67
|
+
}
|
|
68
|
+
name = name.toLowerCase().replace(/[^a-zA-Z._\-/@]/g, "");
|
|
69
|
+
return name// .replace(/![a-z0-9-._~]+/g, '')
|
|
70
|
+
// Remove special characters
|
|
71
|
+
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") || null;
|
|
72
|
+
}
|
|
73
|
+
async function npmViewAsync(...props) {
|
|
74
|
+
var ref;
|
|
75
|
+
const cmd = [
|
|
76
|
+
"view",
|
|
77
|
+
...props,
|
|
78
|
+
"--json"
|
|
79
|
+
];
|
|
80
|
+
const results = (ref = (await (0, _spawnAsync).default("npm", cmd)).stdout) == null ? void 0 : ref.trim();
|
|
81
|
+
const cmdString = `npm ${cmd.join(" ")}`;
|
|
82
|
+
Log.debug("Run:", cmdString);
|
|
83
|
+
if (!results) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(results);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new Error(`Could not parse JSON returned from "${cmdString}".\n\n${results}\n\nError: ${error.message}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function getNpmUrlAsync(packageName) {
|
|
93
|
+
const results = await npmViewAsync(packageName, "dist.tarball");
|
|
94
|
+
(0, _assert).default(results, `Could not get npm url for package "${packageName}"`);
|
|
95
|
+
// Fully qualified url returns a string.
|
|
96
|
+
// Example:
|
|
97
|
+
// 𝝠 npm view expo-template-bare-minimum@sdk-33 dist.tarball --json
|
|
98
|
+
if (typeof results === "string") {
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
// When the tag is arbitrary, the tarball url is an array, return the last value as it's the most recent.
|
|
102
|
+
// Example:
|
|
103
|
+
// 𝝠 npm view expo-template-bare-minimum@33 dist.tarball --json
|
|
104
|
+
if (Array.isArray(results)) {
|
|
105
|
+
return results[results.length - 1];
|
|
106
|
+
}
|
|
107
|
+
throw new _errors.CommandError("Expected results of `npm view ...` to be an array or string. Instead found: " + results);
|
|
108
|
+
}
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
const pipeline = (0, _util).promisify(_stream.Stream.pipeline);
|
|
111
|
+
async function downloadAndExtractNpmModuleAsync(npmName, props) {
|
|
112
|
+
const url = await getNpmUrlAsync(npmName);
|
|
113
|
+
Log.debug("Fetch from URL:", url);
|
|
114
|
+
await extractNpmTarballFromUrlAsync(url, props);
|
|
115
|
+
}
|
|
116
|
+
async function extractLocalNpmTarballAsync(tarFilePath, props) {
|
|
117
|
+
const readStream = _fs.default.createReadStream(tarFilePath);
|
|
118
|
+
await extractNpmTarballAsync(readStream, props);
|
|
119
|
+
}
|
|
120
|
+
function getCacheFilePath() {
|
|
121
|
+
return _path.default.join((0, _getUserState).getExpoHomeDirectory(), "template-cache");
|
|
122
|
+
}
|
|
123
|
+
async function createUrlStreamAsync(url) {
|
|
124
|
+
const response = await cachedFetch(url);
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new Error(`Unexpected response: ${response.statusText}. From url: ${url}`);
|
|
127
|
+
}
|
|
128
|
+
return response.body;
|
|
129
|
+
}
|
|
130
|
+
async function extractNpmTarballFromUrlAsync(url, props) {
|
|
131
|
+
await extractNpmTarballAsync(await createUrlStreamAsync(url), props);
|
|
132
|
+
}
|
|
133
|
+
async function extractNpmTarballAsync(stream, props) {
|
|
134
|
+
const { cwd , strip , name , fileList =[] } = props;
|
|
135
|
+
await (0, _dir).ensureDirectoryAsync(cwd);
|
|
136
|
+
await pipeline(stream, _tar.default.extract({
|
|
137
|
+
cwd,
|
|
138
|
+
transform: (0, _createFileTransform).createFileTransform(name),
|
|
139
|
+
onentry: (0, _createFileTransform).createEntryResolver(name),
|
|
140
|
+
strip: strip != null ? strip : 1
|
|
141
|
+
}, fileList));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=npm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/npm.ts"],"sourcesContent":["import { getExpoHomeDirectory } from '@expo/config/build/getUserState';\nimport { JSONValue } from '@expo/json-file';\nimport spawnAsync from '@expo/spawn-async';\nimport assert from 'assert';\nimport fs from 'fs';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport slugify from 'slugify';\nimport { Stream } from 'stream';\nimport tar from 'tar';\nimport { promisify } from 'util';\n\nimport { FileSystemCache } from '../api/rest/cache/FileSystemCache';\nimport { wrapFetchWithCache } from '../api/rest/cache/wrapFetchWithCache';\nimport * as Log from '../log';\nimport { createEntryResolver, createFileTransform } from './createFileTransform';\nimport { ensureDirectoryAsync } from './dir';\nimport { CommandError } from './errors';\n\nconst cachedFetch = wrapFetchWithCache(\n fetch,\n new FileSystemCache({\n cacheDirectory: getCacheFilePath(),\n // Time to live. How long (in ms) responses remain cached before being automatically ejected. If undefined, responses are never automatically ejected from the cache.\n // ttl: 1000,\n })\n);\n\nexport function sanitizeNpmPackageName(name: string): string {\n // https://github.com/npm/validate-npm-package-name/#naming-rules\n return (\n applyKnownNpmPackageNameRules(name) ||\n applyKnownNpmPackageNameRules(slugify(name)) ||\n // If nothing is left use 'app' like we do in Xcode projects.\n 'app'\n );\n}\n\nfunction applyKnownNpmPackageNameRules(name: string): string | null {\n // https://github.com/npm/validate-npm-package-name/#naming-rules\n\n // package name cannot start with '.' or '_'.\n while (/^(\\.|_)/.test(name)) {\n name = name.substring(1);\n }\n\n name = name.toLowerCase().replace(/[^a-zA-Z._\\-/@]/g, '');\n\n return (\n name\n // .replace(/![a-z0-9-._~]+/g, '')\n // Remove special characters\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '') || null\n );\n}\n\nexport async function npmViewAsync(...props: string[]): Promise<JSONValue> {\n const cmd = ['view', ...props, '--json'];\n const results = (await spawnAsync('npm', cmd)).stdout?.trim();\n const cmdString = `npm ${cmd.join(' ')}`;\n Log.debug('Run:', cmdString);\n if (!results) {\n return null;\n }\n try {\n return JSON.parse(results);\n } catch (error: any) {\n throw new Error(\n `Could not parse JSON returned from \"${cmdString}\".\\n\\n${results}\\n\\nError: ${error.message}`\n );\n }\n}\n\n/** Given a package name like `expo` or `expo@beta`, return the registry URL if it exists. */\nexport async function getNpmUrlAsync(packageName: string): Promise<string> {\n const results = await npmViewAsync(packageName, 'dist.tarball');\n\n assert(results, `Could not get npm url for package \"${packageName}\"`);\n\n // Fully qualified url returns a string.\n // Example:\n // 𝝠 npm view expo-template-bare-minimum@sdk-33 dist.tarball --json\n if (typeof results === 'string') {\n return results;\n }\n\n // When the tag is arbitrary, the tarball url is an array, return the last value as it's the most recent.\n // Example:\n // 𝝠 npm view expo-template-bare-minimum@33 dist.tarball --json\n if (Array.isArray(results)) {\n return results[results.length - 1] as string;\n }\n\n throw new CommandError(\n 'Expected results of `npm view ...` to be an array or string. Instead found: ' + results\n );\n}\n\n// @ts-ignore\nconst pipeline = promisify(Stream.pipeline);\n\nexport async function downloadAndExtractNpmModuleAsync(\n npmName: string,\n props: ExtractProps\n): Promise<void> {\n const url = await getNpmUrlAsync(npmName);\n\n Log.debug('Fetch from URL:', url);\n await extractNpmTarballFromUrlAsync(url, props);\n}\n\nexport async function extractLocalNpmTarballAsync(\n tarFilePath: string,\n props: ExtractProps\n): Promise<void> {\n const readStream = fs.createReadStream(tarFilePath);\n await extractNpmTarballAsync(readStream, props);\n}\n\ntype ExtractProps = {\n name: string;\n cwd: string;\n strip?: number;\n fileList?: string[];\n};\n\nfunction getCacheFilePath() {\n return path.join(getExpoHomeDirectory(), 'template-cache');\n}\n\nasync function createUrlStreamAsync(url: string) {\n const response = await cachedFetch(url);\n if (!response.ok) {\n throw new Error(`Unexpected response: ${response.statusText}. From url: ${url}`);\n }\n\n return response.body;\n}\n\nexport async function extractNpmTarballFromUrlAsync(\n url: string,\n props: ExtractProps\n): Promise<void> {\n await extractNpmTarballAsync(await createUrlStreamAsync(url), props);\n}\n\nexport async function extractNpmTarballAsync(\n stream: NodeJS.ReadableStream,\n props: ExtractProps\n): Promise<void> {\n const { cwd, strip, name, fileList = [] } = props;\n\n await ensureDirectoryAsync(cwd);\n\n await pipeline(\n stream,\n tar.extract(\n {\n cwd,\n transform: createFileTransform(name),\n onentry: createEntryResolver(name),\n strip: strip ?? 1,\n },\n fileList\n )\n );\n}\n"],"names":["sanitizeNpmPackageName","npmViewAsync","getNpmUrlAsync","downloadAndExtractNpmModuleAsync","extractLocalNpmTarballAsync","extractNpmTarballFromUrlAsync","extractNpmTarballAsync","Log","cachedFetch","wrapFetchWithCache","fetch","FileSystemCache","cacheDirectory","getCacheFilePath","name","applyKnownNpmPackageNameRules","slugify","test","substring","toLowerCase","replace","normalize","props","cmd","results","spawnAsync","stdout","trim","cmdString","join","debug","JSON","parse","error","Error","message","packageName","assert","Array","isArray","length","CommandError","pipeline","promisify","Stream","npmName","url","tarFilePath","readStream","fs","createReadStream","path","getExpoHomeDirectory","createUrlStreamAsync","response","ok","statusText","body","stream","cwd","strip","fileList","ensure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AI,CAAC;QAClC8C,KAAK,EAAEA,KAAK,WAALA,KAAK,GAAI,CAAC;KAClB,EACDC,QAAQ,CACT,CACF,CAAC;CACH"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.get = get;
|
|
6
|
+
exports.set = set;
|
|
7
|
+
exports.pickBy = pickBy;
|
|
8
|
+
function get(obj, key) {
|
|
9
|
+
const branches = key.split(".");
|
|
10
|
+
let current = obj;
|
|
11
|
+
let branch;
|
|
12
|
+
while(branch = branches.shift()){
|
|
13
|
+
if (!(branch in current)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
current = current[branch];
|
|
17
|
+
}
|
|
18
|
+
return current;
|
|
19
|
+
}
|
|
20
|
+
function set(obj, key, value) {
|
|
21
|
+
const branches = key.split(".");
|
|
22
|
+
let current = obj;
|
|
23
|
+
let branch;
|
|
24
|
+
while(branch = branches.shift()){
|
|
25
|
+
if (branches.length === 0) {
|
|
26
|
+
current[branch] = value;
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
if (!(branch in current)) {
|
|
30
|
+
current[branch] = {};
|
|
31
|
+
}
|
|
32
|
+
current = current[branch];
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function pickBy(obj, predicate) {
|
|
37
|
+
return Object.entries(obj).reduce((acc, [key, value])=>{
|
|
38
|
+
if (predicate(value, key)) {
|
|
39
|
+
acc[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return acc;
|
|
42
|
+
}, {});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=obj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/obj.ts"],"sourcesContent":["/** `lodash.get` */\nexport function get(obj: any, key: string): any | null {\n const branches = key.split('.');\n let current: any = obj;\n let branch: string | undefined;\n while ((branch = branches.shift())) {\n if (!(branch in current)) {\n return null;\n }\n current = current[branch];\n }\n return current;\n}\n\n/** `lodash.set` */\nexport function set(obj: any, key: string, value: any): any | null {\n const branches = key.split('.');\n let current: any = obj;\n let branch: string | undefined;\n while ((branch = branches.shift())) {\n if (branches.length === 0) {\n current[branch] = value;\n return obj;\n }\n\n if (!(branch in current)) {\n current[branch] = {};\n }\n\n current = current[branch];\n }\n return null;\n}\n\n/** `lodash.pickBy` */\nexport function pickBy<T>(\n obj: { [key: string]: T },\n predicate: (value: T, key: string) => boolean | undefined\n) {\n return Object.entries(obj).reduce((acc, [key, value]) => {\n if (predicate(value, key)) {\n acc[key] = value;\n }\n return acc;\n }, {} as { [key: string]: T });\n}\n"],"names":["get","set","pickBy","obj","key","branches","split","current","branch","shift","value","length","predicate","Object","entries","reduce","acc"],"mappings":"AACA;;;;QAAgBA,GAAG,GAAHA,GAAG;QAcHC,GAAG,GAAHA,GAAG;QAoBHC,MAAM,GAANA,MAAM;AAlCf,SAASF,GAAG,CAACG,GAAQ,EAAEC,GAAW,EAAc;IACrD,MAAMC,QAAQ,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC,AAAC;IAChC,IAAIC,OAAO,GAAQJ,GAAG,AAAC;IACvB,IAAIK,MAAM,AAAoB,AAAC;IAC/B,MAAQA,MAAM,GAAGH,QAAQ,CAACI,KAAK,EAAE,CAAG;QAClC,IAAI,CAAC,CAACD,MAAM,IAAID,OAAO,CAAC,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;QACDA,OAAO,GAAGA,OAAO,CAACC,MAAM,CAAC,CAAC;KAC3B;IACD,OAAOD,OAAO,CAAC;CAChB;AAGM,SAASN,GAAG,CAACE,GAAQ,EAAEC,GAAW,EAAEM,KAAU,EAAc;IACjE,MAAML,QAAQ,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC,AAAC;IAChC,IAAIC,OAAO,GAAQJ,GAAG,AAAC;I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