From b6d8b54e3cb2ad91e5f6e330a6337f4dc7cf0f68 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 4 Nov 2022 22:38:01 +0100 Subject: [PATCH] Fix pnpm compatibility `@npmcli/arborist` (incorrectly?) returns dependencies with no package info when looking in `/node_modules/.pnpm` directory. It does also return correct data from deeper nested dirs like for example `/node_modules/.pnpm/tmp@0.2.1/node_modules/tmp` so we can just ignore the invalid entries. --- index.js | 2 +- tests/pnpm-compatibility/.licensee.json | 10 +++++++++ .../node_modules/.modules.yaml | 21 +++++++++++++++++++ .../node_modules/.pnpm/lock.yaml | 13 ++++++++++++ .../node_modules/mit-licensed/index.js | 1 + .../node_modules/mit-licensed/package.json | 8 +++++++ .../node_modules/mit-licensed | 1 + tests/pnpm-compatibility/package.json | 7 +++++++ tests/pnpm-compatibility/pnpm-lock.yaml | 13 ++++++++++++ tests/pnpm-compatibility/test.js | 5 +++++ 10 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/pnpm-compatibility/.licensee.json create mode 100644 tests/pnpm-compatibility/node_modules/.modules.yaml create mode 100644 tests/pnpm-compatibility/node_modules/.pnpm/lock.yaml create mode 100644 tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/index.js create mode 100644 tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/package.json create mode 120000 tests/pnpm-compatibility/node_modules/mit-licensed create mode 100644 tests/pnpm-compatibility/package.json create mode 100644 tests/pnpm-compatibility/pnpm-lock.yaml create mode 100644 tests/pnpm-compatibility/test.js diff --git a/index.js b/index.js index c0e4822..bae21c7 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ function licensee (configuration, path, callback) { .then(function (tree) { var dependencies = Array.from(tree.inventory.values()) .filter(function (dependency) { - return !dependency.isProjectRoot + return !dependency.isProjectRoot && dependency.package.name }) if (configuration.filterPackages) { dependencies = configuration.filterPackages(dependencies) diff --git a/tests/pnpm-compatibility/.licensee.json b/tests/pnpm-compatibility/.licensee.json new file mode 100644 index 0000000..9f655f7 --- /dev/null +++ b/tests/pnpm-compatibility/.licensee.json @@ -0,0 +1,10 @@ +{ + "licenses": { + "spdx": [ + "Apache-2.0" + ] + }, + "packages": { + "mit-licensed": "1.0.0" + } +} diff --git a/tests/pnpm-compatibility/node_modules/.modules.yaml b/tests/pnpm-compatibility/node_modules/.modules.yaml new file mode 100644 index 0000000..4fc5043 --- /dev/null +++ b/tests/pnpm-compatibility/node_modules/.modules.yaml @@ -0,0 +1,21 @@ +hoistPattern: + - '*' +hoistedDependencies: {} +included: + dependencies: true + devDependencies: true + optionalDependencies: true +injectedDeps: {} +layoutVersion: 5 +nodeLinker: isolated +packageManager: pnpm@7.14.2 +pendingBuilds: [] +prunedAt: Fri, 04 Nov 2022 21:34:40 GMT +publicHoistPattern: + - '*eslint*' + - '*prettier*' +registries: + default: https://registry.npmjs.org/ +skipped: [] +storeDir: /Users/cvx/Library/pnpm/store/v3 +virtualStoreDir: .pnpm diff --git a/tests/pnpm-compatibility/node_modules/.pnpm/lock.yaml b/tests/pnpm-compatibility/node_modules/.pnpm/lock.yaml new file mode 100644 index 0000000..36b5dc2 --- /dev/null +++ b/tests/pnpm-compatibility/node_modules/.pnpm/lock.yaml @@ -0,0 +1,13 @@ +lockfileVersion: 5.4 + +specifiers: + mit-licensed: ^1.0.0 + +dependencies: + mit-licensed: 1.0.0 + +packages: + + /mit-licensed/1.0.0: + resolution: {integrity: sha512-aCppNedGHnTQZvrrNcX43bMZSvLHlH2ZwC7NJqr05onseQjx0+GDGz3a44ONAVpefHPW8GQN8kNW02e+MG088A==} + dev: false diff --git a/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/index.js b/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/index.js new file mode 100644 index 0000000..d0e9332 --- /dev/null +++ b/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/index.js @@ -0,0 +1 @@ +throw new Error('Do not require mit-licensed. It is just for testing license metadata.') diff --git a/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/package.json b/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/package.json new file mode 100644 index 0000000..dbb0145 --- /dev/null +++ b/tests/pnpm-compatibility/node_modules/.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed/package.json @@ -0,0 +1,8 @@ +{ + "name": "mit-licensed", + "version": "1.0.0", + "description": "an empty package that is MIT-licensed", + "author": "Kyle E. Mitchell (https://kemitchell.com/)", + "repository": "jslicense/mit-licensed.js", + "license": "MIT" +} diff --git a/tests/pnpm-compatibility/node_modules/mit-licensed b/tests/pnpm-compatibility/node_modules/mit-licensed new file mode 120000 index 0000000..85cf516 --- /dev/null +++ b/tests/pnpm-compatibility/node_modules/mit-licensed @@ -0,0 +1 @@ +.pnpm/mit-licensed@1.0.0/node_modules/mit-licensed \ No newline at end of file diff --git a/tests/pnpm-compatibility/package.json b/tests/pnpm-compatibility/package.json new file mode 100644 index 0000000..9c7e98a --- /dev/null +++ b/tests/pnpm-compatibility/package.json @@ -0,0 +1,7 @@ +{ + "name": "pnpm-workspace", + "dependencies": { + "mit-licensed": "^1.0.0" + }, + "private": true +} diff --git a/tests/pnpm-compatibility/pnpm-lock.yaml b/tests/pnpm-compatibility/pnpm-lock.yaml new file mode 100644 index 0000000..36b5dc2 --- /dev/null +++ b/tests/pnpm-compatibility/pnpm-lock.yaml @@ -0,0 +1,13 @@ +lockfileVersion: 5.4 + +specifiers: + mit-licensed: ^1.0.0 + +dependencies: + mit-licensed: 1.0.0 + +packages: + + /mit-licensed/1.0.0: + resolution: {integrity: sha512-aCppNedGHnTQZvrrNcX43bMZSvLHlH2ZwC7NJqr05onseQjx0+GDGz3a44ONAVpefHPW8GQN8kNW02e+MG088A==} + dev: false diff --git a/tests/pnpm-compatibility/test.js b/tests/pnpm-compatibility/test.js new file mode 100644 index 0000000..add2337 --- /dev/null +++ b/tests/pnpm-compatibility/test.js @@ -0,0 +1,5 @@ +var tap = require('tap') + +var results = require('../run')([], __dirname) + +tap.equal(results.status, 0)