Skip to content

Commit 0cb2f47

Browse files
Include type of bundle in logging #34
1 parent 8af21d0 commit 0cb2f47

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/bundle-orchastrator.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Config } from "./config/config.js";
55
import extend from "just-extend";
66
import { resolve as resolvePath } from "path";
77
import PluginError from "plugin-error";
8-
import { BundleStreamFactory, Bundle } from "./bundle.js";
8+
import { BundleStreamFactory, Bundle, BundleType } from "./bundle.js";
99

1010
const PluginName = "@userfrosting/gulp-bundle-assets";
1111

@@ -55,6 +55,7 @@ export interface Bundlers {
5555
*/
5656
function bundleFactory(
5757
name: string,
58+
type: BundleType,
5859
rawPaths: string[],
5960
cwd: string,
6061
joiner: BundleStreamFactory,
@@ -67,7 +68,7 @@ function bundleFactory(
6768
paths.push(path);
6869
logger.trace(`Resolved path: "${path}"`);
6970
}
70-
return new Bundle(name, paths, joiner, logger);
71+
return new Bundle(name, type, paths, joiner, logger);
7172
}
7273

7374
/**
@@ -146,14 +147,14 @@ export class BundleOrchastrator extends Transform {
146147
// JS
147148
if (bundle.scripts) {
148149
this.logger.trace("Starting processing of script paths");
149-
this.scriptBundles.add(bundleFactory(name, bundle.scripts, cwd, joiner.Scripts, this.logger));
150+
this.scriptBundles.add(bundleFactory(name, "script", bundle.scripts, cwd, joiner.Scripts, this.logger));
150151
this.logger.trace("Completed processing of script paths");
151152
}
152153

153154
// CSS
154155
if (bundle.styles) {
155156
this.logger.trace("Starting processing of style paths");
156-
this.styleBundles.add(bundleFactory(name, bundle.styles, cwd, joiner.Styles, this.logger));
157+
this.styleBundles.add(bundleFactory(name, "style", bundle.styles, cwd, joiner.Styles, this.logger));
157158
this.logger.trace("Completed processing of style paths");
158159
}
159160
}

src/bundle.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function bundleFactoryEcho(src: Readable): Stream {
1717
test("Ignores unused files", async t => {
1818
const bundle = new Bundle(
1919
"test",
20+
"script",
2021
[
2122
resolvePath("./test-used-1.js"),
2223
resolvePath("./test-used-2.js"),
@@ -44,6 +45,7 @@ test("Ignores unused files", async t => {
4445
test("Returns a stream once feed sends in the last required file", async t => {
4546
const bundle = new Bundle(
4647
"test",
48+
"script",
4749
[
4850
resolvePath("./test-1.js"),
4951
resolvePath("./test-2.js"),
@@ -69,6 +71,7 @@ test("Returns a stream once feed sends in the last required file", async t => {
6971
test("Multiple non-Vinyl chunks returned by bundle stream", async t => {
7072
const bundle = new Bundle(
7173
"test",
74+
"script",
7275
[ resolvePath("./test-1.js") ],
7376
function (): Stream {
7477
return intoStream.object([ {}, {} ]);
@@ -86,6 +89,7 @@ test("Multiple non-Vinyl chunks returned by bundle stream", async t => {
8689
test("Single non-Vinyl chunks returned by bundle stream", async t => {
8790
const bundle = new Bundle(
8891
"test",
92+
"script",
8993
[ resolvePath("./test-1.js") ],
9094
function (): Stream {
9195
return intoStream.object({});

src/bundle.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ export interface BundleStreamFactory {
1616
(src: Readable, name: string): Stream;
1717
}
1818

19+
export type BundleType = "style" | "script";
20+
1921
/**
2022
* Represents a bundle to be bundled, assists in process.
2123
*/
2224
export class Bundle {
2325
public readonly name: string;
26+
private readonly type: BundleType;
2427
private readonly initialPaths: readonly string[];
2528
private remainingPaths: string[];
2629
private readonly files: Map<string, Vinyl> = new Map();
@@ -34,11 +37,13 @@ export class Bundle {
3437
*/
3538
constructor(
3639
name: string,
40+
type: BundleType,
3741
paths: string[],
3842
streamFactory: BundleStreamFactory,
3943
logger: Logger
4044
) {
4145
this.name = name;
46+
this.type = type;
4247
this.initialPaths = paths.slice(0);
4348
this.remainingPaths = paths.slice(0);
4449
this.streamFactory = streamFactory;
@@ -47,6 +52,7 @@ export class Bundle {
4752
"Bundle tracker created",
4853
{
4954
bundleName: this.name,
55+
type: this.type,
5056
files: this.initialPaths,
5157
}
5258
);
@@ -69,6 +75,7 @@ export class Bundle {
6975
"Retaining file for later bundling",
7076
{
7177
bundleName: this.name,
78+
type: this.type,
7279
path: file.path,
7380
}
7481
);
@@ -78,6 +85,7 @@ export class Bundle {
7885
"Ignoring unused file",
7986
{
8087
bundleName: this.name,
88+
type: this.type,
8189
path: file.path,
8290
}
8391
);
@@ -97,10 +105,11 @@ export class Bundle {
97105
"Creating bundle stream",
98106
{
99107
bundleName: this.name,
108+
type: this.type,
100109
inFiles: this.initialPaths,
101110
}
102111
);
103-
this.logger.info("Started bundling", { bundleName: this.name });
112+
this.logger.info("Started bundling", { bundleName: this.name, type: this.type });
104113
const chunks = await getStream.array(
105114
this.streamFactory(
106115
intoStream.object(orderedFiles),
@@ -115,6 +124,7 @@ export class Bundle {
115124
"Chunk returned by bundle stream is not a Vinyl instance",
116125
{
117126
bundleName: this.name,
127+
type: this.type,
118128
chunk,
119129
}
120130
);
@@ -123,8 +133,8 @@ export class Bundle {
123133
}
124134

125135
// Perform bundling, and collect results
126-
this.logger.trace("Bundle stream completed", { bundleName: this.name });
127-
this.logger.info("Finished bundling", { bundleName: this.name });
136+
this.logger.trace("Bundle stream completed", { bundleName: this.name, type: this.type });
137+
this.logger.info("Finished bundling", { bundleName: this.name, type: this.type });
128138

129139
return chunks as Vinyl[];
130140
}

0 commit comments

Comments
 (0)