From 21f28a21d2534f97e5b004ea95ce93b77bc17174 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 23 Sep 2022 13:21:03 +0100 Subject: [PATCH] refactor(rollup): remove unnecessary async waits --- source/index.ts | 6 +++--- source/rollup.ts | 4 ++-- spec/index.spec.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/index.ts b/source/index.ts index 275eb78..05f8ae6 100644 --- a/source/index.ts +++ b/source/index.ts @@ -47,16 +47,16 @@ export const DEFAULT_VARIABLE: Variable = { * get the list of templates provided by this preset * @returns list of preset templates */ -export default async function (): Promise { +export default function (): PresetAsset { return { template: { /* eslint-disable @typescript-eslint/naming-convention */ - 'rollup.config.ts': async (context) => { + 'rollup.config.ts': (context) => { const content = loadFile( resolve(TEMPLATES, 'rollup.config.ts'), 'text', ); - const variable = await getRollupParameter(context); + const variable = getRollupParameter(context); return template(content, variable); /* eslint-enable @typescript-eslint/naming-convention */ diff --git a/source/rollup.ts b/source/rollup.ts index f5e9074..feca86e 100644 --- a/source/rollup.ts +++ b/source/rollup.ts @@ -61,9 +61,9 @@ interface IntermediateRollupConfig { * @param context context about the build environment * @returns template parameter related to rollup */ -export async function getRollupParameter( +export function getRollupParameter( context: ResolvedPresetContext, -): Promise> { +): Record<'rollupImport' | 'rollupExport', string> { const { config, variable } = context.custom; const normalizedConfig = template( diff --git a/spec/index.spec.ts b/spec/index.spec.ts index 2c4ef62..8ba838c 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -27,7 +27,7 @@ jest.mock('path', () => ({ describe('fn:getPresetAsset', () => { it('use all templates', async () => { - const asset = await getPresetAsset(); + const asset = getPresetAsset(); const context = await resolveContext({ graph: [{ name: 'preset', asset, nodes: [] }], context: { @@ -41,9 +41,9 @@ describe('fn:getPresetAsset', () => { await loadDynamicMap(asset.template, context); const TEMPLATES = resolve(__dirname, '..', 'templates'); - const allTemplates = await readdirSync(TEMPLATES); + const allTemplates = readdirSync(TEMPLATES); const CONFIGS = resolve(__dirname, '..', 'configs'); - const supplementaryConfig = await readdirSync(CONFIGS); + const supplementaryConfig = readdirSync(CONFIGS); for (const path of allTemplates) { expect(resolve).toBeCalledWith(TEMPLATES, path);