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

feat(pluginutils): add native node es modules support #419

Merged
merged 4 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/pluginutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"bugs": {
"url": "https://github.com/rollup/plugins/issues"
},
"main": "dist/index.js",
"main": "./dist/cjs/index.js",
"engines": {
"node": ">= 8.0.0"
},
Expand Down Expand Up @@ -75,12 +75,17 @@
"!**/types.ts"
]
},
"module": "dist/index.es.js",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/es/index.js"
},
"module": "./dist/es/index.js",
Comment on lines +78 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question about the choice to nest these within a directory: our prior file format was index.[format].[extension] for output files. e.g. index.es.js. what's the reasoning behind the choice to put them into directories?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es/package.json with {type:module}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to .mjs extension.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Can you explain in the PR description why we need mjs alternative? I've added a bunch more people to review. We're going to need to get majority buy-in to move forward with this since it's a pretty big paradigm shift.

"nyc": {
"extension": [
".js",
".ts"
]
},
"type": "commonjs",
guybedford marked this conversation as resolved.
Show resolved Hide resolved
"types": "types/index.d.ts"
}
13 changes: 4 additions & 9 deletions packages/pluginutils/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';

import { emitModulePackageFile } from '../../shared/rollup.config';

import pkg from './package.json';

export default {
Expand All @@ -13,14 +15,7 @@ export default {
],
external: Object.keys(pkg.dependencies).concat('path', 'util'),
output: [
{
format: 'cjs',
file: pkg.main,
exports: 'named'
},
{
format: 'es',
file: pkg.module
}
{ format: 'cjs', file: pkg.main, exports: 'named' },
{ file: pkg.module, format: 'es', plugins: [emitModulePackageFile()] }
TrySound marked this conversation as resolved.
Show resolved Hide resolved
]
};
13 changes: 13 additions & 0 deletions shared/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ export function createConfig(pkg) {
]
};
}

export function emitModulePackageFile() {
return {
name: 'emit-module-package-file',
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'package.json',
source: `{"type":"module"}`
});
}
};
}