@roots/bud-compiler 6.12.3 → 6.13.1

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.
@@ -1,12 +1,16 @@
1
- import { Service } from '@roots/bud-framework/service';
1
+ import type { MultiCompiler, MultiStats, StatsError } from '@roots/bud-framework/config';
2
2
  import type { Compiler as Contract } from '@roots/bud-framework/services';
3
3
  import type { ErrorWithSourceFile } from '@roots/bud-support/open';
4
- import type webpack from '@roots/bud-support/webpack';
5
- import type { MultiCompiler, MultiStats, StatsError } from '@roots/bud-support/webpack';
4
+ import { Service } from '@roots/bud-framework/service';
5
+ import webpack from 'webpack';
6
6
  /**
7
7
  * Wepback compilation controller class
8
8
  */
9
9
  export declare class Compiler extends Service implements Contract.Service {
10
+ /**
11
+ * Configuration
12
+ */
13
+ config: Contract.Service[`config`];
10
14
  /**
11
15
  * Compiler implementation
12
16
  */
@@ -19,22 +23,18 @@ export declare class Compiler extends Service implements Contract.Service {
19
23
  * Compilation stats
20
24
  */
21
25
  stats: Contract.Service[`stats`];
22
- /**
23
- * Configuration
24
- */
25
- config: Contract.Service[`config`];
26
26
  /**
27
27
  * Initiates compilation
28
28
  */
29
29
  compile(): Promise<MultiCompiler>;
30
- /**
31
- * Stats handler
32
- */
33
- onStats(stats: MultiStats): Promise<void>;
34
30
  /**
35
31
  * Compiler error event
36
32
  */
37
33
  onError(error: Error): Promise<void>;
34
+ /**
35
+ * Stats handler
36
+ */
37
+ onStats(stats: MultiStats): Promise<void>;
38
38
  /**
39
39
  * Parse errors from webpack stats
40
40
  */
@@ -1,24 +1,34 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { pathToFileURL } from 'node:url';
4
3
  import * as App from '@roots/bud-dashboard/app';
5
4
  import { Service } from '@roots/bud-framework/service';
6
5
  import { bind } from '@roots/bud-support/decorators/bind';
7
6
  import { BudError, CompilerError } from '@roots/bud-support/errors';
8
7
  import { duration } from '@roots/bud-support/human-readable';
8
+ import * as Ink from '@roots/bud-support/ink';
9
9
  import stripAnsi from '@roots/bud-support/strip-ansi';
10
- import * as Ink from 'ink';
10
+ import { pathToFileURL } from 'node:url';
11
+ import webpack from 'webpack';
11
12
  /**
12
13
  * Wepback compilation controller class
13
14
  */
14
15
  export class Compiler extends Service {
15
- constructor() {
16
- super(...arguments);
17
- /**
18
- * Configuration
19
- */
20
- this.config = [];
21
- }
16
+ /**
17
+ * Configuration
18
+ */
19
+ config = [];
20
+ /**
21
+ * Compiler implementation
22
+ */
23
+ implementation;
24
+ /**
25
+ * Compiler instance
26
+ */
27
+ instance;
28
+ /**
29
+ * Compilation stats
30
+ */
31
+ stats;
22
32
  /**
23
33
  * Initiates compilation
24
34
  */
@@ -37,11 +47,6 @@ export class Compiler extends Service {
37
47
  }
38
48
  }));
39
49
  await this.app.hooks.fire(`compiler.before`, this.app);
40
- if (this.app.isCLI() && this.app.context.args.dry) {
41
- this.logger.timeEnd(`initialize`);
42
- this.logger.log(`running in dry mode. exiting early.`);
43
- return;
44
- }
45
50
  this.logger.timeEnd(`initialize`);
46
51
  this.logger.await(`compilation`);
47
52
  this.instance = this.implementation(this.config);
@@ -52,6 +57,39 @@ export class Compiler extends Service {
52
57
  await this.app.hooks.fire(`compiler.after`, this.app);
53
58
  return this.instance;
54
59
  }
60
+ /**
61
+ * Compiler error event
62
+ */
63
+ async onError(error) {
64
+ process.exitCode = 1;
65
+ await this.app.hooks.fire(`compiler.error`, error);
66
+ this.app.isDevelopment &&
67
+ this.app.server.appliedMiddleware?.hot?.publish({ error });
68
+ try {
69
+ this.app.notifier.notify({
70
+ group: this.app.label,
71
+ message: error.message,
72
+ subtitle: error.name,
73
+ });
74
+ }
75
+ catch (error) {
76
+ this.logger.error(error);
77
+ }
78
+ try {
79
+ Ink.render(_jsx(App.Error, { error: new CompilerError(error.message, {
80
+ props: {
81
+ details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
82
+ docs: new URL(`https://bud.js.org/`),
83
+ issues: new URL(`https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`),
84
+ stack: error.stack,
85
+ thrownBy: `webpack`,
86
+ },
87
+ }) }));
88
+ }
89
+ catch (error) {
90
+ throw BudError.normalize(error);
91
+ }
92
+ }
55
93
  /**
56
94
  * Stats handler
57
95
  */
@@ -76,11 +114,11 @@ export class Compiler extends Service {
76
114
  if (!error)
77
115
  return;
78
116
  this.app.notifier.notify({
79
- title: makeNoticeTitle(child),
80
- subtitle: error.file ? `Error in ${error.name}` : error.name,
117
+ group: `${this.app.label}-${child.name}`,
81
118
  message: stripAnsi(error.message),
82
119
  open: error.file ? pathToFileURL(error.file) : ``,
83
- group: `${this.app.label}-${child.name}`,
120
+ subtitle: error.file ? `Error in ${error.name}` : error.name,
121
+ title: makeNoticeTitle(child),
84
122
  });
85
123
  this.app.notifier.openEditor(error.file);
86
124
  }
@@ -94,13 +132,13 @@ export class Compiler extends Service {
94
132
  .forEach(child => {
95
133
  try {
96
134
  this.app.notifier.notify({
97
- title: makeNoticeTitle(child),
98
- subtitle: `Build successful`,
135
+ group: `${this.app.label}-${child.name}`,
99
136
  message: child.modules
100
137
  ? `${child.modules.length} modules compiled in ${duration(child.time)}`
101
138
  : `Compiled in ${duration(child.time)}`,
102
- group: `${this.app.label}-${child.name}`,
103
139
  open: this.app.server?.publicUrl.href,
140
+ subtitle: `Build successful`,
141
+ title: makeNoticeTitle(child),
104
142
  });
105
143
  this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
106
144
  }
@@ -110,39 +148,6 @@ export class Compiler extends Service {
110
148
  });
111
149
  await statsUpdate;
112
150
  }
113
- /**
114
- * Compiler error event
115
- */
116
- async onError(error) {
117
- process.exitCode = 1;
118
- await this.app.hooks.fire(`compiler.error`, error);
119
- this.app.isDevelopment &&
120
- this.app.server.appliedMiddleware?.hot?.publish({ error });
121
- try {
122
- this.app.notifier.notify({
123
- subtitle: error.name,
124
- message: error.message,
125
- group: this.app.label,
126
- });
127
- }
128
- catch (error) {
129
- this.logger.error(error);
130
- }
131
- try {
132
- Ink.render(_jsx(App.Error, { error: new CompilerError(error.message, {
133
- props: {
134
- details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
135
- stack: error.stack,
136
- thrownBy: `webpack`,
137
- docs: new URL(`https://bud.js.org/`),
138
- issues: new URL(`https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`),
139
- },
140
- }) }));
141
- }
142
- catch (error) {
143
- throw BudError.normalize(error);
144
- }
145
- }
146
151
  /**
147
152
  * Parse errors from webpack stats
148
153
  */
@@ -167,7 +172,7 @@ export class Compiler extends Service {
167
172
  if (!file) {
168
173
  return error;
169
174
  }
170
- return { ...error, name: module.name ?? error.name, file };
175
+ return { ...error, file, name: module.name ?? error.name };
171
176
  };
172
177
  return errors?.map(parseError).filter(Boolean);
173
178
  }
@@ -186,15 +191,15 @@ __decorate([
186
191
  __decorate([
187
192
  bind,
188
193
  __metadata("design:type", Function),
189
- __metadata("design:paramtypes", [Function]),
194
+ __metadata("design:paramtypes", [Error]),
190
195
  __metadata("design:returntype", Promise)
191
- ], Compiler.prototype, "onStats", null);
196
+ ], Compiler.prototype, "onError", null);
192
197
  __decorate([
193
198
  bind,
194
199
  __metadata("design:type", Function),
195
- __metadata("design:paramtypes", [Error]),
200
+ __metadata("design:paramtypes", [Function]),
196
201
  __metadata("design:returntype", Promise)
197
- ], Compiler.prototype, "onError", null);
202
+ ], Compiler.prototype, "onStats", null);
198
203
  __decorate([
199
204
  bind,
200
205
  __metadata("design:type", Function),
package/lib/index.d.ts CHANGED
@@ -6,6 +6,6 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
9
- import './types.js';
10
9
  import { Compiler } from './compiler.service.js';
10
+ import './types.js';
11
11
  export default Compiler;
package/lib/index.js CHANGED
@@ -8,6 +8,6 @@
8
8
  *
9
9
  * @packageDocumentation
10
10
  */
11
- import './types.js';
12
11
  import { Compiler } from './compiler.service.js';
12
+ import './types.js';
13
13
  export default Compiler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "6.12.3",
3
+ "version": "6.13.1",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -71,19 +71,18 @@
71
71
  "types": "./lib/index.d.ts",
72
72
  "module": "./lib/index.js",
73
73
  "devDependencies": {
74
- "@roots/bud-api": "6.12.3",
74
+ "@roots/bud-api": "6.13.1",
75
75
  "@skypack/package-check": "0.2.2",
76
- "@types/node": "18.16.6",
77
- "@types/react": "18.2.6"
76
+ "@types/node": "18.16.16",
77
+ "@types/react": "18.2.9"
78
78
  },
79
79
  "dependencies": {
80
- "@roots/bud-dashboard": "6.12.3",
81
- "@roots/bud-framework": "6.12.3",
82
- "@roots/bud-support": "6.12.3",
83
- "ink": "4.2.0",
80
+ "@roots/bud-dashboard": "6.13.1",
81
+ "@roots/bud-framework": "6.13.1",
82
+ "@roots/bud-support": "6.13.1",
84
83
  "react": "18.2.0",
85
- "tslib": "2.5.0",
86
- "webpack": "5.82.0"
84
+ "tslib": "2.5.3",
85
+ "webpack": "5.86.0"
87
86
  },
88
87
  "volta": {
89
88
  "extends": "../../../package.json"
@@ -1,30 +1,35 @@
1
- import {pathToFileURL} from 'node:url'
1
+ import type {Bud} from '@roots/bud-framework'
2
+ import type {
3
+ MultiCompiler,
4
+ MultiStats,
5
+ StatsCompilation,
6
+ StatsError,
7
+ } from '@roots/bud-framework/config'
8
+ import type {Compiler as Contract} from '@roots/bud-framework/services'
9
+ import type {
10
+ ErrorWithSourceFile,
11
+ SourceFile,
12
+ } from '@roots/bud-support/open'
2
13
 
3
14
  import * as App from '@roots/bud-dashboard/app'
4
- import type {Bud} from '@roots/bud-framework/bud'
5
15
  import {Service} from '@roots/bud-framework/service'
6
- import type {Compiler as Contract} from '@roots/bud-framework/services'
7
16
  import {bind} from '@roots/bud-support/decorators/bind'
8
17
  import {BudError, CompilerError} from '@roots/bud-support/errors'
9
18
  import {duration} from '@roots/bud-support/human-readable'
10
- import type {
11
- ErrorWithSourceFile,
12
- SourceFile,
13
- } from '@roots/bud-support/open'
19
+ import * as Ink from '@roots/bud-support/ink'
14
20
  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
- import * as Ink from 'ink'
21
+ import {pathToFileURL} from 'node:url'
22
+ import webpack from 'webpack'
23
23
 
24
24
  /**
25
25
  * Wepback compilation controller class
26
26
  */
27
27
  export class Compiler extends Service implements Contract.Service {
28
+ /**
29
+ * Configuration
30
+ */
31
+ public config: Contract.Service[`config`] = []
32
+
28
33
  /**
29
34
  * Compiler implementation
30
35
  */
@@ -40,11 +45,6 @@ export class Compiler extends Service implements Contract.Service {
40
45
  */
41
46
  public stats: Contract.Service[`stats`]
42
47
 
43
- /**
44
- * Configuration
45
- */
46
- public config: Contract.Service[`config`] = []
47
-
48
48
  /**
49
49
  * Initiates compilation
50
50
  */
@@ -74,13 +74,8 @@ export class Compiler extends Service implements Contract.Service {
74
74
 
75
75
  await this.app.hooks.fire(`compiler.before`, this.app)
76
76
 
77
- if (this.app.isCLI() && this.app.context.args.dry) {
78
- this.logger.timeEnd(`initialize`)
79
- this.logger.log(`running in dry mode. exiting early.`)
80
- return
81
- }
82
-
83
77
  this.logger.timeEnd(`initialize`)
78
+
84
79
  this.logger.await(`compilation`)
85
80
 
86
81
  this.instance = this.implementation(this.config)
@@ -94,6 +89,51 @@ export class Compiler extends Service implements Contract.Service {
94
89
  return this.instance
95
90
  }
96
91
 
92
+ /**
93
+ * Compiler error event
94
+ */
95
+ @bind
96
+ public async onError(error: Error) {
97
+ process.exitCode = 1
98
+
99
+ await this.app.hooks.fire(`compiler.error`, error)
100
+
101
+ this.app.isDevelopment &&
102
+ this.app.server.appliedMiddleware?.hot?.publish({error})
103
+
104
+ try {
105
+ this.app.notifier.notify({
106
+ group: this.app.label,
107
+ message: error.message,
108
+ subtitle: error.name,
109
+ })
110
+ } catch (error) {
111
+ this.logger.error(error)
112
+ }
113
+
114
+ try {
115
+ Ink.render(
116
+ <App.Error
117
+ error={
118
+ new CompilerError(error.message, {
119
+ props: {
120
+ details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
121
+ docs: new URL(`https://bud.js.org/`),
122
+ issues: new URL(
123
+ `https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`,
124
+ ),
125
+ stack: error.stack,
126
+ thrownBy: `webpack`,
127
+ },
128
+ })
129
+ }
130
+ />,
131
+ )
132
+ } catch (error) {
133
+ throw BudError.normalize(error)
134
+ }
135
+ }
136
+
97
137
  /**
98
138
  * Stats handler
99
139
  */
@@ -126,11 +166,11 @@ export class Compiler extends Service implements Contract.Service {
126
166
  if (!error) return
127
167
 
128
168
  this.app.notifier.notify({
129
- title: makeNoticeTitle(child),
130
- subtitle: error.file ? `Error in ${error.name}` : error.name,
169
+ group: `${this.app.label}-${child.name}`,
131
170
  message: stripAnsi(error.message),
132
171
  open: error.file ? pathToFileURL(error.file) : ``,
133
- group: `${this.app.label}-${child.name}`,
172
+ subtitle: error.file ? `Error in ${error.name}` : error.name,
173
+ title: makeNoticeTitle(child),
134
174
  })
135
175
  this.app.notifier.openEditor(error.file)
136
176
  } catch (error) {
@@ -144,15 +184,15 @@ export class Compiler extends Service implements Contract.Service {
144
184
  .forEach(child => {
145
185
  try {
146
186
  this.app.notifier.notify({
147
- title: makeNoticeTitle(child),
148
- subtitle: `Build successful`,
187
+ group: `${this.app.label}-${child.name}`,
149
188
  message: child.modules
150
189
  ? `${child.modules.length} modules compiled in ${duration(
151
190
  child.time,
152
191
  )}`
153
192
  : `Compiled in ${duration(child.time)}`,
154
- group: `${this.app.label}-${child.name}`,
155
193
  open: this.app.server?.publicUrl.href,
194
+ subtitle: `Build successful`,
195
+ title: makeNoticeTitle(child),
156
196
  })
157
197
  this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
158
198
  } catch (error) {
@@ -163,51 +203,6 @@ export class Compiler extends Service implements Contract.Service {
163
203
  await statsUpdate
164
204
  }
165
205
 
166
- /**
167
- * Compiler error event
168
- */
169
- @bind
170
- public async onError(error: Error) {
171
- process.exitCode = 1
172
-
173
- await this.app.hooks.fire(`compiler.error`, error)
174
-
175
- this.app.isDevelopment &&
176
- this.app.server.appliedMiddleware?.hot?.publish({error})
177
-
178
- try {
179
- this.app.notifier.notify({
180
- subtitle: error.name,
181
- message: error.message,
182
- group: this.app.label,
183
- })
184
- } catch (error) {
185
- this.logger.error(error)
186
- }
187
-
188
- try {
189
- Ink.render(
190
- <App.Error
191
- error={
192
- new CompilerError(error.message, {
193
- props: {
194
- details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
195
- stack: error.stack,
196
- thrownBy: `webpack`,
197
- docs: new URL(`https://bud.js.org/`),
198
- issues: new URL(
199
- `https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`,
200
- ),
201
- },
202
- })
203
- }
204
- />,
205
- )
206
- } catch (error) {
207
- throw BudError.normalize(error)
208
- }
209
- }
210
-
211
206
  /**
212
207
  * Parse errors from webpack stats
213
208
  */
@@ -245,7 +240,7 @@ export class Compiler extends Service implements Contract.Service {
245
240
  return error
246
241
  }
247
242
 
248
- return {...error, name: module.name ?? error.name, file}
243
+ return {...error, file, name: module.name ?? error.name}
249
244
  }
250
245
 
251
246
  return errors?.map(parseError).filter(Boolean)
@@ -1,4 +1,4 @@
1
- import {Bud, factory} from '@repo/test-kit/bud'
1
+ import {Bud, factory} from '@repo/test-kit'
2
2
  import {beforeEach, describe, expect, it, vi} from 'vitest'
3
3
 
4
4
  import Compiler from './index.js'
@@ -43,14 +43,6 @@ describe(`@roots/bud-compiler`, function () {
43
43
  expect(compiler.config).toHaveLength(2)
44
44
  })
45
45
 
46
- it(`should log early exit (--dry)`, async () => {
47
- // @ts-ignore
48
- bud.context.args.dry = true
49
- const logSpy = vi.spyOn(compiler.logger, `log`)
50
- await compiler.compile()
51
- expect(logSpy).toHaveBeenCalledTimes(3)
52
- })
53
-
54
46
  it(`should set done tap`, async () => {
55
47
  try {
56
48
  await compiler.compile()
package/src/index.ts CHANGED
@@ -10,8 +10,7 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
 
13
- import './types.js'
14
-
15
13
  import {Compiler} from './compiler.service.js'
14
+ import './types.js'
16
15
 
17
16
  export default Compiler