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

1.0 changes #2293

Merged
merged 20 commits into from Dec 28, 2018
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
62 changes: 62 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,67 @@
# rollup changelog

## 1.0.0
*unreleased*

### Breaking Changes
* Several (mostly deprecated) options have been removed or renamed (#2293, #2409):
- banner -> output.banner
- dest -> output.file
- entry -> input
- experimentalCodeSplitting -> now always active
- experimentalDynamicImport -> now always active
- experimentalPreserveModules -> preserveModules
- exports -> output.exports
- extend -> output.extend
- footer -> output.footer
- format -> output.format
- freeze -> output.freeze
- globals -> output.globals
- indent -> output.indent
- interop -> output.interop
- intro -> output.intro
- load -> use plugin API
- moduleName -> output.name
- name -> output.name
- noConflict -> output.noConflict
- output.moduleId -> output.amd.id
- outro -> output.outro
- paths -> output.paths
- preferConst -> output.preferConst
- pureExternalModules -> treeshake.pureExternalModules
- resolveExternal -> use plugin API
- resolveId -> use plugin API
- sourcemap -> output.sourcemap
- sourceMap -> output.sourcemap
- sourceMapFile -> output.sourcemapFile
- strict -> output.strict
- targets -> use output as an array
- transform -> use plugin API
- useStrict -> output.strict
* In general, output options can no longer be used as input options (#2409)
* `bundle.generate` and `bundle.write` now return a new format (#2293)
* Several plugin hooks have become deprecated and will display warnings when used (#2409):
- transformBundle
- transformChunk
- ongenerate
- onwrite
* Plugin transform dependencies are deprecated in favour of the `watchChange` plugin hook (#2409)
* Accessing `this.watcher` in plugin hooks is deprecated in favour of the `watchChange` plugin hook (#2409)
* Using dynamic import statements will by default create a new chunk unless `inlineDynamicImports` is used (#2293)
* Rollup now uses acorn@6 which means that acorn plugins must be compatible with this version; acorn is now external for non-browser builds to make plugins work (#2293)

### Features
* The `--dir` ClI option can now be aliased as `-d` (#2293)
* The `--input` option now supports named entry points via `=` (#2293)

### Bug Fixes
* Both the `--input` option as well as the default CLI option now support named inputs (#2293)

### Pull Requests
* [#2293](https://github.com/rollup/rollup/pull/2293): Unify code paths for 1.0 relase and update documentation (@guybedford and @lukastaegert)
* [#2409](https://github.com/rollup/rollup/pull/2409): Remove old deprecated features and add new deprecation warnings (@guybedford)
* [#2486](https://github.com/rollup/rollup/pull/2486): Upgrade to acorn 6 (@marijnh)

## 0.68.2
*2018-12-23*

Expand Down
59 changes: 39 additions & 20 deletions bin/src/help.md
Expand Up @@ -5,32 +5,51 @@ Usage: rollup [options] <entry file>

Basic options:

-v, --version Show version number
-h, --help Show this help message
-c, --config Use this config file (if argument is used but value
is unspecified, defaults to rollup.config.js)
-w, --watch Watch files in bundle and rebuild on changes
-i, --input Input (alternative to <entry file>)
-o, --file <output> Output (if absent, prints to stdout)
-f, --format [es] Type of output (amd, cjs, es, iife, umd)
-d, --dir Directory for chunks (if absent, prints to stdout)
-e, --external Comma-separate list of module IDs to exclude
-g, --globals Comma-separate list of `module ID:Global` pairs
Any module IDs defined here are added to external
-n, --name Name for UMD export
-f, --format <format> Type of output (amd, cjs, esm, iife, umd)
-g, --globals Comma-separate list of `moduleID:Global` pairs
-h, --help Show this help message
-i, --input Input (alternative to <entry file>)
-m, --sourcemap Generate sourcemap (`-m inline` for inline map)
--amd.id ID for AMD module (default is anonymous)
--amd.define Function to use in place of `define`
--no-strict Don't emit a `"use strict";` in the generated modules.
--no-indent Don't indent result
-n, --name Name for UMD export
-o, --file <output> Single output file (if absent, prints to stdout)
-v, --version Show version number
-w, --watch Watch files in bundle and rebuild on changes
--amd.id <id> ID for AMD module (default is anonymous)
--amd.define <name> Function to use in place of `define`
--assetFileNames <pattern> Name pattern for emitted assets
--banner <text> Code to insert at top of bundle (outside wrapper)
--chunkFileNames <pattern> Name pattern for emitted secondary chunks
--compact Minify wrapper code
--context <variable> Specify top-level `this` value
--entryFileNames <pattern> Name pattern for emitted entry chunks
--environment <values> Settings passed to config file (see example)
--no-conflict Generate a noConflict method for UMD globals
--no-treeshake Disable tree-shaking
--silent Don't print warnings
--intro Content to insert at top of bundle (inside wrapper)
--outro Content to insert at end of bundle (inside wrapper)
--banner Content to insert at top of bundle (outside wrapper)
--footer Content to insert at end of bundle (outside wrapper)
--no-esModule Do not add __esModule property
--exports <mode> Specify export mode (auto, default, named, none)
--extend Extend global variable defined by --name
--footer <text> Code to insert at end of bundle (outside wrapper)
--no-freeze Do not freeze namespace objects
--no-indent Don't indent result
--no-interop Do not include interop block
--inlineDynamicImports Create single bundle when using dynamic imports
--intro <text> Code to insert at top of bundle (inside wrapper)
--namespaceToStringTag Create proper `.toString` methods for namespaces
--noConflict Generate a noConflict method for UMD globals
--no-strict Don't emit `"use strict";` in the generated modules
--outro <text> Code to insert at end of bundle (inside wrapper)
--preferConst Use `const` instead of `var` for exports
--preserveModules Preserve module structure
--preserveSymlinks Do not follow symlinks when resolving files
--shimMissingExports Create shim variables for missing exports
--silent Don't print warnings
--sourcemapExcludeSources Do not include source code in source maps
--sourcemapFile <file> Specify bundle position for source maps
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.propertyReadSideEffects Ignore property access side-effects
--treeshake.pureExternalModules Assume side-effect free externals

Examples:

Expand Down
24 changes: 9 additions & 15 deletions bin/src/run/batchWarnings.ts
Expand Up @@ -55,7 +55,7 @@ export default function batchWarnings() {
handler.fn(warnings);
} else {
warnings.forEach(warning => {
stderr(`${tc.bold.yellow('(!)')} ${tc.bold.yellow(warning.message)}`);
title(warning.message);

if (warning.url) info(warning.url);

Expand Down Expand Up @@ -87,14 +87,6 @@ const immediateHandlers: {
stderr(warning.message);
},

DEPRECATED_OPTIONS: warning => {
title(`Some options have been renamed`);
info(`https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32`);
warning.deprecations.forEach(option => {
stderr(`${tc.bold(option.old)} is now ${option.new}`);
});
},

MISSING_NODE_BUILTINS: warning => {
title(`Missing shims for Node.js built-ins`);

Expand All @@ -103,7 +95,7 @@ const immediateHandlers: {
? `'${warning.modules[0]}'`
: `${warning.modules
.slice(0, -1)
.map(name => `'${name}'`)
.map((name: string) => `'${name}'`)
.join(', ')} and '${warning.modules.slice(-1)}'`;
stderr(
`Creating a browser bundle that depends on ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins`
Expand Down Expand Up @@ -263,11 +255,13 @@ const deferredHandlers: {
items.forEach(warning => {
if (warning.url !== lastUrl) info((lastUrl = warning.url));

const loc = warning.loc
? `${relativeId(warning.id)}: (${warning.loc.line}:${warning.loc.column})`
: relativeId(warning.id);

stderr(tc.bold(relativeId(loc)));
if (warning.id) {
let loc = relativeId(warning.id);
if (warning.loc) {
loc += `: (${warning.loc.line}:${warning.loc.column})`;
}
stderr(tc.bold(loc));
}
if (warning.frame) info(warning.frame);
});
});
Expand Down
36 changes: 20 additions & 16 deletions bin/src/run/build.ts
Expand Up @@ -3,9 +3,10 @@ import * as rollup from 'rollup';
import tc from 'turbocolor';
import {
InputOptions,
OutputAsset,
OutputChunk,
OutputOptions,
RollupBuild,
RollupSingleFileBuild
RollupBuild
} from '../../../src/rollup/types';
import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
Expand All @@ -19,12 +20,7 @@ export default function build(
warnings: BatchWarnings,
silent = false
) {
const useStdout =
outputOptions.length === 1 &&
!outputOptions[0].file &&
!outputOptions[0].dir &&
inputOptions.input instanceof Array === false &&
typeof inputOptions.input !== 'object';
const useStdout = !outputOptions[0].file && !outputOptions[0].dir;

const start = Date.now();
const files = useStdout ? ['stdout'] : outputOptions.map(t => relativeId(t.file || t.dir));
Expand All @@ -44,7 +40,7 @@ export default function build(

return rollup
.rollup(inputOptions)
.then((bundle: RollupSingleFileBuild | RollupBuild) => {
.then((bundle: RollupBuild) => {
if (useStdout) {
const output = outputOptions[0];
if (output.sourcemap && output.sourcemap !== 'inline') {
Expand All @@ -54,21 +50,29 @@ export default function build(
});
}

return (<RollupSingleFileBuild>bundle).generate(output).then(({ code, map }) => {
if (!code) return;
if (output.sourcemap === 'inline') {
code += `\n//# ${SOURCEMAPPING_URL}=${map.toUrl()}\n`;
return bundle.generate(output).then(({ output: outputs }) => {
for (const file of outputs) {
let source: string | Buffer;
if ((<OutputAsset>file).isAsset) {
source = (<OutputAsset>file).source;
} else {
source = (<OutputChunk>file).code;
if (output.sourcemap === 'inline') {
source += `\n//# ${SOURCEMAPPING_URL}=${(<OutputChunk>file).map.toUrl()}\n`;
}
}
if (outputs.length > 1)
process.stdout.write('\n' + tc.cyan(tc.bold('//→ ' + file.fileName + ':')) + '\n');
process.stdout.write(source);
}

process.stdout.write(code);
});
}

return Promise.all(outputOptions.map(output => <Promise<any>>bundle.write(output))).then(
() => bundle
);
})
.then((bundle?: RollupSingleFileBuild | RollupBuild) => {
.then((bundle?: RollupBuild) => {
warnings.flush();
if (!silent)
stderr(
Expand Down
50 changes: 20 additions & 30 deletions bin/src/run/index.ts
Expand Up @@ -10,34 +10,34 @@ import loadConfigFile from './loadConfigFile';
import watch from './watch';

export default function runRollup(command: any) {
if (command._.length >= 1) {
let inputSource;
if (command._.length > 0) {
if (command.input) {
handleError({
code: 'DUPLICATE_IMPORT_OPTIONS',
message: 'use --input, or pass input path as argument'
});
}
inputSource = command._;
} else if (typeof command.input === 'string') {
inputSource = [command.input];
} else {
inputSource = command.input;
}

if (command.dir) {
if (command._.length) {
if (command._.some((input: string) => input.indexOf('=') !== -1)) {
command.input = {};
command._.forEach((input: string) => {
const equalsIndex = input.indexOf('=');
const value = input.substr(equalsIndex + 1);
let key = input.substr(0, equalsIndex);
if (!key) key = getAliasName(input);
command.input[key] = value;
});
} else {
command.input = command._;
}
} else if (typeof command.input === 'string') {
command.input = [command.input];
if (inputSource && inputSource.length > 0) {
if (inputSource.some((input: string) => input.indexOf('=') !== -1)) {
command.input = {};
inputSource.forEach((input: string) => {
const equalsIndex = input.indexOf('=');
const value = input.substr(equalsIndex + 1);
let key = input.substr(0, equalsIndex);
if (!key) key = getAliasName(input);
command.input[key] = value;
});
} else {
command.input = inputSource;
}
} else if (command._.length === 1) {
command.input = command._[0];
}

if (command.environment) {
Expand Down Expand Up @@ -101,22 +101,12 @@ function execute(configFile: string, configs: InputOptions[], command: any) {
for (const config of configs) {
promise = promise.then(() => {
const warnings = batchWarnings();
const { inputOptions, outputOptions, deprecations, optionError } = mergeOptions({
const { inputOptions, outputOptions, optionError } = mergeOptions({
config,
command,
defaultOnWarnHandler: warnings.add
});

if (deprecations.length) {
inputOptions.onwarn({
code: 'DEPRECATED_OPTIONS',
message: `The following options have been renamed — please update your config: ${deprecations
.map(option => `${option.old} -> ${option.new}`)
.join(', ')}`,
deprecations
});
}

if (optionError) inputOptions.onwarn({ code: 'UNKNOWN_OPTION', message: optionError });
return build(inputOptions, outputOptions, warnings, command.silent);
});
Expand Down
7 changes: 4 additions & 3 deletions bin/src/run/loadConfigFile.ts
@@ -1,7 +1,7 @@
import path from 'path';
import rollup from 'rollup';
import tc from 'turbocolor';
import { InputOptions, RollupSingleFileBuild } from '../../../src/rollup/types';
import { InputOptions, RollupBuild, RollupOutput } from '../../../src/rollup/types';
import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import batchWarnings from './batchWarnings';
Expand All @@ -20,12 +20,13 @@ export default function loadConfigFile(
return rollup
.rollup({
input: configFile,
treeshake: false,
external: (id: string) => {
return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json';
},
onwarn: warnings.add
})
.then((bundle: RollupSingleFileBuild) => {
.then((bundle: RollupBuild) => {
if (!silent && warnings.count > 0) {
stderr(tc.bold(`loaded ${relativeId(configFile)} with warnings`));
warnings.flush();
Expand All @@ -35,7 +36,7 @@ export default function loadConfigFile(
format: 'cjs'
});
})
.then(({ code }: { code: string }) => {
.then(({ output: [{ code }] }: RollupOutput) => {
// temporarily override require
const defaultLoader = require.extensions['.js'];
require.extensions['.js'] = (module: NodeModuleWithCompile, filename: string) => {
Expand Down