@roots/bud-compiler 6.10.0 → 6.12.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.
@@ -0,0 +1,43 @@
1
+ import { Service } from '@roots/bud-framework/service';
2
+ import type { Compiler as Contract } from '@roots/bud-framework/services';
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';
6
+ /**
7
+ * Wepback compilation controller class
8
+ */
9
+ export declare class Compiler extends Service implements Contract.Service {
10
+ /**
11
+ * Compiler implementation
12
+ */
13
+ implementation: typeof webpack;
14
+ /**
15
+ * Compiler instance
16
+ */
17
+ instance: Contract.Service[`instance`];
18
+ /**
19
+ * Compilation stats
20
+ */
21
+ stats: Contract.Service[`stats`];
22
+ /**
23
+ * Configuration
24
+ */
25
+ config: Contract.Service[`config`];
26
+ /**
27
+ * Initiates compilation
28
+ */
29
+ compile(): Promise<MultiCompiler>;
30
+ /**
31
+ * Stats handler
32
+ */
33
+ onStats(stats: MultiStats): Promise<void>;
34
+ /**
35
+ * Compiler error event
36
+ */
37
+ onError(error: Error): Promise<void>;
38
+ /**
39
+ * Parse errors from webpack stats
40
+ */
41
+ sourceErrors(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
42
+ }
43
+ //# sourceMappingURL=compiler.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.service.d.ts","sourceRoot":"","sources":["../src/compiler.service.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,EAAC,QAAQ,IAAI,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AAIvE,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAA;AACrD,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EAEV,UAAU,EACX,MAAM,4BAA4B,CAAA;AAGnC;;GAEG;AACH,qBAAa,QAAS,SAAQ,OAAQ,YAAW,QAAQ,CAAC,OAAO;IAC/D;;OAEG;IACI,cAAc,EAAE,OAAO,OAAO,CAAA;IAErC;;OAEG;IACI,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7C;;OAEG;IACI,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvC;;OAEG;IACI,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAK;IAE9C;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAyC9C;;OAEG;IAEU,OAAO,CAAC,KAAK,EAAE,UAAU;IAiEtC;;OAEG;IAEU,OAAO,CAAC,KAAK,EAAE,KAAK;IAyCjC;;OAEG;IAEI,YAAY,CACjB,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,GACxB,KAAK,CAAC,mBAAmB,GAAG,UAAU,CAAC;CAwC3C"}
@@ -0,0 +1,203 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { pathToFileURL } from 'node:url';
4
+ import * as App from '@roots/bud-dashboard/app';
5
+ import { Service } from '@roots/bud-framework/service';
6
+ import { bind } from '@roots/bud-support/decorators';
7
+ import { BudError, CompilerError } from '@roots/bud-support/errors';
8
+ import { duration } from '@roots/bud-support/human-readable';
9
+ import stripAnsi from '@roots/bud-support/strip-ansi';
10
+ import * as Ink from 'ink';
11
+ /**
12
+ * Wepback compilation controller class
13
+ */
14
+ export class Compiler extends Service {
15
+ constructor() {
16
+ super(...arguments);
17
+ /**
18
+ * Configuration
19
+ */
20
+ this.config = [];
21
+ }
22
+ /**
23
+ * Initiates compilation
24
+ */
25
+ async compile() {
26
+ this.implementation = await this.app.module.import(`webpack`, import.meta.url);
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
+ await this.app.hooks.fire(`compiler.before`, this.app);
39
+ if (this.app.isCLI() && this.app.context.args.dry) {
40
+ this.logger.timeEnd(`initialize`);
41
+ this.logger.log(`running in dry mode. exiting early.`);
42
+ return;
43
+ }
44
+ this.logger.timeEnd(`initialize`);
45
+ this.logger.await(`compilation`);
46
+ this.instance = this.implementation(this.config);
47
+ this.instance.hooks.done.tap(this.app.label, async (stats) => {
48
+ await this.onStats(stats);
49
+ await this.app.hooks.fire(`compiler.close`, this.app);
50
+ });
51
+ await this.app.hooks.fire(`compiler.after`, this.app);
52
+ return this.instance;
53
+ }
54
+ /**
55
+ * Stats handler
56
+ */
57
+ async onStats(stats) {
58
+ const makeNoticeTitle = (child) => this.app.label !== child.name
59
+ ? `${this.app.label} (${child.name})`
60
+ : child.name;
61
+ this.stats = stats.toJson(this.app.hooks.filter(`build.stats`));
62
+ await this.app.hooks.fire(`compiler.stats`, stats);
63
+ const statsUpdate = this.app.dashboard.update(stats);
64
+ if (stats.hasErrors()) {
65
+ process.exitCode = 1;
66
+ this.stats.children = this.stats.children?.map(child => ({
67
+ ...child,
68
+ errors: this.sourceErrors(child.errors),
69
+ }));
70
+ this.stats.children
71
+ ?.filter(child => child.errorsCount > 0)
72
+ .forEach(child => {
73
+ try {
74
+ const error = child.errors?.shift();
75
+ if (!error)
76
+ return;
77
+ this.app.notifier.notify({
78
+ title: makeNoticeTitle(child),
79
+ subtitle: error.file ? `Error in ${error.name}` : error.name,
80
+ message: stripAnsi(error.message),
81
+ open: error.file ? pathToFileURL(error.file) : ``,
82
+ group: `${this.app.label}-${child.name}`,
83
+ });
84
+ this.app.notifier.openEditor(error.file);
85
+ }
86
+ catch (error) {
87
+ this.logger.error(error);
88
+ }
89
+ });
90
+ }
91
+ this.stats.children
92
+ ?.filter(child => child.errorsCount === 0)
93
+ .forEach(child => {
94
+ try {
95
+ this.app.notifier.notify({
96
+ title: makeNoticeTitle(child),
97
+ subtitle: `Build successful`,
98
+ message: child.modules
99
+ ? `${child.modules.length} modules compiled in ${duration(child.time)}`
100
+ : `Compiled in ${duration(child.time)}`,
101
+ group: `${this.app.label}-${child.name}`,
102
+ open: this.app.server?.publicUrl.href,
103
+ });
104
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
105
+ }
106
+ catch (error) {
107
+ this.logger.error(error);
108
+ }
109
+ });
110
+ await statsUpdate;
111
+ }
112
+ /**
113
+ * Compiler error event
114
+ */
115
+ async onError(error) {
116
+ process.exitCode = 1;
117
+ await this.app.hooks.fire(`compiler.error`, error);
118
+ this.app.isDevelopment &&
119
+ this.app.server.appliedMiddleware?.hot?.publish({ error });
120
+ try {
121
+ this.app.notifier.notify({
122
+ subtitle: error.name,
123
+ message: error.message,
124
+ group: this.app.label,
125
+ });
126
+ }
127
+ catch (error) {
128
+ this.logger.error(error);
129
+ }
130
+ try {
131
+ Ink.render(_jsx(App.Error, { error: new CompilerError(error.message, {
132
+ props: {
133
+ 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.`,
134
+ stack: error.stack,
135
+ thrownBy: `webpack`,
136
+ docs: new URL(`https://bud.js.org/`),
137
+ issues: new URL(`https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`),
138
+ },
139
+ }) }));
140
+ }
141
+ catch (error) {
142
+ throw BudError.normalize(error);
143
+ }
144
+ }
145
+ /**
146
+ * Parse errors from webpack stats
147
+ */
148
+ sourceErrors(errors) {
149
+ if (!errors || !errors.length)
150
+ return [];
151
+ try {
152
+ const parseError = (error) => {
153
+ let file;
154
+ const modules = this.stats.children.flatMap(child => child.modules);
155
+ const moduleIdent = error.moduleId ?? error.moduleName;
156
+ const module = modules.find(module => module?.id === moduleIdent || module?.name === moduleIdent);
157
+ if (!module) {
158
+ return error;
159
+ }
160
+ if (module.nameForCondition) {
161
+ file = module.nameForCondition;
162
+ }
163
+ else if (module.name) {
164
+ file = this.app.path(`@src`, module.name);
165
+ }
166
+ if (!file) {
167
+ return error;
168
+ }
169
+ return { ...error, name: module.name ?? error.name, file };
170
+ };
171
+ return errors?.map(parseError).filter(Boolean);
172
+ }
173
+ catch (error) {
174
+ this.app.warn(`error parsing errors`, error);
175
+ return [];
176
+ }
177
+ }
178
+ }
179
+ __decorate([
180
+ bind,
181
+ __metadata("design:type", Function),
182
+ __metadata("design:paramtypes", []),
183
+ __metadata("design:returntype", Promise)
184
+ ], Compiler.prototype, "compile", null);
185
+ __decorate([
186
+ bind,
187
+ __metadata("design:type", Function),
188
+ __metadata("design:paramtypes", [Function]),
189
+ __metadata("design:returntype", Promise)
190
+ ], Compiler.prototype, "onStats", null);
191
+ __decorate([
192
+ bind,
193
+ __metadata("design:type", Function),
194
+ __metadata("design:paramtypes", [Error]),
195
+ __metadata("design:returntype", Promise)
196
+ ], Compiler.prototype, "onError", null);
197
+ __decorate([
198
+ bind,
199
+ __metadata("design:type", Function),
200
+ __metadata("design:paramtypes", [Array]),
201
+ __metadata("design:returntype", Array)
202
+ ], Compiler.prototype, "sourceErrors", null);
203
+ //# sourceMappingURL=compiler.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.service.js","sourceRoot":"","sources":["../src/compiler.service.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AAEtC,OAAO,KAAK,GAAG,MAAM,0BAA0B,CAAA;AAE/C,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAClD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAC,QAAQ,EAAC,MAAM,mCAAmC,C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AI;;qCAEK,KAAK;oCACZ,KAAK;4CAuCP"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
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 './types.js';
10
+ import { Compiler } from './compiler.service.js';
11
+ export default Compiler;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAE9C,eAAe,QAAQ,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
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 './types.js';
12
+ import { Compiler } from './compiler.service.js';
13
+ export default Compiler;
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,kCAAkC;AAElC;;;;;;;GAOG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAE9C,eAAe,QAAQ,CAAA"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export {};
2
+ /**
3
+ * @package @roots/bud-compiler
4
+ */
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/lib/types.js ADDED
@@ -0,0 +1,5 @@
1
+ export {};
2
+ /**
3
+ * @package @roots/bud-compiler
4
+ */
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
+ "version": "6.12.0",
3
4
  "description": "Compilation handler",
4
- "version": "6.10.0",
5
- "homepage": "https://roots.io/bud",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/roots/bud.git",
9
- "directory": "sources/@roots/bud-compiler"
5
+ "engines": {
6
+ "node": ">=16"
10
7
  },
11
8
  "contributors": [
12
9
  {
@@ -25,47 +22,63 @@
25
22
  }
26
23
  ],
27
24
  "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/roots/bud/issues"
30
- },
25
+ "homepage": "https://roots.io/bud",
31
26
  "funding": {
32
27
  "type": "github sponsors",
33
28
  "url": "https://github.com/sponsors/roots"
34
29
  },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/roots/bud.git",
33
+ "directory": "sources/@roots/bud-compiler"
34
+ },
35
+ "bugs": "https://github.com/roots/bud/issues",
35
36
  "keywords": [
36
37
  "bud",
37
38
  "bud-framework"
38
39
  ],
39
- "engines": {
40
- "node": ">=16"
41
- },
42
40
  "files": [
43
41
  "docs",
44
42
  "lib",
45
43
  "src"
46
44
  ],
47
45
  "type": "module",
48
- "module": "./lib/index.js",
49
- "types": "./lib/index.d.ts",
50
46
  "exports": {
51
- ".": "./lib/index.js"
47
+ ".": {
48
+ "import": "./lib/index.js",
49
+ "default": "./lib/index.js"
50
+ },
51
+ "./types": {
52
+ "import": "./lib/types.js",
53
+ "default": "./lib/types.js"
54
+ }
52
55
  },
53
56
  "typesVersions": {
54
57
  "*": {
55
58
  ".": [
56
59
  "./lib/index.d.ts"
60
+ ],
61
+ "types": [
62
+ "./lib/types.d.ts"
57
63
  ]
58
64
  }
59
65
  },
66
+ "types": "./lib/index.d.ts",
67
+ "module": "./lib/index.js",
60
68
  "devDependencies": {
61
- "@roots/bud-api": "6.10.0",
69
+ "@roots/bud-api": "6.12.0",
62
70
  "@skypack/package-check": "0.2.2",
63
- "@types/node": "18.11.18"
71
+ "@types/node": "18.15.10",
72
+ "@types/react": "18.0.30"
64
73
  },
65
74
  "dependencies": {
66
- "@roots/bud-dashboard": "6.10.0",
67
- "@roots/bud-framework": "6.10.0",
68
- "@roots/bud-support": "6.10.0"
75
+ "@roots/bud-dashboard": "6.12.0",
76
+ "@roots/bud-framework": "6.12.0",
77
+ "@roots/bud-support": "6.12.0",
78
+ "ink": "4.1.0",
79
+ "react": "18.2.0",
80
+ "tslib": "2.5.0",
81
+ "webpack": "5.76.3"
69
82
  },
70
83
  "volta": {
71
84
  "extends": "../../../package.json"
@@ -5,12 +5,12 @@ import type {Bud} from '@roots/bud-framework/bud'
5
5
  import {Service} from '@roots/bud-framework/service'
6
6
  import type {Compiler as Contract} from '@roots/bud-framework/services'
7
7
  import {bind} from '@roots/bud-support/decorators'
8
+ import {BudError, CompilerError} from '@roots/bud-support/errors'
8
9
  import {duration} from '@roots/bud-support/human-readable'
9
10
  import type {
10
11
  ErrorWithSourceFile,
11
12
  SourceFile,
12
13
  } from '@roots/bud-support/open'
13
- import React from '@roots/bud-support/react'
14
14
  import stripAnsi from '@roots/bud-support/strip-ansi'
15
15
  import type webpack from '@roots/bud-support/webpack'
16
16
  import type {
@@ -19,6 +19,7 @@ import type {
19
19
  StatsCompilation,
20
20
  StatsError,
21
21
  } from '@roots/bud-support/webpack'
22
+ import * as Ink from 'ink'
22
23
 
23
24
  /**
24
25
  * Wepback compilation controller class
@@ -49,7 +50,10 @@ export class Compiler extends Service implements Contract.Service {
49
50
  */
50
51
  @bind
51
52
  public async compile(): Promise<MultiCompiler> {
52
- this.implementation = await this.app.module.import(`webpack`)
53
+ this.implementation = await this.app.module.import(
54
+ `webpack`,
55
+ import.meta.url,
56
+ )
53
57
  this.logger.log(`imported webpack`, this.implementation.version)
54
58
 
55
59
  this.config = !this.app.hasChildren
@@ -67,15 +71,15 @@ export class Compiler extends Service implements Contract.Service {
67
71
  await this.app.hooks.fire(`compiler.before`, this.app)
68
72
 
69
73
  if (this.app.isCLI() && this.app.context.args.dry) {
70
- this.app.context.logger.timeEnd(`initialize`)
74
+ this.logger.timeEnd(`initialize`)
71
75
  this.logger.log(`running in dry mode. exiting early.`)
72
76
  return
73
77
  }
74
78
 
75
- this.app.context.logger.timeEnd(`initialize`)
79
+ this.logger.timeEnd(`initialize`)
80
+ this.logger.await(`compilation`)
76
81
 
77
82
  this.instance = this.implementation(this.config)
78
-
79
83
  this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
80
84
  await this.onStats(stats)
81
85
  await this.app.hooks.fire(`compiler.close`, this.app)
@@ -113,34 +117,43 @@ export class Compiler extends Service implements Contract.Service {
113
117
  this.stats.children
114
118
  ?.filter(child => child.errorsCount > 0)
115
119
  .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)
120
+ try {
121
+ const error = child.errors?.shift()
122
+ if (!error) return
123
+
124
+ this.app.notifier.notify({
125
+ title: makeNoticeTitle(child),
126
+ subtitle: error.file ? `Error in ${error.name}` : error.name,
127
+ message: stripAnsi(error.message),
128
+ open: error.file ? pathToFileURL(error.file) : ``,
129
+ group: `${this.app.label}-${child.name}`,
130
+ })
131
+ this.app.notifier.openEditor(error.file)
132
+ } catch (error) {
133
+ this.logger.error(error)
134
+ }
126
135
  })
127
136
  }
128
137
 
129
138
  this.stats.children
130
139
  ?.filter(child => child.errorsCount === 0)
131
140
  .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)
141
+ try {
142
+ this.app.notifier.notify({
143
+ title: makeNoticeTitle(child),
144
+ subtitle: `Build successful`,
145
+ message: child.modules
146
+ ? `${child.modules.length} modules compiled in ${duration(
147
+ child.time,
148
+ )}`
149
+ : `Compiled in ${duration(child.time)}`,
150
+ group: `${this.app.label}-${child.name}`,
151
+ open: this.app.server?.publicUrl.href,
152
+ })
153
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
154
+ } catch (error) {
155
+ this.logger.error(error)
156
+ }
144
157
  })
145
158
 
146
159
  await statsUpdate
@@ -158,19 +171,37 @@ export class Compiler extends Service implements Contract.Service {
158
171
  this.app.isDevelopment &&
159
172
  this.app.server.appliedMiddleware?.hot?.publish({error})
160
173
 
161
- this.app.notifier.notify({
162
- subtitle: error.name,
163
- message: error.message,
164
- group: this.app.label,
165
- })
174
+ try {
175
+ this.app.notifier.notify({
176
+ subtitle: error.name,
177
+ message: error.message,
178
+ group: this.app.label,
179
+ })
180
+ } catch (error) {
181
+ this.logger.error(error)
182
+ }
166
183
 
167
- await this.app.dashboard.renderer.once(
168
- <App.Error
169
- name="Compiler error"
170
- message={error.message}
171
- stack={error.stack}
172
- />,
173
- )
184
+ try {
185
+ Ink.render(
186
+ <App.Error
187
+ error={
188
+ new CompilerError(error.message, {
189
+ props: {
190
+ 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.`,
191
+ stack: error.stack,
192
+ thrownBy: `webpack`,
193
+ docs: new URL(`https://bud.js.org/`),
194
+ issues: new URL(
195
+ `https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`,
196
+ ),
197
+ },
198
+ })
199
+ }
200
+ />,
201
+ )
202
+ } catch (error) {
203
+ throw BudError.normalize(error)
204
+ }
174
205
  }
175
206
 
176
207
  /**
@@ -48,7 +48,7 @@ describe(`@roots/bud-compiler`, function () {
48
48
  bud.context.args.dry = true
49
49
  const logSpy = vi.spyOn(compiler.logger, `log`)
50
50
  await compiler.compile()
51
- expect(logSpy).toHaveBeenCalledTimes(2)
51
+ expect(logSpy).toHaveBeenCalledTimes(3)
52
52
  })
53
53
 
54
54
  it(`should set done tap`, async () => {
package/src/index.ts CHANGED
@@ -10,6 +10,8 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
 
13
+ import './types.js'
14
+
13
15
  import {Compiler} from './compiler.service.js'
14
16
 
15
17
  export default Compiler
package/src/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ /**
2
+ * @package @roots/bud-compiler
3
+ */