Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use npm workspaces for packages #65681

Draft
wants to merge 17 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions bin/check-licenses.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env node

/**
* External dependencies
*/
import { spawnSync } from 'node:child_process';

/**
* Internal dependencies
*/
import { checkDepsInTree } from '../packages/scripts/utils/license.js';

const ignoreCore = [
'@react-native-community/cli',
'@react-native-community/cli-platform-ios',
'@ampproject/remapping',
'human-signals',
'fb-watchman',
'bser',
'walker',
'chrome-launcher',
'lighthouse-logger',
'chromium-edge-launcher',
];

const ignoreGeneral = [
...ignoreCore,
'jackspeak',
'path-scurry',
'package-json-from-dist',
];

/*
* `wp-scripts check-licenses` uses prod and dev dependencies of the package to scan for dependencies. With npm workspaces, workspace packages (the @wordpress/* packages) are not listed in the main package json and this approach does not work.
*
* Instead, work from an npm query that uses some custom information in package.json files to declare packages that are shipped with WordPress (and must be GPLv2 compatible) or other files that may use more permissive licenses.
*/

/**
* @typedef PackageInfo
* @property {string} name Package name.
*/

/** @type {ReadonlyArray<PackageInfo>} */
const workspacePackages = JSON.parse(
spawnSync(
'npm',
[
'query',
'.workspace:attr([wpScript]), .workspace:attr([wpScriptModuleExports])',
],
/*
* Set the max buffer to ~157MB, since the output size for
* prod is ~21 MB and dev is ~110 MB
*/
{ maxBuffer: 1024 * 1024 * 150 }
).stdout
);

const packageNames = workspacePackages.map( ( { name } ) => name );

const dependenciesToProcess = JSON.parse(
spawnSync(
'npm',
[
'ls',
'--json',
'--long',
'--all',
'--lockfile-only',
'--omit=dev',
...packageNames.map(
( packageName ) => `--workspace=${ packageName }`
),
],
/*
* Set the max buffer to ~157MB, since the output size for
* prod is ~21 MB and dev is ~110 MB
*/
{ maxBuffer: 1024 * 1024 * 150 }
).stdout
).dependencies;

checkDepsInTree( dependenciesToProcess, {
ignored: ignoreGeneral,
gpl2: true,
} );
Loading
Loading