Skip to content

Commit ccea0f5

Browse files
authored
feat: allow altering all configuration (#115)
Fixes #112 #113 #114. BREAKING CHANGE: webpackFinal from user land will receive a configuration object with additional autocomputed properties. BREAKING CHANGE: --widget-definitions CLI option now interprets paths from CWD and not as if they came from the config file.
1 parent 983ce62 commit ccea0f5

7 files changed

Lines changed: 19 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"scripts": {
1818
"build": "tsc",
19+
"build:watch": "tsc --watch",
1920
"test": "jest",
2021
"test:ci": "yarn test --watchAll=false --coverage",
2122
"lint": "eslint .",

renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"config:base"
5-
],
3+
"extends": ["config:base"],
64
"rangeStrategy": "bump",
75
"lockFileMaintenance": {
86
"enabled": true,

src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function initProgram(program: Command, argv: string[]): void {
2929
)
3030
.option(
3131
'--widget-definitions <widget-definitions>',
32-
'when used, the glob(s) provided here will supersede the "register" key in the config file. Use commas to separate multiple values. Relative glob patterns are interpreted from the .widgetRegistry/ location.',
32+
'when used, the glob(s) provided here will supersede the "register" key in the config file. Use commas to separate multiple values.',
3333
)
3434
.option(
3535
'--omit-missing',

src/defaultConfig/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
33
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4-
const CopyPlugin = require('copy-webpack-plugin');
54
const { EnvironmentPlugin } = require('webpack');
65
/* eslint-enable @typescript-eslint/no-var-requires */
76

src/webpack/__snapshots__/buildWebpackConfiguration.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Object {
112112
Object {
113113
"context": ".",
114114
"from": "thumbnail.png",
115+
"noErrorOnMissing": true,
115116
"to": "src/__testData__/widgetDefinitions/widgets/fake/[name].[contenthash:8][ext]",
116117
},
117118
],

src/webpack/buildWebpackConfiguration.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ export default async function buildWebpackConfiguration(
1414
logger?: SideEffects,
1515
): Promise<Configuration> {
1616
let configData: RegistryConfig;
17+
// Default to do no changes if it is not defined.
18+
let webpackFinal = (c: Configuration): Promise<Configuration> =>
19+
Promise.resolve(c);
1720
try {
1821
const importData = await import(registryConfig);
1922
configData = importData?.default || importData;
2023
if (configData.webpackFinal) {
21-
configuration = await configData.webpackFinal(configuration);
24+
webpackFinal = configData.webpackFinal;
2225
}
2326
const { externalPeerDependencies = {} } = configData;
2427
if (Object.keys(externalPeerDependencies).length) {
@@ -66,11 +69,14 @@ export default async function buildWebpackConfiguration(
6669
definition.shortcode,
6770
'[name].[contenthash:8][ext]',
6871
),
72+
noErrorOnMissing: true,
6973
context: path.dirname(definition.entry),
7074
}));
7175
if (copyOptions.length) {
7276
configuration.plugins?.push(new CopyPlugin({ patterns: copyOptions }));
7377
}
78+
// Execute the function in .widgetRegistry/main.js
79+
configuration = await webpackFinal(configuration);
7480
if (logger) {
7581
logger('\n---------------------------------------------------');
7682
logger(' Webpack Config ');

src/webpack/widgetDefinition/discoverWidgetDefinitionFiles.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ export default async function discoverWidgetDefinitionFiles(
2020
widgetDefinitionGlobs: string[],
2121
): Promise<string[]> {
2222
const configData = await loadWidgetRegistryConfig(configFile);
23-
const workingDir = dirname(configFile);
23+
let workingDir = dirname(configFile);
24+
let register = configData.register;
25+
// If there are widget definitions coming from the CLI they are relative to
26+
// the current working directory.
27+
if (widgetDefinitionGlobs.length) {
28+
workingDir = process.cwd();
29+
register = widgetDefinitionGlobs;
30+
}
2431
// Discover the widget definitions based on the glob pattern.
25-
const register = widgetDefinitionGlobs.length
26-
? widgetDefinitionGlobs
27-
: configData.register;
2832
const unflattenned = await Promise.all(
2933
register.map((pattern): Promise<string[]> => {
3034
return new Promise((resolve, reject) =>

0 commit comments

Comments
 (0)