@roots/bud-compiler 5.0.0-next.7 → 5.1.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,7 +1,12 @@
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");
@@ -30,22 +35,20 @@ class Compiler extends bud_framework_1.Service {
30
35
  * @public
31
36
  */
32
37
  this.stats = INITIAL_STATS;
38
+ /**
39
+ * Compiler errors
40
+ */
41
+ this.errors = [];
33
42
  /**
34
43
  * True if compiler is already instantiated
35
44
  *
36
45
  * @public
37
46
  */
38
47
  this.isCompiled = false;
39
- }
40
- /**
41
- * {@inheritDoc @roots/bud-framework#Service.register}
42
- *
43
- * @public
44
- * @decorator `@bind`
45
- */
46
- register() {
47
- this.app.hooks.on('before', () => []);
48
- this.app.hooks.on('after', () => []);
48
+ /**
49
+ * @public
50
+ */
51
+ this.config = [];
49
52
  }
50
53
  /**
51
54
  * Initiates compilation
@@ -55,34 +58,41 @@ class Compiler extends bud_framework_1.Service {
55
58
  * @public
56
59
  * @decorator `@bind`
57
60
  */
58
- compile() {
59
- let instance;
60
- if (this.isCompiled)
61
- this.instance.close(() => {
62
- instance = this.invokeCompiler(this.before());
63
- });
64
- else
65
- instance = this.invokeCompiler(this.before());
66
- return instance;
61
+ async compile() {
62
+ const config = await this.before();
63
+ const compiler = await this.invoke(config);
64
+ this.app.timeEnd('bud');
65
+ return compiler;
67
66
  }
68
67
  /**
69
68
  * @public
70
69
  * @decorator `@bind`
71
70
  */
72
- invokeCompiler(config) {
73
- this.instance = this.app.isDevelopment
74
- ? (0, webpack_1.webpack)(config)
75
- : (0, webpack_1.webpack)(config, this.callback);
76
- this.instance.hooks.done.tap(this.app.name, stats => {
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
77
  stats && Object.assign(this.stats, stats.toJson());
78
- this.app.isProduction &&
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) {
79
82
  this.instance.close(err => {
80
- err && this.stats.errors.push(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();
81
89
  });
90
+ }
82
91
  });
83
92
  new webpack_1.ProgressPlugin((...args) => {
84
93
  this.progress = args;
85
94
  }).apply(this.instance);
95
+ this.app.hooks.filter('event.compiler.after', this.app);
86
96
  return this.instance;
87
97
  }
88
98
  /**
@@ -91,36 +101,36 @@ class Compiler extends bud_framework_1.Service {
91
101
  * @public
92
102
  * @decorator `@bind`
93
103
  */
94
- before() {
104
+ async before() {
95
105
  const config = [];
96
106
  this.stats = INITIAL_STATS;
97
107
  this.isCompiled = true;
98
- this.app.hooks.filter('before').map(cb => cb(this.app));
99
- !this.app.parent &&
100
- this.app.error(`Trying to compile a child directly.`);
101
- const instanceConfig = this.app.build.make();
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();
102
111
  /**
103
112
  * Attempt to use the parent instance in the compilation if there are entries
104
113
  * registered to it or if it has no child instances registered.
105
114
  */
106
- if ((this.app.hasChildren && instanceConfig.entry) ||
107
- !this.app.hasChildren) {
108
- this.app.info('using parent compiler');
109
- config.push(instanceConfig);
115
+ if (!this.app.hasChildren) {
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)`);
110
122
  }
111
123
  /**
112
124
  * If there are {@link Framework.children} instances, iterate through
113
125
  * them and add to `config`
114
126
  */
115
- this.app.hasChildren &&
116
- this.app.children.getValues().map(({ build, name }) => {
117
- if (!name)
118
- return;
119
- this.app.info(`using ${name} compiler`);
120
- const childConfig = build.make();
121
- config.push(childConfig);
122
- });
123
- this.app.log('final config', config);
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
+ }));
124
134
  return config;
125
135
  }
126
136
  /**
@@ -137,36 +147,35 @@ class Compiler extends bud_framework_1.Service {
137
147
  * here we parse the callback args so that we dont have to
138
148
  * duplicate the callback.
139
149
  */
140
- const [err, stats] = args.length > 1 ? args : [null, args.pop()];
141
- if ((stats === null || stats === void 0 ? void 0 : stats.toJson) && isFunction(stats.toJson)) {
142
- this.stats = stats.toJson(this.app.build.config.stats);
143
- this.app.store.is('ci', true) &&
144
- // eslint-disable-next-line no-console
145
- console.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);
146
154
  }
147
155
  if (err) {
148
- this.stats.errors.push(err);
149
- // eslint-disable-next-line no-console
150
- this.app.store.is('ci', true) && console.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);
151
164
  }
152
- const doneCallbacks = this.app.hooks.filter('done');
153
- doneCallbacks === null || doneCallbacks === void 0 ? void 0 : doneCallbacks.map((cb) => cb(this.app));
154
165
  }
155
166
  }
156
- (0, tslib_1.__decorate)([
157
- bud_support_1.bind
158
- ], Compiler.prototype, "register", null);
159
- (0, tslib_1.__decorate)([
160
- bud_support_1.bind
167
+ __decorate([
168
+ bud_support_1.bind,
169
+ bud_support_1.once
161
170
  ], Compiler.prototype, "compile", null);
162
- (0, tslib_1.__decorate)([
163
- bud_support_1.bind
164
- ], Compiler.prototype, "invokeCompiler", null);
165
- (0, tslib_1.__decorate)([
171
+ __decorate([
166
172
  bud_support_1.bind
173
+ ], Compiler.prototype, "invoke", null);
174
+ __decorate([
175
+ bud_support_1.bind,
176
+ bud_support_1.once
167
177
  ], Compiler.prototype, "before", null);
168
- (0, tslib_1.__decorate)([
178
+ __decorate([
169
179
  bud_support_1.bind
170
180
  ], Compiler.prototype, "callback", null);
171
181
  exports.Compiler = Compiler;
172
- //# 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