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
2 changes: 2 additions & 0 deletions src/tooling/piral-cli-webpack5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ module.exports = function(config) {
};
```

Your function may be async or return a Promise as needed.

Otherwise, you can also use the `extend-config` helper module to get the job done without having to know the internals:

```js
Expand Down
15 changes: 11 additions & 4 deletions src/tooling/piral-cli-webpack5/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ import { existsSync } from 'fs';
import { Configuration } from 'webpack';
import { DefaultConfiguration } from './webpack/common';

export function extendConfig(
export async function extendConfig(
[webPackConfig, enhancer]: DefaultConfiguration,
otherConfigPath: string,
overrides: Configuration = {},
): Configuration {
): Promise<Configuration> {
const original = webPackConfig;

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.

if (otherConfig.default) {
// The webpack config file appears to be an ESM module;
// this interop should give us the actual exported config
otherConfig = otherConfig.default;
}

if (typeof otherConfig === 'function') {
webPackConfig = otherConfig(webPackConfig);
// support Promise for returned config:
// https://webpack.js.org/configuration/configuration-types/#exporting-a-promise
webPackConfig = await otherConfig(webPackConfig);
} else if (typeof otherConfig === 'object') {
webPackConfig = {
...webPackConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/tooling/piral-cli-webpack5/src/webpack/pilet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const handler: PiletBuildHandler = {
options.contentHash,
options.minify,
);
const wpConfig = extendConfig(baseConfig, otherConfigPath, {
const wpConfig = await extendConfig(baseConfig, otherConfigPath, {
watch: options.watch,
});

Expand Down
2 changes: 1 addition & 1 deletion src/tooling/piral-cli-webpack5/src/webpack/piral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const handler: PiralBuildHandler = {
options.publicUrl,
hmrPort,
);
const wpConfig = extendConfig(baseConfig, otherConfigPath, {
const wpConfig = await extendConfig(baseConfig, otherConfigPath, {
watch: options.watch,
});

Expand Down
145 changes: 85 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2415,69 +2415,69 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@jsenv/abort@4.3.0":
version "4.3.0"
resolved "https://registry.yarnpkg.com/@jsenv/abort/-/abort-4.3.0.tgz#2069d7ca5f608d0f0df6fe5992cc38ab543da924"
integrity sha512-zavIagUGxZ1yiFp9JURdamVvBcoBYC3M63EmCE7KUBkzIHRvVQP7kIxY/EWuI8WTk40rsIskS94Z0rWouDq0cg==
"@jsenv/abort@4.3.1":
version "4.3.1"
resolved "https://registry.yarnpkg.com/@jsenv/abort/-/abort-4.3.1.tgz#43a0ce85c68c01fccd7e3345160caf90a49b5d89"
integrity sha512-N0IzrxMnxEbtmme45F9cWu+ysd8rlTSCeT74tU5J/H5lQAxcjIaQOSlIWG5WddcdOPSpVKfRB6MhiO2yS79joQ==

"@jsenv/dynamic-import-worker@1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@jsenv/dynamic-import-worker/-/dynamic-import-worker-1.2.1.tgz#3f412cf2c99476ee08f03b3badfb0f4d3adacb27"
integrity sha512-4Do1JGKZ3MoHEcrgInN/922BI0oOWhmGw4tLQtBUSzzjlyVSzPJ7BHCy+bZhkVcJ77xa2Ag+H24f0NJzC5wiKg==

"@jsenv/file-size-impact@14.3.18":
version "14.3.18"
resolved "https://registry.yarnpkg.com/@jsenv/file-size-impact/-/file-size-impact-14.3.18.tgz#29b51ee489653179e89ce7f6a6136869cc0a1870"
integrity sha512-u0gkdHLFg1TxrB1RCKnlVnK/SEal14/oIy1V4tn1iI4B1VdUchSYEzC4ZMoKFIynjo0EoZEtEXeggvp36+9ApA==
"@jsenv/file-size-impact@14.3.33":
version "14.3.33"
resolved "https://registry.yarnpkg.com/@jsenv/file-size-impact/-/file-size-impact-14.3.33.tgz#dc588e07b0949c7ab700a63bc5baf607dee5e771"
integrity sha512-mmpFHx+7H3H4hU2ouCzrrtFAzLZI6FQk+NsZd9zrZQs+GkNxrjK9CfhL+o7b6RRDiCmQrkULeLhEHx1HSWpU5w==
dependencies:
"@jsenv/dynamic-import-worker" "1.2.1"
"@jsenv/filesystem" "4.13.4"
"@jsenv/github-pull-request-impact" "1.8.18"
"@jsenv/humanize" "1.2.8"
"@jsenv/urls" "2.6.0"

"@jsenv/filesystem@4.13.4":
version "4.13.4"
resolved "https://registry.yarnpkg.com/@jsenv/filesystem/-/filesystem-4.13.4.tgz#3af5a32260cd3b7a423a072877889693d221ed9f"
integrity sha512-uyJ46NWfR3AbVb8r0hqYPEkU847948iMKT03o3ivFy4sXnAxxy2U9P2AEl3vUKVT3EVZxjrpWCAAgiMCNaXeLg==
dependencies:
"@jsenv/abort" "4.3.0"
"@jsenv/url-meta" "8.5.3"
"@jsenv/urls" "2.6.0"
"@jsenv/utils" "2.1.2"

"@jsenv/github-pull-request-impact@1.8.18":
version "1.8.18"
resolved "https://registry.yarnpkg.com/@jsenv/github-pull-request-impact/-/github-pull-request-impact-1.8.18.tgz#968975aaa43b9a036b1301a4d0f3beea0e9077b5"
integrity sha512-En4ymoCl5vLI5CYN17aweHuGotUPJVT0EAJrsiTZn80E6obrRM2IiigqE2EkNNhrT2cRRE5ZqhfY1TOeMi+GpQ==
dependencies:
"@jsenv/filesystem" "4.13.4"
"@jsenv/humanize" "1.2.8"

"@jsenv/humanize@1.2.8":
version "1.2.8"
resolved "https://registry.yarnpkg.com/@jsenv/humanize/-/humanize-1.2.8.tgz#4e16d8fb8f304161a1652e3fe5abf01e57a3ce44"
integrity sha512-k3O4daxG40bhi7Q3FSXMH9I7bornS62Hfn3gXX6di1ZS/tf6pVYQ9VplAYC2L0KtqFnwqtCGuJ9+Ls4nrS70gg==
"@jsenv/filesystem" "4.15.6"
"@jsenv/github-pull-request-impact" "1.8.33"
"@jsenv/humanize" "1.6.0"
"@jsenv/urls" "2.9.1"

"@jsenv/filesystem@4.15.6":
version "4.15.6"
resolved "https://registry.yarnpkg.com/@jsenv/filesystem/-/filesystem-4.15.6.tgz#d07a4c1f3c50ac7b29261dc52a4a5eb3c6dd7726"
integrity sha512-GJcwT18gKnh0gyh7vdZuToNfUHYvKqV4QIy+OFqLCoMRwN/3Nc4zE0ggZO4t9G+0fWerMSHoFQDHQzzPR5wj6Q==
dependencies:
"@jsenv/abort" "4.3.1"
"@jsenv/url-meta" "8.5.7"
"@jsenv/urls" "2.9.1"
"@jsenv/utils" "2.3.1"

"@jsenv/github-pull-request-impact@1.8.33":
version "1.8.33"
resolved "https://registry.yarnpkg.com/@jsenv/github-pull-request-impact/-/github-pull-request-impact-1.8.33.tgz#e2fc2d88e563e5c5c670871c6a6d5bf8810af08b"
integrity sha512-V2wM9vR5oxxK6dhTrQlAi4xZ5/UtaZppKShcsLGHE9k8aTbSJgCVvY2XlDyUVfhzyuWCYEqw5gruOJA95fuT6Q==
dependencies:
"@jsenv/filesystem" "4.15.6"
"@jsenv/humanize" "1.6.0"

"@jsenv/humanize@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@jsenv/humanize/-/humanize-1.6.0.tgz#f3d7085580efa9fe9a40c33b125c478c480f4d1c"
integrity sha512-C8uYj4/JyigblnKFpGArHS/ASCZ++z1QYElHspHItQGcO4c5steyfk3D/Lk+77LN5T0q9QPZblrHIObuPqLKGg==
dependencies:
ansi-escapes "7.0.0"
string-width "7.2.0"
strip-ansi "7.1.0"

"@jsenv/url-meta@8.5.3":
version "8.5.3"
resolved "https://registry.yarnpkg.com/@jsenv/url-meta/-/url-meta-8.5.3.tgz#7ceca37f9f23f23575b06627f38439e0a572d0ae"
integrity sha512-6RHIHU7izl9JoQ0etbCgEUTsKL+xwx+mSud204Ga5WSHqPNScI6jKBil/U2el+1sP97YjJieBglbCfZfE0QWQg==
"@jsenv/url-meta@8.5.7":
version "8.5.7"
resolved "https://registry.yarnpkg.com/@jsenv/url-meta/-/url-meta-8.5.7.tgz#a428bab22cd98dc326ffa22fda26319d1114a5eb"
integrity sha512-tHQRYW3wN/QFxFRUGSK0AhReG/27rfOgpD7yVyiL05LpoTpXqjLBihICAI9gBlEEfKvxBb+A3LEnqWxz3XTvkg==

"@jsenv/urls@2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@jsenv/urls/-/urls-2.6.0.tgz#9adf29148b6851d5bb3ff9508aabd487a06d3ddb"
integrity sha512-EzJLsAWSnVXZHzBzZ8hUfG2v5M3/0t4A3eZfOTPwbV8z362aoxUp9pvdZ9gDqMEfwaYzMoGTHZCXYc2IfagSGw==
"@jsenv/urls@2.9.1":
version "2.9.1"
resolved "https://registry.yarnpkg.com/@jsenv/urls/-/urls-2.9.1.tgz#7f7c92e6f4969b91302ef100909686e39826a01b"
integrity sha512-nvj4b0QzWYoGi3alH32+Xta/gMIC92AzNAejK3fB1R5eevjePaMaYo7pwyJgNKXmIMMK/ShMW5dKKtn45mb2fQ==
dependencies:
"@jsenv/humanize" "1.2.8"
"@jsenv/humanize" "1.6.0"

"@jsenv/utils@2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@jsenv/utils/-/utils-2.1.2.tgz#01be70fbe69b363cd37be3b8ac3c98436751d52a"
integrity sha512-0v/bp5xlbZMRKsZET39FpUmTCqF4f96Ve0bow5vnaiyABXISALNLGc0oe7M92cYu5L1t2eAsNqQQ0TqiXdqTZA==
"@jsenv/utils@2.3.1":
version "2.3.1"
resolved "https://registry.yarnpkg.com/@jsenv/utils/-/utils-2.3.1.tgz#7de10a465fe551a4a8acaa9676453f75fae83672"
integrity sha512-d/p96YJTo9vzI5lqvJdvEHOQHqQ9iUBMJmCty3Q3O6RChDbkIgCBYxW9m/xl2vmwoOyMvbPCfWQDrnRzC6NwSQ==

"@lerna/create@8.1.9":
version "8.1.9"
Expand Down Expand Up @@ -11968,7 +11968,7 @@ stickyfilljs@^2.1.0:
resolved "https://registry.yarnpkg.com/stickyfilljs/-/stickyfilljs-2.1.0.tgz#46dabb599d8275d185bdb97db597f86a2e3afa7b"
integrity sha512-LkG0BXArL5HbW2O09IAXfnBQfpScgGqJuUDUrI3Ire5YKjRz/EhakIZEJogHwgXeQ4qnTicM9sK9uYfWN11qKg==

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -11977,14 +11977,14 @@ stickyfilljs@^2.1.0:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@7.2.0, string-width@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-7.2.0.tgz#b5bb8e2165ce275d4d43476dd2700ad9091db6dc"
integrity sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^10.3.0"
get-east-asian-width "^1.0.0"
strip-ansi "^7.1.0"
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
Expand All @@ -11995,6 +11995,15 @@ string-width@^5.0.1, string-width@^5.1.2:
emoji-regex "^9.2.2"
strip-ansi "^7.0.1"

string-width@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-7.2.0.tgz#b5bb8e2165ce275d4d43476dd2700ad9091db6dc"
integrity sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==
dependencies:
emoji-regex "^10.3.0"
get-east-asian-width "^1.0.0"
strip-ansi "^7.1.0"

string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
Expand All @@ -12014,20 +12023,27 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1, strip-ansi@^7.1.0:
strip-ansi@7.1.0, strip-ansi@^7.0.1, strip-ansi@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
integrity sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==
dependencies:
ansi-regex "^6.0.1"

strip-ansi@^6, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
Expand Down Expand Up @@ -13086,7 +13102,7 @@ workerpool@^3.1.1:
object-assign "4.1.1"
rsvp "^4.8.4"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -13104,6 +13120,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
Loading