You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/11/02 09:06:57 UTC
[cordova-fetch] branch master updated: Drop code supporting npm@<5
(#80)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-fetch.git
The following commit(s) were added to refs/heads/master by this push:
new 3659668 Drop code supporting npm@<5 (#80)
3659668 is described below
commit 3659668a20befbaec6bf87100b84a6be279a0de4
Author: Raphael von der Grün <ra...@gmail.com>
AuthorDate: Sat Nov 2 10:06:51 2019 +0100
Drop code supporting npm@<5 (#80)
---
index.js | 15 +++++----------
spec/fetch-unit.spec.js | 14 --------------
2 files changed, 5 insertions(+), 24 deletions(-)
diff --git a/index.js b/index.js
index af47280..c5c03ad 100644
--- a/index.js
+++ b/index.js
@@ -91,17 +91,12 @@ function npmArgs (target, userOptions) {
}
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 @@ describe('getTargetPackageSpecFromNpmInstallOutput', () => {
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);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org