Skip to content

Commit

Permalink
Default sb init in ESM projects to use cjs
Browse files Browse the repository at this point in the history
- Reverts previous commit
  • Loading branch information
kylegach committed Sep 28, 2021
1 parent 69f523d commit 4904adb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type CommandOptions = {
yes?: boolean;
builder?: Builder;
linkable?: boolean;
commonJs?: boolean;
};

const installStorybook = (projectType: ProjectType, options: CommandOptions): Promise<void> => {
Expand All @@ -72,6 +73,7 @@ const installStorybook = (projectType: ProjectType, options: CommandOptions): Pr
language,
builder: options.builder || CoreBuilder.Webpack4,
linkable: !!options.linkable,
commonJs: options.commonJs,
};

const end = () => {
Expand Down Expand Up @@ -206,10 +208,7 @@ const installStorybook = (projectType: ProjectType, options: CommandOptions): Pr
.then(end);

case ProjectType.WEB_COMPONENTS:
return webComponentsGenerator(packageManager, npmOptions, {
...generatorOptions,
commonJs: true,
})
return webComponentsGenerator(packageManager, npmOptions, generatorOptions)
.then(commandLog('Adding Storybook support to your "web components" app'))
.then(end);

Expand Down Expand Up @@ -318,10 +317,13 @@ export function initiate(options: CommandOptions, pkg: Package): Promise<void> {
: 'Detecting project type';
const done = commandLog(infoText);

const packageJson = readPackageJson();
const isEsm = packageJson && packageJson.type === 'module';

try {
if (projectTypeProvided) {
if (installableProjectTypes.includes(options.type)) {
const storybookInstalled = isStorybookInstalled(readPackageJson(), options.force);
const storybookInstalled = isStorybookInstalled(packageJson, options.force);
projectType = storybookInstalled
? ProjectType.ALREADY_HAS_STORYBOOK
: options.type.toUpperCase();
Expand Down Expand Up @@ -349,5 +351,8 @@ export function initiate(options: CommandOptions, pkg: Package): Promise<void> {
cleanOptions.storyFormat = undefined;
}

return installStorybook(projectType, cleanOptions);
return installStorybook(projectType, {
...cleanOptions,
...(isEsm ? { commonJs: true } : undefined),
});
}
1 change: 1 addition & 0 deletions lib/cli/src/js-package-manager/PackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type PackageJson = {
peerDependencies?: Record<string, string>;
scripts?: Record<string, string>;
eslintConfig?: any;
type?: 'module';
};

export type PackageJsonWithDepsAndDevDeps = PackageJson &
Expand Down

0 comments on commit 4904adb

Please sign in to comment.