npq 3.7.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,3 +53,54 @@ test('running marshall tasks fails', async () => {
53
53
 
54
54
  await expect(marshalls.tasks(config)).resolves.toMatchObject(context)
55
55
  })
56
+
57
+ test('running marshall tasks throws error when single package is not found', async () => {
58
+ const PackageRepoUtilsNotFoundMock = class Fake {
59
+ getPackageInfo() {
60
+ return Promise.resolve({ error: 'Not found' })
61
+ }
62
+ }
63
+
64
+ marshalls.collectMarshalls = jest.fn(() => {
65
+ return Promise.resolve([path.join(process.cwd(), '__tests__/__fixtures__/test.marshall.js')])
66
+ })
67
+
68
+ const config = {
69
+ pkgs: [{ packageName: 'nonexistent-package' }],
70
+ packageRepoUtils: new PackageRepoUtilsNotFoundMock()
71
+ }
72
+
73
+ await expect(marshalls.tasks(config)).resolves.toEqual({
74
+ error: true,
75
+ message: 'Package not found: nonexistent-package'
76
+ })
77
+ })
78
+
79
+ test('running marshall tasks filters out not found packages when multiple packages provided', async () => {
80
+ const PackageRepoUtilsMixedMock = class Fake {
81
+ getPackageInfo(packageName) {
82
+ if (packageName === 'nonexistent-package') {
83
+ return Promise.resolve({ error: 'Not found' })
84
+ }
85
+ return Promise.resolve(true)
86
+ }
87
+ }
88
+
89
+ marshalls.collectMarshalls = jest.fn(() => {
90
+ return Promise.resolve([path.join(process.cwd(), '__tests__/__fixtures__/test.marshall.js')])
91
+ })
92
+
93
+ const config = {
94
+ pkgs: [
95
+ { packageName: 'express' },
96
+ { packageName: 'nonexistent-package' },
97
+ { packageName: 'semver' }
98
+ ],
99
+ packageRepoUtils: new PackageRepoUtilsMixedMock()
100
+ }
101
+
102
+ const result = await marshalls.tasks(config)
103
+ // Should filter out the nonexistent package and keep only express and semver
104
+ expect(result.pkgs).toHaveLength(2)
105
+ expect(result.pkgs).toEqual([{ packageName: 'express' }, { packageName: 'semver' }])
106
+ })
@@ -65,7 +65,26 @@ class Marshalls {
65
65
  }
66
66
 
67
67
  static tasks(options) {
68
+ // console.log(options);
69
+ // process.exit(1);
68
70
  return Marshalls.warmUpPackagesCache(options)
71
+ .then((packagesDataList) => {
72
+ // handle error in case we get just one package and it is not found
73
+ if (packagesDataList && packagesDataList.length === 1) {
74
+ if (packagesDataList[0].error && packagesDataList[0].error === 'Not found') {
75
+ throw new Error(`Package not found: ${options.pkgs[0].packageName}`)
76
+ }
77
+ }
78
+
79
+ // handle error in case we get more than one package and at least one is not found
80
+ // in which we case we simply remove the package from the `options` array
81
+ // which lists objects (each have a property of packageName)
82
+ if (packagesDataList && packagesDataList.length > 1) {
83
+ options.pkgs = options.pkgs.filter((pkg, index) => {
84
+ return !packagesDataList[index].error || packagesDataList[index].error !== 'Not found'
85
+ })
86
+ }
87
+ })
69
88
  .then(() => Marshalls.collectMarshalls())
70
89
  .then((marshalls) => {
71
90
  return Marshalls.buildMarshallTasks(marshalls, {
@@ -75,6 +94,12 @@ class Marshalls {
75
94
  .then((tasks) => {
76
95
  return Marshalls.runTasks(tasks, options)
77
96
  })
97
+ .catch((err) => {
98
+ // console.error('Error:', err.message)
99
+ // avoid implementing a custom error message for a not found package
100
+ // because the package manager will yield its own error message
101
+ return { error: true, message: err.message }
102
+ })
78
103
  }
79
104
 
80
105
  static warmUpPackagesCache(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",
@@ -135,7 +135,7 @@
135
135
  "security/detect-no-csrf-before-method-override": "error",
136
136
  "security/detect-non-literal-regexp": "error",
137
137
  "security/detect-non-literal-require": "warn",
138
- "security/detect-object-injection": "warn",
138
+ "security/detect-object-injection": "off",
139
139
  "security/detect-possible-timing-attacks": "error",
140
140
  "security/detect-pseudoRandomBytes": "error",
141
141
  "node/no-unsupported-features/node-builtins": [