Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jan 23, 2022
2 parents 1896ce4 + 3ca594e commit d8e0b75
Show file tree
Hide file tree
Showing 126 changed files with 3,409 additions and 2,003 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Expand Up @@ -73,7 +73,10 @@ module.exports = {
'dot-notation': 'error',
'import/no-unresolved': [
'error',
{ ignore: ['package.json', 'is-reference', 'help.md', 'types'] }
{
// 'fsevents' is ony available on macOS, and not installed on linux/windows
ignore: ['fsevents', 'help.md', 'is-reference', 'package.json', 'types']
}
],
'import/order': ['error', { alphabetize: { order: 'asc' } }],
'no-constant-condition': ['error', { checkLoops: false }],
Expand Down
82 changes: 82 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,87 @@
# rollup changelog

## 2.66.0

_2022-01-22_

### Features

- Note if a module has a default export in ModuleInfo to allow writing better proxy modules (#4356)
- Add option to wait until all imported ids have been resolved when awaiting `this.load` (#4358)

### Pull Requests

- [#4356](https://github.com/rollup/rollup/pull/4356): Add hasDefaultExport to ModuleInfo (@lukastaegert)
- [#4358](https://github.com/rollup/rollup/pull/4358): Add "resolveDependencies" option to "this.load" (@lukastaegert)

## 2.65.0

_2022-01-21_

### Features

- Add complete import resolution objects to ModuleInfo for use in `this.load` (#4354)

### Bug Fixes

- Use correct context in plugin hooks with `perf: true` (#4357)

### Pull Requests

- [#4351](https://github.com/rollup/rollup/pull/4351): refactor: re-use source mapping url (@dnalborczyk)
- [#4352](https://github.com/rollup/rollup/pull/4352): refactor: replace require-relative with built-in require.resolve (@dnalborczyk)
- [#4353](https://github.com/rollup/rollup/pull/4353): chore: bump deps (@dnalborczyk)
- [#4354](https://github.com/rollup/rollup/pull/4354): Add importedIdResolutions to moduleInfo (@lukastaegert)
- [#4355](https://github.com/rollup/rollup/pull/4355): chore: remove external from config (@dnalborczyk)
- [#4357](https://github.com/rollup/rollup/pull/4357): fix: timed plugin context (@dnalborczyk)

## 2.64.0

_2022-01-14_

### Features

- Allow inspecting cached modules and forcing them to be transformed again via shouldTransformCachedModule (#4320)
- Do not wait for the config file to be parsed in watch mode if it is updated before that (#4344)

### Bug Fixes

- Do not mutate objects returned as `meta` from the resolveId hook (#4347)

### Pull Requests

- [#4326](https://github.com/rollup/rollup/pull/4326): refactor: type fixes (@dnalborczyk)
- [#4339](https://github.com/rollup/rollup/pull/4339): More watch test stabilization (@lukastaegert)
- [#4340](https://github.com/rollup/rollup/pull/4340): refactor: performance timers for node.js and browser (@dnalborczyk)
- [#4341](https://github.com/rollup/rollup/pull/4341): Implement shouldTransformCachedModule hook (@lukastaegert)
- [#4344](https://github.com/rollup/rollup/pull/4344): Directly restart Rollup when config file change is detected in watch mode (@lukastaegert)
- [#4347](https://github.com/rollup/rollup/pull/4347): Create a shallow copy when returning meta from resolveId (@lukastaegert)

## 2.63.0

_2022-01-04_

### Features

- Report a helpful error if rollup exits due to an empty event loop when using `this.load` (#4320)
- Allow directly mutating ModuleInfo.meta for modules and never replace this object (#4328)
- Detect additional side effect free array prototype methods (#4332)

### Bug Fixes

- Do not watch if CLI watch options are specified but `--watch` is missing (#4335)

### Pull Requests

- [#4320](https://github.com/rollup/rollup/pull/4320): Detect unfulfilled async hook actions and report error on exit (@kzc)
- [#4328](https://github.com/rollup/rollup/pull/4328): Make initial ModuleInfo.meta mutable and maintain object identity (@lukastaegert)
- [#4318](https://github.com/rollup/rollup/pull/4318): Stabilize watch tests (@lukastaegert)
- [#4331](https://github.com/rollup/rollup/pull/4331): Improve JS docs example (@lukastaegert)
- [#4332](https://github.com/rollup/rollup/pull/4332): add support for Array.prototype.findLast,findLastIndex (@dnalborczyk)
- [#4333](https://github.com/rollup/rollup/pull/4333): convert utils.transform to async function (@dnalborczyk)
- [#4335](https://github.com/rollup/rollup/pull/4335): Do not watch unless --watch is specified explicitly (@lukastaegert)
- [#4338](https://github.com/rollup/rollup/pull/4338): Add build delay for plugin event test (@lukastaegert)

## 2.62.0

_2021-12-24_
Expand Down
7 changes: 0 additions & 7 deletions LICENSE.md
Expand Up @@ -583,13 +583,6 @@ Repository: git://github.com/paulmillr/readdirp.git
---------------------------------------

## require-relative
License: MIT
By: Valerio Proietti
Repository: git://github.com/kamicane/require-relative.git

---------------------------------------

## signal-exit
License: ISC
By: Ben Coe
Expand Down
3 changes: 3 additions & 0 deletions browser/hookActions.ts
@@ -0,0 +1,3 @@
export function addUnresolvedAction(_actionTuple: [string, string, Parameters<any>]): void {}

export function resolveAction(_actionTuple: [string, string, Parameters<any>]): void {}
10 changes: 10 additions & 0 deletions browser/performance.ts
@@ -0,0 +1,10 @@
const global =
typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : {};

export default 'performance' in global
? performance
: {
now(): 0 {
return 0;
}
};
11 changes: 11 additions & 0 deletions browser/process.ts
@@ -0,0 +1,11 @@
interface MemoryUsage {
heapUsed: 0;
}

export default {
memoryUsage(): MemoryUsage {
return {
heapUsed: 0
};
}
};
4 changes: 2 additions & 2 deletions browser/resolveId.ts
Expand Up @@ -13,9 +13,9 @@ export async function resolveId(
importer: string | undefined,
customOptions: CustomPluginOptions | undefined,
isEntry: boolean | undefined,
skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null
skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null
) => Promise<ResolvedId | null>,
skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null,
skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null,
customOptions: CustomPluginOptions | undefined,
isEntry: boolean
): Promise<ResolveIdResult> {
Expand Down
2 changes: 1 addition & 1 deletion build-plugins/conditional-fsevents-import.ts
@@ -1,5 +1,5 @@
import MagicString from 'magic-string';
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

const FSEVENTS_REQUIRE = "require('fsevents')";
const REPLACEMENT = "require('../../../src/watch/fsevents-importer').getFsEvents()";
Expand Down
33 changes: 21 additions & 12 deletions build-plugins/replace-browser-modules.ts
@@ -1,26 +1,35 @@
import path from 'path';
import { Plugin } from 'rollup';
import { dirname, join, resolve } from 'path';
import type { Plugin } from 'rollup';

const ID_CRYPTO = path.resolve('src/utils/crypto');
const ID_FS = path.resolve('src/utils/fs');
const ID_PATH = path.resolve('src/utils/path');
const ID_RESOLVEID = path.resolve('src/utils/resolveId');
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');

export default function replaceBrowserModules(): Plugin {
return {
name: 'replace-browser-modules',
resolveId: (source, importee) => {
resolveId(source, importee) {
if (importee && source[0] === '.') {
const resolved = path.join(path.dirname(importee), source);
const resolved = join(dirname(importee), source);
switch (resolved) {
case ID_CRYPTO:
return path.resolve('browser/crypto.ts');
return resolve('browser/crypto.ts');
case ID_FS:
return path.resolve('browser/fs.ts');
return resolve('browser/fs.ts');
case ID_HOOKACTIONS:
return resolve('browser/hookActions.ts');
case ID_PATH:
return path.resolve('browser/path.ts');
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 path.resolve('browser/resolveId.ts');
return resolve('browser/resolveId.ts');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/logging.ts
Expand Up @@ -3,7 +3,7 @@ import { bold, cyan, dim, red } from '../src/utils/colors';
import relativeId from '../src/utils/relativeId';

// log to stderr to keep `rollup main.js > bundle.js` from breaking
export const stderr = console.error.bind(console);
export const stderr = (...args: unknown[]) => process.stderr.write(`${args.join('')}\n`);

export function handleError(err: RollupError, recover = false): void {
let description = err.message || err;
Expand Down
19 changes: 12 additions & 7 deletions cli/run/batchWarnings.ts
Expand Up @@ -248,20 +248,25 @@ const deferredHandlers: {
}
};

function title(str: string) {
function title(str: string): void {
stderr(bold(yellow(`(!) ${str}`)));
}

function info(url: string) {
function info(url: string): void {
stderr(gray(url));
}

function nest<T>(array: T[], prop: string) {
const nested: { items: T[]; key: string }[] = [];
const lookup = new Map<string, { items: T[]; key: string }>();
interface Nested<T> {
items: T[];
key: string;
}

function nest<T extends Record<string, any>>(array: readonly T[], prop: string): Nested<T>[] {
const nested: Nested<T>[] = [];
const lookup = new Map<string, Nested<T>>();

for (const item of array) {
const key = (item as any)[prop];
const key = item[prop];
getOrCreate(lookup, key, () => {
const items = {
items: [],
Expand All @@ -275,7 +280,7 @@ function nest<T>(array: T[], prop: string) {
return nested;
}

function showTruncatedWarnings(warnings: RollupWarning[]) {
function showTruncatedWarnings(warnings: readonly RollupWarning[]): void {
const nestedByModule = nest(warnings, 'id');

const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
Expand Down
10 changes: 5 additions & 5 deletions cli/run/build.ts
@@ -1,11 +1,11 @@
import ms from 'pretty-ms';
import * as rollup from '../../src/node-entry';
import { MergedRollupOptions } from '../../src/rollup/types';
import { rollup } from '../../src/node-entry';
import type { MergedRollupOptions } from '../../src/rollup/types';
import { bold, cyan, green } from '../../src/utils/colors';
import relativeId from '../../src/utils/relativeId';
import { SOURCEMAPPING_URL } from '../../src/utils/sourceMappingURL';
import { handleError, stderr } from '../logging';
import SOURCEMAPPING_URL from '../sourceMappingUrl';
import { BatchWarnings } from './batchWarnings';
import type { BatchWarnings } from './batchWarnings';
import { printTimings } from './timings';

export default async function build(
Expand All @@ -29,7 +29,7 @@ export default async function build(
stderr(cyan(`\n${bold(inputFiles!)}${bold(files.join(', '))}...`));
}

const bundle = await rollup.rollup(inputOptions as any);
const bundle = await rollup(inputOptions as any);
if (useStdout) {
const output = outputOptions[0];
if (output.sourcemap && output.sourcemap !== 'inline') {
Expand Down
5 changes: 4 additions & 1 deletion cli/run/commandPlugins.ts
Expand Up @@ -38,7 +38,10 @@ export async function addPluginsFromCommandOption(
}
}

async function loadAndRegisterPlugin(inputOptions: InputOptions, pluginText: string) {
async function loadAndRegisterPlugin(
inputOptions: InputOptions,
pluginText: string
): Promise<void> {
let plugin: any = null;
let pluginArg: any = undefined;
if (pluginText[0] === '{') {
Expand Down
15 changes: 7 additions & 8 deletions cli/run/getConfigPath.ts
@@ -1,22 +1,21 @@
import { readdirSync } from 'fs';
import * as path from 'path';
import relative from 'require-relative';
import { resolve } from 'path';
import { cwd } from 'process';
import { handleError } from '../logging';

const DEFAULT_CONFIG_BASE = 'rollup.config';

export function getConfigPath(commandConfig: string | true): string {
const cwd = process.cwd();
if (commandConfig === true) {
return path.resolve(findConfigFileNameInCwd());
return resolve(findConfigFileNameInCwd());
}
if (commandConfig.slice(0, 5) === 'node:') {
const pkgName = commandConfig.slice(5);
try {
return relative.resolve(`rollup-config-${pkgName}`, cwd);
return require.resolve(`rollup-config-${pkgName}`, { paths: [cwd()] });
} catch {
try {
return relative.resolve(pkgName, cwd);
return require.resolve(pkgName, { paths: [cwd()] });
} catch (err: any) {
if (err.code === 'MODULE_NOT_FOUND') {
handleError({
Expand All @@ -28,11 +27,11 @@ export function getConfigPath(commandConfig: string | true): string {
}
}
}
return path.resolve(commandConfig);
return resolve(commandConfig);
}

function findConfigFileNameInCwd(): string {
const filesInWorkingDir = new Set(readdirSync(process.cwd()));
const filesInWorkingDir = new Set(readdirSync(cwd()));
for (const extension of ['mjs', 'cjs', 'ts']) {
const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
if (filesInWorkingDir.has(fileName)) return fileName;
Expand Down
3 changes: 2 additions & 1 deletion cli/run/index.ts
@@ -1,4 +1,5 @@
import { MergedRollupOptions } from '../../src/rollup/types';
import { isWatchEnabled } from '../../src/utils/options/mergeOptions';
import { getAliasName } from '../../src/utils/relativeId';
import { loadFsEvents } from '../../src/watch/fsevents-importer';
import { handleError } from '../logging';
Expand Down Expand Up @@ -56,7 +57,7 @@ export default async function runRollup(command: Record<string, any>): Promise<v
});
}

if (command.watch) {
if (isWatchEnabled(command.watch)) {
await loadFsEvents();
const { watch } = await import('./watch-cli');
watch(command);
Expand Down

0 comments on commit d8e0b75

Please sign in to comment.