Skip to content

Commit cce6155

Browse files
authored
🩹 fix(minor): root only services always resolve to root (#2665)
The following services are only set on the root instance: - bud.server - bud.compiler - bud.dashboard This change makes it so that when accessing these services from a child instance context the services resolve to root: - bud.root.server - bud.root.compiler - bud.root.dashboard ## Type of change **PATCH: backwards compatible change**
1 parent dd69035 commit cce6155

File tree

1 file changed

+39
-25
lines changed
  • sources/@roots/bud-framework/src/bootstrap

1 file changed

+39
-25
lines changed

sources/@roots/bud-framework/src/bootstrap/index.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,30 @@ export const bootstrap = async (bud: Bud) => {
8585

8686
bud.hooks
8787
.fromMap({
88-
'location.@dist': bud.context.paths.output,
89-
'location.@modules': bud.context.paths.modules,
90-
'location.@src': bud.context.paths.input,
91-
'location.@storage': bud.context.paths.storage,
92-
'pattern.css': /^(?!.*\.module\.css$).*\.css$/,
93-
'pattern.cssModule': /\.module\.css$/,
94-
'pattern.csv': /\.(csv|tsv)$/,
95-
'pattern.font': /\.(ttf|otf|eot|woff2?|ico)$/,
96-
'pattern.html': /\.(html?)$/,
97-
'pattern.image': /\.(png|jpe?g|gif|webp)$/,
98-
'pattern.js': /\.(mjs|jsx?)$/,
99-
'pattern.json': /\.json$/,
100-
'pattern.json5': /\.json5$/,
101-
'pattern.md': /\.md$/,
102-
'pattern.modules': /(node_modules|bower_components|vendor)/,
103-
'pattern.sass': /^(?!.*\.module\.s[ac]ss$).*\.s[ac]ss$/,
104-
'pattern.sassModule': /\.module\.s[ac]ss$/,
105-
'pattern.svg': /\.svg$/,
106-
'pattern.toml': /\.toml$/,
107-
'pattern.ts': /\.(m?tsx?)$/,
108-
'pattern.vue': /\.vue$/,
109-
'pattern.webp': /\.webp$/,
110-
'pattern.xml': /\.xml$/,
111-
'pattern.yml': /\.ya?ml$/,
88+
[`location.@dist`]: bud.context.paths.output,
89+
[`location.@modules`]: bud.context.paths.modules,
90+
[`location.@src`]: bud.context.paths.input,
91+
[`location.@storage`]: bud.context.paths.storage,
92+
[`pattern.css`]: /^(?!.*\.module\.css$).*\.css$/,
93+
[`pattern.cssModule`]: /\.module\.css$/,
94+
[`pattern.csv`]: /\.(csv|tsv)$/,
95+
[`pattern.font`]: /\.(ttf|otf|eot|woff2?|ico)$/,
96+
[`pattern.html`]: /\.(html?)$/,
97+
[`pattern.image`]: /\.(png|jpe?g|gif|webp)$/,
98+
[`pattern.js`]: /\.(mjs|jsx?)$/,
99+
[`pattern.json`]: /\.json$/,
100+
[`pattern.json5`]: /\.json5$/,
101+
[`pattern.md`]: /\.md$/,
102+
[`pattern.modules`]: /(node_modules|bower_components|vendor)/,
103+
[`pattern.sass`]: /^(?!.*\.module\.s[ac]ss$).*\.s[ac]ss$/,
104+
[`pattern.sassModule`]: /\.module\.s[ac]ss$/,
105+
[`pattern.svg`]: /\.svg$/,
106+
[`pattern.toml`]: /\.toml$/,
107+
[`pattern.ts`]: /\.(m?tsx?)$/,
108+
[`pattern.vue`]: /\.vue$/,
109+
[`pattern.webp`]: /\.webp$/,
110+
[`pattern.xml`]: /\.xml$/,
111+
[`pattern.yml`]: /\.ya?ml$/,
112112
})
113113
.when(bud.isDevelopment, ({hooks}) =>
114114
hooks.fromMap({
@@ -135,7 +135,21 @@ export const bootstrap = async (bud: Bud) => {
135135
}),
136136
)
137137

138-
bud.isRoot && bud.after(bud.module.after)
138+
/**
139+
* Certain services are only available via the root instance of {@link Bud}.
140+
* Ensure that they always refer to the parent instance.
141+
*/
142+
if (!bud.isRoot) {
143+
bud.set(`compiler`, bud.root.compiler)
144+
bud.set(`dashboard`, bud.root.dashboard)
145+
if (bud.isDevelopment) {
146+
bud.set(`server`, bud.root.server)
147+
}
148+
}
149+
150+
if (bud.isRoot) {
151+
bud.after(bud.module.after)
152+
}
139153

140154
await bud.executeServiceCallbacks(`bootstrap`)
141155
await bud.executeServiceCallbacks(`register`)

0 commit comments

Comments
 (0)