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

fix(commonjs): add .cjs to default file extensions. #524

Merged
merged 6 commits into from Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion packages/commonjs/src/index.js
Expand Up @@ -34,7 +34,7 @@ import {
} from './transform';

export default function commonjs(options = {}) {
const extensions = options.extensions || ['.js'];
const extensions = options.extensions || ['.js', '.cjs'];
ctjlewis marked this conversation as resolved.
Show resolved Hide resolved
const filter = createFilter(options.include, options.exclude);
const {
ignoreGlobal,
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
test: 42
};
@@ -0,0 +1,3 @@
const { test } = require('./export.cjs');

console.log(test);
21 changes: 21 additions & 0 deletions packages/commonjs/test/snapshots/test.js.md
Expand Up @@ -21,3 +21,24 @@ Generated by [AVA](https://avajs.dev).
module.exports = main;␊
`

## imports .cjs file extension by default

> Snapshot 1

`'use strict';␊
var _export = {␊
test: 42␊
};␊
const { test } = _export;␊
console.log(test);␊
var main = {␊
};␊
module.exports = main;␊
`
Binary file modified packages/commonjs/test/snapshots/test.js.snap
Binary file not shown.
9 changes: 9 additions & 0 deletions packages/commonjs/test/test.js
Expand Up @@ -639,3 +639,12 @@ test('logs a warning when the deprecated namedExports option is used', async (t)
'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
);
});

test('imports .cjs file extension by default', async (t) => {
const bundle = await rollup({
input: 'fixtures/samples/cjs-extension/main.js',
plugins: [commonjs()]
});
const code = await getCodeFromBundle(bundle);
t.snapshot(code);
});