@roots/bud-compiler 2023.6.14-154 → 2023.6.15-2014
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/lib/compiler.service.d.ts +2 -2
- package/lib/compiler.service.js +51 -48
- package/package.json +5 -5
- package/src/compiler.service.tsx +60 -62
@@ -2,7 +2,7 @@ import type { MultiCompiler, MultiStats, StatsError } from '@roots/bud-framework
|
|
2
2
|
import type { Compiler as Contract } from '@roots/bud-framework/services';
|
3
3
|
import type { ErrorWithSourceFile } from '@roots/bud-support/open';
|
4
4
|
import { Service } from '@roots/bud-framework/service';
|
5
|
-
import webpack from 'webpack';
|
5
|
+
import webpack from '@roots/bud-support/webpack';
|
6
6
|
/**
|
7
7
|
* Wepback compilation controller class
|
8
8
|
*/
|
@@ -30,7 +30,7 @@ export declare class Compiler extends Service implements Contract.Service {
|
|
30
30
|
/**
|
31
31
|
* Compiler error event
|
32
32
|
*/
|
33
|
-
onError(error:
|
33
|
+
onError(error: webpack.WebpackError): Promise<void>;
|
34
34
|
/**
|
35
35
|
* Stats handler
|
36
36
|
*/
|
package/lib/compiler.service.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
3
|
-
import
|
3
|
+
import { Error } from '@roots/bud-dashboard/app';
|
4
4
|
import { Service } from '@roots/bud-framework/service';
|
5
5
|
import { bind } from '@roots/bud-support/decorators/bind';
|
6
|
-
import { BudError
|
6
|
+
import { BudError } from '@roots/bud-support/errors';
|
7
7
|
import { duration } from '@roots/bud-support/human-readable';
|
8
|
-
import
|
8
|
+
import { render } from '@roots/bud-support/ink';
|
9
9
|
import stripAnsi from '@roots/bud-support/strip-ansi';
|
10
|
+
import webpack from '@roots/bud-support/webpack';
|
10
11
|
import { pathToFileURL } from 'node:url';
|
11
|
-
import webpack from 'webpack';
|
12
12
|
/**
|
13
13
|
* Wepback compilation controller class
|
14
14
|
*/
|
@@ -33,62 +33,66 @@ export class Compiler extends Service {
|
|
33
33
|
* Initiates compilation
|
34
34
|
*/
|
35
35
|
async compile() {
|
36
|
-
const compilerPath = await this.app.module
|
37
|
-
|
38
|
-
|
36
|
+
const compilerPath = await this.app.module
|
37
|
+
.resolve(`webpack`, import.meta.url)
|
38
|
+
.catch(error => {
|
39
|
+
throw BudError.normalize(error);
|
40
|
+
});
|
41
|
+
this.implementation = await this.app.module
|
42
|
+
.import(compilerPath, import.meta.url)
|
43
|
+
.catch(error => {
|
44
|
+
throw BudError.normalize(error);
|
45
|
+
})
|
46
|
+
.finally(() => {
|
47
|
+
this.logger.info(`imported webpack from ${compilerPath}`);
|
48
|
+
});
|
39
49
|
this.config = !this.app.hasChildren
|
40
50
|
? [await this.app.build.make()]
|
41
|
-
: await Promise.all(Object.values(this.app.children).map(async (child) => {
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
catch (error) {
|
46
|
-
throw error;
|
47
|
-
}
|
48
|
-
}));
|
51
|
+
: await Promise.all(Object.values(this.app.children).map(async (child) => await child.build.make().catch(error => {
|
52
|
+
throw error;
|
53
|
+
})));
|
49
54
|
await this.app.hooks.fire(`compiler.before`, this.app);
|
50
55
|
this.logger.timeEnd(`initialize`);
|
51
|
-
|
52
|
-
|
56
|
+
try {
|
57
|
+
this.instance = this.implementation(this.config);
|
58
|
+
}
|
59
|
+
catch (error) {
|
60
|
+
throw BudError.normalize(error);
|
61
|
+
}
|
53
62
|
this.instance.hooks.done.tap(this.app.label, async (stats) => {
|
54
63
|
await this.onStats(stats);
|
55
|
-
await this.app.hooks
|
64
|
+
await this.app.hooks
|
65
|
+
.fire(`compiler.after`, this.app)
|
66
|
+
.catch(error => {
|
67
|
+
this.logger.error(error);
|
68
|
+
});
|
69
|
+
await this.app.hooks
|
70
|
+
.fire(`compiler.close`, this.app)
|
71
|
+
.catch(error => {
|
72
|
+
this.logger.error(error);
|
73
|
+
});
|
56
74
|
});
|
57
|
-
await this.app.hooks.fire(`compiler.after`, this.app);
|
58
75
|
return this.instance;
|
59
76
|
}
|
60
77
|
/**
|
61
78
|
* Compiler error event
|
62
79
|
*/
|
63
80
|
async onError(error) {
|
64
|
-
process.exitCode = 1;
|
65
|
-
await this.app.hooks.fire(`compiler.error`, error);
|
81
|
+
global.process.exitCode = 1;
|
66
82
|
this.app.isDevelopment &&
|
67
83
|
this.app.server.appliedMiddleware?.hot?.publish({ error });
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
});
|
74
|
-
|
75
|
-
|
76
|
-
this.
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
}
|
84
|
+
// @eslint-disable-next-line no-console
|
85
|
+
render(_jsx(Error, { ...new BudError(error.message, {
|
86
|
+
props: {
|
87
|
+
error: BudError.normalize(error),
|
88
|
+
},
|
89
|
+
}) }));
|
90
|
+
await this.app.hooks.fire(`compiler.error`, error);
|
91
|
+
this.app.notifier.notify({
|
92
|
+
group: this.app.label,
|
93
|
+
message: error.message,
|
94
|
+
subtitle: error.name,
|
95
|
+
});
|
92
96
|
}
|
93
97
|
/**
|
94
98
|
* Stats handler
|
@@ -160,9 +164,8 @@ export class Compiler extends Service {
|
|
160
164
|
const modules = this.stats.children.flatMap(child => child.modules);
|
161
165
|
const moduleIdent = error.moduleId ?? error.moduleName;
|
162
166
|
const module = modules.find(module => module?.id === moduleIdent || module?.name === moduleIdent);
|
163
|
-
if (!module)
|
167
|
+
if (!module)
|
164
168
|
return error;
|
165
|
-
}
|
166
169
|
if (module.nameForCondition) {
|
167
170
|
file = module.nameForCondition;
|
168
171
|
}
|
@@ -191,7 +194,7 @@ __decorate([
|
|
191
194
|
__decorate([
|
192
195
|
bind,
|
193
196
|
__metadata("design:type", Function),
|
194
|
-
__metadata("design:paramtypes", [
|
197
|
+
__metadata("design:paramtypes", [webpack.WebpackError]),
|
195
198
|
__metadata("design:returntype", Promise)
|
196
199
|
], Compiler.prototype, "onError", null);
|
197
200
|
__decorate([
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@roots/bud-compiler",
|
3
|
-
"version": "2023.6.
|
3
|
+
"version": "2023.6.15-2014",
|
4
4
|
"description": "Compilation handler",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=16"
|
@@ -71,15 +71,15 @@
|
|
71
71
|
"types": "./lib/index.d.ts",
|
72
72
|
"module": "./lib/index.js",
|
73
73
|
"devDependencies": {
|
74
|
-
"@roots/bud-api": "2023.6.
|
74
|
+
"@roots/bud-api": "2023.6.15-2014",
|
75
75
|
"@skypack/package-check": "0.2.2",
|
76
76
|
"@types/node": "18.16.16",
|
77
77
|
"@types/react": "18.2.9"
|
78
78
|
},
|
79
79
|
"dependencies": {
|
80
|
-
"@roots/bud-dashboard": "2023.6.
|
81
|
-
"@roots/bud-framework": "2023.6.
|
82
|
-
"@roots/bud-support": "2023.6.
|
80
|
+
"@roots/bud-dashboard": "2023.6.15-2014",
|
81
|
+
"@roots/bud-framework": "2023.6.15-2014",
|
82
|
+
"@roots/bud-support": "2023.6.15-2014",
|
83
83
|
"react": "18.2.0",
|
84
84
|
"tslib": "2.5.3",
|
85
85
|
"webpack": "5.86.0"
|
package/src/compiler.service.tsx
CHANGED
@@ -11,15 +11,15 @@ import type {
|
|
11
11
|
SourceFile,
|
12
12
|
} from '@roots/bud-support/open'
|
13
13
|
|
14
|
-
import
|
14
|
+
import {Error} from '@roots/bud-dashboard/app'
|
15
15
|
import {Service} from '@roots/bud-framework/service'
|
16
16
|
import {bind} from '@roots/bud-support/decorators/bind'
|
17
|
-
import {BudError
|
17
|
+
import {BudError} from '@roots/bud-support/errors'
|
18
18
|
import {duration} from '@roots/bud-support/human-readable'
|
19
|
-
import
|
19
|
+
import {render} from '@roots/bud-support/ink'
|
20
20
|
import stripAnsi from '@roots/bud-support/strip-ansi'
|
21
|
+
import webpack from '@roots/bud-support/webpack'
|
21
22
|
import {pathToFileURL} from 'node:url'
|
22
|
-
import webpack from 'webpack'
|
23
23
|
|
24
24
|
/**
|
25
25
|
* Wepback compilation controller class
|
@@ -50,41 +50,56 @@ export class Compiler extends Service implements Contract.Service {
|
|
50
50
|
*/
|
51
51
|
@bind
|
52
52
|
public async compile(): Promise<MultiCompiler> {
|
53
|
-
const compilerPath = await this.app.module
|
54
|
-
`webpack`,
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
const compilerPath = await this.app.module
|
54
|
+
.resolve(`webpack`, import.meta.url)
|
55
|
+
.catch(error => {
|
56
|
+
throw BudError.normalize(error)
|
57
|
+
})
|
58
|
+
|
59
|
+
this.implementation = await this.app.module
|
60
|
+
.import(compilerPath, import.meta.url)
|
61
|
+
.catch(error => {
|
62
|
+
throw BudError.normalize(error)
|
63
|
+
})
|
64
|
+
.finally(() => {
|
65
|
+
this.logger.info(`imported webpack from ${compilerPath}`)
|
66
|
+
})
|
62
67
|
|
63
68
|
this.config = !this.app.hasChildren
|
64
69
|
? [await this.app.build.make()]
|
65
70
|
: await Promise.all(
|
66
|
-
Object.values(this.app.children).map(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}),
|
71
|
+
Object.values(this.app.children).map(
|
72
|
+
async (child: Bud) =>
|
73
|
+
await child.build.make().catch(error => {
|
74
|
+
throw error
|
75
|
+
}),
|
76
|
+
),
|
73
77
|
)
|
74
78
|
|
75
79
|
await this.app.hooks.fire(`compiler.before`, this.app)
|
76
80
|
|
77
81
|
this.logger.timeEnd(`initialize`)
|
78
82
|
|
79
|
-
|
83
|
+
try {
|
84
|
+
this.instance = this.implementation(this.config)
|
85
|
+
} catch (error) {
|
86
|
+
throw BudError.normalize(error)
|
87
|
+
}
|
80
88
|
|
81
|
-
this.instance = this.implementation(this.config)
|
82
89
|
this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
|
83
90
|
await this.onStats(stats)
|
84
|
-
await this.app.hooks
|
85
|
-
|
91
|
+
await this.app.hooks
|
92
|
+
.fire(`compiler.after`, this.app)
|
93
|
+
.catch(error => {
|
94
|
+
this.logger.error(error)
|
95
|
+
})
|
86
96
|
|
87
|
-
|
97
|
+
await this.app.hooks
|
98
|
+
.fire(`compiler.close`, this.app)
|
99
|
+
.catch(error => {
|
100
|
+
this.logger.error(error)
|
101
|
+
})
|
102
|
+
})
|
88
103
|
|
89
104
|
return this.instance
|
90
105
|
}
|
@@ -93,45 +108,30 @@ export class Compiler extends Service implements Contract.Service {
|
|
93
108
|
* Compiler error event
|
94
109
|
*/
|
95
110
|
@bind
|
96
|
-
public async onError(error:
|
97
|
-
process.exitCode = 1
|
98
|
-
|
99
|
-
await this.app.hooks.fire(`compiler.error`, error)
|
111
|
+
public async onError(error: webpack.WebpackError) {
|
112
|
+
global.process.exitCode = 1
|
100
113
|
|
101
114
|
this.app.isDevelopment &&
|
102
115
|
this.app.server.appliedMiddleware?.hot?.publish({error})
|
103
116
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
117
|
+
// @eslint-disable-next-line no-console
|
118
|
+
render(
|
119
|
+
<Error
|
120
|
+
{...new BudError(error.message, {
|
121
|
+
props: {
|
122
|
+
error: BudError.normalize(error),
|
123
|
+
},
|
124
|
+
})}
|
125
|
+
/>,
|
126
|
+
)
|
113
127
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
}
|
128
|
+
await this.app.hooks.fire(`compiler.error`, error)
|
129
|
+
|
130
|
+
this.app.notifier.notify({
|
131
|
+
group: this.app.label,
|
132
|
+
message: error.message,
|
133
|
+
subtitle: error.name,
|
134
|
+
})
|
135
135
|
}
|
136
136
|
|
137
137
|
/**
|
@@ -226,9 +226,7 @@ export class Compiler extends Service implements Contract.Service {
|
|
226
226
|
module?.id === moduleIdent || module?.name === moduleIdent,
|
227
227
|
)
|
228
228
|
|
229
|
-
if (!module)
|
230
|
-
return error
|
231
|
-
}
|
229
|
+
if (!module) return error
|
232
230
|
|
233
231
|
if (module.nameForCondition) {
|
234
232
|
file = module.nameForCondition
|