Skip to content

Commit 43810b4

Browse files
LG-5635 fix unexpected @emotion imports in umd bundle of icons (#3319)
* feat: stricter post-build check on icon package * fix: not waiting for promises to finish
1 parent ec4fad8 commit 43810b4

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

.changeset/great-birds-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/icon': patch
3+
---
4+
5+
Expand post-build script to validate that no unnecessary @emotion packages are imported into icon bundles.

packages/icon/scripts/build/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function chunkArray<T>(arr: Array<T>, size: number): Array<Array<T>> {
2828
* Runs the Rollup build command for index and story files.
2929
*/
3030
async function buildIndex({ verbose }: { verbose?: boolean }): Promise<void> {
31-
buildPackage({ direct: true, verbose });
31+
await buildPackage({ direct: true, verbose });
3232
}
3333

3434
/**

packages/icon/scripts/postbuild/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ function validateBuiltIcons(): void {
2626
const jsFiles = files.filter(file => file.endsWith('.js'));
2727

2828
for (const file of jsFiles) {
29-
// Skip the main index file and glyphCommon as they may have different rules
30-
if (file === 'index.js' || file === 'glyphCommon.js') {
31-
continue;
32-
}
33-
3429
const filePath = path.join(fullPath, file);
3530
const content = fs.readFileSync(filePath, 'utf-8');
3631

tools/build/src/rollup/build-package.ts

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import chalk from 'chalk';
33
import rollup, { type MergedRollupOptions } from 'rollup';
44
import {
5-
type BatchWarnings,
65
type LoadConfigFile,
76
loadConfigFile as _loadConfigFile,
87
} from 'rollup/loadConfigFile';
@@ -25,7 +24,9 @@ interface BuildPackageOptions {
2524
/**
2625
* Builds packages using rollup for the current directory
2726
*/
28-
export function buildPackage({ verbose }: BuildPackageOptions) {
27+
export async function buildPackage({
28+
verbose,
29+
}: BuildPackageOptions): Promise<void> {
2930
const packageDir = process.cwd();
3031

3132
const splitPath = packageDir.split('/');
@@ -36,61 +37,56 @@ export function buildPackage({ verbose }: BuildPackageOptions) {
3637
const rollupConfigPath = findRollupConfigFile(packageName, { verbose });
3738

3839
// load the rollup config file, and run rollup
39-
loadConfigFile(rollupConfigPath, {}).then(
40-
async ({
41-
options,
42-
warnings,
43-
}: {
44-
options: Array<MergedRollupOptions>;
45-
warnings: BatchWarnings;
46-
}) => {
47-
verbose &&
48-
console.log(
49-
`Building ${packageName} with the following config:`,
50-
options.map(config => ({
51-
input: config.input,
52-
output: config.output[0].dir ?? config.output[0].file,
53-
})),
54-
);
40+
const { options, warnings } = await loadConfigFile(rollupConfigPath, {});
5541

56-
if (warnings.count > 0) {
57-
if (verbose) {
58-
// This prints all deferred warnings
59-
warnings.flush();
60-
} else {
61-
console.log(
62-
warnings.count + ' build warnings. Run with `--verbose` for more',
63-
);
64-
}
65-
}
42+
if (verbose) {
43+
console.log(
44+
`Building ${packageName} with the following config:`,
45+
options.map(config => ({
46+
input: config.input,
47+
output: config.output[0].dir ?? config.output[0].file,
48+
})),
49+
);
50+
}
6651

67-
for (const optionsObj of options) {
68-
const config: MergedRollupOptions = {
69-
...optionsObj,
70-
logLevel: verbose ? 'debug' : 'warn',
71-
};
52+
if (warnings.count > 0) {
53+
if (verbose) {
54+
// This prints all deferred warnings
55+
warnings.flush();
56+
} else {
57+
console.log(
58+
warnings.count + ' build warnings. Run with `--verbose` for more',
59+
);
60+
}
61+
}
7262

73-
// Log the bundle stats in verbose mode
74-
if (verbose) {
75-
config.plugins.push(
76-
bundleStats({
77-
html: false,
78-
json: false,
79-
compare: false,
80-
}),
81-
);
82-
}
63+
for (const optionsObj of options) {
64+
const config: MergedRollupOptions = {
65+
...optionsObj,
66+
logLevel: verbose ? 'debug' : 'warn',
67+
};
8368

84-
const bundle = await rollup.rollup(config);
69+
// Log the bundle stats in verbose mode
70+
if (verbose) {
71+
config.plugins.push(
72+
bundleStats({
73+
html: false,
74+
json: false,
75+
compare: false,
76+
}),
77+
);
78+
}
8579

86-
verbose &&
87-
console.log(
88-
`${chalk.bold(optionsObj.input)} > ${chalk.bold(
89-
optionsObj.output.map(obj => obj.dir || obj.file),
90-
)}`,
91-
);
92-
await Promise.all(optionsObj.output.map(bundle.write));
93-
}
94-
},
95-
);
80+
const bundle = await rollup.rollup(config);
81+
82+
if (verbose) {
83+
console.log(
84+
`${chalk.bold(optionsObj.input)} > ${chalk.bold(
85+
optionsObj.output.map(obj => obj.dir || obj.file),
86+
)}`,
87+
);
88+
}
89+
90+
await Promise.all(optionsObj.output.map(bundle.write));
91+
}
9692
}

0 commit comments

Comments
 (0)