From ea3b2f0c5cdcd8d3612c5444879f2f2d66fb8ed1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 21 Jul 2022 06:46:13 +0200 Subject: [PATCH] Use named export for loadConfigFile --- build-plugins/esm-dynamic-import.ts | 8 ++++---- cli/run/index.ts | 4 ++-- cli/run/loadConfigFile.ts | 6 +++--- cli/run/watch-cli.ts | 4 ++-- docs/02-javascript-api.md | 2 +- rollup.config.ts | 2 +- scripts/perf.js | 2 +- test/load-config-file/index.js | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build-plugins/esm-dynamic-import.ts b/build-plugins/esm-dynamic-import.ts index 22551277b21..c776d489997 100644 --- a/build-plugins/esm-dynamic-import.ts +++ b/build-plugins/esm-dynamic-import.ts @@ -1,19 +1,19 @@ import type { Plugin } from 'rollup'; export default function esmDynamicImport(): Plugin { - let importFound = false; + let importsFound = 0; return { generateBundle() { - if (!importFound) { + if (importsFound !== 2) { throw new Error( - 'Could not find dynamic import in "loadConfigFile.ts", was the file renamed?' + 'Could not find 2 dynamic import in "loadConfigFile.ts" and "commandPlugin.ts", were the files renamed or modified?' ); } }, name: 'esm-dynamic-import', renderDynamicImport({ moduleId }) { - importFound = true; if (moduleId.endsWith('commandPlugins.ts') || moduleId.endsWith('loadConfigFile.ts')) { + importsFound++; return { left: 'import(', right: ')' }; } } diff --git a/cli/run/index.ts b/cli/run/index.ts index 47cc8e841df..8fd4e6f3e3e 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -8,7 +8,7 @@ import { handleError } from '../logging'; import type { BatchWarnings } from './batchWarnings'; import build from './build'; import { getConfigPath } from './getConfigPath'; -import loadAndParseConfigFile from './loadConfigFile'; +import { loadConfigFile } from './loadConfigFile'; import loadConfigFromCommand from './loadConfigFromCommand'; export default async function runRollup(command: Record): Promise { @@ -82,7 +82,7 @@ async function getConfigs( ): Promise<{ options: MergedRollupOptions[]; warnings: BatchWarnings }> { if (command.config) { const configFile = await getConfigPath(command.config); - const { options, warnings } = await loadAndParseConfigFile(configFile, command); + const { options, warnings } = await loadConfigFile(configFile, command); return { options, warnings }; } return await loadConfigFromCommand(command); diff --git a/cli/run/loadConfigFile.ts b/cli/run/loadConfigFile.ts index 7f6f5329634..6f790263a70 100644 --- a/cli/run/loadConfigFile.ts +++ b/cli/run/loadConfigFile.ts @@ -16,11 +16,11 @@ interface NodeModuleWithCompile extends NodeModule { _compile(code: string, filename: string): any; } -export default async function loadAndParseConfigFile( +export async function loadConfigFile( fileName: string, commandOptions: any = {} ): Promise<{ options: MergedRollupOptions[]; warnings: BatchWarnings }> { - const configs = await loadConfigFile(fileName, commandOptions); + const configs = await loadConfigsFromFile(fileName, commandOptions); const warnings = batchWarnings(); try { const normalizedConfigs: MergedRollupOptions[] = []; @@ -36,7 +36,7 @@ export default async function loadAndParseConfigFile( } } -async function loadConfigFile( +async function loadConfigsFromFile( fileName: string, commandOptions: Record ): Promise { diff --git a/cli/run/watch-cli.ts b/cli/run/watch-cli.ts index fddc954bf24..c2b483507ee 100644 --- a/cli/run/watch-cli.ts +++ b/cli/run/watch-cli.ts @@ -11,7 +11,7 @@ import relativeId from '../../src/utils/relativeId'; import { handleError, stderr } from '../logging'; import type { BatchWarnings } from './batchWarnings'; import { getConfigPath } from './getConfigPath'; -import loadAndParseConfigFile from './loadConfigFile'; +import { loadConfigFile } from './loadConfigFile'; import loadConfigFromCommand from './loadConfigFromCommand'; import { getResetScreen } from './resetScreen'; import { printTimings } from './timings'; @@ -53,7 +53,7 @@ export async function watch(command: Record): Promise { stderr(`\nReloading updated config...`); } configFileData = newConfigFileData; - const { options, warnings } = await loadAndParseConfigFile(configFile, command); + const { options, warnings } = await loadConfigFile(configFile, command); if (currentConfigFileRevision !== configFileRevision) { return; } diff --git a/docs/02-javascript-api.md b/docs/02-javascript-api.md index e59df36eb0b..b4e2ab7941b 100755 --- a/docs/02-javascript-api.md +++ b/docs/02-javascript-api.md @@ -262,7 +262,7 @@ See above for details on `inputOptions` and `outputOptions`, or consult the [big In order to aid in generating such a config, rollup exposes the helper it uses to load config files in its command line interface via a separate entry-point. This helper receives a resolved `fileName` and optionally an object containing command line parameters: ```js -const loadConfigFile = require('rollup/loadConfigFile'); +const { loadConfigFile } = require('rollup/loadConfigFile'); const path = require('path'); const rollup = require('rollup'); diff --git a/rollup.config.ts b/rollup.config.ts index 89dcfe0ab12..26f2841ea59 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -76,7 +76,7 @@ export default async function ( chunkFileNames: 'shared/[name].js', dir: 'dist', entryFileNames: '[name]', - exports: 'auto', + exports: 'named', externalLiveBindings: false, format: 'cjs', freeze: false, diff --git a/scripts/perf.js b/scripts/perf.js index fc6491235ae..4f21beccc9e 100644 --- a/scripts/perf.js +++ b/scripts/perf.js @@ -6,7 +6,7 @@ import { argv, chdir, cwd, exit } from 'node:process'; import { fileURLToPath } from 'node:url'; import { createColors } from 'colorette'; import prettyBytes from 'pretty-bytes'; -import loadConfigFile from '../dist/loadConfigFile.js'; +import { loadConfigFile } from '../dist/loadConfigFile.js'; import { rollup } from '../dist/rollup.js'; import { findConfigFileName } from './find-config.js'; diff --git a/test/load-config-file/index.js b/test/load-config-file/index.js index 7096004bbf9..f9ef0828076 100644 --- a/test/load-config-file/index.js +++ b/test/load-config-file/index.js @@ -1,6 +1,6 @@ const assert = require('assert'); const path = require('path'); -const loadConfigFile = require('../../dist/loadConfigFile.js'); +const { loadConfigFile } = require('../../dist/loadConfigFile.js'); describe('loadConfigFile', () => { it('loads a config file', async () => {