Skip to content

Commit

Permalink
🩹 fix: config.after (#2359)
Browse files Browse the repository at this point in the history
- 🩹 fix: check if extension is `enabled` before proceeding with `configAfter` callback (applies to _most_ extensions)

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears committed Jul 5, 2023
1 parent 7ac49f6 commit 3db8a36
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
22 changes: 14 additions & 8 deletions sources/@roots/bud-build/src/config/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import isString from '@roots/bud-support/lodash/isString'

import type {Factory} from './index.js'

export const resolve: Factory<`resolve`> = async bud => {
Expand All @@ -6,29 +8,33 @@ export const resolve: Factory<`resolve`> = async bud => {
[`@src`]: bud.path(`@src`),
...(await bud.hooks.filterAsync(`build.resolve.alias`, {})),
},

extensionAlias: await bud.hooks.filterAsync(
`build.resolve.extensionAlias`,
{
[`.js`]: [`.ts`, `.tsx`, `.js`],
[`.mjs`]: [`.mts`, `.mtx`, `.mjs`],
},
),

extensions: Array.from(
bud.hooks.filter(
`build.resolve.extensions`,
new Set([`.js`, `.mjs`, `.jsx`, `.css`]),
),
),
modules: await bud.hooks.filterAsync(`build.resolve.modules`, [
bud.hooks.filter(`location.@src`),
bud.hooks.filter(`location.@modules`),
]),

modules: await bud.hooks.filterAsync(
`build.resolve.modules`,
[
bud.hooks.filter(`location.@src`),
bud.hooks.filter(`location.@modules`),
].filter(v => isString(v) && v.length > 0),
),

/**
* Leave `undefined` to use webpack default (true in dev, false in production)
*/
unsafeCache: bud.hooks.filter(
`build.module.unsafeCache`,
bud.isDevelopment,
),
unsafeCache: bud.hooks.filter(`build.module.unsafeCache`, undefined),
})
}
2 changes: 2 additions & 0 deletions sources/@roots/bud-extensions/src/tsconfig-values/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export default class BudTsConfigValues
* {@link Extension.configAfter}
*/
public override async configAfter(bud: Bud) {
if (!this.isEnabled()) return

// If a base directory has been defined in the tsconfig.json (either as rootDir or baseUrl),
// it is set as the @src path in the bud.js application.
if (this.derivedBaseDir) {
Expand Down
34 changes: 17 additions & 17 deletions sources/@roots/bud-framework/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ export const bootstrap = async function (this: Bud) {

this.hooks
.fromMap({
'location.@dist':
isString(this.context.output) && this.context.output !== ``
? this.context.output
: `dist`,
'location.@modules': isString(this.context.modules)
? this.context.modules
: `node_modules`,
'location.@os-cache': this.context.paths[`os-cache`],
'location.@os-config': this.context.paths[`os-config`],
'location.@os-data': this.context.paths[`os-data`],
'location.@os-log': this.context.paths[`os-log`],
'location.@os-temp': this.context.paths[`os-temp`],
'location.@src':
isString(this.context.input) && this.context.input !== ``
? this.context.input
: `src`,
'location.@storage': this.context.paths.storage,
'pattern.css': /(?!.*\.module)\.css$/,
'pattern.cssModule': /\.module\.css$/,
'pattern.csv': /\.(csv|tsv)$/,
Expand All @@ -185,23 +202,6 @@ export const bootstrap = async function (this: Bud) {
'pattern.xml': /\.xml$/,
'pattern.yml': /\.ya?ml$/,
})
.hooks.fromMap({
'location.@dist': isString(this.context.output)
? this.context.output
: `dist`,
'location.@modules': isString(this.context.modules)
? this.context.modules
: `node_modules`,
'location.@os-cache': this.context.paths[`os-cache`],
'location.@os-config': this.context.paths[`os-config`],
'location.@os-data': this.context.paths[`os-data`],
'location.@os-log': this.context.paths[`os-log`],
'location.@os-temp': this.context.paths[`os-temp`],
'location.@src': isString(this.context.input)
? this.context.input
: `src`,
'location.@storage': this.context.paths.storage,
})
.when(this.isDevelopment, ({hooks}) =>
hooks.fromMap({
'dev.middleware.enabled': [`dev`, `hot`],
Expand Down
3 changes: 1 addition & 2 deletions sources/@roots/bud-framework/src/methods/setPath/setPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ const makeCallback =

bud.hooks
.on(`location.${key}` as keyof SyncRegistry, normal)
.log(`${key} set to ${normal}`)
.info({key, normal, value})
.log(key, `set to`, normal)

bud.hooks.async(`build.resolve.alias`, async (paths = {}) => ({
...paths,
Expand Down
1 change: 1 addition & 0 deletions sources/@roots/bud-react/src/react-refresh/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class BudReactRefresh extends Extension<
*/
@bind
public override async configAfter(bud: Bud) {
if (!this.isEnabled()) return
if (bud.context.mode !== `development`) return
if (bud.context.hot === false) return

Expand Down

0 comments on commit 3db8a36

Please sign in to comment.