Skip to content

Commit

Permalink
Propagate --config argument via SKU_CONFIG envar
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Aug 29, 2023
1 parent f539359 commit 9ac068c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/friendly-ladybugs-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'sku': patch
---

Propagate `--config` argument to Storybook process

Fixes a bug where `sku storybook` and `sku build-storybook` would not honour a custom sku config specified via the `--config` flag
File renamed without changes.
6 changes: 4 additions & 2 deletions packages/sku/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const getSkuConfig = () => {
const tsPath = getPathFromCwd('sku.config.ts');
const jsPath = getPathFromCwd('sku.config.js');

if (args.config) {
appSkuConfigPath = getPathFromCwd(args.config);
const customSkuConfig = args.config || process.env.SKU_CONFIG;

if (customSkuConfig) {
appSkuConfigPath = getPathFromCwd(customSkuConfig);
} else if (fs.existsSync(tsPath)) {
appSkuConfigPath = tsPath;
} else if (fs.existsSync(jsPath)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/scripts/build-storybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ process.env.NODE_ENV = 'production';

const path = require('path');
const { rimraf } = require('rimraf');
const { argv } = require('../config/args');
const { argv, config } = require('../config/args');
const gracefulSpawn = require('../lib/gracefulSpawn');
const { storybookTarget } = require('../context');
const buildStorybookPath = require.resolve('@storybook/cli/bin/index');
Expand All @@ -23,7 +23,7 @@ const { setUpStorybookPreviewFile } = require('../lib/storybook');

const storybookProcess = gracefulSpawn(buildStorybookPath, argv, {
stdio: 'inherit',
env: process.env,
env: { ...process.env, SKU_CONFIG: config },
});

storybookProcess.on('exit', (exitCode) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/scripts/storybook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const { argv } = require('../config/args');
const { argv, config } = require('../config/args');
const gracefulSpawn = require('../lib/gracefulSpawn');
const { storybookPort } = require('../context');
const startStorybookPath = require.resolve('@storybook/cli/bin/index');
Expand All @@ -19,7 +19,7 @@ argv.unshift('dev');

const storybookProcess = gracefulSpawn(startStorybookPath, argv, {
stdio: 'inherit',
env: process.env,
env: { ...process.env, SKU_CONFIG: config },
});

storybookProcess.on('exit', (exitCode) => {
Expand Down
14 changes: 11 additions & 3 deletions tests/storybook-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const {
} = require('@sku-private/test-utils');
const fetch = require('node-fetch');

const skuConfigFileName = 'sku.storybook.config.ts';
const appDir = path.dirname(
require.resolve('@sku-fixtures/storybook-config/sku.config.ts'),
require.resolve(`@sku-fixtures/storybook-config/${skuConfigFileName}`),
);
const storybookDistDir = path.resolve(appDir, 'dist-storybook');

Expand All @@ -25,7 +26,11 @@ describe('storybook-config', () => {
let storybookFrame;

beforeAll(async () => {
server = await runSkuScriptInDir('storybook', appDir, ['--ci']);
server = await runSkuScriptInDir('storybook', appDir, [
'--ci',
'--config',
skuConfigFileName,
]);
await waitForUrls(storybookUrl, middlewareUrl);
storybookFrame = await getStorybookFrame(storybookUrl);
}, 200000);
Expand Down Expand Up @@ -91,7 +96,10 @@ describe('storybook-config', () => {
let storybookFrame;

beforeAll(async () => {
await runSkuScriptInDir('build-storybook', appDir);
await runSkuScriptInDir('build-storybook', appDir, [
'--config',
skuConfigFileName,
]);
closeStorybookServer = await startAssetServer(
assetServerPort,
storybookDistDir,
Expand Down

0 comments on commit 9ac068c

Please sign in to comment.