microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
52bf0a75506c1b3b1cecc9ad89937e596d1bc22a

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/node/package.ts

40lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import {Node} from "../node/node";
5import * as pathModule from "path";
6
7export interface IPackageInformation {
8 name: string;
9 dependencies: { [name: string]: string };
10}
11
12export class Package {
13 private _path: string;
14 private INFORMATION_PACKAGE_FILENAME = "package.json";
15
16 constructor(path: string) {
17 this._path = path;
18 }
19
20 public parsePackageInformation(): Q.Promise<IPackageInformation> {
21 return new Node.FileSystem().readFile(this.informationJsonFilePath(), "utf8")
22 .then(data =>
23 <IPackageInformation>JSON.parse(data));
24 }
25
26 public name(): Q.Promise<string> {
27 return this.parsePackageInformation()
28 .then(packageInformation =>
29 packageInformation.name);
30 }
31
32 public dependencies(): Q.Promise<{ [name: string]: string }> {
33 return this.parsePackageInformation()
34 .then(packageInformation => packageInformation.dependencies);
35 }
36
37 private informationJsonFilePath(): string {
38 return pathModule.resolve(this._path, this.INFORMATION_PACKAGE_FILENAME);
39 }
40}
41