Skip to content

Commit

Permalink
✨ improve(@roots/bud): remove extraneous peer dependencies (#2243)
Browse files Browse the repository at this point in the history
With this change pnpm users can install bud with limited hoisting and no .pnpmfile required:

```
pnpm install --public-hoist-pattern="@roots/*"
```

## Changes

- Remove extraneous peer dependencies from all packages defining them
- Import `bind` from `@roots/bud-support/decorators/bind` directly
- `@roots/bud-compiler`: resolve webpack using `bud.module` before import.
- `@roots/bud-emotion`: add missing dependencies
- `@roots/bud-purgecss`: use `Extension` class
- `@roots/bud-purgecss`: add missing dependencies

## Type of change

**MINOR: feature**
  • Loading branch information
kellymears committed May 9, 2023
1 parent e2ac42b commit 9c8af5f
Show file tree
Hide file tree
Showing 82 changed files with 227 additions and 1,222 deletions.
12 changes: 0 additions & 12 deletions sources/@roots/browserslist-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@
"tslib": "2.5.0",
"update-browserslist-db": "1.0.10"
},
"peerDependencies": {
"browserslist": ">=4.21.5",
"update-browserslist-db": "*"
},
"peerDependenciesMeta": {
"browserslist": {
"optional": true
},
"update-browserslist-db": {
"optional": true
}
},
"scripts": {
"postinstall": "node scripts/postinstall.mjs"
},
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-api/src/api/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Bud} from '@roots/bud-framework'
import {ServiceContainer} from '@roots/bud-framework/service'
import type {Api as Contract} from '@roots/bud-framework/services'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import {BudError, InputError} from '@roots/bud-support/errors'
import isFunction from '@roots/bud-support/lodash/isFunction'

Expand Down
5 changes: 5 additions & 0 deletions sources/@roots/bud-build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

import './types.js'

import {Item} from './item/index.js'
import {Loader} from './loader/index.js'
import {Rule} from './rule/index.js'
import {Build} from './service.js'

export default Build

export {Item, Loader, Rule}
2 changes: 1 addition & 1 deletion sources/@roots/bud-build/src/item/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Bud, Loaders} from '@roots/bud-framework'
import type * as Build from '@roots/bud-framework/services/build'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import isString from '@roots/bud-support/lodash/isString'
import {basename} from 'path'

Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-build/src/rule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
Parser,
Rule as Interface,
} from '@roots/bud-framework/services/build/rule'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import isFunction from '@roots/bud-support/lodash/isFunction'
import isString from '@roots/bud-support/lodash/isString'
import type {RuleSetRule} from '@roots/bud-support/webpack'
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-build/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Items, Loaders, Rules} from '@roots/bud-framework'
import {Service} from '@roots/bud-framework/service'
import type * as Base from '@roots/bud-framework/services/build'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import isFunction from '@roots/bud-support/lodash/isFunction'
import isUndefined from '@roots/bud-support/lodash/isUndefined'
import type {Configuration} from '@roots/bud-support/webpack'
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-build/src/shared/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Bud} from '@roots/bud-framework'
import type {Base as BuildBase} from '@roots/bud-framework/services/build'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import isFunction from '@roots/bud-support/lodash/isFunction'

export default class Base implements BuildBase {
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-cache/src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {join} from 'node:path'
import type {Bud} from '@roots/bud-framework'
import {Service} from '@roots/bud-framework/service'
import type * as Services from '@roots/bud-framework/services'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import isString from '@roots/bud-support/lodash/isString'
import {hash} from '@roots/bud-support/utilities/args'
import type {Configuration} from '@roots/bud-support/webpack'
Expand Down
12 changes: 0 additions & 12 deletions sources/@roots/bud-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@
"dependencies": {
"tslib": "2.5.0"
},
"peerDependencies": {
"@roots/bud": "*",
"@types/webpack-env": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"@types/webpack-env": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
8 changes: 6 additions & 2 deletions sources/@roots/bud-compiler/src/compiler.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as App from '@roots/bud-dashboard/app'
import type {Bud} from '@roots/bud-framework/bud'
import {Service} from '@roots/bud-framework/service'
import type {Compiler as Contract} from '@roots/bud-framework/services'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import {BudError, CompilerError} from '@roots/bud-support/errors'
import {duration} from '@roots/bud-support/human-readable'
import type {
Expand Down Expand Up @@ -50,10 +50,14 @@ export class Compiler extends Service implements Contract.Service {
*/
@bind
public async compile(): Promise<MultiCompiler> {
this.implementation = await this.app.module.import(
const compilerPath = await this.app.module.resolve(
`webpack`,
import.meta.url,
)
this.implementation = await this.app.module.import(
compilerPath,
import.meta.url,
)
this.logger.log(`imported webpack`, this.implementation.version)

this.config = !this.app.hasChildren
Expand Down
16 changes: 2 additions & 14 deletions sources/@roots/bud-compress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,17 @@
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@skypack/package-check": "0.2.2",
"@types/node": "18.15.10"
},
"dependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/bud-support": "workspace:sources/@roots/bud-support",
"compression-webpack-plugin": "^10.0.0",
"compression-webpack-plugin": "10.0.0",
"tslib": "2.5.0",
"webpack": "5.76.3"
},
"peerDependencies": {
"@roots/bud": "*",
"compression-webpack-plugin": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"compression-webpack-plugin": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
22 changes: 1 addition & 21 deletions sources/@roots/bud-criticalcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,19 @@
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@skypack/package-check": "0.2.2",
"@types/node": "18.15.10",
"@types/vinyl": "2.0.7"
},
"dependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/bud-support": "workspace:sources/@roots/bud-support",
"@roots/critical-css-webpack-plugin": "workspace:sources/@roots/critical-css-webpack-plugin",
"critical": "5.0.4",
"tslib": "2.5.0",
"vinyl": "3.0.0"
},
"peerDependencies": {
"@roots/bud": "*",
"@roots/critical-css-webpack-plugin": "*",
"critical": "*",
"vinyl": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"@roots/critical-css-webpack-plugin": {
"optional": true
},
"critical": {
"optional": true
},
"vinyl": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
5 changes: 2 additions & 3 deletions sources/@roots/bud-criticalcss/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
plugin,
} from '@roots/bud-framework/extension/decorators'
import {deprecated} from '@roots/bud-support/decorators'
import CriticalCssWebpackPlugin, {
Options,
} from '@roots/critical-css-webpack-plugin'
import type {Options} from '@roots/critical-css-webpack-plugin'
import CriticalCssWebpackPlugin from '@roots/critical-css-webpack-plugin'

import {extractCss} from './api/extract.js'

Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-dashboard/src/service.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import {Service} from '@roots/bud-framework/service'
import type {Service as Contract} from '@roots/bud-framework/services/dashboard'
import {bind} from '@roots/bud-support/decorators'
import {bind} from '@roots/bud-support/decorators/bind'
import figures from '@roots/bud-support/figures'
import isString from '@roots/bud-support/lodash/isString'
import type {
Expand Down
47 changes: 5 additions & 42 deletions sources/@roots/bud-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,63 +72,26 @@
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-babel": "workspace:sources/@roots/bud-babel",
"@roots/bud-swc": "workspace:sources/@roots/bud-swc",
"@skypack/package-check": "0.2.2",
"@types/babel__core": "7.20.0",
"@types/node": "18.15.10"
"@types/node": "18.15.10",
"@types/react": "18.0.30"
},
"dependencies": {
"@babel/core": "7.21.3",
"@emotion/babel-plugin": "^11.10.6",
"@emotion/css": "^11.10.6",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/bud-support": "workspace:sources/@roots/bud-support",
"@swc/plugin-emotion": "2.5.51",
"react": "18.2.0",
"tslib": "2.5.0"
},
"peerDependencies": {
"@babel/core": "7.20.7",
"@emotion/babel-plugin": "*",
"@emotion/css": "*",
"@emotion/react": "*",
"@emotion/styled": "*",
"@roots/bud": "*"
},
"peerDependenciesMeta": {
"@babel/core": {
"optional": true
},
"@emotion/babel-plugin": {
"optional": true
},
"@emotion/css": {
"optional": true
},
"@emotion/react": {
"optional": true
},
"@emotion/styled": {
"optional": true
},
"@roots/bud": {
"optional": true
},
"@roots/bud-babel": {
"optional": true
},
"@roots/bud-swc": {
"optional": true
},
"@swc/plugin-emotion": {
"optional": true
},
"react": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
26 changes: 9 additions & 17 deletions sources/@roots/bud-emotion/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ export class BudEmotion extends Extension<{}, null> {
*/
@bind
public override async boot(bud: Bud) {
bud
.when(
`babel` in bud,
({babel}) => babel.setPlugin(`@emotion/babel-plugin`),
undefined,
`@roots\/bud-emotion: register \`@emotion/babel-plugin\``,
)
.when(
`swc` in bud,
({swc}) =>
swc.plugins((plugins = []) => [
...plugins,
[`@swc/plugin-emotion`, {}],
]),
undefined,
`@roots\/bud-emotion: register \`@swc/plugin-emotion\``,
)
if (`babel` in bud) {
const babelPlugin = await this.resolve(`@emotion/babel-plugin`)
bud.babel.setPlugin(`@emotion/babel-plugin`, babelPlugin)
}

if (`swc` in bud) {
const swcPlugin = await this.resolve(`@swc/plugin-emotion`)
bud.swc.plugins((plugins = []) => [...plugins, [swcPlugin, {}]])
}
}
}
9 changes: 1 addition & 8 deletions sources/@roots/bud-entrypoints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,11 @@
"@types/node": "18.15.10"
},
"dependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/entrypoints-webpack-plugin": "workspace:sources/@roots/entrypoints-webpack-plugin",
"tslib": "2.5.0"
},
"peerDependencies": {
"@roots/bud": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
18 changes: 1 addition & 17 deletions sources/@roots/bud-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,18 @@
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-build": "workspace:sources/@roots/bud-build",
"@skypack/package-check": "0.2.2",
"@types/node": "18.15.10"
},
"dependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/bud-support": "workspace:sources/@roots/bud-support",
"esbuild-loader": "2.21.0",
"tslib": "2.5.0",
"webpack": "5.76.3"
},
"peerDependencies": {
"@roots/bud": "*",
"esbuild-loader": "*",
"ts-node": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"esbuild-loader": {
"optional": true
},
"ts-node": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
1 change: 1 addition & 0 deletions sources/@roots/bud-esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
import './types.js'

import BudEsbuild from './extension.js'

export default BudEsbuild
4 changes: 1 addition & 3 deletions sources/@roots/bud-esbuild/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
/// <reference types="@roots/bud" />
/// <reference types="@roots/bud-framework" />

import type {Item} from '@roots/bud-build/item'
import type {Loader} from '@roots/bud-build/loader'
import type {Rule} from '@roots/bud-build/rule'
import type {Item, Loader, Rule} from '@roots/bud-build'

import type Esbuild from './extension.js'

Expand Down
Loading

0 comments on commit 9c8af5f

Please sign in to comment.