From 566424107a434a020a60c8c46900b9a1ce43d033 Mon Sep 17 00:00:00 2001 From: Jan Biasi Date: Sat, 13 Jul 2019 03:27:58 +0200 Subject: [PATCH] =?UTF-8?q?style:=20=F0=9F=92=84=20prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Packer.ts | 13 ++++++++++++- src/Taper.ts | 2 +- src/adapter/Lerna.ts | 35 +++++++++++++++++++++++++---------- src/bin/commands/pack.ts | 17 +++++++++++------ src/helper/debug-hooks.ts | 19 ++++++------------- src/types/Runtime.ts | 2 +- src/utils.ts | 27 +++++++++++++++++---------- test/Packer.test.ts | 10 +++++----- 8 files changed, 78 insertions(+), 47 deletions(-) diff --git a/src/Packer.ts b/src/Packer.ts index b349f73..1ed45d7 100644 --- a/src/Packer.ts +++ b/src/Packer.ts @@ -10,7 +10,18 @@ import { ArtificalPackage, IAnalyticsWithIntegrity } from './types'; -import { fs, asyncForEach, pkg, rimraf, copyDir, matcher, execa, displayPath, createHash, createIntegrityHash } from './utils'; +import { + fs, + asyncForEach, + pkg, + rimraf, + copyDir, + matcher, + execa, + displayPath, + createHash, + createIntegrityHash +} from './utils'; import { Taper } from './Taper'; import { AdapterLerna } from './adapter'; import { useDebugHooks } from './helper/debug-hooks'; diff --git a/src/Taper.ts b/src/Taper.ts index 0c6a400..e087e4e 100644 --- a/src/Taper.ts +++ b/src/Taper.ts @@ -11,7 +11,7 @@ export class Taper[ private forwarder: TaperReceiver[] = []; private connected: Taper[] = []; - constructor(private packer: Packer, private factory: Partial) { } + constructor(private packer: Packer, private factory: Partial) {} public on(point: K, taperFn: TaperFunction) { if (!this.factory[point]) { diff --git a/src/adapter/Lerna.ts b/src/adapter/Lerna.ts index 496c584..dc5091a 100644 --- a/src/adapter/Lerna.ts +++ b/src/adapter/Lerna.ts @@ -63,7 +63,11 @@ export class AdapterLerna extends Adapter { } // aggregation of internal dependencies - private async resolveDependantInternals(graph: IAnalytics['graph'] = {}, sourcePackage: Package, lernaPackageInfo: ILernaPackageInfo): Promise { + private async resolveDependantInternals( + graph: IAnalytics['graph'] = {}, + sourcePackage: Package, + lernaPackageInfo: ILernaPackageInfo + ): Promise { // aggregation of installable external dependencies const productionDependencies = extractDependencies(sourcePackage.dependencies, dependency => { return lernaPackageInfo.names.indexOf(dependency) === -1; @@ -84,26 +88,37 @@ export class AdapterLerna extends Adapter { }); // check if the related module(s) also need to be resolved and do so - const recuriveModules = await Promise.all(internalDependencies.map(async entry => { - const childModulePkg = await this.fetchPackage(resolve(entry.location, 'package.json')); - return await this.resolveDependantInternals(graph, childModulePkg, lernaPackageInfo); - })); + const recuriveModules = await Promise.all( + internalDependencies.map(async entry => { + const childModulePkg = await this.fetchPackage(resolve(entry.location, 'package.json')); + return await this.resolveDependantInternals(graph, childModulePkg, lernaPackageInfo); + }) + ); // format recursive output according to type definition - const recursiveInternals = recuriveModules.reduce((prev, curr) => [...prev, ...curr.internal], [] as LernaPackageList) - const recursiveExternals = recuriveModules.reduce((prev, curr) => ({ ...prev, ...curr.external }), {} as DependenciesLike) + const recursiveInternals = recuriveModules.reduce( + (prev, curr) => [...prev, ...curr.internal], + [] as LernaPackageList + ); + const recursiveExternals = recuriveModules.reduce( + (prev, curr) => ({ ...prev, ...curr.external }), + {} as DependenciesLike + ); // create resolved map const resolved: Pick = { internal: internalDependencies.concat(recursiveInternals), external: { ...productionDependencies, ...recursiveExternals } - } + }; // build related graph from recursive modules graph[sourcePackage.name] = { - internal: recursiveInternals.reduce((prev, { name, version }) => ({ ...prev, [name]: version }), {} as DependenciesLike), + internal: recursiveInternals.reduce( + (prev, { name, version }) => ({ ...prev, [name]: version }), + {} as DependenciesLike + ), external: recursiveExternals - } + }; return { ...resolved, diff --git a/src/bin/commands/pack.ts b/src/bin/commands/pack.ts index 757088a..fc46978 100644 --- a/src/bin/commands/pack.ts +++ b/src/bin/commands/pack.ts @@ -22,10 +22,7 @@ export async function pack(opts: IPackerOptions) { init: [ async () => { spinner.succeed( - `Initialized packer v${Packer.version} for ${displayPath( - opts.cwd || CWD, - opts.source - )}` + `Initialized packer v${Packer.version} for ${displayPath(opts.cwd || CWD, opts.source)}` ); if (opts.cwd) { @@ -57,7 +54,10 @@ export async function pack(opts: IPackerOptions) { ); spinner.succeed(`Found ${countMsg(analytics.dependencies.internal, 'internal package')} to copy`); spinner.succeed( - `Found ${countMsg(analytics.dependencies.peer, 'aggregated peer package')} to include in production` + `Found ${countMsg( + analytics.dependencies.peer, + 'aggregated peer package' + )} to include in production` ); } ], @@ -70,7 +70,12 @@ export async function pack(opts: IPackerOptions) { postinstall: [ async (_packer, { dependencies }) => { const [installationTimeInSeconds] = process.hrtime(installTimer); - spinner.succeed(`Production packages have been installed (${countMsg(dependencies, 'package')} in ~${installationTimeInSeconds}s)`); + spinner.succeed( + `Production packages have been installed (${countMsg( + dependencies, + 'package' + )} in ~${installationTimeInSeconds}s)` + ); } ], prelink: [ diff --git a/src/helper/debug-hooks.ts b/src/helper/debug-hooks.ts index 1c75398..11c0368 100644 --- a/src/helper/debug-hooks.ts +++ b/src/helper/debug-hooks.ts @@ -1,7 +1,7 @@ import * as debug from 'debug'; -import { IPackerOptions, HookPhase } from "../types"; -import { Packer, DEFAULT_PACKED_PATH } from "../Packer"; -import { countMsg, displayPath } from "../utils"; +import { IPackerOptions, HookPhase } from '../types'; +import { Packer, DEFAULT_PACKED_PATH } from '../Packer'; +import { countMsg, displayPath } from '../utils'; const CWD = process.cwd(); const log = debug('packer'); @@ -14,12 +14,7 @@ export function useDebugHooks(opts: Pick { - log( - `Initialized packer v${Packer.version} for ${displayPath( - opts.cwd || CWD, - opts.source - )}` - ) + log(`Initialized packer v${Packer.version} for ${displayPath(opts.cwd || CWD, opts.source)}`); log(`Setting packing output to ${opts.target || `${DEFAULT_PACKED_PATH} (default)`}`); } @@ -41,9 +36,7 @@ export function useDebugHooks(opts: Pick { try { return loadJson(`${root}/lerna.json`).packages; - } catch (err) { } + } catch (err) {} try { return loadJson(`${root}/package.json`).workspaces; - } catch (err) { } + } catch (err) {} return []; })() || []; @@ -160,17 +160,24 @@ export function displayPath(base: string, toDisplay: string) { } export function createHash(value: string) { - return createNativeHash('sha256').update(value).digest('hex') + return createNativeHash('sha256') + .update(value) + .digest('hex'); } export function createIntegrityHash(version: string, analytics: IAnalytics) { - return createHash(version + JSON.stringify({ - ...analytics, - dependencies: { - ...analytics.dependencies, - internal: analytics.dependencies.internal.map(entry => `${entry.name}@${entry.version}|${!!entry.private}`) - } - })) + return createHash( + version + + JSON.stringify({ + ...analytics, + dependencies: { + ...analytics.dependencies, + internal: analytics.dependencies.internal.map( + entry => `${entry.name}@${entry.version}|${!!entry.private}` + ) + } + }) + ); } export const pkg = require('../package.json'); diff --git a/test/Packer.test.ts b/test/Packer.test.ts index a341c1d..b9ea851 100644 --- a/test/Packer.test.ts +++ b/test/Packer.test.ts @@ -27,8 +27,8 @@ const analyticsToSnapshot = (analytics: IAnalytics) => { private: entry.private })) } - } -} + }; +}; describe('Packer', () => { describe('Lerna', () => { @@ -60,7 +60,7 @@ describe('Packer', () => { expect(deserialized.dependencies.peer).toBeDefined(); expect(deserialized.dependencies.internal.length).toEqual(1); expect(deserialized.dependencies.peer.smallest).toBeDefined(); - } catch (err) { } + } catch (err) {} }); it('should generate an artificial package correctly', async () => { @@ -71,10 +71,10 @@ describe('Packer', () => { expect(generatedPkg).toMatchSnapshot(); expect(generatedPkg.name).toEqual('@fixture/main-packed'); expect(generatedPkg.dependencies).toStrictEqual({ - "ansi-styles": "4.0.0", // from subsub + 'ansi-styles': '4.0.0', // from subsub debug: '*', // from main smallest: '1.0.1', // from sub - "supports-color": "7.0.0" // from subsubsub + 'supports-color': '7.0.0' // from subsubsub }); });