@roots/bud-build 6.12.3 → 6.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/config/experiments.js +3 -1
  2. package/lib/config/externalsType.js +1 -1
  3. package/lib/config/module.js +5 -1
  4. package/lib/config/optimization.js +13 -3
  5. package/lib/config/output/index.js +1 -1
  6. package/lib/config/performance.js +1 -1
  7. package/lib/config/profile.js +1 -1
  8. package/lib/config/resolve.js +19 -27
  9. package/lib/config/resolveLoader.js +2 -2
  10. package/lib/config/snapshot.js +8 -3
  11. package/lib/handlers/items/items.js +1 -1
  12. package/lib/handlers/rules/js.js +3 -1
  13. package/lib/handlers/rules/json.js +3 -1
  14. package/lib/handlers/rules/toml.js +3 -1
  15. package/lib/item/index.js +13 -0
  16. package/lib/loader/index.js +5 -0
  17. package/lib/rule/index.d.ts +32 -20
  18. package/lib/rule/index.js +75 -14
  19. package/lib/service.d.ts +11 -10
  20. package/lib/service.js +57 -60
  21. package/lib/shared/base.js +1 -0
  22. package/package.json +6 -6
  23. package/src/config/experiments.ts +3 -1
  24. package/src/config/externalsType.ts +2 -1
  25. package/src/config/index.test.ts +4 -4
  26. package/src/config/module.ts +5 -1
  27. package/src/config/optimization.ts +21 -1
  28. package/src/config/output/index.ts +1 -1
  29. package/src/config/performance.ts +1 -1
  30. package/src/config/profile.ts +2 -2
  31. package/src/config/resolve.ts +27 -41
  32. package/src/config/resolveLoader.ts +3 -3
  33. package/src/config/snapshot.ts +21 -4
  34. package/src/handlers/items/items.ts +1 -1
  35. package/src/handlers/rules/js.ts +3 -1
  36. package/src/handlers/rules/json.ts +3 -1
  37. package/src/handlers/rules/toml.ts +3 -1
  38. package/src/rule/index.ts +50 -22
  39. package/src/service.ts +30 -29
@@ -1 +1,3 @@
1
- export const experiments = async ({ hooks }) => hooks.filter(`build.experiments`, undefined);
1
+ export const experiments = async ({ hooks }) => hooks.filter(`build.experiments`, {
2
+ backCompat: false,
3
+ });
@@ -1 +1 @@
1
- export const externalsType = async (app) => `var`;
1
+ export const externalsType = async (app) => undefined;
@@ -19,4 +19,8 @@ const getRules = ({ filter, path, rules }) => [
19
19
  ...filter(`build.module.rules.after`, []),
20
20
  ];
21
21
  const getNoParse = (filter) => filter(`build.module.noParse`, undefined);
22
- const getUnsafeCache = (filter) => filter(`build.module.unsafeCache`, false);
22
+ /**
23
+ * By leaving undefined, webpack will strongly cache parsed modules from node_modules
24
+ * but leave the rest. This is the default behavior.
25
+ */
26
+ const getUnsafeCache = (filter) => filter(`build.module.unsafeCache`, undefined);
@@ -1,10 +1,20 @@
1
- export const optimization = async ({ hooks: { filter }, isDevelopment, isProduction, }) => filter(`build.optimization`, {
1
+ export const optimization = async ({ hooks: { filter }, isDevelopment, isProduction, mode, }) => filter(`build.optimization`, {
2
2
  emitOnErrors: filter(`build.optimization.emitOnErrors`, isDevelopment),
3
+ innerGraph: filter(`build.optimization.innerGraph`, isProduction),
4
+ mergeDuplicateChunks: filter(`build.optimization.mergeDuplicateChunks`, isProduction),
3
5
  minimize: filter(`build.optimization.minimize`, isProduction),
4
6
  minimizer: filter(`build.optimization.minimizer`, []),
5
7
  moduleIds: filter(`build.optimization.moduleIds`, `named`),
6
- removeEmptyChunks: filter(`build.optimization.removeEmptyChunks`, false),
7
- runtimeChunk: filter(`build.optimization.runtimeChunk`, false),
8
+ nodeEnv: filter(`build.optimization.nodeEnv`, mode),
9
+ removeEmptyChunks: filter(`build.optimization.removeEmptyChunks`, isProduction),
10
+ /**
11
+ * Will be new default in webpack 6
12
+ * @see {@link https://webpack.js.org/configuration/optimization/#optimizationremoveavailablemodules}
13
+ */
14
+ removeAvailableModules: filter(`build.optimization.removeAvailableModules`, false),
15
+ runtimeChunk: filter(`build.optimization.runtimeChunk`, `single`),
16
+ sideEffects: filter(`build.optimization.sideEffects`, isProduction),
8
17
  splitChunks: filter(`build.optimization.splitChunks`, false),
18
+ providedExports: filter(`build.optimization.providedExports`, isProduction),
9
19
  usedExports: filter(`build.optimization.usedExports`, isProduction),
10
20
  });
@@ -10,7 +10,7 @@ export const output = async ({ hooks: { filter }, isProduction, path, relPath, }
10
10
  filename: filename({ filter, relPath }),
11
11
  module: filter(`build.output.module`, false),
12
12
  path: filter(`build.output.path`, path(`@dist`)),
13
- pathinfo: filter(`build.output.pathinfo`),
13
+ pathinfo: filter(`build.output.pathinfo`, false),
14
14
  publicPath: filter(`build.output.publicPath`, `auto`),
15
15
  scriptType: filter(`build.output.scriptType`, isMjs(filter) ? `module` : false),
16
16
  uniqueName: filter(`build.output.uniqueName`, `@roots/bud`),
@@ -1 +1 @@
1
- export const performance = async ({ hooks }) => hooks.filter(`build.performance`, { hints: false });
1
+ export const performance = async ({ hooks }) => hooks.filter(`build.performance`, false);
@@ -1 +1 @@
1
- export const profile = async (app) => app.hooks.filter(`build.profile`, undefined);
1
+ export const profile = async (bud) => bud.hooks.filter(`build.profile`, bud.context.debug);
@@ -1,29 +1,21 @@
1
1
  export const resolve = async (bud) => {
2
- const modules = await getModules(bud);
3
- const value = {
4
- alias: await getAlias(bud),
5
- extensions: getExtensions(bud),
6
- modules,
7
- };
8
- return await bud.hooks.filterAsync(`build.resolve`, value);
2
+ return await bud.hooks.filterAsync(`build.resolve`, {
3
+ alias: {
4
+ [`@src`]: bud.path(`@src`),
5
+ ...(await bud.hooks.filterAsync(`build.resolve.alias`, {})),
6
+ },
7
+ extensionAlias: await bud.hooks.filterAsync(`build.resolve.extensionAlias`, {
8
+ [`.js`]: [`.ts`, `.tsx`, `.js`],
9
+ [`.mjs`]: [`.mts`, `.mtx`, `.mjs`],
10
+ }),
11
+ extensions: Array.from(bud.hooks.filter(`build.resolve.extensions`, new Set([`.js`, `.mjs`, `.jsx`, `.css`]))),
12
+ modules: await bud.hooks.filterAsync(`build.resolve.modules`, [
13
+ bud.hooks.filter(`location.@src`),
14
+ bud.hooks.filter(`location.@modules`),
15
+ ]),
16
+ /**
17
+ * Leave `undefined` to use webpack default (true in dev, false in production)
18
+ */
19
+ unsafeCache: bud.hooks.filter(`build.module.unsafeCache`, undefined),
20
+ });
9
21
  };
10
- const getAlias = async (bud) => await bud.hooks.filterAsync(`build.resolve.alias`, {
11
- '@src': bud.path(`@src`),
12
- });
13
- const getExtensions = (bud) => Array.from(bud.hooks.filter(`build.resolve.extensions`, new Set([
14
- `.mjs`,
15
- `.js`,
16
- `.jsx`,
17
- `.css`,
18
- `.json`,
19
- `.wasm`,
20
- `.yml`,
21
- `.yaml`,
22
- `.xml`,
23
- `.toml`,
24
- `.csv`,
25
- ])));
26
- const getModules = async (bud) => await bud.hooks.filterAsync(`build.resolve.modules`, [
27
- bud.hooks.filter(`location.@src`),
28
- bud.hooks.filter(`location.@modules`),
29
- ]);
@@ -1,3 +1,3 @@
1
- export const resolveLoader = async (bud) => bud.hooks.filter(`build.resolveLoader`, {
2
- alias: {},
1
+ export const resolveLoader = async ({ hooks }) => hooks.filter(`build.resolveLoader`, {
2
+ alias: hooks.filter(`build.resolveLoader.alias`, {}),
3
3
  });
@@ -1,5 +1,10 @@
1
- export const snapshot = async (app) => app.hooks.filter(`build.snapshot`, {
2
- managedPaths: app.hooks.filter(`build.snapshot.managedPaths`, [
3
- ...new Set([app.path(`@modules`)]),
1
+ export const snapshot = async ({ env, hooks, path }) => hooks.filter(`build.snapshot`, {
2
+ immutablePaths: hooks.filter(`build.snapshot.immutablePaths`, []),
3
+ managedPaths: hooks.filter(`build.snapshot.managedPaths`, [
4
+ ...new Set([path(`@modules`)]),
4
5
  ]),
6
+ buildDependencies: hooks.filter(`build.snapshot.buildDependencies`, env.isTrue(`CI`) ? { hash: true } : { timestamp: true }),
7
+ module: hooks.filter(`build.snapshot.module`, env.isTrue(`CI`) ? { hash: true } : { timestamp: true }),
8
+ resolve: hooks.filter(`build.snapshot.resolve`, env.isTrue(`CI`) ? { hash: true } : { timestamp: true }),
9
+ resolveBuildDependencies: hooks.filter(`build.snapshot.resolveBuildDependencies`, env.isTrue(`CI`) ? { hash: true } : { timestamp: true }),
5
10
  });
@@ -48,7 +48,7 @@ export const minicss = async ({ makeItem }) => makeItem()
48
48
  .setLoader(`minicss`)
49
49
  .setIdent(`minicss`)
50
50
  .setOptions(app => ({
51
- publicPath: app.hooks.filter(`build.output.publicPath`),
51
+ publicPath: app.publicPath(),
52
52
  }));
53
53
  /**
54
54
  * Raw loader
@@ -1,4 +1,6 @@
1
1
  export const js = async ({ filter, makeRule, path }) => makeRule()
2
2
  .setTest(filter(`pattern.js`))
3
3
  .setInclude([() => path(`@src`)])
4
- .setUse([]);
4
+ .setResolve({
5
+ fullySpecified: false,
6
+ });
@@ -3,4 +3,6 @@ export const json = async ({ filter, makeRule, path }) => makeRule()
3
3
  .setType(`json`)
4
4
  .setInclude([() => path()])
5
5
  .setTest(filter(`pattern.json`))
6
- .setParser({ parse: json5.parse });
6
+ .setParser({
7
+ parse: json5.parse,
8
+ });
@@ -3,4 +3,6 @@ export const toml = async ({ filter, makeRule, path }) => makeRule()
3
3
  .setType(`json`)
4
4
  .setInclude([() => path()])
5
5
  .setTest(() => filter(`pattern.toml`))
6
- .setParser({ parse: tomlParser.parse });
6
+ .setParser({
7
+ parse: tomlParser.parse,
8
+ });
package/lib/item/index.js CHANGED
@@ -8,6 +8,19 @@ import Base from '../shared/base.js';
8
8
  * Item class
9
9
  */
10
10
  class Item extends Base {
11
+ _app;
12
+ /**
13
+ * Identifier
14
+ */
15
+ ident;
16
+ /**
17
+ * Loader
18
+ */
19
+ loader;
20
+ /**
21
+ * Loader options
22
+ */
23
+ options;
11
24
  /**
12
25
  * Class constructor
13
26
  */
@@ -3,6 +3,11 @@ import Base from '../shared/base.js';
3
3
  * Bud Loader
4
4
  */
5
5
  class Loader extends Base {
6
+ _app;
7
+ /**
8
+ * Factory returning the loader path
9
+ */
10
+ src;
6
11
  /**
7
12
  * Class constructor
8
13
  *
@@ -6,10 +6,14 @@ import Base from '../shared/base.js';
6
6
  * RuleSetRule
7
7
  */
8
8
  declare class Rule extends Base implements Interface {
9
+ /**
10
+ * RuleSetRule resolve
11
+ */
12
+ resolve?: Options[`resolve`];
9
13
  /**
10
14
  * RuleSetRule test
11
15
  */
12
- test: Options['test'];
16
+ test: Options[`test`];
13
17
  /**
14
18
  * RuleSetRule use
15
19
  */
@@ -17,73 +21,81 @@ declare class Rule extends Base implements Interface {
17
21
  /**
18
22
  * RuleSetRule include
19
23
  */
20
- include?: Options['include'];
24
+ include?: Options[`include`];
21
25
  /**
22
26
  * RuleSetRule exclude
23
27
  */
24
- exclude?: Options['exclude'];
28
+ exclude?: Options[`exclude`];
25
29
  /**
26
30
  * RuleSetRule type
27
31
  */
28
- type?: Options['type'];
32
+ type?: Options[`type`];
29
33
  /**
30
34
  * RuleSetRule resourceQuery
31
35
  */
32
- resourceQuery?: Options['resourceQuery'];
36
+ resourceQuery?: Options[`resourceQuery`];
33
37
  /**
34
38
  * RuleSetRule parser
35
39
  */
36
- parser?: Options['parser'];
40
+ parser?: Options[`parser`];
37
41
  /**
38
42
  * RuleSetRule generator
39
43
  */
40
- generator?: Options['generator'];
44
+ generator?: Options[`generator`];
41
45
  /**
42
46
  * Class constructor
43
47
  */
44
48
  constructor(_app: () => Bud, options?: Options);
45
49
  /**
46
- * Test value
50
+ * Set resolve value
51
+ */
52
+ getResolve(): Output[`resolve`];
53
+ /**
54
+ * Set resolve value
55
+ */
56
+ setResolve(resolve: Options[`resolve`]): this;
57
+ /**
58
+ * Get `test` value
47
59
  */
48
60
  getTest(): Output['test'];
49
61
  /**
50
- * Set test value
62
+ * Set `test` value
51
63
  */
52
64
  setTest(test: Options['test']): this;
53
65
  /**
54
- * Get parser value
66
+ * Get `parser` value
55
67
  */
56
68
  getParser(): Output['parser'];
57
69
  /**
58
- * Set parser value
70
+ * Set `parser` value
59
71
  */
60
72
  setParser(parser: Interface['parser']): this;
61
73
  /**
62
- * Get use value
74
+ * Get `use` value
63
75
  */
64
76
  getUse(): Options[`use`];
65
77
  /**
66
- * Set use value
78
+ * Set `use` value
67
79
  */
68
80
  setUse(use: Options[`use`] | ((use: Options[`use`]) => Options[`use`])): this;
69
81
  /**
70
- * Get include value
82
+ * Get `include` value
71
83
  */
72
84
  getInclude(): Array<string | RegExp>;
73
85
  /**
74
- * Set include value
86
+ * Set `include` value
75
87
  */
76
88
  setInclude(includes: Options['include']): this;
77
89
  /**
78
- * Get include value
90
+ * Get `include` value
79
91
  */
80
92
  getResourceQuery(): Output[`resourceQuery`];
81
93
  /**
82
- * Set include value
94
+ * Set `include` value
83
95
  */
84
96
  setResourceQuery(query: Options['resourceQuery']): this;
85
97
  /**
86
- * Get exclude value
98
+ * Get `exclude` value
87
99
  */
88
100
  getExclude(): Array<string | RegExp>;
89
101
  /**
@@ -91,7 +103,7 @@ declare class Rule extends Base implements Interface {
91
103
  */
92
104
  setExclude(excludes: Options['exclude'] | ((excludes: Options['exclude']) => Options['exclude'])): this;
93
105
  /**
94
- * Get type value
106
+ * Get `type` value
95
107
  */
96
108
  getType(): string;
97
109
  /**
@@ -114,4 +126,4 @@ declare class Rule extends Base implements Interface {
114
126
  toWebpack(): Output & RuleSetRule;
115
127
  }
116
128
  export { Rule };
117
- export { Interface, Options, Output, Parser };
129
+ export type { Interface, Options, Output, Parser };
package/lib/rule/index.js CHANGED
@@ -7,6 +7,42 @@ import Base from '../shared/base.js';
7
7
  * RuleSetRule
8
8
  */
9
9
  class Rule extends Base {
10
+ /**
11
+ * RuleSetRule resolve
12
+ */
13
+ resolve;
14
+ /**
15
+ * RuleSetRule test
16
+ */
17
+ test;
18
+ /**
19
+ * RuleSetRule use
20
+ */
21
+ use;
22
+ /**
23
+ * RuleSetRule include
24
+ */
25
+ include;
26
+ /**
27
+ * RuleSetRule exclude
28
+ */
29
+ exclude;
30
+ /**
31
+ * RuleSetRule type
32
+ */
33
+ type;
34
+ /**
35
+ * RuleSetRule resourceQuery
36
+ */
37
+ resourceQuery;
38
+ /**
39
+ * RuleSetRule parser
40
+ */
41
+ parser;
42
+ /**
43
+ * RuleSetRule generator
44
+ */
45
+ generator;
10
46
  /**
11
47
  * Class constructor
12
48
  */
@@ -22,74 +58,92 @@ class Rule extends Base {
22
58
  this.setType(options.type);
23
59
  this.setParser(options.parser);
24
60
  this.setGenerator(options.generator);
61
+ this.setResolve(options.resolve);
62
+ }
63
+ /**
64
+ * Set resolve value
65
+ */
66
+ getResolve() {
67
+ return this.unwrap(this.resolve);
25
68
  }
26
69
  /**
27
- * Test value
70
+ * Set resolve value
71
+ */
72
+ setResolve(resolve) {
73
+ this.resolve = resolve;
74
+ return this;
75
+ }
76
+ /**
77
+ * Get `test` value
28
78
  */
29
79
  getTest() {
30
80
  return this.unwrap(this.test);
31
81
  }
32
82
  /**
33
- * Set test value
83
+ * Set `test` value
34
84
  */
35
85
  setTest(test) {
36
86
  this.test = test;
37
87
  return this;
38
88
  }
39
89
  /**
40
- * Get parser value
90
+ * Get `parser` value
41
91
  */
42
92
  getParser() {
43
93
  return this.unwrap(this.parser);
44
94
  }
45
95
  /**
46
- * Set parser value
96
+ * Set `parser` value
47
97
  */
48
98
  setParser(parser) {
49
99
  this.parser = this.wrap(parser);
50
100
  return this;
51
101
  }
52
102
  /**
53
- * Get use value
103
+ * Get `use` value
54
104
  */
55
105
  getUse() {
56
106
  return this.use;
57
107
  }
58
108
  /**
59
- * Set use value
109
+ * Set `use` value
60
110
  */
61
111
  setUse(use) {
62
112
  this.use = isFunction(use) ? use(this.getUse()) : use;
63
113
  return this;
64
114
  }
65
115
  /**
66
- * Get include value
116
+ * Get `include` value
67
117
  */
68
118
  getInclude() {
69
119
  return this.include?.map(item => isFunction(item) ? item(this.app) : item);
70
120
  }
71
121
  /**
72
- * Set include value
122
+ * Set `include` value
73
123
  */
74
124
  setInclude(includes) {
75
125
  this.include = isFunction(includes) ? includes(this.include) : includes;
76
126
  return this;
77
127
  }
78
128
  /**
79
- * Get include value
129
+ * Get `include` value
80
130
  */
81
131
  getResourceQuery() {
82
- return this.resourceQuery;
132
+ return isFunction(this.resourceQuery)
133
+ ? this.resourceQuery(this.app)
134
+ : this.resourceQuery;
83
135
  }
84
136
  /**
85
- * Set include value
137
+ * Set `include` value
86
138
  */
87
139
  setResourceQuery(query) {
88
- this.resourceQuery = query;
140
+ this.resourceQuery = isFunction(query)
141
+ ? query(this.resourceQuery)
142
+ : query;
89
143
  return this;
90
144
  }
91
145
  /**
92
- * Get exclude value
146
+ * Get `exclude` value
93
147
  */
94
148
  getExclude() {
95
149
  return this.exclude?.map(this.unwrap);
@@ -102,7 +156,7 @@ class Rule extends Base {
102
156
  return this;
103
157
  }
104
158
  /**
105
- * Get type value
159
+ * Get `type` value
106
160
  */
107
161
  getType() {
108
162
  return this.unwrap(this.type);
@@ -146,6 +200,7 @@ class Rule extends Base {
146
200
  resourceQuery: this.getResourceQuery(),
147
201
  include: this.getInclude(),
148
202
  exclude: this.getExclude(),
203
+ resolve: this.getResolve(),
149
204
  }).reduce((a, [k, v]) => {
150
205
  if (v === undefined)
151
206
  return a;
@@ -154,6 +209,12 @@ class Rule extends Base {
154
209
  return output;
155
210
  }
156
211
  }
212
+ __decorate([
213
+ bind,
214
+ __metadata("design:type", Function),
215
+ __metadata("design:paramtypes", [Object]),
216
+ __metadata("design:returntype", Object)
217
+ ], Rule.prototype, "setResolve", null);
157
218
  __decorate([
158
219
  bind,
159
220
  __metadata("design:type", Function),
package/lib/service.d.ts CHANGED
@@ -5,7 +5,8 @@ import type { Configuration } from '@roots/bud-support/webpack';
5
5
  import { register } from './handlers/register.js';
6
6
  import { Item } from './item/index.js';
7
7
  import { Loader } from './loader/index.js';
8
- import { Options as RuleOptions, Rule } from './rule/index.js';
8
+ import type { Options as RuleOptions } from './rule/index.js';
9
+ import { Rule } from './rule/index.js';
9
10
  /**
10
11
  * Webpack configuration builder class
11
12
  */
@@ -33,7 +34,7 @@ export declare class Build extends Service implements Base.Service {
33
34
  * `loaders`, `items`, and `rules` are instantiated dumbly
34
35
  * because it is painful to think about how to map the typings..
35
36
  */
36
- register?: typeof register;
37
+ register: typeof register;
37
38
  /**
38
39
  * Make webpack configuration
39
40
  */
@@ -42,14 +43,6 @@ export declare class Build extends Service implements Base.Service {
42
43
  * Get rule
43
44
  */
44
45
  getRule<K extends `${keyof Rules & string}`>(ident: K): Rules[K];
45
- /**
46
- * Set Rule
47
- */
48
- setRule<K extends `${keyof Rules & string}`>(name: K, input?: RuleOptions | Rule): this;
49
- /**
50
- * Make Rule
51
- */
52
- makeRule(options?: RuleOptions): Rule;
53
46
  /**
54
47
  * Get loader
55
48
  */
@@ -74,4 +67,12 @@ export declare class Build extends Service implements Base.Service {
74
67
  * Make item
75
68
  */
76
69
  makeItem(options?: Partial<Item['options']>): Item;
70
+ /**
71
+ * Set Rule
72
+ */
73
+ setRule<K extends `${keyof Rules & string}`>(name: K, input?: RuleOptions | Rule): this;
74
+ /**
75
+ * Make Rule
76
+ */
77
+ makeRule(options?: RuleOptions): Rule;
77
78
  }