Skip to content

Commit de44599

Browse files
Dimitar KerezovMitko-Kerezov
authored andcommitted
Expose npm operations
Expose node-package-manager functonality to be usable when CLI is `require`-d. * Remove occurrences of `this.$options` in node-package-manager * Start using `--dry-run` and `--json` for parsing output
1 parent 76a619f commit de44599

11 files changed

+297
-77
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $injector.requireCommand("appstore|upload", "./commands/appstore-upload");
6565
$injector.requireCommand("publish|ios", "./commands/appstore-upload");
6666
$injector.require("itmsTransporterService", "./services/itmstransporter-service");
6767

68-
$injector.require("npm", "./node-package-manager");
68+
$injector.requirePublic("npm", "./node-package-manager");
6969
$injector.require("npmInstallationManager", "./npm-installation-manager");
7070
$injector.require("lockfile", "./lockfile");
7171
$injector.require("dynamicHelpProvider", "./dynamic-help-provider");

lib/commands/install.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class InstallCommand implements ICommand {
1414
private $fs: IFileSystem,
1515
private $stringParameter: ICommandParameter,
1616
private $npm: INodePackageManager) {
17-
this.$projectData.initializeProjectData();
18-
}
17+
this.$projectData.initializeProjectData();
18+
}
1919

2020
public async execute(args: string[]): Promise<void> {
2121
return args[0] ? this.installModule(args[0]) : this.installProjectDependencies();
@@ -51,7 +51,13 @@ export class InstallCommand implements ICommand {
5151
moduleName = devPrefix + moduleName;
5252
}
5353

54-
await this.$npm.install(moduleName, projectDir, { 'save-dev': true });
54+
await this.$npm.install(moduleName, projectDir, {
55+
'save-dev': true,
56+
disableNpmInstall: this.$options.disableNpmInstall,
57+
frameworkPath: this.$options.frameworkPath,
58+
ignoreScripts: this.$options.ignoreScripts,
59+
path: this.$options.path
60+
});
5561
}
5662
}
5763

lib/commands/test-init.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class TestInitCommand implements ICommand {
1717
private $resources: IResourceLoader,
1818
private $pluginsService: IPluginsService,
1919
private $logger: ILogger) {
20-
this.$projectData.initializeProjectData();
21-
}
20+
this.$projectData.initializeProjectData();
21+
}
2222

2323
public async execute(args: string[]): Promise<void> {
2424
let projectDir = this.$projectData.projectDir;
@@ -36,6 +36,10 @@ class TestInitCommand implements ICommand {
3636
await this.$npm.install(mod, projectDir, {
3737
'save-dev': true,
3838
optional: false,
39+
disableNpmInstall: this.$options.disableNpmInstall,
40+
frameworkPath: this.$options.frameworkPath,
41+
ignoreScripts: this.$options.ignoreScripts,
42+
path: this.$options.path
3943
});
4044

4145
const modulePath = path.join(projectDir, "node_modules", mod);

lib/declarations.d.ts

Lines changed: 169 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
interface INodePackageManager {
2-
install(packageName: string, pathToSave: string, config?: any): Promise<any>;
2+
/**
3+
* Installs dependency
4+
* @param {string} packageName The name of the dependency - can be a path, a url or a string.
5+
* @param {string} pathToSave The destination of the installation.
6+
* @param {INodePackageManagerInstallOptions} config Additional options that can be passed to manipulate installation.
7+
* @return {Promise<INpmInstallResultInfo>} Information about installed package.
8+
*/
9+
install(packageName: string, pathToSave: string, config: INodePackageManagerInstallOptions): Promise<INpmInstallResultInfo>;
310
uninstall(packageName: string, config?: any, path?: string): Promise<any>;
411
view(packageName: string, config: Object): Promise<any>;
512
search(filter: string[], config: any): Promise<any>;
@@ -13,6 +20,160 @@ interface INpmInstallationManager {
1320
getInspectorFromCache(inspectorNpmPackageName: string, projectDir: string): Promise<string>;
1421
}
1522

23+
/**
24+
* Describes options that can be passed to manipulate package installation.
25+
*/
26+
interface INodePackageManagerInstallOptions extends INpmInstallConfigurationOptions, IDictionary<string | boolean> {
27+
/**
28+
* Destination of the installation.
29+
* @type {string}
30+
* @optional
31+
*/
32+
path?: string;
33+
}
34+
35+
/**
36+
* Describes information about dependency packages.
37+
*/
38+
interface INpmDependencyInfo {
39+
/**
40+
* Dependency name.
41+
*/
42+
[key: string]: {
43+
/**
44+
* Dependency version.
45+
* @type {string}
46+
*/
47+
version: string;
48+
/**
49+
* How was the dependency resolved. For example: lodash@latest or underscore@>=1.8.3 <2.0.0
50+
* @type {string}
51+
*/
52+
from: string;
53+
/**
54+
* Where was the dependency resolved from. For example: https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz
55+
* @type {string}
56+
*/
57+
resolved: string;
58+
/**
59+
* Dependencies of the dependency.
60+
* @type {INpmDependencyInfo}
61+
*/
62+
dependencies?: INpmDependencyInfo;
63+
/**
64+
* Set to true when the dependency is invalid.
65+
* @type {boolean}
66+
*/
67+
invalid?: boolean;
68+
/**
69+
* If invalid is set to true this will contain errors which make the dependency invalid.
70+
*/
71+
problems?: string[];
72+
}
73+
}
74+
75+
/**
76+
* Describes information about peer dependency packages.
77+
*/
78+
interface INpmPeerDependencyInfo {
79+
required: {
80+
/**
81+
* Id used in package.json - for example: zone.js@^0.8.4
82+
* @type {string}
83+
*/
84+
_id: string;
85+
/**
86+
* Dependency name.
87+
* @type {string}
88+
*/
89+
name: string;
90+
/**
91+
* Dependency version.
92+
* @type {string}
93+
*/
94+
version: string;
95+
/**
96+
* If peerMissing below is set to true this will contain information about missing peers.
97+
*/
98+
peerMissing?: [
99+
{
100+
/**
101+
* The id of the package which requires the unmet peer dependency.
102+
* @type {string}
103+
*/
104+
requiredBy: string;
105+
/**
106+
* The id of the unmet peer dependency.
107+
* @type {string}
108+
*/
109+
requires: string;
110+
}
111+
];
112+
/**
113+
* Dependencies of the dependency.
114+
* @type {INpmDependencyInfo}
115+
*/
116+
dependencies: INpmDependencyInfo;
117+
/**
118+
* Whether the dependency was found or not.
119+
* @type {boolean}
120+
*/
121+
_found: boolean;
122+
};
123+
/**
124+
* Set to true if peer dependency unmet.
125+
* @type {boolean}
126+
*/
127+
peerMissing: boolean;
128+
}
129+
130+
/**
131+
* Describes information returned by the npm CLI upon calling install with --json flag.
132+
*/
133+
interface INpmInstallCLIResult {
134+
/**
135+
* The name of the destination package. Note that this is not the installed package.
136+
* @type {string}
137+
*/
138+
name: string;
139+
/**
140+
* The version of the destination package. Note that this is not the installed package.
141+
* @type {string}
142+
*/
143+
version: string;
144+
/**
145+
* Installed dependencies. Note that whenever installing a particular dependency it is listed as the first key and after it any number of peer dependencies may follow.
146+
* Whenever installing npm prints the information by reversing the tree of operations and because the initial dependency was installed last it is listed first.
147+
* @type {INpmDependencyInfo | INpmPeerDependencyInfo}
148+
*/
149+
dependencies: INpmDependencyInfo | INpmPeerDependencyInfo;
150+
/**
151+
* Describes problems that might have occurred during installation. For example missing peer dependencies.
152+
*/
153+
problems?: string[];
154+
}
155+
156+
/**
157+
* Describes information about installed package.
158+
*/
159+
interface INpmInstallResultInfo {
160+
/**
161+
* Installed package's name.
162+
* @type {string}
163+
*/
164+
name: string;
165+
/**
166+
* Installed package's version.
167+
* @type {string}
168+
*/
169+
version: string;
170+
/**
171+
* The original output that npm CLI produced upon installation.
172+
* @type {INpmInstallCLIResult}
173+
*/
174+
originalOutput: INpmInstallCLIResult;
175+
}
176+
16177
interface INpmInstallOptions {
17178
pathToSave?: string;
18179
version?: string;
@@ -112,7 +273,13 @@ interface IAndroidReleaseOptions {
112273
keyStorePath?: string;
113274
}
114275

115-
interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions {
276+
interface INpmInstallConfigurationOptions {
277+
frameworkPath: string;
278+
disableNpmInstall: boolean;
279+
ignoreScripts: boolean; //npm flag
280+
}
281+
282+
interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions {
116283
all: boolean;
117284
client: boolean;
118285
compileSdk: number;
@@ -121,10 +288,7 @@ interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator
121288
forDevice: boolean;
122289
framework: string;
123290
frameworkName: string;
124-
frameworkPath: string;
125291
frameworkVersion: string;
126-
ignoreScripts: boolean; //npm flag
127-
disableNpmInstall: boolean;
128292
ipa: string;
129293
tsc: boolean;
130294
ng: boolean;

0 commit comments

Comments
 (0)