Skip to content

Commit

Permalink
[v3.0] Use named export for loadConfigFile
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 30, 2022
1 parent e5b3ba0 commit e5a1d3b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions 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: ')' };
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/run/index.ts
Expand Up @@ -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<string, any>): Promise<void> {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions cli/run/loadConfigFile.ts
Expand Up @@ -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[] = [];
Expand All @@ -36,7 +36,7 @@ export default async function loadAndParseConfigFile(
}
}

async function loadConfigFile(
async function loadConfigsFromFile(
fileName: string,
commandOptions: Record<string, unknown>
): Promise<GenericConfigObject[]> {
Expand Down
4 changes: 2 additions & 2 deletions cli/run/watch-cli.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function watch(command: Record<string, any>): Promise<void> {
stderr(`\nReloading updated config...`);
}
configFileData = newConfigFileData;
const { options, warnings } = await loadAndParseConfigFile(configFile, command);
const { options, warnings } = await loadConfigFile(configFile, command);
if (currentConfigFileRevision !== configFileRevision) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/02-javascript-api.md
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion rollup.config.ts
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scripts/perf.js
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion 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 () => {
Expand Down

0 comments on commit e5a1d3b

Please sign in to comment.