Skip to content

Commit

Permalink
Merge branch 'next' into feature/ensure-gitignore-updated-via-cli-end…
Browse files Browse the repository at this point in the history
…s-with-a-newline
  • Loading branch information
kasperpeulen authored Sep 24, 2024
2 parents 3d4f7ec + 60e266a commit 9a059d9
Show file tree
Hide file tree
Showing 85 changed files with 549 additions and 354 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ jobs:
mkdir empty-<< parameters.template >>-no-install
cd empty-<< parameters.template >>-no-install
npx storybook init --yes --skip-install
npm install
npm run build-storybook
environment:
IN_STORYBOOK_SANDBOX: true
STORYBOOK_INIT_EMPTY_TYPE: << parameters.template >>
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 8.3.2

- CLI: Fix skip-install for stable latest releases - [#29133](https://github.com/storybookjs/storybook/pull/29133), thanks @valentinpalkovic!
- Core: Do not add packageManager field to package.json during `storybook dev` - [#29152](https://github.com/storybookjs/storybook/pull/29152), thanks @valentinpalkovic!

## 8.3.1

- Angular: Fix sourceDecorator to apply excludeDecorators flag - [#29069](https://github.com/storybookjs/storybook/pull/29069), thanks @JSMike!
- Core: Do not prebundle better-opn - [#29137](https://github.com/storybookjs/storybook/pull/29137), thanks @valentinpalkovic!
- Core: Do not prebundle jsdoc-type-pratt-parser - [#29134](https://github.com/storybookjs/storybook/pull/29134), thanks @valentinpalkovic!
- Next.js: Upgrade sass-loader from ^12 to ^13 - [#29040](https://github.com/storybookjs/storybook/pull/29040), thanks @HoncharenkoZhenya!

## 8.3.0

Fresh out of the oven! Storybook 8.3 brings you:
Expand Down
29 changes: 0 additions & 29 deletions code/__mocks__/fs.js

This file was deleted.

32 changes: 32 additions & 0 deletions code/__mocks__/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { vi } from 'vitest';

// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let mockFiles = Object.create(null);

// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/naming-convention
export function __setMockFiles(newMockFiles: Record<string, string | null>) {
mockFiles = newMockFiles;
}

export const readFileSync = (filePath = '') => mockFiles[filePath];
export const existsSync = (filePath: string) => !!mockFiles[filePath];
export const lstatSync = (filePath: string) => ({
isFile: () => !!mockFiles[filePath],
});
export const realpathSync = vi.fn();
export const readdir = vi.fn();
export const readdirSync = vi.fn();
export const readlinkSync = vi.fn();

export default {
__setMockFiles,
readFileSync,
existsSync,
lstatSync,
realpathSync,
readdir,
readdirSync,
readlinkSync,
};
32 changes: 32 additions & 0 deletions code/__mocks__/fs/promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { vi } from 'vitest';

// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let mockFiles = Object.create(null);

// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/naming-convention
export function __setMockFiles(newMockFiles: Record<string, string | null>) {
mockFiles = newMockFiles;
}

export const writeFile = vi.fn(async (filePath: string, content: string) => {
mockFiles[filePath] = content;
});
export const readFile = vi.fn(async (filePath: string) => mockFiles[filePath]);
export const lstat = vi.fn(async (filePath: string) => ({
isFile: () => !!mockFiles[filePath],
}));
export const readdir = vi.fn();
export const readlink = vi.fn();
export const realpath = vi.fn();

export default {
__setMockFiles,
writeFile,
readFile,
lstat,
readdir,
readlink,
realpath,
};
1 change: 0 additions & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"@storybook/global": "^5.0.0",
"@storybook/react-dom-shim": "workspace:*",
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"fs-extra": "^11.1.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
"rehype-external-links": "^3.0.0",
Expand Down
1 change: 0 additions & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"ts-dedent": "^2.0.0"
},
"devDependencies": {
"fs-extra": "^11.1.0",
"typescript": "^5.3.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion code/addons/links/scripts/fix-preview-api-reference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile, writeFile } from 'fs-extra';
import { readFile, writeFile } from 'node:fs/promises';

/* I wish this wasn't needed..
* There seems to be some bug in tsup / the unlaying lib that does DTS bundling
Expand Down
2 changes: 1 addition & 1 deletion code/addons/themes/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const myCustomDecorator = ({ themes, defaultState, ...rest }) => {
Let's use Vuetify as an example. Vuetify uses it's own global state to know which theme to render. To build a custom decorator to accommodate this method we'll need to do the following

```js
// .storybook/withVeutifyTheme.decorator.js
// .storybook/withVuetifyTheme.decorator.js
import { DecoratorHelpers } from '@storybook/addon-themes';
import { useTheme } from 'vuetify';

Expand Down
1 change: 0 additions & 1 deletion code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"es-module-lexer": "^1.5.0",
"express": "^4.19.2",
"find-cache-dir": "^3.0.0",
"fs-extra": "^11.1.0",
"magic-string": "^0.30.0",
"ts-dedent": "^2.0.0"
},
Expand Down
12 changes: 6 additions & 6 deletions code/builders/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// noinspection JSUnusedGlobalSymbols
import { cp, readFile } from 'node:fs/promises';
import { join, parse } from 'node:path';

import { NoStatsForViteDevError } from 'storybook/internal/server-errors';
import type { Options } from 'storybook/internal/types';

import type { RequestHandler } from 'express';
import express from 'express';
import * as fs from 'fs-extra';
import { corePath } from 'storybook/core-path';
import type { ViteDevServer } from 'vite';

Expand Down Expand Up @@ -34,10 +34,9 @@ function iframeMiddleware(options: Options, server: ViteDevServer): RequestHandl
return;
}

const indexHtml = await fs.readFile(
require.resolve('@storybook/builder-vite/input/iframe.html'),
'utf-8'
);
const indexHtml = await readFile(require.resolve('@storybook/builder-vite/input/iframe.html'), {
encoding: 'utf8',
});
const generated = await transformIframeHtml(indexHtml, options);
const transformed = await server.transformIndexHtml('/iframe.html', generated);
res.setHeader('Content-Type', 'text/html');
Expand Down Expand Up @@ -85,14 +84,15 @@ export const build: ViteBuilder['build'] = async ({ options }) => {
const previewDirOrigin = previewResolvedDir;
const previewDirTarget = join(options.outputDir || '', `sb-preview`);

const previewFiles = fs.copy(previewDirOrigin, previewDirTarget, {
const previewFiles = cp(previewDirOrigin, previewDirTarget, {
filter: (src) => {
const { ext } = parse(src);
if (ext) {
return ext === '.js';
}
return true;
},
recursive: true,
});

const [out] = await Promise.all([viteCompilation, previewFiles]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { join } from 'node:path';
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';

import { init, parse } from 'es-module-lexer';
import findCacheDirectory from 'find-cache-dir';
import { ensureFile, writeFile } from 'fs-extra';
import MagicString from 'magic-string';
import type { Alias, Plugin } from 'vite';

Expand Down Expand Up @@ -59,7 +60,10 @@ export async function externalGlobalsPlugin(externals: Record<string, string>) {
(Object.keys(externals) as Array<keyof typeof externals>).map(async (externalKey) => {
const externalCachePath = join(cachePath, `${externalKey}.js`);
newAlias.push({ find: new RegExp(`^${externalKey}$`), replacement: externalCachePath });
await ensureFile(externalCachePath);
if (!existsSync(externalCachePath)) {
const directory = dirname(externalCachePath);
await mkdir(directory, { recursive: true });
}
await writeFile(externalCachePath, `module.exports = ${externals[externalKey]};`);
})
);
Expand Down
1 change: 0 additions & 1 deletion code/builders/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"es-module-lexer": "^1.5.0",
"express": "^4.19.2",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"fs-extra": "^11.1.0",
"html-webpack-plugin": "^5.5.0",
"magic-string": "^0.30.5",
"path-browserify": "^1.0.1",
Expand Down
5 changes: 3 additions & 2 deletions code/builders/builder-webpack5/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cp } from 'node:fs/promises';
import { join, parse } from 'node:path';

import { PREVIEW_BUILDER_PROGRESS } from 'storybook/internal/core-events';
Expand All @@ -12,7 +13,6 @@ import type { Builder, Options } from 'storybook/internal/types';
import { checkWebpackVersion } from '@storybook/core-webpack';

import express from 'express';
import fs from 'fs-extra';
import prettyTime from 'pretty-hrtime';
import { corePath } from 'storybook/core-path';
import type { Configuration, Stats, StatsOptions } from 'webpack';
Expand Down Expand Up @@ -292,14 +292,15 @@ const builder: BuilderFunction = async function* builderGeneratorFn({ startTime,
const previewDirOrigin = previewResolvedDir;
const previewDirTarget = join(options.outputDir || '', `sb-preview`);

const previewFiles = fs.copy(previewDirOrigin, previewDirTarget, {
const previewFiles = cp(previewDirOrigin, previewDirTarget, {
filter: (src) => {
const { ext } = parse(src);
if (ext) {
return ext === '.js';
}
return true;
},
recursive: true,
});

const [webpackCompilationOutput] = await Promise.all([webpackCompilation, previewFiles]);
Expand Down
7 changes: 3 additions & 4 deletions code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@
"dependencies": {
"@storybook/csf": "^0.1.11",
"@types/express": "^4.17.21",
"better-opn": "^3.0.2",
"browser-assert": "^1.2.1",
"esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0",
"esbuild-register": "^3.5.0",
"express": "^4.19.2",
"jsdoc-type-pratt-parser": "^4.0.0",
"process": "^0.11.10",
"recast": "^0.23.5",
"semver": "^7.6.2",
Expand Down Expand Up @@ -320,7 +322,6 @@
"@types/diff": "^5.0.9",
"@types/ejs": "^3.1.1",
"@types/find-cache-dir": "^5.0.0",
"@types/fs-extra": "^11.0.1",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.167",
"@types/node": "^22.0.0",
Expand All @@ -340,7 +341,6 @@
"ansi-to-html": "^0.7.2",
"assert": "^2.1.0",
"babel-plugin-react-docgen": "4.2.1",
"better-opn": "^3.0.2",
"boxen": "^7.1.1",
"browser-dtector": "^3.4.0",
"camelcase": "^8.0.0",
Expand Down Expand Up @@ -371,14 +371,13 @@
"find-cache-dir": "^5.0.0",
"find-up": "^7.0.0",
"flush-promises": "^1.0.2",
"fs-extra": "^11.1.0",
"fuse.js": "^3.6.1",
"get-npm-tarball-url": "^2.0.3",
"glob": "^10.0.0",
"globby": "^14.0.1",
"handlebars": "^4.7.7",
"jiti": "^1.21.6",
"js-yaml": "^4.1.0",
"jsdoc-type-pratt-parser": "^4.0.0",
"lazy-universal-dotenv": "^4.0.0",
"leven": "^4.0.0",
"lodash": "^4.17.21",
Expand Down
7 changes: 4 additions & 3 deletions code/core/scripts/helpers/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

import { readJson } from 'fs-extra';

export async function flattenDependencies(
list: string[],
output: string[] = [],
Expand All @@ -18,7 +17,9 @@ export async function flattenDependencies(
console.log(dep + ' not found');
return;
}
const { dependencies = {}, peerDependencies = {} } = await readJson(path);
const { dependencies = {}, peerDependencies = {} } = JSON.parse(
await readFile(path, { encoding: 'utf8' })
);
const all: string[] = [
...new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)]),
]
Expand Down
5 changes: 2 additions & 3 deletions code/core/scripts/helpers/generatePackageJsonFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { writeFile } from 'node:fs/promises';
import { readFile, writeFile } from 'node:fs/promises';
import { join, relative } from 'node:path';

import { readJSON } from 'fs-extra';
import slash from 'slash';

import { sortPackageJson } from '../../../../scripts/prepare/tools';
Expand All @@ -11,7 +10,7 @@ const cwd = process.cwd();

export async function generatePackageJsonFile(entries: ReturnType<typeof getEntries>) {
const location = join(cwd, 'package.json');
const pkgJson = await readJSON(location);
const pkgJson = JSON.parse(await readFile(location, { encoding: 'utf8' }));

/**
* Re-create the `exports` field in `code/core/package.json` This way we only need to update the
Expand Down
12 changes: 7 additions & 5 deletions code/core/scripts/helpers/generateTypesMapperFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { writeFile } from 'node:fs/promises';
import { join, relative } from 'node:path';

import { ensureFile } from 'fs-extra';
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname, join, relative } from 'node:path';

import { dedent } from '../../../../scripts/prepare/tools';
import type { getEntries } from '../entries';
Expand Down Expand Up @@ -34,7 +33,10 @@ export async function generateTypesMapperFiles(entries: ReturnType<typeof getEnt
await Promise.all(
all.map(async (filePath) => {
const location = filePath.replace('src', 'dist').replace(/\.tsx?/, '.d.ts');
await ensureFile(location);
if (!existsSync(location)) {
const directory = dirname(location);
await mkdir(directory, { recursive: true });
}
await writeFile(location, await generateTypesMapperContent(filePath));
})
);
Expand Down
8 changes: 4 additions & 4 deletions code/core/scripts/prep.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable local-rules/no-uncategorized-errors */
import { watch } from 'node:fs';
import { existsSync, mkdirSync, watch } from 'node:fs';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';

import { ensureDir } from 'fs-extra';

import {
chalk,
dedent,
Expand Down Expand Up @@ -320,7 +318,9 @@ async function run() {
const outName =
keys.length === 1 ? dirname(keys[0]).replace('dist/', '') : `meta-${format}-${index}`;

await ensureDir('report');
if (!existsSync('report')) {
mkdirSync('report');
}
await writeFile(`report/${outName}.json`, JSON.stringify(out.metafile, null, 2));
await writeFile(
`report/${outName}.txt`,
Expand Down
Loading

0 comments on commit 9a059d9

Please sign in to comment.