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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-storybook-plugin",
"comment": "Add `disableTelemetry` option to set STORYBOOK_DISABLE_TELEMETRY=1 when invoking Storybook; always set COREPACK_ENABLE_AUTO_PIN=0 in the subprocess environment",
"type": "minor"
}
],
"packageName": "@rushstack/heft-storybook-plugin"
}
32 changes: 28 additions & 4 deletions heft-plugins/heft-storybook-plugin/src/StorybookPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ export interface IStorybookPluginOptions {
* Specifies whether to capture the webpack stats for the storybook build by adding the `--webpack-stats-json` CLI flag.
*/
captureWebpackStats?: boolean;

/**
* If true, sets the `STORYBOOK_DISABLE_TELEMETRY=1` environment variable when invoking the Storybook subprocess,
* which disables Storybook's telemetry data collection.
*/
disableTelemetry?: boolean;
}

interface IRunStorybookOptions extends IPrepareStorybookOptions {
Expand Down Expand Up @@ -499,17 +505,27 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
storybookArgs.push('--docs');
}

const storybookEnv: NodeJS.ProcessEnv = {
...process.env,
// Prevent corepack from prompting to pin a package manager version
COREPACK_ENABLE_AUTO_PIN: '0'
};
if (options.disableTelemetry) {
storybookEnv.STORYBOOK_DISABLE_TELEMETRY = '1';
}

if (isServeMode) {
// Instantiate storybook runner synchronously for incremental builds
// this ensure that the process is not killed when heft watcher detects file changes
this._invokeSync(
logger,
resolvedModulePath,
storybookArgs,
storybookEnv,
storybookCliVersion === StorybookCliVersion.STORYBOOK8
);
} else {
await this._invokeAsSubprocessAsync(logger, resolvedModulePath, storybookArgs, workingDirectory);
await this._invokeAsSubprocessAsync(logger, resolvedModulePath, storybookArgs, workingDirectory, storybookEnv);
}
}

Expand All @@ -524,15 +540,15 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
logger: IScopedLogger,
command: string,
args: string[],
cwd: string
cwd: string,
env: NodeJS.ProcessEnv
): Promise<void> {
return await new Promise<void>((resolve, reject) => {
const storybookEnv: NodeJS.ProcessEnv = { ...process.env };
const forkedProcess: child_process.ChildProcess = child_process.fork(command, args, {
execArgv: process.execArgv,
cwd,
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
env: storybookEnv,
env,
...SubprocessTerminator.RECOMMENDED_OPTIONS
});

Expand Down Expand Up @@ -587,6 +603,7 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
logger: IScopedLogger,
command: string,
args: string[],
env: NodeJS.ProcessEnv,
patchNpmConfigUserAgent: boolean
): void {
logger.terminal.writeLine('Launching ' + command);
Expand All @@ -608,6 +625,13 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
process.env.npm_config_user_agent = 'npm';
}

// Apply custom environment variables
for (const [key, value] of Object.entries(env)) {
if (value !== undefined) {
process.env[key] = value;
}
}

// invoke command synchronously
require(command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"title": "Specifies whether to capture the webpack stats for storybook build.",
"description": "If this is true, then it will capture the webpack stats for storybook build. Defaults to false.",
"type": "boolean"
},
"disableTelemetry": {
"title": "Specifies whether to disable Storybook telemetry.",
"description": "If true, sets the STORYBOOK_DISABLE_TELEMETRY=1 environment variable when invoking the Storybook subprocess, which disables Storybook's telemetry data collection. Defaults to false.",
"type": "boolean"
}
}
}
Loading