Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade storybook #415

Merged
merged 3 commits into from Jan 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions .storybook/main.cjs
Expand Up @@ -28,6 +28,46 @@ module.exports = {
const cssLoaderOptions = cssRule.use[1].options;
cssLoaderOptions.modules = { namedExport: true };

workaroundRequireNotDefined(config);

return config;
},
};

/** Workaround for https://github.com/storybookjs/storybook/issues/14877 */
function workaroundRequireNotDefined(config) {
function replaceFileExtension(filePath, newExtension) {
const { name, root, dir } = path.parse(filePath);
return path.format({
name,
root,
dir,
ext: newExtension,
});
}

// Find the plugin instance that needs to be mutated
const virtualModulesPlugin = config.plugins.find(
(plugin) => plugin.constructor.name === "VirtualModulesPlugin"
);

// Change the file extension to .cjs for all files that end with "generated-stories-entry.js"
virtualModulesPlugin._staticModules = Object.fromEntries(
Object.entries(virtualModulesPlugin._staticModules).map(
([key, value]) => {
if (key.endsWith("generated-stories-entry.js")) {
return [replaceFileExtension(key, ".cjs"), value];
}
return [key, value];
}
)
);

// Change the entry points to point to the appropriate .cjs files
config.entry = config.entry.map((entry) => {
if (entry.endsWith("generated-stories-entry.js")) {
return replaceFileExtension(entry, ".cjs");
}
return entry;
});
}
19 changes: 10 additions & 9 deletions package.json
Expand Up @@ -59,16 +59,16 @@
"@jest/globals": "^27.4.6",
"@parcel/optimizer-data-url": "^2.0.1",
"@parcel/transformer-inline-string": "^2.0.1",
"@storybook/addon-actions": "6.3.12",
"@storybook/addon-actions": "^6.4.13",
"@storybook/addon-console": "^1.2.3",
"@storybook/addon-controls": "6.3.12",
"@storybook/addon-links": "6.3.12",
"@storybook/addon-toolbars": "6.3.12",
"@storybook/addon-viewport": "6.3.12",
"@storybook/addons": "6.3.12",
"@storybook/builder-webpack5": "6.3.12",
"@storybook/manager-webpack5": "6.3.12",
"@storybook/react": "6.3.12",
"@storybook/addon-controls": "^6.4.13",
"@storybook/addon-links": "^6.4.13",
"@storybook/addon-toolbars": "^6.4.13",
"@storybook/addon-viewport": "^6.4.13",
"@storybook/addons": "^6.4.13",
"@storybook/builder-webpack5": "^6.4.13",
"@storybook/manager-webpack5": "^6.4.13",
"@storybook/react": "^6.4.13",
"@testing-library/dom": "^8.11.1",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
Expand Down Expand Up @@ -96,6 +96,7 @@
"parcel": "^2.0.1",
"pino-pretty": "^7.3.0",
"prettier": "^2.5.1",
"react-router": "^5.2.1",
"stylelint": "^14.2.0",
"stylelint-config-css-modules": "^2.3.0",
"stylelint-config-standard": "^24.0.0",
Expand Down