Skip to content

Commit

Permalink
Merge branch 'master' into sourcemap-types
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jul 4, 2019
2 parents fdf55e9 + 198a7b6 commit b98e5c9
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 37 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Expand Up @@ -9,6 +9,15 @@ unit_tests: &unit_tests
name: Run unit tests.
command: npm run ci:test

unit_tests_12: &unit_tests_12
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Run unit tests.
command: npm run ci:test_12

jobs:
analysis:
docker:
Expand Down Expand Up @@ -42,6 +51,10 @@ jobs:
docker:
- image: rollupcabal/circleci-node-v10:latest
<<: *unit_tests
node-v12-latest:
docker:
- image: rollupcabal/circleci-node-v12:latest
<<: *unit_tests_12

workflows:
version: 2
Expand Down Expand Up @@ -69,3 +82,9 @@ workflows:
filters:
tags:
only: /.*/
- node-v12-latest:
requires:
- analysis
filters:
tags:
only: /.*/
22 changes: 21 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,25 @@
# rollup changelog

## 1.16.6
*2019-07-04*

### Bug Fixes
* Do not pass undefined to resolveDynamicImport for unresolvable template literals (#2984)

### Pull Requests
* [#2984](https://github.com/rollup/rollup/pull/2984): Always forward AST nodes for unresolvable dynamic imports (@lukastaegert)

## 1.16.5
*2019-07-04*

### Bug Fixes
* onwarn should still be called when --silent is used (#2982)
* Properly clean up watchers for files that are deleted between builds (#2982)

### Pull Requests
* [#2981](https://github.com/rollup/rollup/pull/2981): Do not skip onwarn handler when --silent is used (@lukastaegert)
* [#2982](https://github.com/rollup/rollup/pull/2982): Make tests run on Node 12, fix watcher cleanup issue (@lukastaegert)

## 1.16.4
*2019-07-02*

Expand All @@ -8,7 +28,7 @@
* Use the correct TypeScript type for Sourcemap.version (#2976)

### Pull Requests
* [#2965](https://github.com/rollup/rollup/pull/2974): Use async readFile in getRollupDefaultPlugin (@kaksmet)
* [#2965](https://github.com/rollup/rollup/pull/2965): Use async readFile in getRollupDefaultPlugin (@kaksmet)
* [#2974](https://github.com/rollup/rollup/pull/2974): Align TS types, docs and implementation for this.warn and this.error (@lukastaegert)
* [#2976](https://github.com/rollup/rollup/pull/2976): Fix sourcemap type and update dependencies (@lukastaegert)

Expand Down
2 changes: 1 addition & 1 deletion bin/src/run/batchWarnings.ts
Expand Up @@ -253,7 +253,7 @@ const deferredHandlers: {
let lastUrl: string;

nestedByMessage.forEach(({ key: message, items }) => {
title(`${plugin} plugin: ${message}`);
title(`Plugin ${plugin}: ${message}`);
items.forEach(warning => {
if (warning.url !== lastUrl) info((lastUrl = warning.url as string));

Expand Down
9 changes: 5 additions & 4 deletions bin/src/run/build.ts
Expand Up @@ -77,13 +77,14 @@ export default function build(
);
})
.then((bundle?: RollupBuild) => {
warnings.flush();
if (!silent)
if (!silent) {
warnings.flush();
stderr(
tc.green(`created ${tc.bold(files.join(', '))} in ${tc.bold(ms(Date.now() - start))}`)
);
if (bundle && bundle.getTimings) {
printTimings(bundle.getTimings());
if (bundle && bundle.getTimings) {
printTimings(bundle.getTimings());
}
}
})
.catch((err: any) => {
Expand Down
4 changes: 2 additions & 2 deletions docs/01-command-line-reference.md
Expand Up @@ -165,7 +165,7 @@ $ rollup --config
$ rollup --config my.config.js
```

You can also export a function that returns any of the above configuration formats. This function will be passed the current command line arguments so that you can dynamically adapt your configuration to respect e.g. `--silent`. You can even define your own command line options if you prefix them with `config`:
You can also export a function that returns any of the above configuration formats. This function will be passed the current command line arguments so that you can dynamically adapt your configuration to respect e.g. [`--silent`](guide/en/#--silent). You can even define your own command line options if you prefix them with `config`:

```javascript
// rollup.config.js
Expand Down Expand Up @@ -254,7 +254,7 @@ Rebuild the bundle when its source files change on disk.

#### `--silent`

Don't print warnings to the console.
Don't print warnings to the console. If your configuration file contains an `onwarn` handler, this handler will still be called. To manually prevent that, you can access the command line options in your configuration file as described at the end of [Configuration Files](guide/en/#configuration-files).

#### `--environment <values>`

Expand Down
2 changes: 1 addition & 1 deletion docs/999-big-list-of-options.md
Expand Up @@ -317,7 +317,7 @@ Be aware that manual chunks can change the behaviour of the application if side-
#### onwarn
Type: `(warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void;`

A function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console.
A function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console. When using the [`--silent`](guide/en/#--silent) CLI option, this handler is the only way to get notified about warnings.

The function receives two arguments: the warning object and the default handler. Warnings objects have, at a minimum, a `code` and a `message` property, allowing you to control how different kinds of warnings are handled. Other properties are added depending on the type of warning.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "1.16.4",
"version": "1.16.6",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/rollup.es.js",
Expand All @@ -16,6 +16,7 @@
"ci:coverage": "npm run test:coverage",
"ci:lint": "npm run lint:nofix && npm run security",
"ci:test": "npm run build:test && npm run build:bootstrap && npm run test:all",
"ci:test_12": "npm run build:test && npm run build:bootstrap && npm run test:only && npm run test:typescript",
"lint": "npm run lint:ts -- --fix && npm run lint:js -- --fix && npm run lint:markdown",
"lint:nofix": "npm run lint:ts && npm run lint:js && npm run lint:markdown",
"lint:ts": "tslint --project .",
Expand Down
21 changes: 10 additions & 11 deletions src/Module.ts
Expand Up @@ -303,18 +303,17 @@ export default class Module {
getDynamicImportExpressions(): (string | Node)[] {
return this.dynamicImports.map(({ node }) => {
const importArgument = node.parent.arguments[0];
if (importArgument instanceof TemplateLiteral) {
if (importArgument.expressions.length === 0 && importArgument.quasis.length === 1) {
return importArgument.quasis[0].value.cooked;
}
} else if (importArgument instanceof Literal) {
if (typeof importArgument.value === 'string') {
return importArgument.value;
}
} else {
return importArgument;
if (
importArgument instanceof TemplateLiteral &&
importArgument.quasis.length === 1 &&
importArgument.quasis[0].value.cooked
) {
return importArgument.quasis[0].value.cooked;
}
if (importArgument instanceof Literal && typeof importArgument.value === 'string') {
return importArgument.value;
}
return undefined as any;
return importArgument;
});
}

Expand Down
7 changes: 2 additions & 5 deletions src/utils/mergeOptions.ts
Expand Up @@ -58,12 +58,9 @@ const defaultOnWarn: WarningHandler = warning => {

const getOnWarn = (
config: GenericConfigObject,
command: CommandConfigObject,
defaultOnWarnHandler: WarningHandler = defaultOnWarn
): WarningHandler =>
command.silent
? () => {}
: config.onwarn
config.onwarn
? warning => (config.onwarn as WarningHandlerWithDefault)(warning, defaultOnWarnHandler)
: defaultOnWarnHandler;

Expand Down Expand Up @@ -225,7 +222,7 @@ function getInputOptions(
input: getOption('input', []),
manualChunks: getOption('manualChunks'),
moduleContext: config.moduleContext as any,
onwarn: getOnWarn(config, command, defaultOnWarnHandler),
onwarn: getOnWarn(config, defaultOnWarnHandler),
perf: getOption('perf', false),
plugins: config.plugins as any,
preserveModules: getOption('preserveModules'),
Expand Down
14 changes: 7 additions & 7 deletions src/watch/index.ts
Expand Up @@ -211,26 +211,26 @@ export class Task {
return rollup(options)
.then(result => {
if (this.closed) return undefined as any;

const previouslyWatched = this.watched;
const watched = (this.watched = new Set());

this.cache = result.cache;
this.watchFiles = result.watchFiles;
(this.cache.modules as ModuleJSON[]).forEach(module => {
for (const module of this.cache.modules as ModuleJSON[]) {
if (module.transformDependencies) {
module.transformDependencies.forEach(depId => {
watched.add(depId);
this.watchFile(depId, true);
});
}
});
this.watchFiles.forEach(id => {
}
for (const id of this.watchFiles) {
watched.add(id);
this.watchFile(id);
});
this.watched.forEach(id => {
}
for (const id of previouslyWatched) {
if (!watched.has(id)) deleteTask(id, this, this.chokidarOptionsHash);
});
}

return Promise.all(this.outputs.map(output => result.write(output))).then(() => result);
})
Expand Down
10 changes: 10 additions & 0 deletions test/cli/samples/silent-onwarn/_config.js
@@ -0,0 +1,10 @@
const assert = require('assert');

module.exports = {
description: 'triggers onwarn with --silent',
command: 'rollup -c --silent',
stderr: stderr => {
assert.equal(stderr, '');
return true;
}
};
5 changes: 5 additions & 0 deletions test/cli/samples/silent-onwarn/_expected.js
@@ -0,0 +1,5 @@
var doIt = () => console.log('main');

doIt();

export default doIt;
5 changes: 5 additions & 0 deletions test/cli/samples/silent-onwarn/main.js
@@ -0,0 +1,5 @@
import doIt from './main.js';

export default () => console.log('main');

doIt();
20 changes: 20 additions & 0 deletions test/cli/samples/silent-onwarn/rollup.config.js
@@ -0,0 +1,20 @@
import assert from 'assert';

const warnings = [];

export default {
input: 'main.js',
output: {
format: 'esm'
},
onwarn(warning) {
warnings.push(warning);
},
plugins: {
generateBundle(bundle) {
assert.strictEqual(warnings.length, 1);
assert.strictEqual(warnings[0].code, 'CIRCULAR_DEPENDENCY');
}
}

}
20 changes: 20 additions & 0 deletions test/form/samples/dynamic-import-unresolvable/_config.js
@@ -0,0 +1,20 @@
const assert = require('assert');

module.exports = {
solo: true,
description: 'Returns the raw AST nodes for unresolvable dynamic imports',
options: {
plugins: [
{
resolveDynamicImport(specifier) {
assert.ok(specifier);
assert.strictEqual(typeof specifier, 'object');
if (specifier.type !== 'TemplateLiteral' && specifier.type !== 'Literal') {
throw new Error(`Unexpected specifier type ${specifier.type}.`);
}
return false;
}
}
]
}
};
3 changes: 3 additions & 0 deletions test/form/samples/dynamic-import-unresolvable/_expected.js
@@ -0,0 +1,3 @@
import(`${globalVar}`);
import(`My ${globalVar}`);
import(7);
3 changes: 3 additions & 0 deletions test/form/samples/dynamic-import-unresolvable/main.js
@@ -0,0 +1,3 @@
import(`${globalVar}`);
import(`My ${globalVar}`);
import(7);
Expand Up @@ -10,7 +10,8 @@ module.exports = {
return exports.then(result => {
assert.strictEqual(result[0].message, 'exists-named');
assert.strictEqual(result[1].message, 'exists-default');
assert.strictEqual(result[2].message, "Cannot find module 'does-not-exist'");
const expectedError = "Cannot find module 'does-not-exist'";
assert.strictEqual(result[2].message.slice(0, expectedError.length), expectedError);
});
}
};
5 changes: 4 additions & 1 deletion test/function/samples/dynamic-import-expression/_config.js
Expand Up @@ -24,6 +24,9 @@ module.exports = {
]
},
exports(exports) {
return exports.catch(err => assert.strictEqual(err.message, "Cannot find module 'x/y'"));
const expectedError = "Cannot find module 'x/y'";
return exports.catch(err =>
assert.strictEqual(err.message.slice(0, expectedError.length), expectedError)
);
}
};
5 changes: 4 additions & 1 deletion test/function/samples/dynamic-import-rewriting/_config.js
Expand Up @@ -13,6 +13,9 @@ module.exports = {
]
},
exports(exports) {
return exports.promise.catch(err => assert.equal(err.message, "Cannot find module 'asdf'"));
const expectedError = "Cannot find module 'asdf'";
return exports.promise.catch(err =>
assert.strictEqual(err.message.slice(0, expectedError.length), expectedError)
);
}
};

0 comments on commit b98e5c9

Please sign in to comment.