@roots/bud-compiler 6.9.0 → 6.10.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.
package/README.md CHANGED
@@ -53,7 +53,9 @@ Keep track of development and community news.
53
53
 
54
54
  ## Sponsors
55
55
 
56
- Help support our open-source development efforts by [becoming a patron](https://www.patreon.com/rootsdev).
56
+ **Bud** is an open source project and completely free to use.
57
+
58
+ However, the amount of effort needed to maintain and develop new features and projects within the Roots ecosystem is not sustainable without proper financial backing. If you have the capability, please consider [sponsoring Roots](https://github.com/sponsors/roots).
57
59
 
58
60
  <a href="https://k-m.com/">
59
61
  <img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="200" height="150"/>
@@ -70,3 +72,6 @@ Help support our open-source development efforts by [becoming a patron](https://
70
72
  <a href="https://worksitesafety.ca/careers/">
71
73
  <img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="200" height="150"/>
72
74
  </a>
75
+ <a href="https://www.copiadigital.com/">
76
+ <img src="https://cdn.roots.io/app/uploads/copia-digital.svg" alt="Copia Digital" width="200" height="150"/>
77
+ </a>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
3
  "description": "Compilation handler",
4
- "version": "6.9.0",
4
+ "version": "6.10.0",
5
5
  "homepage": "https://roots.io/bud",
6
6
  "repository": {
7
7
  "type": "git",
@@ -58,13 +58,14 @@
58
58
  }
59
59
  },
60
60
  "devDependencies": {
61
- "@roots/bud-api": "6.9.0",
61
+ "@roots/bud-api": "6.10.0",
62
62
  "@skypack/package-check": "0.2.2",
63
63
  "@types/node": "18.11.18"
64
64
  },
65
65
  "dependencies": {
66
- "@roots/bud-framework": "6.9.0",
67
- "@roots/bud-support": "6.9.0"
66
+ "@roots/bud-dashboard": "6.10.0",
67
+ "@roots/bud-framework": "6.10.0",
68
+ "@roots/bud-support": "6.10.0"
68
69
  },
69
70
  "volta": {
70
71
  "extends": "../../../package.json"
@@ -0,0 +1,222 @@
1
+ import {pathToFileURL} from 'node:url'
2
+
3
+ import * as App from '@roots/bud-dashboard/app'
4
+ import type {Bud} from '@roots/bud-framework/bud'
5
+ import {Service} from '@roots/bud-framework/service'
6
+ import type {Compiler as Contract} from '@roots/bud-framework/services'
7
+ import {bind} from '@roots/bud-support/decorators'
8
+ import {duration} from '@roots/bud-support/human-readable'
9
+ import type {
10
+ ErrorWithSourceFile,
11
+ SourceFile,
12
+ } from '@roots/bud-support/open'
13
+ import React from '@roots/bud-support/react'
14
+ import stripAnsi from '@roots/bud-support/strip-ansi'
15
+ import type webpack from '@roots/bud-support/webpack'
16
+ import type {
17
+ MultiCompiler,
18
+ MultiStats,
19
+ StatsCompilation,
20
+ StatsError,
21
+ } from '@roots/bud-support/webpack'
22
+
23
+ /**
24
+ * Wepback compilation controller class
25
+ */
26
+ export class Compiler extends Service implements Contract.Service {
27
+ /**
28
+ * Compiler implementation
29
+ */
30
+ public implementation: typeof webpack
31
+
32
+ /**
33
+ * Compiler instance
34
+ */
35
+ public instance: Contract.Service[`instance`]
36
+
37
+ /**
38
+ * Compilation stats
39
+ */
40
+ public stats: Contract.Service[`stats`]
41
+
42
+ /**
43
+ * Configuration
44
+ */
45
+ public config: Contract.Service[`config`] = []
46
+
47
+ /**
48
+ * Initiates compilation
49
+ */
50
+ @bind
51
+ public async compile(): Promise<MultiCompiler> {
52
+ this.implementation = await this.app.module.import(`webpack`)
53
+ this.logger.log(`imported webpack`, this.implementation.version)
54
+
55
+ this.config = !this.app.hasChildren
56
+ ? [await this.app.build.make()]
57
+ : await Promise.all(
58
+ Object.values(this.app.children).map(async (child: Bud) => {
59
+ try {
60
+ return await child.build.make()
61
+ } catch (error) {
62
+ throw error
63
+ }
64
+ }),
65
+ )
66
+
67
+ await this.app.hooks.fire(`compiler.before`, this.app)
68
+
69
+ if (this.app.isCLI() && this.app.context.args.dry) {
70
+ this.app.context.logger.timeEnd(`initialize`)
71
+ this.logger.log(`running in dry mode. exiting early.`)
72
+ return
73
+ }
74
+
75
+ this.app.context.logger.timeEnd(`initialize`)
76
+
77
+ this.instance = this.implementation(this.config)
78
+
79
+ this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
80
+ await this.onStats(stats)
81
+ await this.app.hooks.fire(`compiler.close`, this.app)
82
+ })
83
+
84
+ await this.app.hooks.fire(`compiler.after`, this.app)
85
+
86
+ return this.instance
87
+ }
88
+
89
+ /**
90
+ * Stats handler
91
+ */
92
+ @bind
93
+ public async onStats(stats: MultiStats) {
94
+ const makeNoticeTitle = (child: StatsCompilation) =>
95
+ this.app.label !== child.name
96
+ ? `${this.app.label} (${child.name})`
97
+ : child.name
98
+
99
+ this.stats = stats.toJson(this.app.hooks.filter(`build.stats`))
100
+
101
+ await this.app.hooks.fire(`compiler.stats`, stats)
102
+
103
+ const statsUpdate = this.app.dashboard.update(stats)
104
+
105
+ if (stats.hasErrors()) {
106
+ process.exitCode = 1
107
+
108
+ this.stats.children = this.stats.children?.map(child => ({
109
+ ...child,
110
+ errors: this.sourceErrors(child.errors),
111
+ }))
112
+
113
+ this.stats.children
114
+ ?.filter(child => child.errorsCount > 0)
115
+ .forEach(child => {
116
+ const error = child.errors?.shift()
117
+ if (!error) return
118
+ this.app.notifier.notify({
119
+ title: makeNoticeTitle(child),
120
+ subtitle: error.file ? `Error in ${error.name}` : error.name,
121
+ message: stripAnsi(error.message),
122
+ open: error.file ? pathToFileURL(error.file) : ``,
123
+ group: `${this.app.label}-${child.name}`,
124
+ })
125
+ this.app.notifier.openEditor(error.file)
126
+ })
127
+ }
128
+
129
+ this.stats.children
130
+ ?.filter(child => child.errorsCount === 0)
131
+ .forEach(child => {
132
+ this.app.notifier.notify({
133
+ title: makeNoticeTitle(child),
134
+ subtitle: `Build successful`,
135
+ message: child.modules
136
+ ? `${child.modules.length} modules compiled in ${duration(
137
+ child.time,
138
+ )}`
139
+ : `Compiled in ${duration(child.time)}`,
140
+ group: `${this.app.label}-${child.name}`,
141
+ open: this.app.server?.publicUrl.href,
142
+ })
143
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
144
+ })
145
+
146
+ await statsUpdate
147
+ }
148
+
149
+ /**
150
+ * Compiler error event
151
+ */
152
+ @bind
153
+ public async onError(error: Error) {
154
+ process.exitCode = 1
155
+
156
+ await this.app.hooks.fire(`compiler.error`, error)
157
+
158
+ this.app.isDevelopment &&
159
+ this.app.server.appliedMiddleware?.hot?.publish({error})
160
+
161
+ this.app.notifier.notify({
162
+ subtitle: error.name,
163
+ message: error.message,
164
+ group: this.app.label,
165
+ })
166
+
167
+ await this.app.dashboard.renderer.once(
168
+ <App.Error
169
+ name="Compiler error"
170
+ message={error.message}
171
+ stack={error.stack}
172
+ />,
173
+ )
174
+ }
175
+
176
+ /**
177
+ * Parse errors from webpack stats
178
+ */
179
+ @bind
180
+ public sourceErrors(
181
+ errors: Array<StatsError>,
182
+ ): Array<ErrorWithSourceFile | StatsError> {
183
+ if (!errors || !errors.length) return []
184
+
185
+ try {
186
+ const parseError = (
187
+ error: StatsError,
188
+ ): ErrorWithSourceFile | StatsError => {
189
+ let file: SourceFile[`file`] | undefined
190
+
191
+ const modules = this.stats.children.flatMap(child => child.modules)
192
+ const moduleIdent = error.moduleId ?? error.moduleName
193
+
194
+ const module = modules.find(
195
+ module =>
196
+ module?.id === moduleIdent || module?.name === moduleIdent,
197
+ )
198
+
199
+ if (!module) {
200
+ return error
201
+ }
202
+
203
+ if (module.nameForCondition) {
204
+ file = module.nameForCondition
205
+ } else if (module.name) {
206
+ file = this.app.path(`@src`, module.name)
207
+ }
208
+
209
+ if (!file) {
210
+ return error
211
+ }
212
+
213
+ return {...error, name: module.name ?? error.name, file}
214
+ }
215
+
216
+ return errors?.map(parseError).filter(Boolean)
217
+ } catch (error) {
218
+ this.app.warn(`error parsing errors`, error)
219
+ return []
220
+ }
221
+ }
222
+ }
@@ -1,54 +0,0 @@
1
- import { Service } from '@roots/bud-framework/service';
2
- import type { Compiler as Contract } from '@roots/bud-framework/services';
3
- import type webpack from '@roots/bud-support/webpack';
4
- import type { MultiCompiler, MultiStats, WebpackError } from '@roots/bud-support/webpack';
5
- /**
6
- * Wepback compilation controller class
7
- */
8
- export declare class Compiler extends Service implements Contract.Service {
9
- /**
10
- * Compiler implementation
11
- * @public
12
- */
13
- implementation: typeof webpack;
14
- /**
15
- * Compiler instance
16
- * @public
17
- */
18
- instance: Contract.Service[`instance`];
19
- /**
20
- * Compilation stats
21
- * @public
22
- */
23
- stats: Contract.Service[`stats`];
24
- /**
25
- * Configuration
26
- * @public
27
- */
28
- config: Contract.Service[`config`];
29
- /**
30
- * Initiates compilation
31
- *
32
- * @returns the compiler instance
33
- *
34
- * @public
35
- * @decorator `@bind`
36
- * @decorator `@once`
37
- */
38
- compile(): Promise<MultiCompiler>;
39
- /**
40
- * Stats handler
41
- *
42
- * @public
43
- * @decorator `@bind`
44
- */
45
- onStats(stats: MultiStats): Promise<void>;
46
- /**
47
- * Compiler error event
48
- *
49
- * @public
50
- * @decorator `@bind`
51
- */
52
- onError(error: WebpackError): void;
53
- }
54
- //# sourceMappingURL=compiler.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compiler.service.d.ts","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,EAAC,QAAQ,IAAI,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AAEvE,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAA;AACrD,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACb,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,QAAS,SAAQ,OAAQ,YAAW,QAAQ,CAAC,OAAO;IAC/D;;;OAGG;IACI,cAAc,EAAE,OAAO,OAAO,CAAA;IAErC;;;OAGG;IACI,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7C;;;OAGG;IACI,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvC;;;OAGG;IACI,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAK;IAE9C;;;;;;;;OAQG;IAEU,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAyC9C;;;;;OAKG;IAEU,OAAO,CAAC,KAAK,EAAE,UAAU;IAgBtC;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,YAAY;CAMnC"}
@@ -1,108 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { Service } from '@roots/bud-framework/service';
3
- import { bind } from '@roots/bud-support/decorators';
4
- /**
5
- * Wepback compilation controller class
6
- */
7
- export class Compiler extends Service {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * Configuration
12
- * @public
13
- */
14
- this.config = [];
15
- }
16
- /**
17
- * Initiates compilation
18
- *
19
- * @returns the compiler instance
20
- *
21
- * @public
22
- * @decorator `@bind`
23
- * @decorator `@once`
24
- */
25
- async compile() {
26
- this.implementation = await this.app.module.import(`webpack`);
27
- this.logger.log(`imported webpack`, this.implementation.version);
28
- this.config = !this.app.hasChildren
29
- ? [await this.app.build.make()]
30
- : await Promise.all(Object.values(this.app.children).map(async (child) => {
31
- try {
32
- return await child.build.make();
33
- }
34
- catch (error) {
35
- throw error;
36
- }
37
- }));
38
- try {
39
- await this.app.hooks.fire(`compiler.before`);
40
- }
41
- catch (error) {
42
- throw error;
43
- }
44
- if (this.app.isCLI() && this.app.context.args.dry) {
45
- this.logger.log(`running in dry mode. exiting early.`);
46
- return;
47
- }
48
- this.app.context.logger.timeEnd(`initialize`);
49
- this.instance = this.implementation(this.config);
50
- this.instance.hooks.done.tap(this.app.label, async (stats) => {
51
- await this.onStats(stats);
52
- });
53
- this.instance.hooks.done.tap(`${this.app.label}-close`, async () => {
54
- await this.app.hooks.fire(`compiler.close`);
55
- });
56
- await this.app.hooks.fire(`compiler.after`);
57
- return this.instance;
58
- }
59
- /**
60
- * Stats handler
61
- *
62
- * @public
63
- * @decorator `@bind`
64
- */
65
- async onStats(stats) {
66
- this.stats = stats.toJson(this.app.hooks.filter(`build.stats`));
67
- if (this.stats.errorsCount > 0 ||
68
- this.stats.children?.some(child => child.errorsCount > 0)) {
69
- process.exitCode = 1;
70
- }
71
- try {
72
- await this.app.dashboard.update(stats);
73
- }
74
- catch (error) {
75
- throw error;
76
- }
77
- }
78
- /**
79
- * Compiler error event
80
- *
81
- * @public
82
- * @decorator `@bind`
83
- */
84
- onError(error) {
85
- this.app.isDevelopment &&
86
- this.app.server.appliedMiddleware?.hot?.publish({ error });
87
- throw error;
88
- }
89
- }
90
- __decorate([
91
- bind,
92
- __metadata("design:type", Function),
93
- __metadata("design:paramtypes", []),
94
- __metadata("design:returntype", Promise)
95
- ], Compiler.prototype, "compile", null);
96
- __decorate([
97
- bind,
98
- __metadata("design:type", Function),
99
- __metadata("design:paramtypes", [Function]),
100
- __metadata("design:returntype", Promise)
101
- ], Compiler.prototype, "onStats", null);
102
- __decorate([
103
- bind,
104
- __metadata("design:type", Function),
105
- __metadata("design:paramtypes", [Function]),
106
- __metadata("design:returntype", void 0)
107
- ], Compiler.prototype, "onError", null);
108
- //# sourceMappingURL=compiler.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compiler.service.js","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAQlD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,OAAO;IAArC;;QAmBE;;;WAGG;QACI,WAAM,GAA+B,EAAE,CAAA;IAyFhD,CAAC;IAvFC;;;;;;;;OAQG;IAEU,AAAN,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,cAAc,GAAG,MAAM,IAAI,CAAC,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AAC,CAAC,CAAA;QAE1D,MAAM,KAAK,CAAA;IACb,CAAC;CACF;AA7Ec;IADZ,IAAI;;;;uCAwCJ;AASY;IADZ,IAAI;;;;uCAeJ;AAQD;IAAC,IAAI;;;;uCAMJ"}
package/lib/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * The bud compiler interface
3
- *
4
- * @see https://bud.js.org
5
- * @see https://github.com/roots/bud
6
- *
7
- * @packageDocumentation
8
- */
9
- import { Compiler } from './compiler.service.js';
10
- export default Compiler;
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAE9C,eAAe,QAAQ,CAAA"}
package/lib/index.js DELETED
@@ -1,13 +0,0 @@
1
- // Copyright © Roots Software Foundation LLC
2
- // Licensed under the MIT license.
3
- /**
4
- * The bud compiler interface
5
- *
6
- * @see https://bud.js.org
7
- * @see https://github.com/roots/bud
8
- *
9
- * @packageDocumentation
10
- */
11
- import { Compiler } from './compiler.service.js';
12
- export default Compiler;
13
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,kCAAkC;AAElC;;;;;;;GAOG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAE9C,eAAe,QAAQ,CAAA"}
@@ -1,127 +0,0 @@
1
- import type {Bud} from '@roots/bud-framework/bud'
2
- import {Service} from '@roots/bud-framework/service'
3
- import type {Compiler as Contract} from '@roots/bud-framework/services'
4
- import {bind} from '@roots/bud-support/decorators'
5
- import type webpack from '@roots/bud-support/webpack'
6
- import type {
7
- MultiCompiler,
8
- MultiStats,
9
- WebpackError,
10
- } from '@roots/bud-support/webpack'
11
-
12
- /**
13
- * Wepback compilation controller class
14
- */
15
- export class Compiler extends Service implements Contract.Service {
16
- /**
17
- * Compiler implementation
18
- * @public
19
- */
20
- public implementation: typeof webpack
21
-
22
- /**
23
- * Compiler instance
24
- * @public
25
- */
26
- public instance: Contract.Service[`instance`]
27
-
28
- /**
29
- * Compilation stats
30
- * @public
31
- */
32
- public stats: Contract.Service[`stats`]
33
-
34
- /**
35
- * Configuration
36
- * @public
37
- */
38
- public config: Contract.Service[`config`] = []
39
-
40
- /**
41
- * Initiates compilation
42
- *
43
- * @returns the compiler instance
44
- *
45
- * @public
46
- * @decorator `@bind`
47
- * @decorator `@once`
48
- */
49
- @bind
50
- public async compile(): Promise<MultiCompiler> {
51
- this.implementation = await this.app.module.import(`webpack`)
52
- this.logger.log(`imported webpack`, this.implementation.version)
53
-
54
- this.config = !this.app.hasChildren
55
- ? [await this.app.build.make()]
56
- : await Promise.all(
57
- Object.values(this.app.children).map(async (child: Bud) => {
58
- try {
59
- return await child.build.make()
60
- } catch (error) {
61
- throw error
62
- }
63
- }),
64
- )
65
-
66
- try {
67
- await this.app.hooks.fire(`compiler.before`)
68
- } catch (error) {
69
- throw error
70
- }
71
-
72
- if (this.app.isCLI() && this.app.context.args.dry) {
73
- this.logger.log(`running in dry mode. exiting early.`)
74
- return
75
- }
76
-
77
- this.app.context.logger.timeEnd(`initialize`)
78
-
79
- this.instance = this.implementation(this.config)
80
- this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
81
- await this.onStats(stats)
82
- })
83
- this.instance.hooks.done.tap(`${this.app.label}-close`, async () => {
84
- await this.app.hooks.fire(`compiler.close`)
85
- })
86
-
87
- await this.app.hooks.fire(`compiler.after`)
88
- return this.instance
89
- }
90
-
91
- /**
92
- * Stats handler
93
- *
94
- * @public
95
- * @decorator `@bind`
96
- */
97
- @bind
98
- public async onStats(stats: MultiStats) {
99
- this.stats = stats.toJson(this.app.hooks.filter(`build.stats`))
100
- if (
101
- this.stats.errorsCount > 0 ||
102
- this.stats.children?.some(child => child.errorsCount > 0)
103
- ) {
104
- process.exitCode = 1
105
- }
106
-
107
- try {
108
- await this.app.dashboard.update(stats)
109
- } catch (error) {
110
- throw error
111
- }
112
- }
113
-
114
- /**
115
- * Compiler error event
116
- *
117
- * @public
118
- * @decorator `@bind`
119
- */
120
- @bind
121
- public onError(error: WebpackError) {
122
- this.app.isDevelopment &&
123
- this.app.server.appliedMiddleware?.hot?.publish({error})
124
-
125
- throw error
126
- }
127
- }