Drop code supporting npm@<5 (#80)
diff --git a/index.js b/index.js
index af47280..c5c03ad 100644
--- a/index.js
+++ b/index.js
@@ -91,17 +91,12 @@
}
function getTargetPackageSpecFromNpmInstallOutput (npmInstallOutput) {
- const lines = npmInstallOutput.split('\n');
- for (let i = 0; i < lines.length; i++) {
- if (lines[i].startsWith('+ ')) {
- // npm >= 5
- return lines[i].slice(2);
- } else if (lines[i].startsWith('└─') || lines[i].startsWith('`-')) {
- // 3 <= npm <= 4
- return lines[i].slice(4).split(' ')[0];
- }
+ const packageInfoLine = npmInstallOutput.split('\n')
+ .find(line => line.startsWith('+ '));
+ if (!packageInfoLine) {
+ throw new CordovaError('Could not determine package name from output:\n' + npmInstallOutput);
}
- throw new CordovaError('Could not determine package name from output:\n' + npmInstallOutput);
+ return packageInfoLine.slice(2);
}
// Resolves to installation path of package defined by spec if the right version
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
index 514126e..fff3981 100644
--- a/spec/fetch-unit.spec.js
+++ b/spec/fetch-unit.spec.js
@@ -82,33 +82,19 @@
const fetch = rewire('..');
const getTargetPackageSpecFromNpmInstallOutput = fetch.__get__('getTargetPackageSpecFromNpmInstallOutput');
const outputSampleNpm5 = '+ cordova-electron@1.0.0-dev';
- const outputSampleNpm3 = 'helloworld@1.0.0 /cordova-project\n' +
- '└─┬ cordova-electron@1.0.0-dev (git://github.com/apache/cordova-electron.git)';
const outputSampleNpm5WithPostinstall = '> electron@3.1.1 postinstall /cordova-project/node_modules/electron\n' +
'> node install.js\n\n' +
'+ cordova-electron@1.0.0-dev\n';
- const outputSampleNpm3WithPostinstall = '> electron@3.1.1 postinstall /cordova-project/node_modules/electron\n' +
- '> node install.js\n' +
- 'helloworld@1.0.0 /cordova-project\n' +
- '└─┬ cordova-electron@1.0.0-dev (git://github.com/apache/cordova-electron.git)';
const wrongOutputSample = 'Wrong output';
it('should parse the package name using npm >= 5', () => {
expect(getTargetPackageSpecFromNpmInstallOutput(outputSampleNpm5)).toEqual('cordova-electron@1.0.0-dev');
});
- it('should parse the package name using npm 3 <= npm <= 4', () => {
- expect(getTargetPackageSpecFromNpmInstallOutput(outputSampleNpm3)).toEqual('cordova-electron@1.0.0-dev');
- });
-
it('should parse the package name using npm >= 5 with postinstall ', () => {
expect(getTargetPackageSpecFromNpmInstallOutput(outputSampleNpm5WithPostinstall)).toEqual('cordova-electron@1.0.0-dev');
});
- it('should parse the package name using npm 3 <= npm <= 4 with postinstall', () => {
- expect(getTargetPackageSpecFromNpmInstallOutput(outputSampleNpm3WithPostinstall)).toEqual('cordova-electron@1.0.0-dev');
- });
-
it('should gracefully handle if could not determine the package name from output', () => {
expect(() => {
getTargetPackageSpecFromNpmInstallOutput(wrongOutputSample);