Skip to content

Support webpack promise config and esm config files#774

Merged
FlorianRappl merged 4 commits intosmapiot:developfrom
grant-progress:feat/webpack-promise-config
Aug 26, 2025
Merged

Support webpack promise config and esm config files#774
FlorianRappl merged 4 commits intosmapiot:developfrom
grant-progress:feat/webpack-promise-config

Conversation

@grant-progress
Copy link
Contributor

@grant-progress grant-progress commented Aug 14, 2025

New Pull Request

For more information, see the CONTRIBUTING guide.

Prerequisites

Please make sure you can check the following boxes:

  • I have read the CONTRIBUTING document
  • My code follows the code style of this project
  • All new and existing tests passed

Type(s) of Changes

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue, please reference the issue id)
  • New feature (non-breaking change which adds functionality, make sure to open an associated issue first)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • I have updated the documentation accordingly
  • I have added tests to cover my changes

Description

Updates piral-cli-webpack5 to support the Promise-based Webpack config format.

Remarks

Using a Promise to resolve the final config is niche but necessary for integrating ESM-only plugins, like UnoCSS

I have linked and tested piral-cli-webpack5 with a local project which uses async Webpack config and ESM module syntax (export default config) and piral dev runs and transpiles my app successfully with the correct modified config.

@CLAassistant
Copy link

CLAassistant commented Aug 14, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Aug 14, 2025

File size impact

Impact on file sizes when merging feat/webpack-promise-config into develop.

empty-piral (no impact)
Files new size
Unmodified (2) 30.3 kB (0 B / +0%) 👻
Total (2) 30.3 kB (0 B / +0%) 👻
minimal-piral (no impact)
Files new size
Unmodified (2) 278 kB (0 B / +0%) 👻
Total (2) 278 kB (0 B / +0%) 👻
sample-cross-fx (no impact)
Files new size
Unmodified (3) 2.2 MB (0 B / +0%) 👻
Total (3) 2.2 MB (0 B / +0%) 👻
sample-piral (no impact)
Files new size
Unmodified (3) 697 kB (0 B / +0%) 👻
Total (3) 697 kB (0 B / +0%) 👻
sample-piral-core (no impact)
Files new size
Unmodified (3) 355 kB (0 B / +0%) 👻
Total (3) 355 kB (0 B / +0%) 👻
Generated by @jsenv/file-size-impact during check-bundle-size#17041980162 on 5ef5945

// support Promise for returned config:
// https://webpack.js.org/configuration/configuration-types/#exporting-a-promise
if (configResult instanceof Promise) {
webPackConfig = await configResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unnecessary. We can just await configResult independent if its a Promise or not. JavaScript await is lax here, it will just work:

await 5; // 5
await Promise.resolve(5); // 5
await thisPromiseYieldsFive; // 5

is all equivalent; so no need to have the instanceof check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, I felt this approach was more explicit in intention. Sometimes developers accidentally await non-Promises and another dev comes by and fixes it by removing the await ... I wanted to make it clear that even though in 90% of cases this won't be a promise, the await should be preserved for a reason and was not a mistake.

The comment alone does this, but not everybody reads the docs!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure I see the intention - I just want to make sure the code remains easy to digest and does not do unnecessary detours.

Also just a remark: The CLA was not signed as the associated email address does not seem to be registered with your account. You'll either need to add this email address or re-do commits with a different config using an email that you either have or can associate with your GitHub account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, I'll make that change for you.

Yeah, I understand the CLA. I'm a new employee at my workplace so I'm tracking down our OSS contribution process.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any news on this one? Otherwise I'd close and re-do.

if (existsSync(otherConfigPath)) {
try {
const otherConfig = require(otherConfigPath);
let otherConfig = require(otherConfigPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question here: Would it make sense to check / support mjs extension here? And maybe use import(...) instead of require(...) when an mjs file is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could do that, although the CJS/ESM interop seems to work well enough here, and you'd still want it for plain .js cases, so I'd say it's more concise to leave this as-is.

Copy link
Contributor

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

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

I like it - presumably other bundler integrations should support Promise results, too.

Thanks!

@FlorianRappl FlorianRappl added cli Concerns the piral-cli application. webpack Concerns the integration of the Webpack bundler in the CLI. labels Aug 14, 2025
@FlorianRappl FlorianRappl added this to the 1.9.0 milestone Aug 14, 2025
@grant-progress
Copy link
Contributor Author

Just checking in, I'm still navigating our legal department to confirm the CLA. Will update as soon as I have an answer.

@grant-progress
Copy link
Contributor Author

Ok, I got approval and the CLA has been signed.

@FlorianRappl FlorianRappl merged commit 311be80 into smapiot:develop Aug 26, 2025
6 checks passed
@FlorianRappl
Copy link
Contributor

Awesome - I'll try to wrap up the 1.9.0 and release it this week.

@grant-progress grant-progress deleted the feat/webpack-promise-config branch August 26, 2025 17:28
@grant-progress grant-progress restored the feat/webpack-promise-config branch September 3, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Concerns the piral-cli application. webpack Concerns the integration of the Webpack bundler in the CLI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants