Skip to content

Commit 6df3790

Browse files
Copilotdmichon-msft
andcommitted
feat(heft-storybook-plugin): add disableTelemetry option; always set COREPACK_ENABLE_AUTO_PIN=0
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent 1b86ea0 commit 6df3790

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-storybook-plugin",
5+
"comment": "Add `disableTelemetry` option to set STORYBOOK_DISABLE_TELEMETRY=1 when invoking Storybook; always set COREPACK_ENABLE_AUTO_PIN=0 in the subprocess environment",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-storybook-plugin"
10+
}

heft-plugins/heft-storybook-plugin/src/StorybookPlugin.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ export interface IStorybookPluginOptions {
158158
* Specifies whether to capture the webpack stats for the storybook build by adding the `--webpack-stats-json` CLI flag.
159159
*/
160160
captureWebpackStats?: boolean;
161+
162+
/**
163+
* If true, sets the `STORYBOOK_DISABLE_TELEMETRY=1` environment variable when invoking the Storybook subprocess,
164+
* which disables Storybook's telemetry data collection.
165+
*/
166+
disableTelemetry?: boolean;
161167
}
162168

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

508+
const storybookEnv: NodeJS.ProcessEnv = {
509+
...process.env,
510+
// Prevent corepack from prompting to pin a package manager version
511+
COREPACK_ENABLE_AUTO_PIN: '0'
512+
};
513+
if (options.disableTelemetry) {
514+
storybookEnv.STORYBOOK_DISABLE_TELEMETRY = '1';
515+
}
516+
502517
if (isServeMode) {
503518
// Instantiate storybook runner synchronously for incremental builds
504519
// this ensure that the process is not killed when heft watcher detects file changes
505520
this._invokeSync(
506521
logger,
507522
resolvedModulePath,
508523
storybookArgs,
524+
storybookEnv,
509525
storybookCliVersion === StorybookCliVersion.STORYBOOK8
510526
);
511527
} else {
512-
await this._invokeAsSubprocessAsync(logger, resolvedModulePath, storybookArgs, workingDirectory);
528+
await this._invokeAsSubprocessAsync(logger, resolvedModulePath, storybookArgs, workingDirectory, storybookEnv);
513529
}
514530
}
515531

@@ -524,15 +540,15 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
524540
logger: IScopedLogger,
525541
command: string,
526542
args: string[],
527-
cwd: string
543+
cwd: string,
544+
env: NodeJS.ProcessEnv
528545
): Promise<void> {
529546
return await new Promise<void>((resolve, reject) => {
530-
const storybookEnv: NodeJS.ProcessEnv = { ...process.env };
531547
const forkedProcess: child_process.ChildProcess = child_process.fork(command, args, {
532548
execArgv: process.execArgv,
533549
cwd,
534550
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
535-
env: storybookEnv,
551+
env,
536552
...SubprocessTerminator.RECOMMENDED_OPTIONS
537553
});
538554

@@ -587,6 +603,7 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
587603
logger: IScopedLogger,
588604
command: string,
589605
args: string[],
606+
env: NodeJS.ProcessEnv,
590607
patchNpmConfigUserAgent: boolean
591608
): void {
592609
logger.terminal.writeLine('Launching ' + command);
@@ -608,6 +625,13 @@ export default class StorybookPlugin implements IHeftTaskPlugin<IStorybookPlugin
608625
process.env.npm_config_user_agent = 'npm';
609626
}
610627

628+
// Apply custom environment variables
629+
for (const [key, value] of Object.entries(env)) {
630+
if (value !== undefined) {
631+
process.env[key] = value;
632+
}
633+
}
634+
611635
// invoke command synchronously
612636
require(command);
613637

heft-plugins/heft-storybook-plugin/src/schemas/storybook.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"title": "Specifies whether to capture the webpack stats for storybook build.",
3838
"description": "If this is true, then it will capture the webpack stats for storybook build. Defaults to false.",
3939
"type": "boolean"
40+
},
41+
"disableTelemetry": {
42+
"title": "Specifies whether to disable Storybook telemetry.",
43+
"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.",
44+
"type": "boolean"
4045
}
4146
}
4247
}

0 commit comments

Comments
 (0)