-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
660 additions
and
67 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,5 +1,3 @@ | ||
installStatePath: ./.yarn/root-install-state.gz | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.4.1.cjs |
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
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,18 +1,61 @@ | ||
import { dirname } from 'path'; | ||
import type { SupportedFrameworks, SupportedRenderers } from './project_types'; | ||
import { dirname, join } from 'path'; | ||
|
||
// @ts-expect-error (has no typings) | ||
import downloadTarball from 'download-tarball'; | ||
import getNpmTarballUrl from 'get-npm-tarball-url'; | ||
import * as tempy from 'tempy'; | ||
|
||
import { externalFrameworks } from './project_types'; | ||
import type { SupportedFrameworks, SupportedRenderers } from './project_types'; | ||
import type { JsPackageManager } from './js-package-manager'; | ||
import versions from './versions'; | ||
|
||
export function getCliDir() { | ||
return dirname(require.resolve('@storybook/cli/package.json')); | ||
} | ||
|
||
export function getRendererDir(renderer: SupportedFrameworks | SupportedRenderers) { | ||
const resolveUsingBranchInstall = async (packageManager: JsPackageManager, request: string) => { | ||
const tempDirectory = tempy.directory(); | ||
const name = request as keyof typeof versions; | ||
|
||
// FIXME: this might not be the right version for community packages | ||
const version = versions[name] || (await packageManager.latestVersion(request)); | ||
|
||
const url = getNpmTarballUrl(request, version); | ||
|
||
// this unzips the tarball into the temp directory | ||
await downloadTarball({ url, dir: tempDirectory }); | ||
|
||
return join(tempDirectory, 'package'); | ||
}; | ||
|
||
export async function getRendererDir( | ||
packageManager: JsPackageManager, | ||
renderer: SupportedFrameworks | SupportedRenderers | ||
) { | ||
const externalFramework = externalFrameworks.find((framework) => framework.name === renderer); | ||
const frameworkPackageName = | ||
externalFramework?.renderer || externalFramework?.packageName || `@storybook/${renderer}`; | ||
return dirname( | ||
require.resolve(`${frameworkPackageName}/package.json`, { | ||
paths: [process.cwd()], | ||
}) | ||
); | ||
|
||
const packageJsonPath = `${frameworkPackageName}/package.json`; | ||
|
||
const errors: Error[] = []; | ||
|
||
try { | ||
return dirname( | ||
require.resolve(packageJsonPath, { | ||
paths: [process.cwd()], | ||
}) | ||
); | ||
} catch (e) { | ||
errors.push(e); | ||
} | ||
|
||
try { | ||
return await resolveUsingBranchInstall(packageManager, frameworkPackageName); | ||
} catch (e) { | ||
errors.push(e); | ||
} | ||
|
||
throw new Error(`Cannot find ${packageJsonPath}, ${errors.map((e) => e.stack).join('\n\n')}`); | ||
} |
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
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
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
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
Oops, something went wrong.