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

Add .mjs support. #108

Merged
merged 1 commit into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function compile(code, options) {
const parse = getOption(options, "parse");
code = code.replace(shebangRegExp, "");

if (! importExportRegExp.test(code)) {
if (! getOption(options, "force") && ! importExportRegExp.test(code)) {
options.identical = true;

const result = { code };
Expand Down
1 change: 1 addition & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const hasOwn = Object.prototype.hasOwnProperty;

const defaultCompileOptions = {
ast: false,
force: false,
generateLetDeclarations: false,
get parse () {
return require("./parsers/default.js").parse;
Expand Down
11 changes: 6 additions & 5 deletions node/caching-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ function compileWithCache(pkgInfo, content, options) {
}
}

const filename = options.filename;
const force = !!filename && path.extname(filename) === ".mjs";

const compileOptions = {
ast: false
ast: false,
force
};

if (reify && reify.parser) {
Expand Down Expand Up @@ -246,10 +250,7 @@ function readPkgInfo(dir) {
for (let i = 0; i < filesCount; ++i) {
// Later we'll change the value to the actual contents of the
// file, but for now we merely register that it exists.
const file = cacheFiles[i];
if (/\.js$/.test(file)) {
pkgInfo.cache[file] = true;
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is okay because we write .js cache files even if the original file was .mjs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, the check, /\.js$/, didn't seem to be needed as all files were .js anyways.

pkgInfo.cache[cacheFiles[i]] = true;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions node/compile-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ if (! _compile.reified) {
);
}).reified = _compile;
}

const exts = require.extensions;
const _extMjs = exts['.mjs'];
if (! (_extMjs && _extMjs.reified)) {
(exts['.mjs'] = function (module, filename) {
return exts['.js'](module, filename);
}).reified = _extMjs;
}