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

Use npm workspaces for packages #65681

Merged
merged 18 commits into from
Oct 21, 2024
Merged
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
69 changes: 69 additions & 0 deletions bin/check-licenses.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env node

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

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

const ignored = [ '@ampproject/remapping' ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it’s licensed under Apache-2.0 license so it would be handy to add now a comment explaining why it can be ignored. I hope it’s only listed as a dependency of a dependency but never used.

Copy link
Member

@gziolo gziolo Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a dependency of @babel/core. The only production package that depends on @babel/core that I could locate is @emotion/css. It's used in a single place:

// eslint-disable-next-line no-restricted-imports
import type { ClassNamesArg } from '@emotion/css';
// eslint-disable-next-line no-restricted-imports
import { cx as innerCx } from '@emotion/css';

It doesn't seem to use Babel at all:

cx is emotion's version of the popular classnames library.

The latest version of @emotion/css doesn't define @babel/core as a peer dependency anymore:

https://github.com/emotion-js/emotion/blob/main/packages/css/package.json

It has changed with the following PR: emotion-js/emotion#2985. The package was at 11.10.5 at the time of that change. The version used in the Gutenberg repository is 11.7.1. It could be that bumping these dependencies would make this ignore obsolete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice, but I'd prefer to leave upgrades for after this PR has landed. It's already quite a big and potentially disruptive PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to document everything as I was digging into the details of prior decisions. There is no need for any follow-up in this PR.


/*
* `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,
gpl2: true,
} );
6 changes: 1 addition & 5 deletions docs/contributors/code/managing-packages.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Managing Packages

This repository uses [monorepo] to manage WordPress modules and publish them with [lerna] as packages to [npm]. This enforces certain steps in the workflow which are described in details in [packages](https://github.com/WordPress/gutenberg/blob/HEAD/packages/README.md) documentation.
This repository uses [npm workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) to manage WordPress packages and [lerna](https://lerna.js.org/) to publish them to [npm](https://www.npmjs.com/). This enforces certain steps in the workflow which are described in details in [packages](https://github.com/WordPress/gutenberg/blob/HEAD/packages/README.md) documentation.

Maintaining dozens of npm packages is difficult—it can be tough to keep track of changes. That's why we use `CHANGELOG.md` files for each package to simplify the release process. As a contributor, you should add an entry to the aforementioned file each time you contribute adding production code as described in [Maintaining Changelogs](https://github.com/WordPress/gutenberg/blob/HEAD/packages/README.md#maintaining-changelogs) section.

Publishing WordPress packages to npm is automated by synchronizing it with the bi-weekly Gutenberg plugin RC1 release. You can learn more about this process and other ways to publish new versions of npm packages in the [Gutenberg Release Process document](/docs/contributors/code/release.md#packages-releases-to-npm-and-wordpress-core-updates).

[lerna]: https://lerna.js.org/
[monorepo]: https://monorepo.tools
[npm]: https://www.npmjs.com/
Loading
Loading