Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 5x 5x 5x 5x 17x 17x 17x 17x 7x 7x 7x 7x 7x 7x 7x | import fs from 'fs-extra' import { join } from 'path' import { MissingFileError } from '../class/error/missing-file-error' import { validateGitRepoUrl } from '@/utils' interface NpmConfig { main?: string name?: string repository?: { type?: 'git' url?: string } } export default async(path: string): Promise<NpmConfig> => { const packageJsonPath = join(path, 'package.json') const exist = await fs.pathExists(packageJsonPath) if (!exist) throw new MissingFileError(path) try { const config: NpmConfig = await fs.readJson(packageJsonPath) Iif (typeof config.repository === 'string') { if (validateGitRepoUrl(config.repository)) { config.repository = { type: 'git', url: config.repository } } else { config.repository = { url: config.repository } } } Iif (typeof config.repository === 'object') { if (config.repository.type === 'git' && config.repository.url) { const url = config.repository.url.replace(/^git\+/, '') config.repository = { type: 'git', url } } else { config.repository = { url: config.repository.url } } } else { config.repository = undefined } Eif (typeof config.main !== 'string') config.main = undefined return config } catch (e) { throw new Error([ `Cannot load package.json from ${path}.`, 'Maybe syntax error in package.json', ].join('\n')) } } |