@roots/bud-compiler 5.0.0 → 5.3.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.
- package/lib/cjs/Compiler/compiler.service.js +180 -0
- package/lib/cjs/Compiler/process/index.js +26 -0
- package/lib/cjs/Compiler/process/logger.js +7 -0
- package/lib/cjs/Compiler/process/stats.js +110 -0
- package/lib/cjs/index.js +2 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -25
- package/types/Compiler/{index.d.ts → compiler.service.d.ts} +7 -11
- package/types/Compiler/compiler.service.d.ts.map +1 -0
- package/types/Compiler/process/index.d.ts +4 -0
- package/types/Compiler/process/index.d.ts.map +1 -0
- package/types/Compiler/process/logger.d.ts +2 -0
- package/types/Compiler/process/logger.d.ts.map +1 -0
- package/types/Compiler/process/stats.d.ts +4 -0
- package/types/Compiler/process/stats.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/lib/cjs/Compiler/index.js +0 -187
- package/lib/cjs/Compiler/index.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/esm/Compiler/index.js +0 -183
- package/lib/esm/Compiler/index.js.map +0 -1
- package/lib/esm/index.js +0 -13
- package/lib/esm/index.js.map +0 -1
- package/lib/tsconfig-esm.tsbuildinfo +0 -1
- package/types/Compiler/index.d.ts.map +0 -1
@@ -0,0 +1,180 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
17
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
19
|
+
};
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
21
|
+
if (mod && mod.__esModule) return mod;
|
22
|
+
var result = {};
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
24
|
+
__setModuleDefault(result, mod);
|
25
|
+
return result;
|
26
|
+
};
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
28
|
+
exports.Compiler = void 0;
|
29
|
+
const bud_framework_1 = require("@roots/bud-framework");
|
30
|
+
const bud_support_1 = require("@roots/bud-support");
|
31
|
+
const webpack_1 = require("webpack");
|
32
|
+
const budProcess = __importStar(require("./process"));
|
33
|
+
const { isFunction } = bud_support_1.lodash;
|
34
|
+
/**
|
35
|
+
* Wepback compilation controller class
|
36
|
+
*
|
37
|
+
* @public
|
38
|
+
*/
|
39
|
+
class Compiler extends bud_framework_1.Service {
|
40
|
+
constructor() {
|
41
|
+
super(...arguments);
|
42
|
+
/**
|
43
|
+
* Compilation stats
|
44
|
+
*
|
45
|
+
* @public
|
46
|
+
*/
|
47
|
+
this.stats = {
|
48
|
+
assets: [],
|
49
|
+
errors: [],
|
50
|
+
warnings: [],
|
51
|
+
};
|
52
|
+
/**
|
53
|
+
* Compiler errors
|
54
|
+
*/
|
55
|
+
this.errors = [];
|
56
|
+
/**
|
57
|
+
* True if compiler is already instantiated
|
58
|
+
*
|
59
|
+
* @public
|
60
|
+
*/
|
61
|
+
this.isCompiled = false;
|
62
|
+
/**
|
63
|
+
* @public
|
64
|
+
*/
|
65
|
+
this.config = [];
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* Initiates compilation
|
69
|
+
*
|
70
|
+
* @returns the compiler instance
|
71
|
+
*
|
72
|
+
* @public
|
73
|
+
* @decorator `@bind`
|
74
|
+
*/
|
75
|
+
async compile() {
|
76
|
+
const config = await this.before();
|
77
|
+
const compiler = await this.invoke(config);
|
78
|
+
this.app.timeEnd('bud');
|
79
|
+
return compiler;
|
80
|
+
}
|
81
|
+
/**
|
82
|
+
* @public
|
83
|
+
* @decorator `@bind`
|
84
|
+
*/
|
85
|
+
async invoke(config) {
|
86
|
+
config = await this.app.hooks.filterAsync('event.compiler.before', config);
|
87
|
+
this.instance = (0, webpack_1.webpack)(this.app.hooks.filter('config.override', config));
|
88
|
+
this.instance.hooks.done.tap(config.shift().name, async (stats) => {
|
89
|
+
if (this.app.isDevelopment)
|
90
|
+
await this.handleStats(stats);
|
91
|
+
});
|
92
|
+
new webpack_1.ProgressPlugin((...args) => {
|
93
|
+
args[1] = args[1].replace('[0] ', '');
|
94
|
+
const shouldLog = !this.progress ||
|
95
|
+
!this.progress[1] ||
|
96
|
+
(args[1] !== this.progress[1] && args[1] !== '');
|
97
|
+
this.progress = [args[0] * 100, args[1]];
|
98
|
+
this.progress[0] < 100 && shouldLog
|
99
|
+
? budProcess.logger.await(`[${Math.ceil(this.progress[0])}] `, this.progress[1])
|
100
|
+
: budProcess.logger.success(`[${Math.ceil(this.progress[0])}] `, `🎉 ${this.progress[1]}`);
|
101
|
+
}).apply(this.instance);
|
102
|
+
this.app.hooks.filter('event.compiler.after', this.app);
|
103
|
+
return this.instance;
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* Returns final webpack configuration
|
107
|
+
*
|
108
|
+
* @public
|
109
|
+
* @decorator `@bind`
|
110
|
+
*/
|
111
|
+
async before() {
|
112
|
+
const config = [];
|
113
|
+
this.isCompiled = true;
|
114
|
+
await this.app.build.make();
|
115
|
+
/**
|
116
|
+
* Attempt to use the parent instance in the compilation if there are entries
|
117
|
+
* registered to it or if it has no child instances registered.
|
118
|
+
*/
|
119
|
+
if (!this.app.hasChildren) {
|
120
|
+
this.app.info(`using config from parent compiler`);
|
121
|
+
config.push(this.app.build.config);
|
122
|
+
return config;
|
123
|
+
}
|
124
|
+
this.app.warn(`root compiler will not be tapped (child compilers in use)`);
|
125
|
+
/**
|
126
|
+
* If there are {@link Framework.children} instances, iterate through
|
127
|
+
* them and add to `config`
|
128
|
+
*/
|
129
|
+
await Promise.all(this.app.children?.getValues().map(async (instance) => {
|
130
|
+
if (!instance.name)
|
131
|
+
return;
|
132
|
+
await instance.build.make();
|
133
|
+
config.push(instance.build.config);
|
134
|
+
}));
|
135
|
+
return config;
|
136
|
+
}
|
137
|
+
async callback(error, stats) {
|
138
|
+
await this.handleErrors(error);
|
139
|
+
await this.handleStats(stats);
|
140
|
+
this.instance.close(err => {
|
141
|
+
err && this.app.error(err);
|
142
|
+
this.app.close();
|
143
|
+
});
|
144
|
+
}
|
145
|
+
async handleStats(stats) {
|
146
|
+
if (!stats?.toJson || !isFunction(stats?.toJson))
|
147
|
+
return;
|
148
|
+
this.stats = stats.toJson(this.app.store.get('build.stats'));
|
149
|
+
budProcess.stats.write(this.stats, this.app.store.get('theme.colors'));
|
150
|
+
await this.app.hooks.filter('event.compiler.stats', async () => this.stats);
|
151
|
+
}
|
152
|
+
async handleErrors(error) {
|
153
|
+
if (!error)
|
154
|
+
return;
|
155
|
+
this.app.isDevelopment &&
|
156
|
+
this.app.server.middleware?.hot?.publish({ error });
|
157
|
+
this.app.error(error);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
__decorate([
|
161
|
+
bud_support_1.bind,
|
162
|
+
bud_support_1.once
|
163
|
+
], Compiler.prototype, "compile", null);
|
164
|
+
__decorate([
|
165
|
+
bud_support_1.bind
|
166
|
+
], Compiler.prototype, "invoke", null);
|
167
|
+
__decorate([
|
168
|
+
bud_support_1.bind,
|
169
|
+
bud_support_1.once
|
170
|
+
], Compiler.prototype, "before", null);
|
171
|
+
__decorate([
|
172
|
+
bud_support_1.bind
|
173
|
+
], Compiler.prototype, "callback", null);
|
174
|
+
__decorate([
|
175
|
+
bud_support_1.bind
|
176
|
+
], Compiler.prototype, "handleStats", null);
|
177
|
+
__decorate([
|
178
|
+
bud_support_1.bind
|
179
|
+
], Compiler.prototype, "handleErrors", null);
|
180
|
+
exports.Compiler = Compiler;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
22
|
+
exports.logger = exports.stats = void 0;
|
23
|
+
const stats = __importStar(require("./stats"));
|
24
|
+
exports.stats = stats;
|
25
|
+
var logger_1 = require("./logger");
|
26
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
@@ -0,0 +1,110 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.write = void 0;
|
4
|
+
const bud_support_1 = require("@roots/bud-support");
|
5
|
+
function makeTable(data) {
|
6
|
+
return bud_support_1.table.table(data, {
|
7
|
+
border: bud_support_1.table.getBorderCharacters('void'),
|
8
|
+
columnDefault: {
|
9
|
+
alignment: 'left',
|
10
|
+
paddingLeft: 2,
|
11
|
+
paddingRight: 2,
|
12
|
+
},
|
13
|
+
columns: [
|
14
|
+
{ alignment: 'left' },
|
15
|
+
{ alignment: 'center' },
|
16
|
+
{ alignment: 'center' },
|
17
|
+
{ alignment: 'right' },
|
18
|
+
],
|
19
|
+
});
|
20
|
+
}
|
21
|
+
function write(stats, colors) {
|
22
|
+
const compilers = stats.children?.map(compilation => {
|
23
|
+
if (!compilation?.entrypoints)
|
24
|
+
return compilation;
|
25
|
+
const errors = compilation.errors?.map(error => {
|
26
|
+
return (0, bud_support_1.boxen)(`\n${error.message}`, {
|
27
|
+
title: `${error.title ?? 'error'}`,
|
28
|
+
margin: {
|
29
|
+
top: 0,
|
30
|
+
bottom: 1,
|
31
|
+
left: 0,
|
32
|
+
right: 0,
|
33
|
+
},
|
34
|
+
padding: {
|
35
|
+
top: 0,
|
36
|
+
bottom: 0,
|
37
|
+
right: 0,
|
38
|
+
left: 0,
|
39
|
+
},
|
40
|
+
borderColor: colors.error,
|
41
|
+
});
|
42
|
+
});
|
43
|
+
const warnings = compilation.warnings?.map(warning => {
|
44
|
+
return (0, bud_support_1.boxen)(`\n${warning.message}`, {
|
45
|
+
title: `${warning.title ?? 'warning'}`,
|
46
|
+
margin: {
|
47
|
+
top: 0,
|
48
|
+
bottom: 1,
|
49
|
+
left: 0,
|
50
|
+
right: 0,
|
51
|
+
},
|
52
|
+
padding: {
|
53
|
+
top: 0,
|
54
|
+
bottom: 0,
|
55
|
+
right: 0,
|
56
|
+
left: 0,
|
57
|
+
},
|
58
|
+
borderColor: colors.warning,
|
59
|
+
});
|
60
|
+
});
|
61
|
+
const assets = (0, bud_support_1.boxen)(makeTable([
|
62
|
+
[' name', 'cached', 'hot', 'size'].map(i => bud_support_1.chalk.bold.hex(colors.flavor)(i)),
|
63
|
+
...compilation.assets
|
64
|
+
?.filter(({ emitted }) => emitted)
|
65
|
+
.map(asset => [
|
66
|
+
bud_support_1.chalk.hex(asset.info.error
|
67
|
+
? colors.error
|
68
|
+
: asset.info.warn
|
69
|
+
? colors.warning
|
70
|
+
: '#FFFFFF')(` ${asset.name}`),
|
71
|
+
asset.cached
|
72
|
+
? bud_support_1.chalk.hex(colors.success)('✔')
|
73
|
+
: bud_support_1.chalk.hex(colors.faded)('✘'),
|
74
|
+
asset.info.hotModuleReplacement
|
75
|
+
? bud_support_1.chalk.hex(colors.success)('✔')
|
76
|
+
: bud_support_1.chalk.hex(colors.faded)('✘'),
|
77
|
+
bud_support_1.humanReadable.sizeFormatter()(asset.info.size),
|
78
|
+
]),
|
79
|
+
]), {
|
80
|
+
title: `assets`,
|
81
|
+
margin: {
|
82
|
+
top: 1,
|
83
|
+
bottom: 1,
|
84
|
+
left: 0,
|
85
|
+
right: 0,
|
86
|
+
},
|
87
|
+
padding: {
|
88
|
+
left: 0,
|
89
|
+
top: 1,
|
90
|
+
right: 0,
|
91
|
+
bottom: 0,
|
92
|
+
},
|
93
|
+
borderColor: colors.accent,
|
94
|
+
});
|
95
|
+
return {
|
96
|
+
...compilation,
|
97
|
+
boxes: [
|
98
|
+
compilation.errorsCount ? errors.join('\n') : null,
|
99
|
+
compilation.warningsCount ? warnings.join('\n') : null,
|
100
|
+
compilation.assets.filter(({ emitted }) => emitted).length
|
101
|
+
? assets
|
102
|
+
: null,
|
103
|
+
].filter(Boolean),
|
104
|
+
};
|
105
|
+
});
|
106
|
+
const out = compilers?.map(compiler => compiler.boxes.join(''));
|
107
|
+
// eslint-disable-next-line no-console
|
108
|
+
console.log(out.join(''));
|
109
|
+
}
|
110
|
+
exports.write = write;
|
package/lib/cjs/index.js
CHANGED
@@ -12,6 +12,5 @@ exports.Compiler = void 0;
|
|
12
12
|
*
|
13
13
|
* @packageDocumentation
|
14
14
|
*/
|
15
|
-
var
|
16
|
-
Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return
|
17
|
-
//# sourceMappingURL=index.js.map
|
15
|
+
var compiler_service_1 = require("./Compiler/compiler.service");
|
16
|
+
Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return compiler_service_1.Compiler; } });
|