Skip to content

Commit af081d7

Browse files
committed
feat: migrate from read-pkg-up
Migrates away from using read-pkg-up to a lighter alternative with fewer deep dependencies.
1 parent 08d51e8 commit af081d7

File tree

12 files changed

+49
-90
lines changed

12 files changed

+49
-90
lines changed

code/frameworks/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"@types/react-dom": "^18.0.11",
5555
"@types/semver": "^7.3.4",
5656
"@types/webpack-env": "^1.18.0",
57+
"fd-package-json": "^1.2.0",
5758
"find-up": "^5.0.0",
58-
"read-pkg-up": "^7.0.1",
5959
"semver": "^7.3.7",
6060
"telejson": "^7.2.0",
6161
"ts-dedent": "^2.0.0",

code/frameworks/angular/src/builders/build-storybook/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { JsonObject } from '@angular-devkit/core';
1111
import { from, of, throwError } from 'rxjs';
1212
import { catchError, map, mapTo, switchMap } from 'rxjs/operators';
1313
import { sync as findUpSync } from 'find-up';
14-
import { sync as readUpSync } from 'read-pkg-up';
14+
import { findPackageSync } from 'fd-package-json';
1515
import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit/build-angular';
1616

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

109109
const standaloneOptions: StandaloneBuildOptions = {
110-
packageJson: readUpSync({ cwd: __dirname }).packageJson,
110+
packageJson: findPackageSync(__dirname),
111111
configDir,
112112
...(docs ? { docs } : {}),
113113
loglevel,

code/frameworks/angular/src/builders/start-storybook/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit
1111
import { from, Observable, of } from 'rxjs';
1212
import { map, switchMap, mapTo } from 'rxjs/operators';
1313
import { sync as findUpSync } from 'find-up';
14-
import { sync as readUpSync } from 'read-pkg-up';
14+
import { findPackageSync } from 'fd-package-json';
1515

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

125125
const standaloneOptions: StandaloneOptions = {
126-
packageJson: readUpSync({ cwd: __dirname }).packageJson,
126+
packageJson: findPackageSync(__dirname),
127127
ci,
128128
configDir,
129129
...(docs ? { docs } : {}),

code/lib/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"detect-indent": "^6.1.0",
7777
"envinfo": "^7.7.3",
7878
"execa": "^5.0.0",
79+
"fd-package-json": "^1.2.0",
7980
"find-up": "^5.0.0",
8081
"fs-extra": "^11.1.0",
8182
"get-npm-tarball-url": "^2.0.3",
@@ -86,7 +87,6 @@
8687
"ora": "^5.4.1",
8788
"prettier": "^3.1.1",
8889
"prompts": "^2.4.0",
89-
"read-pkg-up": "^7.0.1",
9090
"semver": "^7.3.7",
9191
"strip-json-comments": "^3.0.1",
9292
"tempy": "^3.1.0",

code/lib/cli/src/build.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { sync as readUpSync } from 'read-pkg-up';
1+
import { findPackageSync } from 'fd-package-json';
22
import { buildStaticStandalone, withTelemetry } from '@storybook/core-server';
33
import { cache } from '@storybook/core-common';
44
import invariant from 'tiny-invariant';
55

66
export const build = async (cliOptions: any) => {
7-
const readUpResult = readUpSync({ cwd: __dirname });
8-
invariant(readUpResult, 'Failed to find the closest package.json file.');
7+
const packageJson = findPackageSync(__dirname);
8+
invariant(packageJson, 'Failed to find the closest package.json file.');
99
const options = {
1010
...cliOptions,
1111
configDir: cliOptions.configDir || './.storybook',
1212
outputDir: cliOptions.outputDir || './storybook-static',
1313
ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview,
1414
configType: 'PRODUCTION',
1515
cache,
16-
packageJson: readUpResult.packageJson,
16+
packageJson,
1717
};
1818
await withTelemetry('build', { cliOptions, presetOptions: options }, () =>
1919
buildStaticStandalone(options)

code/lib/cli/src/dev.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dedent } from 'ts-dedent';
2-
import { sync as readUpSync } from 'read-pkg-up';
2+
import { findPackageSync } from 'fd-package-json';
33
import { logger, instance as npmLog } from '@storybook/node-logger';
44
import { buildDevStandalone, withTelemetry } from '@storybook/core-server';
55
import { cache } from '@storybook/core-common';
@@ -40,15 +40,15 @@ function printError(error: any) {
4040
export const dev = async (cliOptions: CLIOptions) => {
4141
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
4242

43-
const readUpResult = readUpSync({ cwd: __dirname });
44-
invariant(readUpResult, 'Failed to find the closest package.json file.');
43+
const packageJson = findPackageSync(__dirname);
44+
invariant(packageJson, 'Failed to find the closest package.json file.');
4545
const options = {
4646
...cliOptions,
4747
configDir: cliOptions.configDir || './.storybook',
4848
configType: 'DEVELOPMENT',
4949
ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview,
5050
cache,
51-
packageJson: readUpSync({ cwd: __dirname })?.packageJson,
51+
packageJson,
5252
} as Parameters<typeof buildDevStandalone>[0];
5353

5454
await withTelemetry(

code/lib/cli/src/generate.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import program from 'commander';
22
import chalk from 'chalk';
33
import envinfo from 'envinfo';
44
import leven from 'leven';
5-
import { sync as readUpSync } from 'read-pkg-up';
5+
import { findPackageSync } from 'fd-package-json';
66
import invariant from 'tiny-invariant';
77

88
import { logger } from '@storybook/node-logger';
@@ -30,9 +30,8 @@ import { doctor } from './doctor';
3030

3131
addToGlobalContext('cliVersion', versions.storybook);
3232

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

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

328-
program.usage('<command> [options]').version(pkg.version).parse(process.argv);
327+
program.usage('<command> [options]').version(String(pkg.version)).parse(process.argv);

code/lib/core-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@
8585
"detect-port": "^1.3.0",
8686
"diff": "^5.2.0",
8787
"express": "^4.19.2",
88+
"fd-package-json": "^1.2.0",
8889
"fs-extra": "^11.1.0",
8990
"globby": "^14.0.1",
9091
"lodash": "^4.17.21",
9192
"open": "^8.4.0",
9293
"pretty-hrtime": "^1.0.3",
9394
"prompts": "^2.4.0",
94-
"read-pkg-up": "^7.0.1",
9595
"semver": "^7.3.7",
9696
"telejson": "^7.2.0",
9797
"tiny-invariant": "^1.3.1",

code/lib/core-server/src/standalone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { sync as readUpSync } from 'read-pkg-up';
1+
import { findPackageSync } from 'fd-package-json';
22
import { buildStaticStandalone } from './build-static';
33
import { buildDevStandalone } from './build-dev';
44

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

99
const commonOptions = {
1010
...options,

code/lib/telemetry/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"@storybook/csf-tools": "workspace:*",
5050
"chalk": "^4.1.0",
5151
"detect-package-manager": "^2.0.1",
52+
"fd-package-json": "^1.2.0",
5253
"fetch-retry": "^5.0.2",
53-
"fs-extra": "^11.1.0",
54-
"read-pkg-up": "^7.0.1"
54+
"fs-extra": "^11.1.0"
5555
},
5656
"devDependencies": {
5757
"nanoid": "^4.0.2",

0 commit comments

Comments
 (0)