Skip to content

Commit

Permalink
[v3.0] Use named export for loadConfigFile (#4581)
Browse files Browse the repository at this point in the history
* [v3.0] Use named export for loadConfigFile

* Only expose files in dist with their full names

* Move browser sources to src subfolder

3.0.0-3

Fix release script
  • Loading branch information
lukastaegert committed Sep 6, 2022
1 parent 311eee5 commit a7b4a46
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 121 deletions.
2 changes: 1 addition & 1 deletion browser/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "3.0.0-2",
"version": "3.0.0-3",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
Expand Down
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
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

0 comments on commit a7b4a46

Please sign in to comment.