Skip to content

Commit

Permalink
Extend documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 20, 2022
1 parent 94cdd29 commit 588c25e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 37 deletions.
2 changes: 2 additions & 0 deletions docs/02-javascript-api.md
Expand Up @@ -12,6 +12,8 @@ On a `bundle` object, you can call `bundle.generate` multiple times with differe

Once you're finished with the `bundle` object, you should call `bundle.close()`, which will let plugins clean up their external processes or services via the [`closeBundle`](guide/en/#closebundle) hook.

If an error occurs at either stage, it will return a Promise rejected with an Error, which you can identify via their `code` property. Besides `code` and `message`, many errors have additional properties you can use for custom reporting, see [`utils/error.ts`](https://github.com/rollup/rollup/blob/master/src/utils/error.ts) for a complete list of errors and warnings together with their codes and properties.

```javascript
import { rollup } from 'rollup';

Expand Down
6 changes: 4 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -370,7 +370,7 @@ Type: `(warning: RollupWarning, defaultHandler: (warning: string | RollupWarning
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.
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. See [`utils/error.ts`](https://github.com/rollup/rollup/blob/master/src/utils/error.ts) for a complete list of errors and warnings together with their codes and properties.
```js
// rollup.config.js
Expand All @@ -381,7 +381,9 @@ export default {
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return;

// throw on others
if (warning.code === 'MISSING_EXPORT') throw new Error(warning.message);
// Using Object.assign over new Error(warning.message) will make the CLI
// print additional information such as warning location and help url.
if (warning.code === 'MISSING_EXPORT') throw Object.assign(new Error(), warning);

// Use default for everything else
warn(warning);
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.ts
Expand Up @@ -47,7 +47,7 @@ const onwarn: WarningHandlerWithDefault = warning => {
'Building Rollup produced warnings that need to be resolved. ' +
'Please keep in mind that the browser build may never have external dependencies!'
);
throw new Error(warning.message);
throw Object.assign(new Error(), warning);
};

const moduleAliases = {
Expand Down
24 changes: 0 additions & 24 deletions src/Chunk.ts
Expand Up @@ -1353,28 +1353,4 @@ function getImportedBindingsPerDependency(
return importedBindingsPerDependency;
}

function getImportedBindingsPerDependency(
renderedDependencies: RenderedDependencies,
resolveFileName: (dependency: Chunk | ExternalChunk) => string
): {
[imported: string]: string[];
} {
const importedBindingsPerDependency: { [imported: string]: string[] } = {};
for (const [dependency, declaration] of renderedDependencies) {
const specifiers = new Set<string>();
if (declaration.imports) {
for (const { imported } of declaration.imports) {
specifiers.add(imported);
}
}
if (declaration.reexports) {
for (const { imported } of declaration.reexports) {
specifiers.add(imported);
}
}
importedBindingsPerDependency[resolveFileName(dependency)] = [...specifiers];
}
return importedBindingsPerDependency;
}

const QUERY_HASH_REGEX = /[?#]/;
@@ -1,10 +1,6 @@
define(['require'], (function (require) { 'use strict';

console.log('main');
<<<<<<<< HEAD:test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-5940aabc-amd.js
new Promise(function (resolve, reject) { require(['./chunk-deb-87ce45a9-amd'], resolve, reject); }).then(console.log);
========
new Promise(function (resolve, reject) { require(['./chunk-deb-faae56f2-amd'], resolve, reject); }).then(console.log);
>>>>>>>> 113353e74 ([v3.0] New hashing algorithm that "fixes (nearly) everything" (#4543)):test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-aaf15a0c-amd.js

}));
@@ -1,8 +1,4 @@
'use strict';

console.log('main');
<<<<<<<< HEAD:test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-9cf3a232-cjs.js
Promise.resolve().then(function () { return require('./chunk-deb-69905607-cjs.js'); }).then(console.log);
========
Promise.resolve().then(function () { return require('./chunk-deb-2221fa83-cjs.js'); }).then(console.log);
>>>>>>>> 113353e74 ([v3.0] New hashing algorithm that "fixes (nearly) everything" (#4543)):test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-69b6552e-cjs.js
Expand Up @@ -2,6 +2,7 @@ const assert = require('assert');
const path = require('path');
const { assertIncludes } = require('../../../utils.js');
const ID_MAIN = path.join(__dirname, 'main.js');
const ID_FOO = path.join(__dirname, 'foo.js');

module.exports = {
description: 'warns for reassignments to namespace exports',
Expand All @@ -13,8 +14,7 @@ module.exports = {
{
binding: 'bar',
code: 'MISSING_EXPORT',
exporter:
'/Users/lukastaegert/Github/rollup/test/function/samples/namespace-reassign-import-fails/foo.js',
exporter: ID_FOO,
id: ID_MAIN,
message: '"bar" is not exported by "foo.js", imported by "main.js".',
url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module',
Expand Down

0 comments on commit 588c25e

Please sign in to comment.