Merge branch 'next' into tech/jest-swc-standalone

This commit is contained in:
Norbert de Langen 2022-12-23 16:13:16 +01:00
commit a8c00039e6
No known key found for this signature in database
GPG Key ID: FD0E78AF9A837762
11 changed files with 147 additions and 584 deletions

View File

@ -125,7 +125,7 @@ Storybook Docs renders all Ember stories inside `iframe`s, with a default height
To update the global default, modify `.storybook/preview.js`: To update the global default, modify `.storybook/preview.js`:
```ts ```ts
export const parameters = { docs: { iframeHeight: 400 } }; export const parameters = { docs: { iframeHeight: 400 } };
``` ```
For `DocsPage`, you need to update the parameter locally in a story: For `DocsPage`, you need to update the parameter locally in a story:

View File

@ -98,7 +98,6 @@ Some **markdown** description, or whatever you want.
## Inline stories ## Inline stories
Storybook Docs renders all React stories inline by default. Storybook Docs renders all React stories inline by default.
However, you can render stories in an iframe, with a default height of `60px` (configurable using the `docs.iframeHeight` story parameter), by using the `docs.inlineStories` parameter. However, you can render stories in an iframe, with a default height of `60px` (configurable using the `docs.iframeHeight` story parameter), by using the `docs.inlineStories` parameter.

View File

@ -140,7 +140,7 @@ However, you can render stories in an iframe, with a default height of `60px` (c
To do so for all stories, update `.storybook/preview.js`: To do so for all stories, update `.storybook/preview.js`:
```js ```js
export const parameters = { docs: { inlineStories: false, }, }; export const parameters = { docs: { inlineStories: false } };
``` ```
## More resources ## More resources

View File

@ -112,7 +112,6 @@ For a full example see the [web-components-kitchen-sink/custom-elements.json](..
## Stories not inline ## Stories not inline
Storybook Docs renders all web components stories inline by default. Storybook Docs renders all web components stories inline by default.
However, you can render stories in an iframe, with a default height of `60px` (configurable using the `docs.iframeHeight` story parameter), by using the `docs.inlineStories` parameter. However, you can render stories in an iframe, with a default height of `60px` (configurable using the `docs.iframeHeight` story parameter), by using the `docs.inlineStories` parameter.

View File

@ -84,7 +84,7 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.5", "@babel/core": "^7.20.5",
"@babel/types": "^7.20.5", "@babel/types": "^7.20.5",
"@storybook/addon-actions": "7.0.0-beta.12", "@storybook/addon-actions": "7.0.0-beta.14",
"@types/babel__core": "^7", "@types/babel__core": "^7",
"next": "^13.0.5", "next": "^13.0.5",
"typescript": "^4.9.3", "typescript": "^4.9.3",

View File

@ -46,12 +46,14 @@
"@storybook/manager": "7.0.0-beta.14", "@storybook/manager": "7.0.0-beta.14",
"@storybook/node-logger": "7.0.0-beta.14", "@storybook/node-logger": "7.0.0-beta.14",
"@types/ejs": "^3.1.1", "@types/ejs": "^3.1.1",
"@types/find-cache-dir": "^3.2.1",
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.10", "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.10",
"browser-assert": "^1.2.1", "browser-assert": "^1.2.1",
"ejs": "^3.1.8", "ejs": "^3.1.8",
"esbuild": "^0.16.4", "esbuild": "^0.16.4",
"esbuild-plugin-alias": "^0.2.1", "esbuild-plugin-alias": "^0.2.1",
"express": "^4.17.3", "express": "^4.17.3",
"find-cache-dir": "^4.0.0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"process": "^0.11.10", "process": "^0.11.10",
"slash": "^3.0.0", "slash": "^3.0.0",

View File

@ -10,6 +10,7 @@ import aliasPlugin from 'esbuild-plugin-alias';
import { getTemplatePath, renderHTML } from './utils/template'; import { getTemplatePath, renderHTML } from './utils/template';
import { definitions } from './utils/globals'; import { definitions } from './utils/globals';
import { wrapManagerEntries } from './utils/managerEntries';
import type { import type {
BuilderBuildResult, BuilderBuildResult,
BuilderFunction, BuilderFunction,
@ -34,10 +35,14 @@ export const getConfig: ManagerBuilder['getConfig'] = async (options) => {
getTemplatePath('addon.tsconfig.json'), getTemplatePath('addon.tsconfig.json'),
]); ]);
const entryPoints = customManagerEntryPoint
? [...addonsEntryPoints, customManagerEntryPoint]
: addonsEntryPoints;
const realEntryPoints = await wrapManagerEntries(entryPoints);
return { return {
entryPoints: customManagerEntryPoint entryPoints: realEntryPoints,
? [...addonsEntryPoints, customManagerEntryPoint]
: addonsEntryPoints,
outdir: join(options.outputDir || './', 'sb-addons'), outdir: join(options.outputDir || './', 'sb-addons'),
format: 'esm', format: 'esm',
write: false, write: false,

View File

@ -0,0 +1,37 @@
import { join, parse, relative } from 'path';
import fs from 'fs-extra';
import findCacheDirectory from 'find-cache-dir';
/**
* Manager entries should be **self-invoking** bits of code.
* They can of-course import from modules, and ESbuild will bundle all of that into a single file.
* But they should not export anything. However this can't be enforced, so what we do is wrap the given file, in a bit of code like this:
*
* ```js
* import '<<file>>';
* ```
*
* That way we are indicating to ESbuild that we do not care about this files exports, and they will be dropped in the bundle.
*
* We do all of that so we can wrap a try-catch around the code.
* That would have been invalid syntax had the export statements been left in place.
*
* We need to wrap each managerEntry with a try-catch because if we do not, a failing managerEntry can stop execution of other managerEntries.
*/
export async function wrapManagerEntries(entrypoints: string[]) {
return Promise.all(
entrypoints.map(async (entry) => {
const { name, dir } = parse(entry);
const cacheLocation = findCacheDirectory({ name: 'sb-manager' });
if (!cacheLocation) {
throw new Error('Could not create/find cache directory');
}
const location = join(cacheLocation, relative(process.cwd(), dir), `${name}-bundle.mjs`);
await fs.ensureFile(location);
await fs.writeFile(location, `import '${entry}';`);
return location;
})
);
}

View File

@ -196,7 +196,7 @@
"@storybook/html-webpack5": "workspace:*", "@storybook/html-webpack5": "workspace:*",
"@storybook/instrumenter": "workspace:*", "@storybook/instrumenter": "workspace:*",
"@storybook/jest": "next", "@storybook/jest": "next",
"@storybook/linter-config": "^2.5.0", "@storybook/linter-config": "^3.1.2",
"@storybook/manager": "workspace:*", "@storybook/manager": "workspace:*",
"@storybook/manager-api": "workspace:*", "@storybook/manager-api": "workspace:*",
"@storybook/nextjs": "workspace:*", "@storybook/nextjs": "workspace:*",

File diff suppressed because it is too large Load Diff