refactor(rollup): remove unnecessary async waits

This commit is contained in:
Alvis HT Tang 2022-09-23 13:21:03 +01:00
parent 93a1ed2b0d
commit 21f28a21d2
3 changed files with 8 additions and 8 deletions

View File

@ -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<PresetAsset> {
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 */

View File

@ -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>> {
): Record<'rollupImport' | 'rollupExport', string> {
const { config, variable } = context.custom;
const normalizedConfig = template(

View File

@ -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);