Skip to content

Commit bfb1f15

Browse files
committed
Revert "Revert "Packages: Use npm workspaces (#65681)" (#66270)"
This reverts commit 91272a2.
1 parent e43a1c5 commit bfb1f15

File tree

182 files changed

+797
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+797
-866
lines changed

bin/check-licenses.mjs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* External dependencies
5+
*/
6+
import { spawnSync } from 'node:child_process';
7+
8+
/**
9+
* Internal dependencies
10+
*/
11+
import { checkDepsInTree } from '../packages/scripts/utils/license.js';
12+
13+
const ignored = [ '@ampproject/remapping' ];
14+
15+
/*
16+
* `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.
17+
*
18+
* 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.
19+
*/
20+
21+
/**
22+
* @typedef PackageInfo
23+
* @property {string} name Package name.
24+
*/
25+
26+
/** @type {ReadonlyArray<PackageInfo>} */
27+
const workspacePackages = JSON.parse(
28+
spawnSync(
29+
'npm',
30+
[
31+
'query',
32+
'.workspace:attr([wpScript]), .workspace:attr([wpScriptModuleExports])',
33+
],
34+
/*
35+
* Set the max buffer to ~157MB, since the output size for
36+
* prod is ~21 MB and dev is ~110 MB
37+
*/
38+
{ maxBuffer: 1024 * 1024 * 150 }
39+
).stdout
40+
);
41+
42+
const packageNames = workspacePackages.map( ( { name } ) => name );
43+
44+
const dependenciesToProcess = JSON.parse(
45+
spawnSync(
46+
'npm',
47+
[
48+
'ls',
49+
'--json',
50+
'--long',
51+
'--all',
52+
'--lockfile-only',
53+
'--omit=dev',
54+
...packageNames.map(
55+
( packageName ) => `--workspace=${ packageName }`
56+
),
57+
],
58+
/*
59+
* Set the max buffer to ~157MB, since the output size for
60+
* prod is ~21 MB and dev is ~110 MB
61+
*/
62+
{ maxBuffer: 1024 * 1024 * 150 }
63+
).stdout
64+
).dependencies;
65+
66+
checkDepsInTree( dependenciesToProcess, {
67+
ignored,
68+
gpl2: true,
69+
} );
+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# Managing Packages
22

3-
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.
3+
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.
44

55
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.
66

77
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).
8-
9-
[lerna]: https://lerna.js.org/
10-
[monorepo]: https://monorepo.tools
11-
[npm]: https://www.npmjs.com/

package.json

+6-105
Original file line numberDiff line numberDiff line change
@@ -21,81 +21,6 @@
2121
"config": {
2222
"IS_GUTENBERG_PLUGIN": true
2323
},
24-
"dependencies": {
25-
"@wordpress/a11y": "file:packages/a11y",
26-
"@wordpress/annotations": "file:packages/annotations",
27-
"@wordpress/api-fetch": "file:packages/api-fetch",
28-
"@wordpress/autop": "file:packages/autop",
29-
"@wordpress/blob": "file:packages/blob",
30-
"@wordpress/block-directory": "file:packages/block-directory",
31-
"@wordpress/block-editor": "file:packages/block-editor",
32-
"@wordpress/block-library": "file:packages/block-library",
33-
"@wordpress/block-serialization-default-parser": "file:packages/block-serialization-default-parser",
34-
"@wordpress/block-serialization-spec-parser": "file:packages/block-serialization-spec-parser",
35-
"@wordpress/blocks": "file:packages/blocks",
36-
"@wordpress/commands": "file:packages/commands",
37-
"@wordpress/components": "file:packages/components",
38-
"@wordpress/compose": "file:packages/compose",
39-
"@wordpress/core-commands": "file:packages/core-commands",
40-
"@wordpress/core-data": "file:packages/core-data",
41-
"@wordpress/customize-widgets": "file:packages/customize-widgets",
42-
"@wordpress/data": "file:packages/data",
43-
"@wordpress/data-controls": "file:packages/data-controls",
44-
"@wordpress/dataviews": "file:packages/dataviews",
45-
"@wordpress/date": "file:packages/date",
46-
"@wordpress/deprecated": "file:packages/deprecated",
47-
"@wordpress/dom": "file:packages/dom",
48-
"@wordpress/dom-ready": "file:packages/dom-ready",
49-
"@wordpress/edit-post": "file:packages/edit-post",
50-
"@wordpress/edit-site": "file:packages/edit-site",
51-
"@wordpress/edit-widgets": "file:packages/edit-widgets",
52-
"@wordpress/editor": "file:packages/editor",
53-
"@wordpress/element": "file:packages/element",
54-
"@wordpress/escape-html": "file:packages/escape-html",
55-
"@wordpress/fields": "file:packages/fields",
56-
"@wordpress/format-library": "file:packages/format-library",
57-
"@wordpress/hooks": "file:packages/hooks",
58-
"@wordpress/html-entities": "file:packages/html-entities",
59-
"@wordpress/i18n": "file:packages/i18n",
60-
"@wordpress/icons": "file:packages/icons",
61-
"@wordpress/interactivity": "file:packages/interactivity",
62-
"@wordpress/interactivity-router": "file:packages/interactivity-router",
63-
"@wordpress/interface": "file:packages/interface",
64-
"@wordpress/is-shallow-equal": "file:packages/is-shallow-equal",
65-
"@wordpress/keyboard-shortcuts": "file:packages/keyboard-shortcuts",
66-
"@wordpress/keycodes": "file:packages/keycodes",
67-
"@wordpress/list-reusable-blocks": "file:packages/list-reusable-blocks",
68-
"@wordpress/media-utils": "file:packages/media-utils",
69-
"@wordpress/notices": "file:packages/notices",
70-
"@wordpress/nux": "file:packages/nux",
71-
"@wordpress/patterns": "file:packages/patterns",
72-
"@wordpress/plugins": "file:packages/plugins",
73-
"@wordpress/preferences": "file:packages/preferences",
74-
"@wordpress/preferences-persistence": "file:packages/preferences-persistence",
75-
"@wordpress/primitives": "file:packages/primitives",
76-
"@wordpress/priority-queue": "file:packages/priority-queue",
77-
"@wordpress/private-apis": "file:packages/private-apis",
78-
"@wordpress/react-i18n": "file:packages/react-i18n",
79-
"@wordpress/react-native-aztec": "file:packages/react-native-aztec",
80-
"@wordpress/react-native-bridge": "file:packages/react-native-bridge",
81-
"@wordpress/react-native-editor": "file:packages/react-native-editor",
82-
"@wordpress/redux-routine": "file:packages/redux-routine",
83-
"@wordpress/reusable-blocks": "file:packages/reusable-blocks",
84-
"@wordpress/rich-text": "file:packages/rich-text",
85-
"@wordpress/router": "file:packages/router",
86-
"@wordpress/server-side-render": "file:packages/server-side-render",
87-
"@wordpress/shortcode": "file:packages/shortcode",
88-
"@wordpress/style-engine": "file:packages/style-engine",
89-
"@wordpress/sync": "file:packages/sync",
90-
"@wordpress/token-list": "file:packages/token-list",
91-
"@wordpress/undo-manager": "file:packages/undo-manager",
92-
"@wordpress/url": "file:packages/url",
93-
"@wordpress/viewport": "file:packages/viewport",
94-
"@wordpress/vips": "file:packages/vips",
95-
"@wordpress/warning": "file:packages/warning",
96-
"@wordpress/widgets": "file:packages/widgets",
97-
"@wordpress/wordcount": "file:packages/wordcount"
98-
},
9924
"devDependencies": {
10025
"@actions/core": "1.9.1",
10126
"@actions/github": "5.0.0",
@@ -145,33 +70,6 @@
14570
"@types/semver": "7.3.8",
14671
"@types/sprintf-js": "1.1.2",
14772
"@types/uuid": "8.3.1",
148-
"@wordpress/babel-plugin-import-jsx-pragma": "file:packages/babel-plugin-import-jsx-pragma",
149-
"@wordpress/babel-plugin-makepot": "file:packages/babel-plugin-makepot",
150-
"@wordpress/babel-preset-default": "file:packages/babel-preset-default",
151-
"@wordpress/base-styles": "file:packages/base-styles",
152-
"@wordpress/browserslist-config": "file:packages/browserslist-config",
153-
"@wordpress/create-block": "file:packages/create-block",
154-
"@wordpress/create-block-tutorial-template": "file:packages/create-block-tutorial-template",
155-
"@wordpress/dependency-extraction-webpack-plugin": "file:packages/dependency-extraction-webpack-plugin",
156-
"@wordpress/docgen": "file:packages/docgen",
157-
"@wordpress/e2e-test-utils": "file:packages/e2e-test-utils",
158-
"@wordpress/e2e-test-utils-playwright": "file:packages/e2e-test-utils-playwright",
159-
"@wordpress/e2e-tests": "file:packages/e2e-tests",
160-
"@wordpress/env": "file:packages/env",
161-
"@wordpress/eslint-plugin": "file:packages/eslint-plugin",
162-
"@wordpress/jest-console": "file:packages/jest-console",
163-
"@wordpress/jest-preset-default": "file:packages/jest-preset-default",
164-
"@wordpress/jest-puppeteer-axe": "file:packages/jest-puppeteer-axe",
165-
"@wordpress/lazy-import": "file:packages/lazy-import",
166-
"@wordpress/npm-package-json-lint-config": "file:packages/npm-package-json-lint-config",
167-
"@wordpress/postcss-plugins-preset": "file:packages/postcss-plugins-preset",
168-
"@wordpress/postcss-themes": "file:packages/postcss-themes",
169-
"@wordpress/prettier-config": "file:packages/prettier-config",
170-
"@wordpress/project-management-automation": "file:packages/project-management-automation",
171-
"@wordpress/readable-js-assets-webpack-plugin": "file:packages/readable-js-assets-webpack-plugin",
172-
"@wordpress/report-flaky-tests": "file:packages/report-flaky-tests",
173-
"@wordpress/scripts": "file:packages/scripts",
174-
"@wordpress/stylelint-config": "file:packages/stylelint-config",
17573
"ajv": "8.7.1",
17674
"appium": "2.0.0",
17775
"babel-jest": "29.7.0",
@@ -276,7 +174,7 @@
276174
"build": "npm run build:packages && wp-scripts build",
277175
"build:analyze-bundles": "npm run build -- --webpack-bundle-analyzer",
278176
"build:package-types": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js",
279-
"prebuild:packages": "npm run clean:packages && lerna run build",
177+
"prebuild:packages": "npm run clean:packages && npm run --if-present --workspaces build",
280178
"build:packages": "npm run --silent build:package-types && node ./bin/packages/build.js",
281179
"build:plugin-zip": "bash ./bin/build-plugin-zip.sh",
282180
"clean:package-types": "tsc --build --clean && rimraf \"./packages/*/build-types\"",
@@ -310,7 +208,7 @@
310208
"lint:pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'",
311209
"native": "npm run --prefix packages/react-native-editor",
312210
"other:changelog": "node ./bin/plugin/cli.js changelog",
313-
"other:check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2 --ignore=@react-native-community/cli,@react-native-community/cli-platform-ios,@ampproject/remapping,human-signals,fb-watchman,walker,chrome-launcher,lighthouse-logger,chromium-edge-launcher\" \"wp-scripts check-licenses --dev\"",
211+
"other:check-licenses": "concurrently \"node ./bin/check-licenses.mjs\" \"wp-scripts check-licenses --dev\"",
314212
"preother:check-local-changes": "npm run docs:build",
315213
"other:check-local-changes": "node ./bin/check-local-changes.js",
316214
"other:cherry-pick": "node ./bin/cherry-pick.mjs",
@@ -389,5 +287,8 @@
389287
"**/tsconfig.json": [
390288
"npm run lint:tsconfig"
391289
]
392-
}
290+
},
291+
"workspaces": [
292+
"packages/*"
293+
]
393294
}

packages/README.md

+15-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Managing Packages
22

3-
This repository uses [monorepo] to manage WordPress modules and publish them with [lerna] as packages to [npm].
3+
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 with to [npm](https://www.npmjs.com/).
44

55
## Creating a New Package
66

@@ -36,19 +36,15 @@ When creating a new package, you need to provide at least the following:
3636
}
3737
```
3838
This assumes that your code is located in the `src` folder and will be transpiled with `Babel`.
39-
2. `.npmrc` file which disables creating `package-lock.json` file for the package:
40-
```
41-
package-lock=false
42-
```
43-
3. `README.md` file containing at least:
39+
1. `README.md` file containing at least:
4440
- Package name
4541
- Package description
4642
- Installation details
4743
- Usage example
4844
- API documentation, if applicable ([more info](#maintaining-api-documentation))
4945
- A link to the contributing guidelines ([here's an example](https://github.com/WordPress/gutenberg/tree/HEAD/packages/a11y/README.md#contributing-to-this-package) from the a11y package)
5046
- `Code is Poetry` logo (`<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>`)
51-
4. `CHANGELOG.md` file containing at least:
47+
1. `CHANGELOG.md` file containing at least:
5248

5349
```
5450
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->
@@ -70,35 +66,32 @@ Production dependencies are stored in the `dependencies` section of the package
7066

7167
#### Adding New Dependencies
7268

73-
The simplest way to add a production dependency to one of the packages is to run a very convenient [lerna add](https://github.com/lerna/lerna/tree/HEAD/commands/add#readme) command from the root of the project.
69+
The simplest way to add a production dependency to one of the packages is to run a command like the following from the root of the project.
7470

7571
_Example:_
7672

7773
```bash
78-
lerna add change-case packages/a11y
74+
npm install change-case -w packages/a11y
7975
```
8076

81-
This command adds the latest version of `change-case` as a dependency to the `@wordpress/a11y` package, which is located in `packages/a11y` folder.
77+
This command adds the `change-case` as a dependency to the `@wordpress/a11y` package, which is located in `packages/a11y` folder. If there was the same dependency installed then the version specified in the `package-lock.json` file is going to be reused. If you want to enforce a different version, you can do so by adding the `@` suffix to the package name.
78+
79+
_Example:_
80+
81+
```bash
82+
npm install change-case@latest -w packages/a11y
83+
```
8284

8385
#### Removing Existing Dependencies
8486

85-
Removing a dependency from one of the WordPress packages requires some manual work. You need to remove the line in the corresponding `dependencies` section of the `package.json` file.
87+
Removing a dependency from one of the WordPress packages is similar to installation. You need to run a command like the following from the root of the project.
8688

8789
_Example:_
8890

89-
```diff
90-
+++ b/packages/scripts/package.json
91-
@@ -43,7 +43,6 @@
92-
"check-node-version": "^4.1.0",
93-
"cross-spawn": "^5.1.0",
94-
"eslint": "^7.1.0",
95-
- "jest": "^29.6.2",
96-
"minimist": "^1.2.0",
97-
"npm-package-json-lint": "^6.4.0",
91+
```bash
92+
npm uninstall change-case -w packages/a11y
9893
```
9994

100-
Next, you need to run `npm install` in the root of the project to ensure that `package-lock.json` file gets properly regenerated.
101-
10295
#### Updating Existing Dependencies
10396

10497
This is the most confusing part of working with [monorepo] which causes a lot of hassles for contributors. The most successful strategy so far is to do the following:
@@ -239,10 +232,6 @@ For consumers to use the published type declarations, we'll set the `types` fiel
239232

240233
Ensure that the `build-types` directory will be included in the published package, for example if a `files` field is declared.
241234

242-
[lerna]: https://lerna.js.org/
243-
[monorepo]: https://monorepo.tools
244-
[npm]: https://www.npmjs.com/
245-
246235
## Optimizing for bundlers
247236

248237
In order for bundlers to tree-shake packages effectively, they often need to know whether a package includes side effects in its code. This is done through the `sideEffects` field in the package's `package.json`.

packages/a11y/.npmrc

-1
This file was deleted.

packages/a11y/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
"wpScriptModuleExports": "./build-module/module/index.js",
3232
"dependencies": {
3333
"@babel/runtime": "7.25.7",
34-
"@wordpress/dom-ready": "file:../dom-ready",
35-
"@wordpress/i18n": "file:../i18n"
34+
"@wordpress/dom-ready": "*",
35+
"@wordpress/i18n": "*"
3636
},
3737
"publishConfig": {
3838
"access": "public"
39-
}
39+
},
40+
"wpScript": true
4041
}

packages/annotations/.npmrc

-1
This file was deleted.

packages/annotations/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
"react-native": "src/index",
2828
"dependencies": {
2929
"@babel/runtime": "7.25.7",
30-
"@wordpress/data": "file:../data",
31-
"@wordpress/hooks": "file:../hooks",
32-
"@wordpress/i18n": "file:../i18n",
33-
"@wordpress/rich-text": "file:../rich-text",
30+
"@wordpress/data": "*",
31+
"@wordpress/hooks": "*",
32+
"@wordpress/i18n": "*",
33+
"@wordpress/rich-text": "*",
3434
"uuid": "^9.0.1"
3535
},
3636
"peerDependencies": {
3737
"react": "^18.0.0"
3838
},
3939
"publishConfig": {
4040
"access": "public"
41-
}
41+
},
42+
"wpScript": true
4243
}

packages/api-fetch/.npmrc

-1
This file was deleted.

packages/api-fetch/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
"types": "build-types",
3030
"dependencies": {
3131
"@babel/runtime": "7.25.7",
32-
"@wordpress/i18n": "file:../i18n",
33-
"@wordpress/url": "file:../url"
32+
"@wordpress/i18n": "*",
33+
"@wordpress/url": "*"
3434
},
3535
"publishConfig": {
3636
"access": "public"
37-
}
37+
},
38+
"wpScript": true
3839
}

packages/autop/.npmrc

-1
This file was deleted.

packages/autop/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
},
3333
"publishConfig": {
3434
"access": "public"
35-
}
35+
},
36+
"wpScript": true
3637
}

packages/babel-plugin-import-jsx-pragma/.npmrc

-1
This file was deleted.

packages/babel-plugin-makepot/.npmrc

-1
This file was deleted.

packages/babel-preset-default/.npmrc

-1
This file was deleted.

0 commit comments

Comments
 (0)