Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-birds-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/icon': patch
---

Expand post-build script to validate that no unnecessary @emotion packages are imported into icon bundles.
2 changes: 1 addition & 1 deletion packages/icon/scripts/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function chunkArray<T>(arr: Array<T>, size: number): Array<Array<T>> {
* Runs the Rollup build command for index and story files.
*/
async function buildIndex({ verbose }: { verbose?: boolean }): Promise<void> {
buildPackage({ direct: true, verbose });
await buildPackage({ direct: true, verbose });
}

/**
Expand Down
5 changes: 0 additions & 5 deletions packages/icon/scripts/postbuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ function validateBuiltIcons(): void {
const jsFiles = files.filter(file => file.endsWith('.js'));

for (const file of jsFiles) {
// Skip the main index file and glyphCommon as they may have different rules
if (file === 'index.js' || file === 'glyphCommon.js') {
continue;
}

const filePath = path.join(fullPath, file);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this need to be removed?

Copy link
Collaborator Author

@nima-taheri-mongodb nima-taheri-mongodb Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this exception was made in the first place. Currently, none of the source files directly import @emotion.

perhaps @TheSonOfThomp can chime in here and share the genesis of it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite remember. I think I had more specific logic focused on the individual icons at first. I think this is correct though to check all the files

const content = fs.readFileSync(filePath, 'utf-8');

Expand Down
104 changes: 50 additions & 54 deletions tools/build/src/rollup/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import chalk from 'chalk';
import rollup, { type MergedRollupOptions } from 'rollup';
import {
type BatchWarnings,
type LoadConfigFile,
loadConfigFile as _loadConfigFile,
} from 'rollup/loadConfigFile';
Expand All @@ -25,7 +24,9 @@ interface BuildPackageOptions {
/**
* Builds packages using rollup for the current directory
*/
export function buildPackage({ verbose }: BuildPackageOptions) {
export async function buildPackage({
verbose,
}: BuildPackageOptions): Promise<void> {
const packageDir = process.cwd();

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

// load the rollup config file, and run rollup
loadConfigFile(rollupConfigPath, {}).then(
async ({
options,
warnings,
}: {
options: Array<MergedRollupOptions>;
warnings: BatchWarnings;
}) => {
verbose &&
console.log(
`Building ${packageName} with the following config:`,
options.map(config => ({
input: config.input,
output: config.output[0].dir ?? config.output[0].file,
})),
);
const { options, warnings } = await loadConfigFile(rollupConfigPath, {});

if (warnings.count > 0) {
if (verbose) {
// This prints all deferred warnings
warnings.flush();
} else {
console.log(
warnings.count + ' build warnings. Run with `--verbose` for more',
);
}
}
if (verbose) {
console.log(
`Building ${packageName} with the following config:`,
options.map(config => ({
input: config.input,
output: config.output[0].dir ?? config.output[0].file,
})),
);
}

for (const optionsObj of options) {
const config: MergedRollupOptions = {
...optionsObj,
logLevel: verbose ? 'debug' : 'warn',
};
if (warnings.count > 0) {
if (verbose) {
// This prints all deferred warnings
warnings.flush();
} else {
console.log(
warnings.count + ' build warnings. Run with `--verbose` for more',
);
}
}

// Log the bundle stats in verbose mode
if (verbose) {
config.plugins.push(
bundleStats({
html: false,
json: false,
compare: false,
}),
);
}
for (const optionsObj of options) {
const config: MergedRollupOptions = {
...optionsObj,
logLevel: verbose ? 'debug' : 'warn',
};

const bundle = await rollup.rollup(config);
// Log the bundle stats in verbose mode
if (verbose) {
config.plugins.push(
bundleStats({
html: false,
json: false,
compare: false,
}),
);
}

verbose &&
console.log(
`${chalk.bold(optionsObj.input)} > ${chalk.bold(
optionsObj.output.map(obj => obj.dir || obj.file),
)}`,
);
await Promise.all(optionsObj.output.map(bundle.write));
}
},
);
const bundle = await rollup.rollup(config);

if (verbose) {
console.log(
`${chalk.bold(optionsObj.input)} > ${chalk.bold(
optionsObj.output.map(obj => obj.dir || obj.file),
)}`,
);
}

await Promise.all(optionsObj.output.map(bundle.write));
}
}
Loading