Skip to content

Commit bbd47a1

Browse files
committed
Bug 2065363 - Check the licenses of the vendored node packages r=firefox-build-system-reviewers,linter-reviewers,Standard8,sergesanspaille
The `node-licenses` lint normally reinstalls `node_modules` with `npm`. For vendored trees that `pnpm` manages, it checks the existing tree instead and reports an error when it is missing. Differential Revision: https://phabricator.services.mozilla.com/D320324
1 parent 95aa7c1 commit bbd47a1

12 files changed

Lines changed: 92 additions & 0 deletions

File tree

‎taskcluster/kinds/source-test/mozlint.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ node-licenses:
354354
- tools/lint/eslint/eslint-plugin-mozilla/package.json
355355
- tools/lint/stylelint/stylelint-plugin-mozilla/package.json
356356
- tools/terser/package.json
357+
- third_party/node/**
357358
fetches:
358359
toolchain:
359360
- linux64-node

‎tools/lint/node-licenses.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ node-licenses:
88
- tools/lint/eslint/eslint-plugin-mozilla/package.json
99
- tools/lint/stylelint/stylelint-plugin-mozilla/package.json
1010
- tools/terser/package.json
11+
- third_party/node/package.json
1112
exclude: []
1213
extensions:
1314
- json

‎tools/lint/node-licenses/__init__.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ def lint(paths, config, binary=None, skip_reinstall=False, **lintargs):
6161
# - When the package is the top-level package.json, because the top level
6262
# node_modules is looked after by the setup, and we don't want to be
6363
# removing it from underneath ourselves.
64+
# - When a pnpm-lock.yaml shows that pnpm owns the node_modules, which
65+
# npm cannot safely reinstall.
6466
if (
6567
not skip_reinstall
6668
and not os.environ.get("MOZ_AUTOMATION")
6769
and dirname != lintargs["root"]
70+
and not os.path.exists(os.path.join(dirname, "pnpm-lock.yaml"))
6871
):
6972
status = setup_helper.package_setup(
7073
dirname, os.path.basename(dirname), skip_logging=True
@@ -80,6 +83,20 @@ def lint(paths, config, binary=None, skip_reinstall=False, **lintargs):
8083
},
8184
)
8285
)
86+
elif not skip_reinstall and not os.path.isdir(
87+
os.path.join(dirname, "node_modules")
88+
):
89+
issues.append(
90+
result.from_config(
91+
config,
92+
**{
93+
"path": path,
94+
"message": "No node_modules to check for this package, so no dependency was checked",
95+
"level": "error",
96+
},
97+
)
98+
)
99+
continue
83100

84101
output = run_license_checker(binary, path, lintargs)
85102
if output == 1:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"description": "vendored with pnpm, tree absent",
3+
"devDependencies": {
4+
"@mozilla/known-license": "0.0.1"
5+
}
6+
}

‎tools/lint/test/files/node-licenses/pnpm-missing/pnpm-lock.yaml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/lint/test/files/node-licenses/pnpm-unknown/node_modules/@mozilla/unknown-license/package.json‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"description": "vendored with pnpm, unknown license",
3+
"devDependencies": {
4+
"@mozilla/unknown-license": "0.0.1"
5+
}
6+
}

‎tools/lint/test/files/node-licenses/pnpm-unknown/pnpm-lock.yaml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/lint/test/files/node-licenses/pnpm-vendored/node_modules/@mozilla/known-license/package.json‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"description": "vendored with pnpm",
3+
"devDependencies": {
4+
"@mozilla/known-license": "0.0.1"
5+
}
6+
}

0 commit comments

Comments
 (0)