Skip to content

Commit 2677b9c

Browse files
committed
fix(scripts): missing name in single compiler mode
When in single compiler mode, webpack doesn't pass (for some reason) the name. So we go around it by cleverly creating a sentence.
1 parent 4bb0d3a commit 2677b9c

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

Diff for: examples/plugin/inc/class-wpackio-plugin-init.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function __construct() {
1717

1818

1919
function plugin_enqueue() {
20-
$this->enqueue->enqueue( 'app', 'main', [] );
21-
$this->enqueue->enqueue( 'app', 'mobile', [] );
22-
$this->enqueue->enqueue( 'foo', 'main', [] );
20+
// $this->enqueue->enqueue( 'app', 'main', [] );
21+
// $this->enqueue->enqueue( 'app', 'mobile', [] );
22+
// $this->enqueue->enqueue( 'foo', 'main', [] );
2323
$this->enqueue->enqueue( 'tsapp', 'main', [] );
2424
}
2525

2626
function reactapp( $atts, $content = null ) {
2727
// Enqueue our react app scripts
28-
$this->enqueue->enqueue( 'reactapp', 'main', [] );
28+
// $this->enqueue->enqueue( 'reactapp', 'main', [] );
2929

3030
// Print the entry point
3131
return '<div id="wpackio-reactapp"></div>';

Diff for: packages/scripts/src/bin/utils.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,38 @@ export function printCompileTimeMessage(stat: any, lastStat: any | null) {
6464
!lastStat.builtAt ||
6565
stat.builtAt !== lastStat.builtAt
6666
) {
67-
const entryName = chalk.bold(stat.name);
68-
let name = chalk.green(entryName);
67+
// get bundle name
68+
let name = '';
69+
if (stat.name) {
70+
const entryName = stat.name;
71+
name = chalk.green(entryName);
72+
if (stat.errors.length) {
73+
name = chalk.red(entryName);
74+
} else if (stat.warnings.length) {
75+
name = chalk.yellow(entryName);
76+
}
77+
name = `${name} `;
78+
}
79+
80+
// get log symbol
6981
let symbol = logSymbols.success;
7082
if (stat.errors.length) {
71-
name = chalk.red(entryName);
7283
symbol = logSymbols.error;
7384
} else if (stat.warnings.length) {
74-
name = chalk.yellow(entryName);
7585
symbol = logSymbols.warning;
7686
}
87+
88+
// get log message
89+
let msg = 'was rebuilt in';
90+
if (lastStat === null) {
91+
msg = 'was built in';
92+
}
93+
7794
console.log(
7895
addTimeStampToLog(
79-
`${symbol} entry ${name} in ${chalk.magenta(`${stat.time}ms`)}.`
96+
`${symbol} bundle ${name}${msg} ${chalk.magenta(
97+
`${stat.time}ms`
98+
)}.`
8099
)
81100
);
82101
}
@@ -97,6 +116,8 @@ export const webpackStatToJsonOptions: webpack.Stats.ToJsonOptions = {
97116
errors: true,
98117
warnings: true,
99118
modules: false,
119+
publicPath: false,
120+
depth: false,
100121
};
101122

102123
export function printCompileTimeMessages(
@@ -126,7 +147,7 @@ export function printCompileTimeMessages(
126147
printCompileTimeMessage(sj, lastStatsJson.children[index]);
127148
}
128149
});
129-
} else if (statsJson.time && statsJson.name) {
150+
} else if (statsJson.time) {
130151
// if it is single compiler
131152
if (lastStatsJson === null) {
132153
printCompileTimeMessage(statsJson, null);

0 commit comments

Comments
 (0)