-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from chromaui/next
Upgrade to Storybook 8
- Loading branch information
Showing
11 changed files
with
2,702 additions
and
2,706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
// this configuration is used by jest, not for actual building the addon | ||
|
||
module.exports = { | ||
targets: "defaults", | ||
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"], | ||
targets: "defaults", | ||
presets: ["@babel/preset-env", "@babel/preset-typescript"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"buildScriptName": "build:storybook", | ||
"projectId": "Project:6008aabce49a640021858011" | ||
"projectId": "Project:6008aabce49a640021858011", | ||
"zip": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
if (module && module.hot && module.hot.decline) { | ||
module.hot.decline() | ||
} | ||
|
||
// make it work with --isolatedModules | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "ES2022", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"incremental": false, | ||
"isolatedModules": true, | ||
"jsx": "react", | ||
} | ||
"module": "ES2022", | ||
"moduleResolution": "node", | ||
"rootDir": "./src", | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"target": "ES2022", | ||
}, | ||
"include": ["src/**/*"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,112 @@ | ||
import { defineConfig } from "tsup" | ||
import { defineConfig, type Options } from "tsup"; | ||
import { readFile } from "fs/promises"; | ||
import { globalPackages as globalManagerPackages } from "@storybook/manager/globals"; | ||
import { globalPackages as globalPreviewPackages } from "@storybook/preview/globals"; | ||
|
||
export default defineConfig(() => { | ||
return { | ||
dts: { entry: ["src/index.ts", "src/manager.ts", "src/preview.ts"] }, | ||
entry: ["src/index.ts", "src/manager.ts", "src/preview.ts"], | ||
format: ["esm", "cjs"], | ||
// The current browsers supported by Storybook v7 | ||
const BROWSER_TARGET: Options['target'] = ["chrome100", "safari15", "firefox91"]; | ||
const NODE_TARGET: Options['target'] = ["node18"]; | ||
|
||
type BundlerConfig = { | ||
bundler?: { | ||
exportEntries?: string[]; | ||
nodeEntries?: string[]; | ||
managerEntries?: string[]; | ||
previewEntries?: string[]; | ||
}; | ||
}; | ||
|
||
export default defineConfig(async (options) => { | ||
// reading the three types of entries from package.json, which has the following structure: | ||
// { | ||
// ... | ||
// "bundler": { | ||
// "exportEntries": ["./src/index.ts"], | ||
// "managerEntries": ["./src/manager.ts"], | ||
// "previewEntries": ["./src/preview.ts"] | ||
// "nodeEntries": ["./src/preset.ts"] | ||
// } | ||
// } | ||
const packageJson = await readFile('./package.json', 'utf8').then(JSON.parse) as BundlerConfig; | ||
const { | ||
bundler: { | ||
exportEntries = [], | ||
managerEntries = [], | ||
previewEntries = [], | ||
nodeEntries = [], | ||
} = {}, | ||
} = packageJson; | ||
|
||
const commonConfig: Options = { | ||
splitting: false, | ||
minify: !options.watch, | ||
treeshake: true, | ||
sourcemap: true, | ||
clean: true, | ||
}; | ||
|
||
const configs: Options[] = []; | ||
|
||
// export entries are entries meant to be manually imported by the user | ||
// they are not meant to be loaded by the manager or preview | ||
// they'll be usable in both node and browser environments, depending on which features and modules they depend on | ||
if (exportEntries.length) { | ||
configs.push({ | ||
...commonConfig, | ||
entry: exportEntries, | ||
dts: { | ||
resolve: true, | ||
}, | ||
format: ["esm", "cjs"], | ||
target: [...BROWSER_TARGET, ...NODE_TARGET], | ||
platform: "neutral", | ||
external: [...globalManagerPackages, ...globalPreviewPackages], | ||
}); | ||
} | ||
|
||
// manager entries are entries meant to be loaded into the manager UI | ||
// they'll have manager-specific packages externalized and they won't be usable in node | ||
// they won't have types generated for them as they're usually loaded automatically by Storybook | ||
if (managerEntries.length) { | ||
configs.push({ | ||
...commonConfig, | ||
entry: managerEntries, | ||
format: ["esm"], | ||
target: BROWSER_TARGET, | ||
platform: "browser", | ||
external: globalManagerPackages, | ||
}); | ||
} | ||
|
||
// preview entries are entries meant to be loaded into the preview iframe | ||
// they'll have preview-specific packages externalized and they won't be usable in node | ||
// they'll have types generated for them so they can be imported when setting up Portable Stories | ||
if (previewEntries.length) { | ||
configs.push({ | ||
...commonConfig, | ||
entry: previewEntries, | ||
dts: { | ||
resolve: true, | ||
}, | ||
format: ["esm", "cjs"], | ||
target: BROWSER_TARGET, | ||
platform: "browser", | ||
external: globalPreviewPackages, | ||
}); | ||
} | ||
}) | ||
|
||
// node entries are entries meant to be used in node-only | ||
// this is useful for presets, which are loaded by Storybook when setting up configurations | ||
// they won't have types generated for them as they're usually loaded automatically by Storybook | ||
if (nodeEntries.length) { | ||
configs.push({ | ||
...commonConfig, | ||
entry: nodeEntries, | ||
format: ["cjs"], | ||
target: NODE_TARGET, | ||
platform: "node", | ||
}); | ||
} | ||
|
||
return configs; | ||
}); |
Oops, something went wrong.