Skip to content

Commit

Permalink
Merge branch 'master' into node-resolve-external-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Mar 14, 2021
2 parents 995d616 + 2d06c44 commit f0fd052
Show file tree
Hide file tree
Showing 86 changed files with 1,208 additions and 665 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Expand Up @@ -70,6 +70,9 @@ jobs:
- run:
name: Run linting.
command: pnpm run ci:lint
- run:
name: Check TypeScript types.
command: pnpm run test:ts
- save_cache:
key: dependency-cache-{{ checksum "pnpm-lock.yaml" }}
paths:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -15,7 +15,8 @@
"pub": "node scripts/pub.js",
"publish": "node scripts/publish.js",
"security": "pnpm audit --audit-level=moderate",
"test": "node scripts/run-changed.js test"
"test": "node scripts/run-changed.js test",
"test:ts": "node scripts/run-changed.js test:ts"
},
"dependencies": {
"conventional-commits-parser": "^3.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/alias/package.json
Expand Up @@ -29,7 +29,8 @@
"prepare": "pnpm run build",
"prepublishOnly": "pnpm run lint && pnpm run test",
"pretest": "pnpm run build",
"test": "ava"
"test": "ava",
"test:ts": "tsc --noEmit"
},
"files": [
"dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/auto-install/package.json
Expand Up @@ -26,7 +26,8 @@
"prepare": "pnpm run build",
"prepublishOnly": "pnpm run lint",
"pretest": "pnpm run build",
"test": "ava"
"test": "ava",
"test:ts": "tsc --noEmit"
},
"files": [
"dist",
Expand Down
14 changes: 14 additions & 0 deletions packages/babel/CHANGELOG.md
@@ -1,5 +1,19 @@
# @rollup/plugin-babel ChangeLog

## v5.3.0

_2021-02-14_

### Features

- feat: add custom filter option (#767)
- feat: pass rollup context as this context into override config function (#784)

### Updates

- docs: typo in README.md (#800)
- chore: commit updated readme format (bfda6d8)

## v5.2.3

_2021-01-29_
Expand Down
42 changes: 21 additions & 21 deletions packages/babel/README.md
Expand Up @@ -45,9 +45,9 @@ const config = {
input: 'src/index.js',
output: {
dir: 'output',
format: 'esm'
format: 'esm',
},
plugins: [babel({ babelHelpers: 'bundled' })]
plugins: [babel({ babelHelpers: 'bundled' })],
};

export default config;
Expand Down Expand Up @@ -84,7 +84,7 @@ All options are as per the [Babel documentation](https://babeljs.io/docs/en/opti

Type: `String | RegExp | Array[...String|RegExp]`<br>

A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. When relaying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. When relying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.

### `include`

Expand Down Expand Up @@ -169,13 +169,13 @@ export default {
input: 'main.js',
plugins: [
getBabelOutputPlugin({
presets: ['@babel/preset-env']
})
presets: ['@babel/preset-env'],
}),
],
output: [
{ file: 'bundle.cjs.js', format: 'cjs' },
{ file: 'bundle.esm.js', format: 'esm' }
]
{ file: 'bundle.esm.js', format: 'esm' },
],
};
```

Expand All @@ -192,9 +192,9 @@ export default {
{
file: 'bundle.es5.js',
format: 'esm',
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })]
}
]
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })],
},
],
};
```

Expand All @@ -213,9 +213,9 @@ export default {
{
file: 'bundle.js',
format: 'esm',
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })]
}
]
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })],
},
],
};
```

Expand All @@ -225,7 +225,7 @@ Unlike the regular `babel` plugin, `getBabelOutputPlugin(...)` will **not** auto

```js
getBabelOutputPlugin({
configFile: path.resolve(__dirname, 'babel.config.js')
configFile: path.resolve(__dirname, 'babel.config.js'),
});
```

Expand Down Expand Up @@ -327,10 +327,10 @@ It's main purpose is to allow other tools for configuration of transpilation wit
```js
import { createBabelInputPluginFactory } from '@rollup/plugin-babel';

export default createBabelInputPluginFactory(babelCore => {
export default createBabelInputPluginFactory((babelCore) => {
function myPlugin() {
return {
visitor: {}
visitor: {},
};
}

Expand All @@ -342,7 +342,7 @@ export default createBabelInputPluginFactory(babelCore => {
customOptions: { opt1, opt2 },

// Pass the options back with the two custom options removed.
pluginOptions
pluginOptions,
};
},

Expand All @@ -358,17 +358,17 @@ export default createBabelInputPluginFactory(babelCore => {
...(cfg.options.plugins || []),

// Include a custom plugin in the options.
myPlugin
]
myPlugin,
],
};
},

result(result, { code, customOptions, config, transformOptions }) {
return {
...result,
code: result.code + '\n// Generated by some custom plugin'
code: result.code + '\n// Generated by some custom plugin',
};
}
},
};
});
```
Expand Down
2 changes: 1 addition & 1 deletion packages/babel/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-babel",
"version": "5.2.3",
"version": "5.3.0",
"publishConfig": {
"access": "public"
},
Expand Down
43 changes: 31 additions & 12 deletions packages/commonjs/README.md
Expand Up @@ -34,9 +34,9 @@ export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
format: 'cjs',
},
plugins: [commonjs()]
plugins: [commonjs()],
};
```

Expand Down Expand Up @@ -66,8 +66,8 @@ commonjs({
'!node_modules/logform/index.js',
'!node_modules/logform/format.js',
'!node_modules/logform/levels.js',
'!node_modules/logform/browser.js'
]
'!node_modules/logform/browser.js',
],
});
```

Expand Down Expand Up @@ -134,6 +134,25 @@ Due to the conversion of `require` to a static `import` - the call is hoisted to
- `string[]`: Pass an array containing the IDs to left unconverted.
- `((id: string) => boolean|'remove')`: Pass a function that control individual IDs.

### `ignoreDynamicRequires`

Type: `boolean`
Default: false

Some `require` calls cannot be resolved statically to be translated to imports, e.g.

```js
function wrappedRequire(target) {
return require(target);
}
wrappedRequire('foo');
wrappedRequire('bar');
```

When this option is set to `false`, the generated code will either directly throw an error when such a call is encountered or, when `dynamicRequireTargets` is used, when such a call cannot be resolved with a configured dynamic require target.

Setting this option to `true` will instead leave the `require` call in the code or use it as a fallback for `dynamicRequireTargets`.

### `esmExternals`

Type: `boolean | string[] | ((id: string) => boolean)`
Expand Down Expand Up @@ -188,7 +207,7 @@ This is in line with how other bundlers handle this situation and is also the mo

var dep$1 = /*#__PURE__*/ Object.freeze({
__proto__: null,
default: dep
default: dep,
});

console.log(dep$1.default);
Expand Down Expand Up @@ -219,7 +238,7 @@ For these situations, you can change Rollup's behaviour either globally or per m
enumerable: true,
get: function () {
return n[k];
}
},
}
);
});
Expand Down Expand Up @@ -295,9 +314,9 @@ export default {
output: {
file: 'bundle.js',
format: 'iife',
name: 'MyModule'
name: 'MyModule',
},
plugins: [resolve(), commonjs()]
plugins: [resolve(), commonjs()],
};
```

Expand All @@ -307,7 +326,7 @@ Symlinks are common in monorepos and are also created by the `npm link` command.

```js
commonjs({
include: /node_modules/
include: /node_modules/,
});
```

Expand All @@ -330,11 +349,11 @@ function cjsDetectionPlugin() {
moduleParsed({
id,
meta: {
commonjs: { isCommonJS }
}
commonjs: { isCommonJS },
},
}) {
console.log(`File ${id} is CommonJS: ${isCommonJS}`);
}
},
};
}
```
Expand Down
16 changes: 10 additions & 6 deletions packages/commonjs/src/helpers.js
Expand Up @@ -48,18 +48,20 @@ export function getAugmentedNamespace(n) {
}
`;

const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`;

const HELPER_NON_DYNAMIC = `
export function createCommonjsModule(fn) {
var module = { exports: {} }
return fn(module, module.exports), module.exports;
}
export function commonjsRequire (target) {
throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.');
export function commonjsRequire (path) {
${FAILED_REQUIRE_ERROR}
}
`;

const HELPERS_DYNAMIC = `
const getDynamicHelpers = (ignoreDynamicRequires) => `
export function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
Expand Down Expand Up @@ -231,13 +233,15 @@ export function commonjsRequire (path, originalModuleDir) {
return cachedModule.exports;
};
}
return require(path);
${ignoreDynamicRequires ? 'return require(path);' : FAILED_REQUIRE_ERROR}
}
commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;
commonjsRequire.resolve = commonjsResolve;
`;

export function getHelpersModule(isDynamicRequireModulesEnabled) {
return `${HELPERS}${isDynamicRequireModulesEnabled ? HELPERS_DYNAMIC : HELPER_NON_DYNAMIC}`;
export function getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires) {
return `${HELPERS}${
isDynamicRequireModulesEnabled ? getDynamicHelpers(ignoreDynamicRequires) : HELPER_NON_DYNAMIC
}`;
}
7 changes: 6 additions & 1 deletion packages/commonjs/src/index.js
Expand Up @@ -44,6 +44,7 @@ export default function commonjs(options = {}) {
const filter = createFilter(options.include, options.exclude);
const {
ignoreGlobal,
ignoreDynamicRequires,
requireReturnsDefault: requireReturnsDefaultOption,
esmExternals
} = options;
Expand Down Expand Up @@ -97,6 +98,7 @@ export default function commonjs(options = {}) {

function transformAndCheckExports(code, id) {
if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) {
// eslint-disable-next-line no-param-reassign
code =
getDynamicPackagesEntryIntro(dynamicRequireModuleDirPaths, dynamicRequireModuleSet) + code;
}
Expand Down Expand Up @@ -125,6 +127,7 @@ export default function commonjs(options = {}) {
// avoid wrapping in createCommonjsModule, as this is a commonjsRegister call
if (isModuleRegisterProxy(id)) {
disableWrap = true;
// eslint-disable-next-line no-param-reassign
id = unwrapModuleRegisterProxy(id);
}

Expand All @@ -135,6 +138,7 @@ export default function commonjs(options = {}) {
isEsModule,
ignoreGlobal || isEsModule,
ignoreRequire,
ignoreDynamicRequires && !isDynamicRequireModulesEnabled,
getIgnoreTryCatchRequireStatementMode,
sourceMap,
isDynamicRequireModulesEnabled,
Expand All @@ -161,7 +165,7 @@ export default function commonjs(options = {}) {

load(id) {
if (id === HELPERS_ID) {
return getHelpersModule(isDynamicRequireModulesEnabled);
return getHelpersModule(isDynamicRequireModulesEnabled, ignoreDynamicRequires);
}

if (id.startsWith(HELPERS_ID)) {
Expand Down Expand Up @@ -232,6 +236,7 @@ export default function commonjs(options = {}) {
}
},

// eslint-disable-next-line no-shadow
moduleParsed({ id, meta: { commonjs } }) {
if (commonjs) {
const isCjs = commonjs.isCommonJS;
Expand Down

0 comments on commit f0fd052

Please sign in to comment.