From 0930e4d8d354298f96e4bf9cefb1c0ce1a15e116 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 9 Dec 2020 13:23:02 +0100 Subject: [PATCH] move version.json --- lib/cli/package.json | 2 +- lib/cli/scripts/generate-sb-packages-versions.js | 4 +++- lib/cli/src/js-package-manager/JsPackageManager.ts | 6 +++--- lib/cli/src/js-package-manager/NPMProxy.test.ts | 2 +- lib/cli/{ => src}/versions.json | 0 lib/cli/tsconfig.json | 3 ++- 6 files changed, 10 insertions(+), 7 deletions(-) rename lib/cli/{ => src}/versions.json (100%) diff --git a/lib/cli/package.json b/lib/cli/package.json index 1f4514b1ea5..78b7ec3260b 100644 --- a/lib/cli/package.json +++ b/lib/cli/package.json @@ -38,7 +38,7 @@ "versions.json" ], "scripts": { - "prepare": "node ../../scripts/prepare.js && node ./scripts/generate-sb-packages-versions.js", + "prepare": "node ./scripts/generate-sb-packages-versions.js && node ../../scripts/prepare.js", "test": "jest test/**/*.test.js", "postversion": "node ./scripts/generate-sb-packages-versions.js" }, diff --git a/lib/cli/scripts/generate-sb-packages-versions.js b/lib/cli/scripts/generate-sb-packages-versions.js index 3fcb348c9e6..069d9359627 100644 --- a/lib/cli/scripts/generate-sb-packages-versions.js +++ b/lib/cli/scripts/generate-sb-packages-versions.js @@ -32,7 +32,9 @@ const run = async () => { .sort((package1, package2) => package1.name.localeCompare(package2.name)) .reduce((acc, { name, version }) => ({ ...acc, [name]: version }), {}); - await writeJson(path.join(__dirname, '..', 'versions.json'), packageToVersionMap, { spaces: 2 }); + await writeJson(path.join(__dirname, '..', 'src', 'versions.json'), packageToVersionMap, { + spaces: 2, + }); }; run().catch((e) => { diff --git a/lib/cli/src/js-package-manager/JsPackageManager.ts b/lib/cli/src/js-package-manager/JsPackageManager.ts index ec87016d640..2b88c034a21 100644 --- a/lib/cli/src/js-package-manager/JsPackageManager.ts +++ b/lib/cli/src/js-package-manager/JsPackageManager.ts @@ -4,10 +4,9 @@ import { sync as spawnSync } from 'cross-spawn'; import { commandLog } from '../helpers'; import { PackageJson, PackageJsonWithDepsAndDevDeps } from './PackageJson'; import { readPackageJson, writePackageJson } from './PackageJsonHelper'; +import storybookPackagesVersions from '../versions.json'; const logger = console; -// Cannot be `import` as it's not under TS root dir -const storybookPackagesVersions = require('../../versions.json'); export abstract class JsPackageManager { public abstract readonly type: 'npm' | 'yarn1' | 'yarn2'; @@ -137,9 +136,10 @@ export abstract class JsPackageManager { } public async getVersion(packageName: string, constraint?: string): Promise { - let current; + let current: string; if (/@storybook/.test(packageName)) { + // @ts-ignore current = storybookPackagesVersions[packageName]; } diff --git a/lib/cli/src/js-package-manager/NPMProxy.test.ts b/lib/cli/src/js-package-manager/NPMProxy.test.ts index 2bb77e9adc5..18f55cc41dd 100644 --- a/lib/cli/src/js-package-manager/NPMProxy.test.ts +++ b/lib/cli/src/js-package-manager/NPMProxy.test.ts @@ -86,7 +86,7 @@ describe('NPM Proxy', () => { describe('getVersion', () => { it('with a Storybook package listed in versions.json it returns the version', async () => { // eslint-disable-next-line global-require - const storybookAngularVersion = require('../../versions.json')['@storybook/angular']; + const storybookAngularVersion = require('../versions.json')['@storybook/angular']; const executeCommandSpy = jest.spyOn(npmProxy, 'executeCommand').mockReturnValue('"5.3.19"'); const version = await npmProxy.getVersion('@storybook/angular'); diff --git a/lib/cli/versions.json b/lib/cli/src/versions.json similarity index 100% rename from lib/cli/versions.json rename to lib/cli/src/versions.json diff --git a/lib/cli/tsconfig.json b/lib/cli/tsconfig.json index d87605d41af..0cf58d330af 100644 --- a/lib/cli/tsconfig.json +++ b/lib/cli/tsconfig.json @@ -9,7 +9,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "resolveJsonModule": true }, "include": ["src/**/*"], "exclude": ["src/**/template*", "src/frameworks/**/*"]