@roots/bud-compiler 5.0.0-next.8 → 5.2.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
@@ -1,41 +1,25 @@
1
1
  <p align="center">
2
- <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
2
+ <img src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" alt="Bud" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <img
7
- alt="MIT License"
8
- src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square"
9
- />
10
- <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Froots%2Fbud?ref=badge_small" alt="FOSSA Status">
11
- <img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Froots%2Fbud.svg?type=small"/>
12
- </a>
13
- <a href="https://www.npmjs.com/package/@roots/bud">
14
- <img src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" />
15
- </a>
16
- <a href="https://codecov.io/gh/roots/bud">
17
- <img src="https://codecov.io/gh/roots/bud/branch/next/graph/badge.svg?token=DRJ28OD8XD"/>
18
- </a>
19
- <a href="https://twitter.com/rootswp">
20
- <img
21
- alt="Follow Roots"
22
- src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square"
23
- />
24
- </a>
6
+ <img alt="MIT License" src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square" /> <img alt="npm" src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" /> <img alt="Follow Roots" src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square" />
25
7
  </p>
26
8
 
27
-
28
9
  <h1 align="center">
29
10
  <strong>@roots/bud-compiler</strong>
30
11
  </h1>
31
12
 
32
- > Compilation handler
13
+ <p align="center">
14
+ Compilation handler
15
+ </p>
16
+
33
17
  ## Installation
34
18
 
35
19
  Install **@roots/bud-compiler** to your project.
36
20
 
37
21
  ```shell
38
- yarn add @roots/bud-compiler
22
+ yarn add @roots/bud-compiler --dev
39
23
  ```
40
24
 
41
25
  ## Documentation
@@ -67,8 +51,4 @@ Help support our open-source development efforts by [becoming a patron](https://
67
51
  <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
68
52
  <a href="https://www.c21redwood.com/"><img src="https://cdn.roots.io/app/uploads/c21redwood.svg" alt="C21 Redwood Realty" width="200" height="150"/></a>
69
53
  <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/></a>
70
- <a href="https://icons8.com/"><img src="https://cdn.roots.io/app/uploads/icons8.svg" alt="Icons8" width="200" height="150"/></a>
71
- <a href="https://www.harnessup.com/"><img src="https://cdn.roots.io/app/uploads/harness-software.svg" alt="Harness Software" width="200" height="150"/></a>
72
- <a href="https://www.codersclan.com/"><img src="https://cdn.roots.io/app/uploads/coders-clan.svg" alt="Coders Clan" width="200" height="150"/></a>
73
- <a href="https://generodigital.com/"><img src="https://cdn.roots.io/app/uploads/genero.svg" alt="Genero" width="200" height="150"/></a>
74
- <a href="https://motto.ca/roots"><img src="https://cdn.roots.io/app/uploads/motto.svg" alt="Motto" width="200" height="150"/></a>
54
+ <a href="https://pantheon.io/"><img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/></a>
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.Compiler = void 0;
4
- const tslib_1 = require("tslib");
5
10
  const bud_framework_1 = require("@roots/bud-framework");
6
11
  const bud_support_1 = require("@roots/bud-support");
7
12
  const webpack_1 = require("webpack");
8
13
  const { isFunction } = bud_support_1.lodash;
9
- const helpful_decorators_1 = require("helpful-decorators");
10
14
  /**
11
15
  * Initial state
12
16
  *
@@ -31,6 +35,10 @@ class Compiler extends bud_framework_1.Service {
31
35
  * @public
32
36
  */
33
37
  this.stats = INITIAL_STATS;
38
+ /**
39
+ * Compiler errors
40
+ */
41
+ this.errors = [];
34
42
  /**
35
43
  * True if compiler is already instantiated
36
44
  *
@@ -42,15 +50,6 @@ class Compiler extends bud_framework_1.Service {
42
50
  */
43
51
  this.config = [];
44
52
  }
45
- /**
46
- * {@inheritDoc @roots/bud-framework#Service.register}
47
- *
48
- * @public
49
- * @decorator `@bind`
50
- */
51
- register() {
52
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { });
53
- }
54
53
  /**
55
54
  * Initiates compilation
56
55
  *
@@ -59,40 +58,42 @@ class Compiler extends bud_framework_1.Service {
59
58
  * @public
60
59
  * @decorator `@bind`
61
60
  */
62
- compile() {
63
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
64
- const config = yield this.before();
65
- const compiler = yield this.invokeCompiler(config);
66
- this.app.timeEnd('bud');
67
- return compiler;
68
- });
61
+ async compile() {
62
+ const config = await this.before();
63
+ const compiler = await this.invoke(config);
64
+ this.app.timeEnd('bud');
65
+ return compiler;
69
66
  }
70
67
  /**
71
68
  * @public
72
69
  * @decorator `@bind`
73
70
  */
74
- invokeCompiler(config) {
75
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
76
- this.app.hooks.filter('before.compiler');
77
- this.instance = (0, webpack_1.webpack)(config);
78
- this.instance.hooks.done.tap(config[0].name, (stats) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
79
- stats && Object.assign(this.stats, stats.toJson());
80
- if (this.app.isProduction) {
81
- this.instance.close(err => {
82
- if (err) {
83
- this.stats.errors.push(err);
84
- this.log('error', err);
85
- }
86
- this.app.close(() => { });
87
- });
88
- }
89
- }));
90
- new webpack_1.ProgressPlugin((...args) => {
91
- this.progress = args;
92
- }).apply(this.instance);
93
- this.app.hooks.filter('after.compiler');
94
- return this.instance;
71
+ async invoke(config) {
72
+ config = await this.app.hooks.filterAsync('event.compiler.before', config);
73
+ config = this.app.hooks.filter('config.override', config);
74
+ this.instance = (0, webpack_1.webpack)(config);
75
+ this.instance.hooks.done.tap(config[0].name, async (stats) => {
76
+ this.app.hooks.filter('event.compiler.done', stats);
77
+ stats && Object.assign(this.stats, stats.toJson());
78
+ if (this.app.store.is('features.dashboard', false)) {
79
+ this.log('log', stats.toString(this.app.store.get('build.stats')));
80
+ }
81
+ if (this.app.isProduction) {
82
+ this.instance.close(err => {
83
+ if (err) {
84
+ err = this.app.hooks.filter('event.compiler.error', err);
85
+ this.stats.errors.push(err);
86
+ this.log('error', err);
87
+ }
88
+ !this.app.dashboard.instance && this.app.close();
89
+ });
90
+ }
95
91
  });
92
+ new webpack_1.ProgressPlugin((...args) => {
93
+ this.progress = args;
94
+ }).apply(this.instance);
95
+ this.app.hooks.filter('event.compiler.after', this.app);
96
+ return this.instance;
96
97
  }
97
98
  /**
98
99
  * Returns final webpack configuration
@@ -100,39 +101,37 @@ class Compiler extends bud_framework_1.Service {
100
101
  * @public
101
102
  * @decorator `@bind`
102
103
  */
103
- before() {
104
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
105
- const config = [];
106
- this.stats = INITIAL_STATS;
107
- this.isCompiled = true;
108
- !this.app.isRoot &&
109
- this.log('error', `Attempting to compile a child directly. Only the parent instance should be compiled.`);
110
- yield this.app.build.make();
111
- /**
112
- * Attempt to use the parent instance in the compilation if there are entries
113
- * registered to it or if it has no child instances registered.
114
- */
115
- if (this.app.children.getEntries().length === 0) {
116
- this.app.info(`using config from parent compiler`);
117
- config.push(this.app.build.config);
118
- return config;
119
- }
120
- else {
121
- this.app.warn(`root compiler will not be tapped (child compilers in use)`);
122
- }
123
- /**
124
- * If there are {@link Framework.children} instances, iterate through
125
- * them and add to `config`
126
- */
127
- yield Promise.all(this.app.children.getValues().map((instance) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
128
- if (!instance.name)
129
- return;
130
- this.log('success', `\`${instance.name}\` compiler will be tapped`);
131
- yield instance.build.make();
132
- config.push(instance.build.config);
133
- })));
104
+ async before() {
105
+ const config = [];
106
+ this.stats = INITIAL_STATS;
107
+ this.isCompiled = true;
108
+ !this.app.isRoot &&
109
+ this.log('error', `Attempting to compile a child directly. Only the parent instance should be compiled.`);
110
+ await this.app.build.make();
111
+ /**
112
+ * Attempt to use the parent instance in the compilation if there are entries
113
+ * registered to it or if it has no child instances registered.
114
+ */
115
+ if (!this.app.hasChildren) {
116
+ this.app.info(`using config from parent compiler`);
117
+ config.push(this.app.build.config);
134
118
  return config;
135
- });
119
+ }
120
+ else {
121
+ this.app.warn(`root compiler will not be tapped (child compilers in use)`);
122
+ }
123
+ /**
124
+ * If there are {@link Framework.children} instances, iterate through
125
+ * them and add to `config`
126
+ */
127
+ await Promise.all(this.app.children?.getValues().map(async (instance) => {
128
+ if (!instance.name)
129
+ return;
130
+ this.log('success', `\`${instance.name}\` compiler will be tapped`);
131
+ await instance.build.make();
132
+ config.push(instance.build.config);
133
+ }));
134
+ return config;
136
135
  }
137
136
  /**
138
137
  * Compilation callback
@@ -141,7 +140,6 @@ class Compiler extends bud_framework_1.Service {
141
140
  * @decorator `@bind`
142
141
  */
143
142
  callback(...args) {
144
- var _a;
145
143
  /**
146
144
  * production mode callback takes two parameters (webpack err and stats)
147
145
  * however, the done hook used in development just takes one (stats)
@@ -149,33 +147,35 @@ class Compiler extends bud_framework_1.Service {
149
147
  * here we parse the callback args so that we dont have to
150
148
  * duplicate the callback.
151
149
  */
152
- const [err, stats] = args.length > 1 ? args : [null, args.pop()];
153
- if ((stats === null || stats === void 0 ? void 0 : stats.toJson) && isFunction(stats.toJson)) {
154
- this.stats = stats.toJson((_a = this.app.build.config.stats) !== null && _a !== void 0 ? _a : { preset: 'normal' });
155
- this.app.store.is('ci', true) &&
156
- this.app.log(stats.toString());
150
+ let [err, stats] = args.length > 1 ? args : [null, args.pop()];
151
+ if (stats?.toJson && isFunction(stats.toJson)) {
152
+ this.stats = stats.toJson(this.app.store.get('build.stats'));
153
+ this.stats = this.app.hooks.filter('event.compiler.stats', this.stats);
157
154
  }
158
155
  if (err) {
159
- this.stats.errors.push(err);
160
- this.app.store.is('ci', true) && this.log('error', err);
156
+ if (this.app.isDevelopment) {
157
+ this.app.server.middleware?.hot?.publish({
158
+ errors: stats.toJson(this.app.store.get('build.stats')).errors,
159
+ });
160
+ }
161
+ this.errors.push(this.app.hooks.filter('event.compiler.error', err));
162
+ this.app.store.is('features.dashboard', false) &&
163
+ this.log('error', err);
161
164
  }
162
165
  }
163
166
  }
164
- (0, tslib_1.__decorate)([
165
- bud_support_1.bind
166
- ], Compiler.prototype, "register", null);
167
- (0, tslib_1.__decorate)([
168
- bud_support_1.bind
167
+ __decorate([
168
+ bud_support_1.bind,
169
+ bud_support_1.once
169
170
  ], Compiler.prototype, "compile", null);
170
- (0, tslib_1.__decorate)([
171
+ __decorate([
171
172
  bud_support_1.bind
172
- ], Compiler.prototype, "invokeCompiler", null);
173
- (0, tslib_1.__decorate)([
173
+ ], Compiler.prototype, "invoke", null);
174
+ __decorate([
174
175
  bud_support_1.bind,
175
- helpful_decorators_1.once
176
+ bud_support_1.once
176
177
  ], Compiler.prototype, "before", null);
177
- (0, tslib_1.__decorate)([
178
+ __decorate([
178
179
  bud_support_1.bind
179
180
  ], Compiler.prototype, "callback", null);
180
181
  exports.Compiler = Compiler;
181
- //# sourceMappingURL=index.js.map
package/lib/cjs/index.js CHANGED
@@ -10,8 +10,7 @@ exports.Compiler = void 0;
10
10
  * @see https://roots.io/bud
11
11
  * @see https://github.com/roots/bud
12
12
  *
13
- * @core @packageDocumentation @betaDocumentation
13
+ * @packageDocumentation
14
14
  */
15
15
  var Compiler_1 = require("./Compiler");
16
16
  Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return Compiler_1.Compiler; } });
17
- //# sourceMappingURL=index.js.map