Skip to content

Commit

Permalink
Merge pull request #28272 from 43081j/pkgdown
Browse files Browse the repository at this point in the history
Deps: Migrate from `read-pkg-up` to `fd-package-json`
  • Loading branch information
shilman committed Jun 23, 2024
2 parents 31ddd03 + af081d7 commit 1266a65
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 90 deletions.
2 changes: 1 addition & 1 deletion code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"@types/react-dom": "^18.0.11",
"@types/semver": "^7.3.4",
"@types/webpack-env": "^1.18.0",
"fd-package-json": "^1.2.0",
"find-up": "^5.0.0",
"read-pkg-up": "^7.0.1",
"semver": "^7.3.7",
"telejson": "^7.2.0",
"ts-dedent": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/angular/src/builders/build-storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { JsonObject } from '@angular-devkit/core';
import { from, of, throwError } from 'rxjs';
import { catchError, map, mapTo, switchMap } from 'rxjs/operators';
import { sync as findUpSync } from 'find-up';
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit/build-angular';

import { CLIOptions } from '@storybook/types';
Expand Down Expand Up @@ -107,7 +107,7 @@ const commandBuilder: BuilderHandlerFn<StorybookBuilderOptions> = (
} = options;

const standaloneOptions: StandaloneBuildOptions = {
packageJson: readUpSync({ cwd: __dirname }).packageJson,
packageJson: findPackageSync(__dirname),
configDir,
...(docs ? { docs } : {}),
loglevel,
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/angular/src/builders/start-storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit
import { from, Observable, of } from 'rxjs';
import { map, switchMap, mapTo } from 'rxjs/operators';
import { sync as findUpSync } from 'find-up';
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';

import { CLIOptions } from '@storybook/types';
import { getEnvConfig, versions } from '@storybook/core-common';
Expand Down Expand Up @@ -123,7 +123,7 @@ const commandBuilder: BuilderHandlerFn<StorybookBuilderOptions> = (options, cont
} = options;

const standaloneOptions: StandaloneOptions = {
packageJson: readUpSync({ cwd: __dirname }).packageJson,
packageJson: findPackageSync(__dirname),
ci,
configDir,
...(docs ? { docs } : {}),
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"detect-indent": "^6.1.0",
"envinfo": "^7.7.3",
"execa": "^5.0.0",
"fd-package-json": "^1.2.0",
"find-up": "^5.0.0",
"fs-extra": "^11.1.0",
"get-npm-tarball-url": "^2.0.3",
Expand All @@ -86,7 +87,6 @@
"ora": "^5.4.1",
"prettier": "^3.1.1",
"prompts": "^2.4.0",
"read-pkg-up": "^7.0.1",
"semver": "^7.3.7",
"strip-json-comments": "^3.0.1",
"tempy": "^3.1.0",
Expand Down
8 changes: 4 additions & 4 deletions code/lib/cli/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import { buildStaticStandalone, withTelemetry } from '@storybook/core-server';
import { cache } from '@storybook/core-common';
import invariant from 'tiny-invariant';

export const build = async (cliOptions: any) => {
const readUpResult = readUpSync({ cwd: __dirname });
invariant(readUpResult, 'Failed to find the closest package.json file.');
const packageJson = findPackageSync(__dirname);
invariant(packageJson, 'Failed to find the closest package.json file.');
const options = {
...cliOptions,
configDir: cliOptions.configDir || './.storybook',
outputDir: cliOptions.outputDir || './storybook-static',
ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview,
configType: 'PRODUCTION',
cache,
packageJson: readUpResult.packageJson,
packageJson,
};
await withTelemetry('build', { cliOptions, presetOptions: options }, () =>
buildStaticStandalone(options)
Expand Down
8 changes: 4 additions & 4 deletions code/lib/cli/src/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dedent } from 'ts-dedent';
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import { logger, instance as npmLog } from '@storybook/node-logger';
import { buildDevStandalone, withTelemetry } from '@storybook/core-server';
import { cache } from '@storybook/core-common';
Expand Down Expand Up @@ -40,15 +40,15 @@ function printError(error: any) {
export const dev = async (cliOptions: CLIOptions) => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';

const readUpResult = readUpSync({ cwd: __dirname });
invariant(readUpResult, 'Failed to find the closest package.json file.');
const packageJson = findPackageSync(__dirname);
invariant(packageJson, 'Failed to find the closest package.json file.');
const options = {
...cliOptions,
configDir: cliOptions.configDir || './.storybook',
configType: 'DEVELOPMENT',
ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview,
cache,
packageJson: readUpSync({ cwd: __dirname })?.packageJson,
packageJson,
} as Parameters<typeof buildDevStandalone>[0];

await withTelemetry(
Expand Down
9 changes: 4 additions & 5 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import program from 'commander';
import chalk from 'chalk';
import envinfo from 'envinfo';
import leven from 'leven';
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import invariant from 'tiny-invariant';

import { logger } from '@storybook/node-logger';
Expand Down Expand Up @@ -30,9 +30,8 @@ import { doctor } from './doctor';

addToGlobalContext('cliVersion', versions.storybook);

const readUpResult = readUpSync({ cwd: __dirname });
invariant(readUpResult, 'Failed to find the closest package.json file.');
const pkg = readUpResult.packageJson;
const pkg = findPackageSync(__dirname);
invariant(pkg, 'Failed to find the closest package.json file.');
const consoleLogger = console;

const command = (name: string) =>
Expand Down Expand Up @@ -325,4 +324,4 @@ program.on('command:*', ([invalidCmd]) => {
process.exit(1);
});

program.usage('<command> [options]').version(pkg.version).parse(process.argv);
program.usage('<command> [options]').version(String(pkg.version)).parse(process.argv);
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
"detect-port": "^1.3.0",
"diff": "^5.2.0",
"express": "^4.19.2",
"fd-package-json": "^1.2.0",
"fs-extra": "^11.1.0",
"globby": "^14.0.1",
"lodash": "^4.17.21",
"open": "^8.4.0",
"pretty-hrtime": "^1.0.3",
"prompts": "^2.4.0",
"read-pkg-up": "^7.0.1",
"semver": "^7.3.7",
"telejson": "^7.2.0",
"tiny-invariant": "^1.3.1",
Expand Down
4 changes: 2 additions & 2 deletions code/lib/core-server/src/standalone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { sync as readUpSync } from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import { buildStaticStandalone } from './build-static';
import { buildDevStandalone } from './build-dev';

async function build(options: any = {}, frameworkOptions: any = {}) {
const { mode = 'dev' } = options;
const packageJson = readUpSync({ cwd: __dirname })?.packageJson;
const packageJson = findPackageSync(__dirname);

const commonOptions = {
...options,
Expand Down
4 changes: 2 additions & 2 deletions code/lib/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"@storybook/csf-tools": "workspace:*",
"chalk": "^4.1.0",
"detect-package-manager": "^2.0.1",
"fd-package-json": "^1.2.0",
"fetch-retry": "^5.0.2",
"fs-extra": "^11.1.0",
"read-pkg-up": "^7.0.1"
"fs-extra": "^11.1.0"
},
"devDependencies": {
"nanoid": "^4.0.2",
Expand Down
6 changes: 3 additions & 3 deletions code/lib/telemetry/src/storybook-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import readPkgUp from 'read-pkg-up';
import { findPackageSync } from 'fd-package-json';
import { detect, getNpmVersion } from 'detect-package-manager';
import {
loadMainConfig,
Expand Down Expand Up @@ -224,15 +224,15 @@ export const getStorybookMetadata = async (_configDir?: string) => {
return cachedMetadata;
}

const { packageJson = {} } = readPkgUp.sync({ cwd: process.cwd(), normalize: false }) || {};
const packageJson = findPackageSync(process.cwd()) || {};
// TODO: improve the way configDir is extracted, as a "storybook" script might not be present
// Scenarios:
// 1. user changed it to something else e.g. "storybook:dev"
// 2. they are using angular/nx where the storybook config is defined somewhere else
const configDir =
(_configDir ||
(getStorybookConfiguration(
packageJson?.scripts?.storybook || '',
String((packageJson?.scripts as Record<string, unknown> | undefined)?.storybook || ''),
'-c',
'--config-dir'
) as string)) ??
Expand Down
77 changes: 14 additions & 63 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5508,8 +5508,8 @@ __metadata:
"@types/tmp": "npm:^0.2.3"
"@types/webpack-env": "npm:^1.18.0"
cross-spawn: "npm:^7.0.3"
fd-package-json: "npm:^1.2.0"
find-up: "npm:^5.0.0"
read-pkg-up: "npm:^7.0.1"
semver: "npm:^7.3.7"
telejson: "npm:^7.2.0"
tmp: "npm:^0.2.1"
Expand Down Expand Up @@ -5763,6 +5763,7 @@ __metadata:
detect-indent: "npm:^6.1.0"
envinfo: "npm:^7.7.3"
execa: "npm:^5.0.0"
fd-package-json: "npm:^1.2.0"
find-up: "npm:^5.0.0"
fs-extra: "npm:^11.1.0"
get-npm-tarball-url: "npm:^2.0.3"
Expand All @@ -5773,7 +5774,6 @@ __metadata:
ora: "npm:^5.4.1"
prettier: "npm:^3.1.1"
prompts: "npm:^2.4.0"
read-pkg-up: "npm:^7.0.1"
semver: "npm:^7.3.7"
slash: "npm:^5.0.0"
strip-ansi: "npm:^7.1.0"
Expand Down Expand Up @@ -5971,14 +5971,14 @@ __metadata:
detect-port: "npm:^1.3.0"
diff: "npm:^5.2.0"
express: "npm:^4.19.2"
fd-package-json: "npm:^1.2.0"
fs-extra: "npm:^11.1.0"
globby: "npm:^14.0.1"
lodash: "npm:^4.17.21"
node-fetch: "npm:^3.3.1"
open: "npm:^8.4.0"
pretty-hrtime: "npm:^1.0.3"
prompts: "npm:^2.4.0"
read-pkg-up: "npm:^7.0.1"
semver: "npm:^7.3.7"
slash: "npm:^5.0.0"
telejson: "npm:^7.2.0"
Expand Down Expand Up @@ -7025,11 +7025,11 @@ __metadata:
"@storybook/csf-tools": "workspace:*"
chalk: "npm:^4.1.0"
detect-package-manager: "npm:^2.0.1"
fd-package-json: "npm:^1.2.0"
fetch-retry: "npm:^5.0.2"
fs-extra: "npm:^11.1.0"
nanoid: "npm:^4.0.2"
node-fetch: "npm:^3.3.1"
read-pkg-up: "npm:^7.0.1"
typescript: "npm:^5.3.2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -8114,13 +8114,6 @@ __metadata:
languageName: node
linkType: hard

"@types/normalize-package-data@npm:^2.4.0":
version: 2.4.2
resolution: "@types/normalize-package-data@npm:2.4.2"
checksum: 10c0/e38713ca1befc341701c078d592d1fddc1d13eec73b4d81fbab14638221733029f03cdf410b4486b23d48fd8d3809fa36611de98220e76f71517d42b582b3509
languageName: node
linkType: hard

"@types/npmlog@npm:^4.1.2":
version: 4.1.6
resolution: "@types/npmlog@npm:4.1.6"
Expand Down Expand Up @@ -16700,13 +16693,6 @@ __metadata:
languageName: node
linkType: hard

"hosted-git-info@npm:^2.1.4":
version: 2.8.9
resolution: "hosted-git-info@npm:2.8.9"
checksum: 10c0/317cbc6b1bbbe23c2a40ae23f3dafe9fa349ce42a89a36f930e3f9c0530c179a3882d2ef1e4141a4c3674d6faaea862138ec55b43ad6f75e387fda2483a13c70
languageName: node
linkType: hard

"hosted-git-info@npm:^7.0.0":
version: 7.0.1
resolution: "hosted-git-info@npm:7.0.1"
Expand Down Expand Up @@ -21344,18 +21330,6 @@ __metadata:
languageName: node
linkType: hard

"normalize-package-data@npm:^2.5.0":
version: 2.5.0
resolution: "normalize-package-data@npm:2.5.0"
dependencies:
hosted-git-info: "npm:^2.1.4"
resolve: "npm:^1.10.0"
semver: "npm:2 || 3 || 4 || 5"
validate-npm-package-license: "npm:^3.0.1"
checksum: 10c0/357cb1646deb42f8eb4c7d42c4edf0eec312f3628c2ef98501963cc4bbe7277021b2b1d977f982b2edce78f5a1014613ce9cf38085c3df2d76730481357ca504
languageName: node
linkType: hard

"normalize-package-data@npm:^6.0.0":
version: 6.0.0
resolution: "normalize-package-data@npm:6.0.0"
Expand Down Expand Up @@ -23902,29 +23876,6 @@ __metadata:
languageName: node
linkType: hard

"read-pkg-up@npm:^7.0.1":
version: 7.0.1
resolution: "read-pkg-up@npm:7.0.1"
dependencies:
find-up: "npm:^4.1.0"
read-pkg: "npm:^5.2.0"
type-fest: "npm:^0.8.1"
checksum: 10c0/82b3ac9fd7c6ca1bdc1d7253eb1091a98ff3d195ee0a45386582ce3e69f90266163c34121e6a0a02f1630073a6c0585f7880b3865efcae9c452fa667f02ca385
languageName: node
linkType: hard

"read-pkg@npm:^5.2.0":
version: 5.2.0
resolution: "read-pkg@npm:5.2.0"
dependencies:
"@types/normalize-package-data": "npm:^2.4.0"
normalize-package-data: "npm:^2.5.0"
parse-json: "npm:^5.0.0"
type-fest: "npm:^0.6.0"
checksum: 10c0/b51a17d4b51418e777029e3a7694c9bd6c578a5ab99db544764a0b0f2c7c0f58f8a6bc101f86a6fceb8ba6d237d67c89acf6170f6b98695d0420ddc86cf109fb
languageName: node
linkType: hard

"readable-stream@npm:^2.0.0, readable-stream@npm:^2.0.1, readable-stream@npm:~2.3.6":
version: 2.3.8
resolution: "readable-stream@npm:2.3.8"
Expand Down Expand Up @@ -25236,15 +25187,6 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.3.0, semver@npm:^5.5.0, semver@npm:^5.6.0":
version: 5.7.2
resolution: "semver@npm:5.7.2"
bin:
semver: bin/semver
checksum: 10c0/e4cf10f86f168db772ae95d86ba65b3fd6c5967c94d97c708ccb463b778c2ee53b914cd7167620950fc07faf5a564e6efe903836639e512a1aa15fbc9667fa25
languageName: node
linkType: hard

"semver@npm:7.6.0, semver@npm:^7.0.0, semver@npm:^7.1.1, semver@npm:^7.2.1, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0":
version: 7.6.0
resolution: "semver@npm:7.6.0"
Expand All @@ -25256,6 +25198,15 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^5.3.0, semver@npm:^5.5.0, semver@npm:^5.6.0":
version: 5.7.2
resolution: "semver@npm:5.7.2"
bin:
semver: bin/semver
checksum: 10c0/e4cf10f86f168db772ae95d86ba65b3fd6c5967c94d97c708ccb463b778c2ee53b914cd7167620950fc07faf5a564e6efe903836639e512a1aa15fbc9667fa25
languageName: node
linkType: hard

"semver@npm:^6.0.0, semver@npm:^6.3.0, semver@npm:^6.3.1":
version: 6.3.1
resolution: "semver@npm:6.3.1"
Expand Down Expand Up @@ -28103,7 +28054,7 @@ __metadata:
languageName: node
linkType: hard

"validate-npm-package-license@npm:^3.0.1, validate-npm-package-license@npm:^3.0.4":
"validate-npm-package-license@npm:^3.0.4":
version: 3.0.4
resolution: "validate-npm-package-license@npm:3.0.4"
dependencies:
Expand Down

0 comments on commit 1266a65

Please sign in to comment.