microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
improve-configuration

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/exponent/xdlInterface.ts

152lines · modeblame

7059d307Patricio Beltran9 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
65e55367RedMickey4 years ago4import { join as pathJoin } from "path";
7059d307Patricio Beltran9 years ago5import * as XDLPackage from "xdl";
242759feJiglioNero5 years ago6import * as MetroConfigPackage from "metro-config";
716f31d0JiglioNero5 years ago7import { PackageLoader, PackageConfig } from "../../common/packageLoader";
65e55367RedMickey4 years ago8import { removeModuleFromRequireCacheByName } from "../../common/utils";
716f31d0JiglioNero5 years ago9import { SettingsHelper } from "../settingsHelper";
0a68f8dbArtem Egorov8 years ago10
00a26245RedMickey5 years ago11const XDL_PACKAGE = "xdl";
242759feJiglioNero5 years ago12const METRO_CONFIG_PACKAGE = "@expo/metro-config";
13
716f31d0JiglioNero5 years ago14const xdlPackageConfig = new PackageConfig(
15XDL_PACKAGE,
16SettingsHelper.getExpoDependencyVersion(XDL_PACKAGE),
17);
18const metroConfigPackageConfig = new PackageConfig(
19METRO_CONFIG_PACKAGE,
c0dc4020etatanova4 years ago20SettingsHelper.getExpoDependencyVersion(METRO_CONFIG_PACKAGE),
716f31d0JiglioNero5 years ago21);
22
23const ngrokPackageConfig = new PackageConfig(
24xdlPackageConfig.getPackageName(),
25xdlPackageConfig.getVersion(),
26"build/start/resolveNgrok",
27);
28
29// There is the problem with '--no-save' flag for 'npm install' command for npm v6.
30// Installing npm dependencies with the `--no-save` flag will remove
31// other dependencies that were installed previously in the same manner (https://github.com/npm/cli/issues/1460).
32// So we should workaround it passing all packages for install to only one npm install command
33const EXPO_DEPS: PackageConfig[] = [xdlPackageConfig, metroConfigPackageConfig];
242759feJiglioNero5 years ago34
09f6024fHeniker4 years ago35export const getXDLPackage: () => Promise<typeof XDLPackage> =
36PackageLoader.getInstance().generateGetPackageFunction<typeof XDLPackage>(
37xdlPackageConfig,
38...EXPO_DEPS,
39);
40export const getMetroConfigPackage: () => Promise<typeof MetroConfigPackage> =
41PackageLoader.getInstance().generateGetPackageFunction<typeof MetroConfigPackage>(
42metroConfigPackageConfig,
43...EXPO_DEPS,
44);
45export const getNgrokResolver: () => Promise<XDLPackage.ResolveNgrok> =
46PackageLoader.getInstance().generateGetPackageFunction<XDLPackage.ResolveNgrok>(
47ngrokPackageConfig,
48...EXPO_DEPS,
49);
7059d307Patricio Beltran9 years ago50
51export type IUser = XDLPackage.IUser;
52
0d77292aJiglioNero4 years ago53export async function configReactNativeVersionWarnings(): Promise<void> {
50a7f6ecbenjaminbi2 years ago54const xdlPackage = await getXDLPackage();
55if (xdlPackage.Config.validation !== undefined) {
56xdlPackage.Config.validation.reactNativeVersionWarnings = false;
57}
7059d307Patricio Beltran9 years ago58}
59
0d77292aJiglioNero4 years ago60export async function attachLoggerStream(
34472878RedMickey5 years ago61rootPath: string,
62options?: XDLPackage.IBunyanStream | any,
63): Promise<void> {
0d77292aJiglioNero4 years ago64(await getXDLPackage()).ProjectUtils.attachLoggerStream(rootPath, options);
7059d307Patricio Beltran9 years ago65}
66
0d77292aJiglioNero4 years ago67export async function currentUser(): Promise<XDLPackage.IUser> {
68const xdl = await getXDLPackage();
69return await (xdl.User
70? xdl.User.getCurrentUserAsync()
71: xdl.UserManager.getCurrentUserAsync());
7059d307Patricio Beltran9 years ago72}
73
0d77292aJiglioNero4 years ago74export async function login(username: string, password: string): Promise<XDLPackage.IUser> {
75const xdl = await getXDLPackage();
76return await (xdl.User
09f6024fHeniker4 years ago77? xdl.User.loginAsync("user-pass", { username, password })
0d77292aJiglioNero4 years ago78: xdl.UserManager.loginAsync("user-pass", {
09f6024fHeniker4 years ago79username,
80password,
0d77292aJiglioNero4 years ago81}));
7059d307Patricio Beltran9 years ago82}
83
0d77292aJiglioNero4 years ago84export async function getExpoSdkVersions(): Promise<XDLPackage.SDKVersions> {
85return (await getXDLPackage()).Versions.sdkVersionsAsync();
8f50947fRedMickey5 years ago86}
87
0d77292aJiglioNero4 years ago88export async function getReleasedExpoSdkVersions(): Promise<XDLPackage.SDKVersions> {
89return (await getXDLPackage()).Versions.releasedSdkVersionsAsync();
7059d307Patricio Beltran9 years ago90}
91
0d77292aJiglioNero4 years ago92export async function publish(
34472878RedMickey5 years ago93projectRoot: string,
94options?: XDLPackage.IPublishOptions,
95): Promise<XDLPackage.IPublishResponse> {
0d77292aJiglioNero4 years ago96return (await getXDLPackage()).Project.publishAsync(projectRoot, options);
7059d307Patricio Beltran9 years ago97}
98
ec230406RedMickey4 years ago99export async function setOptions(projectRoot: string, options: XDLPackage.IOptions): Promise<void> {
100await (await getXDLPackage()).ProjectSettings.setPackagerInfoAsync(projectRoot, options);
7059d307Patricio Beltran9 years ago101}
102
0d77292aJiglioNero4 years ago103export async function startExponentServer(projectRoot: string): Promise<void> {
104await (await getXDLPackage()).Project.startExpoServerAsync(projectRoot);
7059d307Patricio Beltran9 years ago105}
106
0d77292aJiglioNero4 years ago107export async function startTunnels(projectRoot: string): Promise<void> {
108await (await getXDLPackage()).Project.startTunnelsAsync(projectRoot);
7059d307Patricio Beltran9 years ago109}
110
0d77292aJiglioNero4 years ago111export async function getUrl(
112projectRoot: string,
113options?: XDLPackage.IUrlOptions,
114): Promise<string> {
115return (await getXDLPackage()).UrlUtils.constructManifestUrlAsync(projectRoot, options);
7059d307Patricio Beltran9 years ago116}
117
0d77292aJiglioNero4 years ago118export async function stopAll(projectRoot: string): Promise<void> {
119await (await getXDLPackage()).Project.stopAsync(projectRoot);
7059d307Patricio Beltran9 years ago120}
62c4de22RedMickey6 years ago121
0d77292aJiglioNero4 years ago122export async function startAdbReverse(projectRoot: string): Promise<boolean> {
123return (await getXDLPackage()).Android.startAdbReverseAsync(projectRoot);
62c4de22RedMickey6 years ago124}
125
0d77292aJiglioNero4 years ago126export async function stopAdbReverse(projectRoot: string): Promise<void> {
127await (await getXDLPackage()).Android.stopAdbReverseAsync(projectRoot);
242759feJiglioNero5 years ago128}
129
0d77292aJiglioNero4 years ago130export async function getMetroConfig(
131projectRoot: string,
132): Promise<MetroConfigPackage.IMetroConfig> {
133return (await getMetroConfigPackage()).loadAsync(projectRoot);
62c4de22RedMickey6 years ago134}
efb436fcRedMickey5 years ago135
0d77292aJiglioNero4 years ago136export async function isNgrokInstalled(projectRoot: string): Promise<boolean> {
137const ngrokResolver = await getNgrokResolver();
138try {
139const ngrok = await ngrokResolver.resolveNgrokAsync(projectRoot, {
140shouldPrompt: false,
141autoInstall: false,
65e55367RedMickey4 years ago142});
0d77292aJiglioNero4 years ago143return !!ngrok;
144} catch (err) {
145// If unsupported version of the "@expo/ngrok" package was detected, we need to update the package.
146// Since the "require" method used to parse the "ngrok⁄package.json" file in the "xdl" package caches
147// all processed modules, we have to remove this file from cache to be able to require a new version
148// of that file after the update of the "@expo/ngrok" package
149removeModuleFromRequireCacheByName(pathJoin("ngrok", "package.json"));
150throw err;
151}
efb436fcRedMickey5 years ago152}