Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.0] Use named export for loadConfigFile #4581

Merged
merged 3 commits into from Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion browser/error.ts → browser/src/error.ts
@@ -1,4 +1,4 @@
import { errNoFileSystemInBrowser, error } from '../src/utils/error';
import { errNoFileSystemInBrowser, error } from '../../src/utils/error';

export const throwNoFileSystem = (method: string) => (): never =>
error(errNoFileSystemInBrowser(method));
File renamed without changes.
2 changes: 1 addition & 1 deletion browser/hookActions.ts → browser/src/hookActions.ts
@@ -1,4 +1,4 @@
import { PluginDriver } from '../src/utils/PluginDriver';
import { PluginDriver } from '../../src/utils/PluginDriver';

export function catchUnfinishedHookActions<T>(
_pluginDriver: PluginDriver,
Expand Down
6 changes: 3 additions & 3 deletions browser/package.json → browser/src/package.json
Expand Up @@ -2,8 +2,8 @@
"name": "@rollup/browser",
"version": "3.0.0-2",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
"main": "../dist/rollup.browser.js",
"module": "../dist/es/rollup.browser.js",
"types": "dist/rollup.browser.d.ts",
"repository": "rollup/rollup",
"keywords": [
Expand All @@ -22,7 +22,7 @@
"files": [
"dist/**/*.js",
"dist/*.d.ts",
"dist/es/package.json",
"../dist/es/package.json",
"dist/rollup.browser.js.map"
],
"exports": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions browser/resolveId.ts → browser/src/resolveId.ts
@@ -1,6 +1,11 @@
import type { CustomPluginOptions, Plugin, ResolvedId, ResolveIdResult } from '../src/rollup/types';
import type { PluginDriver } from '../src/utils/PluginDriver';
import { resolveIdViaPlugins } from '../src/utils/resolveIdViaPlugins';
import type {
CustomPluginOptions,
Plugin,
ResolvedId,
ResolveIdResult
} from '../../src/rollup/types';
import type { PluginDriver } from '../../src/utils/PluginDriver';
import { resolveIdViaPlugins } from '../../src/utils/resolveIdViaPlugins';
import { throwNoFileSystem } from './error';

export async function resolveId(
Expand Down
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
33 changes: 11 additions & 22 deletions build-plugins/replace-browser-modules.ts
@@ -1,35 +1,24 @@
import { dirname, join, resolve } from 'path';
import type { Plugin } from 'rollup';

const ID_CRYPTO = resolve('src/utils/crypto');
const ID_FS = resolve('src/utils/fs');
const ID_HOOKACTIONS = resolve('src/utils/hookActions');
const ID_PATH = resolve('src/utils/path');
const ID_PERFORMANCE = resolve('src/utils/performance');
const ID_PROCESS = resolve('src/utils/process');
const ID_RESOLVEID = resolve('src/utils/resolveId');
const resolutions = {
[resolve('src/utils/crypto')]: resolve('browser/src/crypto.ts'),
[resolve('src/utils/fs')]: resolve('browser/src/fs.ts'),
[resolve('src/utils/hookActions')]: resolve('browser/src/hookActions.ts'),
[resolve('src/utils/path')]: resolve('browser/src/path.ts'),
[resolve('src/utils/performance')]: resolve('browser/src/performance.ts'),
[resolve('src/utils/process')]: resolve('browser/src/process.ts'),
[resolve('src/utils/resolveId')]: resolve('browser/src/resolveId.ts')
};

export default function replaceBrowserModules(): Plugin {
return {
name: 'replace-browser-modules',
resolveId(source, importee) {
if (importee && source[0] === '.') {
const resolved = join(dirname(importee), source);
switch (resolved) {
case ID_CRYPTO:
return resolve('browser/crypto.ts');
case ID_FS:
return resolve('browser/fs.ts');
case ID_HOOKACTIONS:
return resolve('browser/hookActions.ts');
case ID_PATH:
return resolve('browser/path.ts');
case ID_PERFORMANCE:
return resolve('browser/performance.ts');
case ID_PROCESS:
return resolve('browser/process.ts');
case ID_RESOLVEID:
return resolve('browser/resolveId.ts');
if (resolutions[resolved]) {
return resolutions[resolved];
}
}
}
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