Skip to content

Commit eb6290a

Browse files
committed
heft-storybook-plugin prevents "heft start" from launching Webpack
1 parent 7743b31 commit eb6290a

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

build-tests-samples/heft-storybook-react-tutorial-storybook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"description": "Storybook build dependencies for heft-storybook-react-tutorial",
66
"scripts": {
7-
"test": ""
7+
"build": ""
88
},
99
"devDependencies": {
1010
"@babel/core": "^7.14.8",

build-tests-samples/heft-storybook-react-tutorial/.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Debug Jest tests",
10+
"name": "Debug \"heft start\"",
1111
"program": "${workspaceFolder}/node_modules/@rushstack/heft/lib/start.js",
1212
"cwd": "${workspaceFolder}",
13-
"args": ["--debug", "test", "--clean"],
13+
"args": ["--debug", "start"],
1414
"console": "integratedTerminal",
1515
"sourceMaps": true
1616
},

build-tests-samples/heft-storybook-react-tutorial/config/heft.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
},
5050
{
5151
"plugin": "@rushstack/heft-jest-plugin"
52-
53-
/**
54-
* An optional object that provides additional settings that may be defined by the plugin.
55-
*/
52+
// "options": { }
53+
},
54+
{
55+
"plugin": "@rushstack/heft-storybook-plugin"
5656
// "options": { }
5757
}
5858
]

common/reviews/api/heft-webpack4-plugin.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface IWebpackBuildStageProperties extends IBuildStageProperties {
2222

2323
// @public (undocumented)
2424
export interface IWebpackBundleSubstageProperties extends IBundleSubstageProperties {
25-
webpackConfiguration?: webpack.Configuration | webpack.Configuration[];
25+
webpackConfiguration?: webpack.Configuration | webpack.Configuration[] | null;
2626
}
2727

2828
// @public (undocumented)
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import type { HeftConfiguration, HeftSession, IHeftPlugin } from '@rushstack/heft';
4+
import type {
5+
HeftConfiguration,
6+
HeftSession,
7+
IBuildStageContext,
8+
IBundleSubstage,
9+
IHeftPlugin
10+
} from '@rushstack/heft';
511

612
const PLUGIN_NAME: string = 'StorybookPlugin';
713

@@ -11,5 +17,17 @@ export class StorybookPlugin implements IHeftPlugin {
1117
/**
1218
* Generate typings for Sass files before TypeScript compilation.
1319
*/
14-
public apply(heftSession: HeftSession, heftConfiguration: HeftConfiguration): void {}
20+
public apply(heftSession: HeftSession, heftConfiguration: HeftConfiguration): void {
21+
heftSession.hooks.build.tap(PLUGIN_NAME, (build: IBuildStageContext) => {
22+
build.hooks.bundle.tap(PLUGIN_NAME, (bundle: IBundleSubstage) => {
23+
bundle.hooks.configureWebpack.tap(
24+
{ name: PLUGIN_NAME, stage: Number.MAX_SAFE_INTEGER },
25+
(webpackConfiguration: unknown) => {
26+
// Discard Webpack's configuration to prevent Webpack from running
27+
return null;
28+
}
29+
);
30+
});
31+
});
32+
}
1533
}

heft-plugins/heft-webpack4-plugin/src/WebpackPlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class WebpackPlugin implements IHeftPlugin {
109109
buildProperties: IBuildStageProperties,
110110
supportsColor: boolean
111111
): Promise<void> {
112-
const webpackConfiguration: IWebpackConfiguration = bundleSubstageProperties.webpackConfiguration;
112+
const webpackConfiguration: IWebpackConfiguration | undefined | null =
113+
bundleSubstageProperties.webpackConfiguration;
113114
if (!webpackConfiguration) {
114115
return;
115116
}

heft-plugins/heft-webpack4-plugin/src/shared.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ export interface IWebpackBundleSubstageProperties extends IBundleSubstagePropert
2929
* for Webpack to run. If webpackConfigFilePath is specified,
3030
* this will be populated automatically with the exports of the
3131
* config file referenced in that property.
32+
*
33+
* @remarks
34+
* Tapable event handlers can return `null` instead of `undefined` to suppress
35+
* other handlers from creating a configuration object.
3236
*/
33-
webpackConfiguration?: webpack.Configuration | webpack.Configuration[];
37+
// We are inheriting this problem from Tapable's API
38+
// eslint-disable-next-line @rushstack/no-new-null
39+
webpackConfiguration?: webpack.Configuration | webpack.Configuration[] | null;
3440
}
3541

3642
/**

0 commit comments

Comments
 (0)