Skip to content

Commit

Permalink
Merge pull request #20150 from storybookjs/tech/tsup-csf-plugin
Browse files Browse the repository at this point in the history
Build: use tsup for csf-plugin
  • Loading branch information
ndelangen authored Jan 5, 2023
2 parents 104e3d6 + 7a3c66b commit 0aed2d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
24 changes: 16 additions & 8 deletions code/lib/csf-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
"sideEffects": false,
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.mjs",
"types": "./dist/types/index.d.ts"
"node": "./dist/index.js",
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"README.md",
Expand All @@ -39,7 +40,7 @@
],
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf-tools": "7.0.0-beta.19",
Expand All @@ -54,7 +55,14 @@
"bundler": {
"entries": [
"./src/index.ts"
]
],
"externals": [
"webpack",
"vite",
"rollup",
"esbuild"
],
"platform": "node"
},
"gitHead": "da902f312eb354d20aa83bf0f0035b9744f93791"
}
5 changes: 4 additions & 1 deletion code/lib/csf-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
};
});

export const { vite, rollup, webpack, esbuild } = unplugin;
export const { esbuild } = unplugin;
export const { webpack } = unplugin;
export const { rollup } = unplugin;
export const { vite } = unplugin;
14 changes: 11 additions & 3 deletions scripts/prepare/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { exec } from '../utils/exec';
type Formats = 'esm' | 'cjs';
type BundlerConfig = {
entries: string[];
untypedEntries: string[];
externals: string[];
platform: Options['platform'];
pre: string;
post: string;
Expand All @@ -33,7 +33,14 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
name,
dependencies,
peerDependencies,
bundler: { entries = [], untypedEntries = [], platform, pre, post, formats = ['esm', 'cjs'] },
bundler: {
entries = [],
externals: extraExternals = [],
platform,
pre,
post,
formats = ['esm', 'cjs'],
},
} = (await fs.readJson(join(cwd, 'package.json'))) as PackageJsonWithBundlerConfig;

if (pre) {
Expand All @@ -53,10 +60,11 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
const outDir = join(process.cwd(), 'dist');
const externals = [
name,
...extraExternals,
...Object.keys(dependencies || {}),
...Object.keys(peerDependencies || {}),
];
const allEntries = [...entries, ...untypedEntries].map((e: string) => slash(join(cwd, e)));
const allEntries = entries.map((e: string) => slash(join(cwd, e)));

const { dtsBuild, dtsConfig, tsConfigExists } = await getDTSConfigs({
formats,
Expand Down

0 comments on commit 0aed2d1

Please sign in to comment.