@roots/bud-compiler 6.6.9 → 6.7.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 +3 -0
- package/lib/compiler.service.d.ts +0 -2
- package/lib/compiler.service.d.ts.map +1 -1
- package/lib/compiler.service.js +11 -4
- package/lib/compiler.service.js.map +1 -1
- package/package.json +15 -7
- package/src/compiler.service.ts +127 -0
- package/src/compiler.test.ts +75 -0
- package/src/index.ts +15 -0
package/README.md
CHANGED
@@ -67,3 +67,6 @@ Help support our open-source development efforts by [becoming a patron](https://
|
|
67
67
|
<a href="https://pantheon.io/">
|
68
68
|
<img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/>
|
69
69
|
</a>
|
70
|
+
<a href="https://worksitesafety.ca/careers/">
|
71
|
+
<img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="200" height="150"/>
|
72
|
+
</a>
|
@@ -4,8 +4,6 @@ import type webpack from '@roots/bud-support/webpack';
|
|
4
4
|
import type { MultiCompiler, MultiStats, WebpackError } from '@roots/bud-support/webpack';
|
5
5
|
/**
|
6
6
|
* Wepback compilation controller class
|
7
|
-
*
|
8
|
-
* @public
|
9
7
|
*/
|
10
8
|
export declare class Compiler extends Service implements Contract.Service {
|
11
9
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"compiler.service.d.ts","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,EAAC,QAAQ,IAAI,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AAEvE,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAA;AACrD,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACb,MAAM,4BAA4B,CAAA;AAEnC
|
1
|
+
{"version":3,"file":"compiler.service.d.ts","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,EAAC,QAAQ,IAAI,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AAEvE,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAA;AACrD,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACb,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,QAAS,SAAQ,OAAQ,YAAW,QAAQ,CAAC,OAAO;IAC/D;;;OAGG;IACI,cAAc,EAAE,OAAO,OAAO,CAAA;IAErC;;;OAGG;IACI,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7C;;;OAGG;IACI,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvC;;;OAGG;IACI,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAK;IAE9C;;;;;;;;OAQG;IAEU,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAyC9C;;;;;OAKG;IAEU,OAAO,CAAC,KAAK,EAAE,UAAU;IAgBtC;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,YAAY;CAMnC"}
|
package/lib/compiler.service.js
CHANGED
@@ -3,8 +3,6 @@ import { Service } from '@roots/bud-framework/service';
|
|
3
3
|
import { bind } from '@roots/bud-support/decorators';
|
4
4
|
/**
|
5
5
|
* Wepback compilation controller class
|
6
|
-
*
|
7
|
-
* @public
|
8
6
|
*/
|
9
7
|
export class Compiler extends Service {
|
10
8
|
constructor() {
|
@@ -65,8 +63,17 @@ export class Compiler extends Service {
|
|
65
63
|
* @decorator `@bind`
|
66
64
|
*/
|
67
65
|
async onStats(stats) {
|
68
|
-
this.stats = stats;
|
69
|
-
|
66
|
+
this.stats = stats.toJson(this.app.hooks.filter(`build.stats`));
|
67
|
+
if (this.stats.errorsCount > 0 ||
|
68
|
+
this.stats.children?.some(child => child.errorsCount > 0)) {
|
69
|
+
process.exitCode = 1;
|
70
|
+
}
|
71
|
+
try {
|
72
|
+
await this.app.dashboard.update(stats);
|
73
|
+
}
|
74
|
+
catch (error) {
|
75
|
+
throw error;
|
76
|
+
}
|
70
77
|
}
|
71
78
|
/**
|
72
79
|
* Compiler error event
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"compiler.service.js","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAQlD
|
1
|
+
{"version":3,"file":"compiler.service.js","sourceRoot":"","sources":["../src/compiler.service.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAQlD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,OAAO;IAArC;;QAmBE;;;WAGG;QACI,WAAM,GAA+B,EAAE,CAAA;IAyFhD,CAAC;IAvFC;;;;;;;;OAQG;IAEU,AAAN,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,cAAc,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAC7D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QAEhE,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW;YACjC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAA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AAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IAEU,AAAN,KAAK,CAAC,OAAO,CAAC,KAAiB;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;QAC/D,IACE,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,EACzD;YACA,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;SACrB;QAED,IAAI;YACF,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;SACvC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;IAED;;;;;OAKG;IAEI,OAAO,CAAC,KAAmB;QAChC,IAAI,CAAC,GAAG,CAAC,aAAa;YACpB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,GAAG,EAAE,OAAO,CAAC,EAAC,KAAK,EAAC,CAAC,CAAA;QAE1D,MAAM,KAAK,CAAA;IACb,CAAC;CACF;AA7Ec;IADZ,IAAI;;;;uCAwCJ;AASY;IADZ,IAAI;;;;uCAeJ;AAQD;IAAC,IAAI;;;;uCAMJ"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@roots/bud-compiler",
|
3
3
|
"description": "Compilation handler",
|
4
|
-
"version": "6.
|
4
|
+
"version": "6.7.0",
|
5
5
|
"homepage": "https://roots.io/bud",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
@@ -10,9 +10,15 @@
|
|
10
10
|
},
|
11
11
|
"contributors": [
|
12
12
|
{
|
13
|
-
"name": "
|
13
|
+
"name": "Kelly Mears",
|
14
|
+
"email": "developers@tinypixel.dev",
|
14
15
|
"url": "https://github.com/kellymears"
|
15
16
|
},
|
17
|
+
{
|
18
|
+
"name": "Ben Word",
|
19
|
+
"email": "ben@benword.com",
|
20
|
+
"url": "https://github.com/retlehs"
|
21
|
+
},
|
16
22
|
{
|
17
23
|
"name": "QWp6t",
|
18
24
|
"url": "https://github.com/QWp6t"
|
@@ -34,7 +40,9 @@
|
|
34
40
|
"node": ">=16"
|
35
41
|
},
|
36
42
|
"files": [
|
37
|
-
"
|
43
|
+
"docs",
|
44
|
+
"lib",
|
45
|
+
"src"
|
38
46
|
],
|
39
47
|
"type": "module",
|
40
48
|
"module": "./lib/index.js",
|
@@ -50,13 +58,13 @@
|
|
50
58
|
}
|
51
59
|
},
|
52
60
|
"devDependencies": {
|
53
|
-
"@roots/bud-api": "6.
|
61
|
+
"@roots/bud-api": "6.7.0",
|
54
62
|
"@skypack/package-check": "0.2.2",
|
55
|
-
"@types/node": "
|
63
|
+
"@types/node": "18.11.18"
|
56
64
|
},
|
57
65
|
"dependencies": {
|
58
|
-
"@roots/bud-framework": "6.
|
59
|
-
"@roots/bud-support": "6.
|
66
|
+
"@roots/bud-framework": "6.7.0",
|
67
|
+
"@roots/bud-support": "6.7.0"
|
60
68
|
},
|
61
69
|
"volta": {
|
62
70
|
"extends": "../../../package.json"
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import type {Bud} from '@roots/bud-framework/bud'
|
2
|
+
import {Service} from '@roots/bud-framework/service'
|
3
|
+
import type {Compiler as Contract} from '@roots/bud-framework/services'
|
4
|
+
import {bind} from '@roots/bud-support/decorators'
|
5
|
+
import type webpack from '@roots/bud-support/webpack'
|
6
|
+
import type {
|
7
|
+
MultiCompiler,
|
8
|
+
MultiStats,
|
9
|
+
WebpackError,
|
10
|
+
} from '@roots/bud-support/webpack'
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Wepback compilation controller class
|
14
|
+
*/
|
15
|
+
export class Compiler extends Service implements Contract.Service {
|
16
|
+
/**
|
17
|
+
* Compiler implementation
|
18
|
+
* @public
|
19
|
+
*/
|
20
|
+
public implementation: typeof webpack
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Compiler instance
|
24
|
+
* @public
|
25
|
+
*/
|
26
|
+
public instance: Contract.Service[`instance`]
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Compilation stats
|
30
|
+
* @public
|
31
|
+
*/
|
32
|
+
public stats: Contract.Service[`stats`]
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Configuration
|
36
|
+
* @public
|
37
|
+
*/
|
38
|
+
public config: Contract.Service[`config`] = []
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Initiates compilation
|
42
|
+
*
|
43
|
+
* @returns the compiler instance
|
44
|
+
*
|
45
|
+
* @public
|
46
|
+
* @decorator `@bind`
|
47
|
+
* @decorator `@once`
|
48
|
+
*/
|
49
|
+
@bind
|
50
|
+
public async compile(): Promise<MultiCompiler> {
|
51
|
+
this.implementation = await this.app.module.import(`webpack`)
|
52
|
+
this.logger.log(`imported webpack`, this.implementation.version)
|
53
|
+
|
54
|
+
this.config = !this.app.hasChildren
|
55
|
+
? [await this.app.build.make()]
|
56
|
+
: await Promise.all(
|
57
|
+
Object.values(this.app.children).map(async (child: Bud) => {
|
58
|
+
try {
|
59
|
+
return await child.build.make()
|
60
|
+
} catch (error) {
|
61
|
+
throw error
|
62
|
+
}
|
63
|
+
}),
|
64
|
+
)
|
65
|
+
|
66
|
+
try {
|
67
|
+
await this.app.hooks.fire(`compiler.before`)
|
68
|
+
} catch (error) {
|
69
|
+
throw error
|
70
|
+
}
|
71
|
+
|
72
|
+
if (this.app.isCLI() && this.app.context.args.dry) {
|
73
|
+
this.logger.log(`running in dry mode. exiting early.`)
|
74
|
+
return
|
75
|
+
}
|
76
|
+
|
77
|
+
this.app.context.logger.timeEnd(`initialize`)
|
78
|
+
|
79
|
+
this.instance = this.implementation(this.config)
|
80
|
+
this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
|
81
|
+
await this.onStats(stats)
|
82
|
+
})
|
83
|
+
this.instance.hooks.done.tap(`${this.app.label}-close`, async () => {
|
84
|
+
await this.app.hooks.fire(`compiler.close`)
|
85
|
+
})
|
86
|
+
|
87
|
+
await this.app.hooks.fire(`compiler.after`)
|
88
|
+
return this.instance
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Stats handler
|
93
|
+
*
|
94
|
+
* @public
|
95
|
+
* @decorator `@bind`
|
96
|
+
*/
|
97
|
+
@bind
|
98
|
+
public async onStats(stats: MultiStats) {
|
99
|
+
this.stats = stats.toJson(this.app.hooks.filter(`build.stats`))
|
100
|
+
if (
|
101
|
+
this.stats.errorsCount > 0 ||
|
102
|
+
this.stats.children?.some(child => child.errorsCount > 0)
|
103
|
+
) {
|
104
|
+
process.exitCode = 1
|
105
|
+
}
|
106
|
+
|
107
|
+
try {
|
108
|
+
await this.app.dashboard.update(stats)
|
109
|
+
} catch (error) {
|
110
|
+
throw error
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Compiler error event
|
116
|
+
*
|
117
|
+
* @public
|
118
|
+
* @decorator `@bind`
|
119
|
+
*/
|
120
|
+
@bind
|
121
|
+
public onError(error: WebpackError) {
|
122
|
+
this.app.isDevelopment &&
|
123
|
+
this.app.server.appliedMiddleware?.hot?.publish({error})
|
124
|
+
|
125
|
+
throw error
|
126
|
+
}
|
127
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import {Bud, factory} from '@repo/test-kit/bud'
|
2
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest'
|
3
|
+
|
4
|
+
import Compiler from './index.js'
|
5
|
+
|
6
|
+
describe(`@roots/bud-compiler`, function () {
|
7
|
+
let bud: Bud
|
8
|
+
let compiler: Compiler
|
9
|
+
|
10
|
+
beforeEach(async () => {
|
11
|
+
vi.clearAllMocks()
|
12
|
+
|
13
|
+
bud = await factory({mode: `development`})
|
14
|
+
compiler = new Compiler(() => bud)
|
15
|
+
})
|
16
|
+
|
17
|
+
it(`has compile fn`, () => {
|
18
|
+
expect(compiler.compile).toBeInstanceOf(Function)
|
19
|
+
})
|
20
|
+
|
21
|
+
it(`should call logger.log`, async () => {
|
22
|
+
const logSpy = vi.spyOn(compiler.logger, `log`)
|
23
|
+
await compiler.compile()
|
24
|
+
expect(logSpy).toHaveBeenCalled()
|
25
|
+
})
|
26
|
+
|
27
|
+
it(`should have config with array length 1`, async () => {
|
28
|
+
await compiler.compile()
|
29
|
+
expect(compiler.config).toHaveLength(1)
|
30
|
+
})
|
31
|
+
|
32
|
+
it(`should have config with array length 2 when hasChildren is true`, async () => {
|
33
|
+
// @ts-ignore
|
34
|
+
await bud.make(`foo`)
|
35
|
+
await bud.make(`bar`)
|
36
|
+
|
37
|
+
compiler.app.children = {
|
38
|
+
foo: compiler.app,
|
39
|
+
bar: compiler.app,
|
40
|
+
}
|
41
|
+
|
42
|
+
await compiler.compile()
|
43
|
+
expect(compiler.config).toHaveLength(2)
|
44
|
+
})
|
45
|
+
|
46
|
+
it(`should log early exit (--dry)`, async () => {
|
47
|
+
// @ts-ignore
|
48
|
+
bud.context.args.dry = true
|
49
|
+
const logSpy = vi.spyOn(compiler.logger, `log`)
|
50
|
+
await compiler.compile()
|
51
|
+
expect(logSpy).toHaveBeenCalledTimes(2)
|
52
|
+
})
|
53
|
+
|
54
|
+
it(`should set done tap`, async () => {
|
55
|
+
try {
|
56
|
+
await compiler.compile()
|
57
|
+
expect(compiler.instance.hooks.done.tap).toHaveBeenCalledWith(
|
58
|
+
`MOCK-dev-handle`,
|
59
|
+
compiler.onStats,
|
60
|
+
)
|
61
|
+
} catch (e) {}
|
62
|
+
})
|
63
|
+
|
64
|
+
it(`has onStats fn`, () => {
|
65
|
+
expect(compiler.onStats).toBeInstanceOf(Function)
|
66
|
+
})
|
67
|
+
|
68
|
+
it(`has error handler`, () => {
|
69
|
+
expect(compiler.onError).toBeInstanceOf(Function)
|
70
|
+
})
|
71
|
+
|
72
|
+
it(`has close handler`, () => {
|
73
|
+
expect(compiler.onError).toBeInstanceOf(Function)
|
74
|
+
})
|
75
|
+
})
|
package/src/index.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
// Copyright © Roots Software Foundation LLC
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
|
4
|
+
/**
|
5
|
+
* The bud compiler interface
|
6
|
+
*
|
7
|
+
* @see https://bud.js.org
|
8
|
+
* @see https://github.com/roots/bud
|
9
|
+
*
|
10
|
+
* @packageDocumentation
|
11
|
+
*/
|
12
|
+
|
13
|
+
import {Compiler} from './compiler.service.js'
|
14
|
+
|
15
|
+
export default Compiler
|