-
Notifications
You must be signed in to change notification settings - Fork 292
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
major: output ESM for .mjs or "type": "module" builds #720
Merged
+201
−214
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1ccdd50
Revert "increase jest watcher timeout"
guybedford 3808d04
--esm flag for emitting es modules
guybedford 595b92f
add fixture
guybedford 42098d2
disable v8cache for esm
guybedford adba554
use node14 target
guybedford bfdbbc4
output esm automatically for mjs / type module
guybedford 62128ff
mjs for mjs
guybedford 33d17dc
update unit tests
guybedford 696cb75
update cli tests
guybedford cfa7e2f
update asset relocator loader
guybedford b095409
fixup filename handling
guybedford 0a86107
fixup resolve ref
guybedford cb1a8a3
fixup fs ref
guybedford baaa12c
update unit tests
guybedford ccd57ba
fixup esm check
guybedford 369ac30
fixup external type
guybedford 1ee927e
fixup webpack externals
guybedford 4758297
webpack@5.44
guybedford 8c557aa
update fixtures
guybedford d71b185
add fixtures update script
guybedford c6d63a2
unify package boundary check
guybedford c33e2ac
Remove newline
styfle c01d291
fixup: pr feedback
guybedford 981e853
fixup: include has type module module
guybedford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { resolve } = require('path'); | ||
const { readFileSync } = require('fs'); | ||
|
||
exports.hasTypeModule = function hasTypeModule (path) { | ||
while (path !== (path = resolve(path, '..'))) { | ||
try { | ||
return JSON.parse(readFileSync(eval('resolve')(path, 'package.json')).toString()).type === 'module'; | ||
} | ||
catch (e) { | ||
if (e.code === 'ENOENT') | ||
continue; | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('./no-dep.js'); | ||
|
||
exports.aRealExport = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ // The require scope | ||
/******/ var __nccwpck_require__ = {}; | ||
/******/ | ||
/******/ "use strict"; | ||
/******/ /* webpack/runtime/compat */ | ||
/******/ | ||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __nccwpck_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/compat */ | ||
/******/ | ||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// ESM COMPAT FLAG | ||
__nccwpck_require__.r(__webpack_exports__); | ||
|
||
;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js | ||
var x = 'x'; | ||
|
||
;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js | ||
|
||
console.log(x); | ||
|
||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; | ||
console.log(x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ // The require scope | ||
/******/ var __nccwpck_require__ = {}; | ||
/******/ | ||
/******/ "use strict"; | ||
/******/ /* webpack/runtime/compat */ | ||
/******/ | ||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __nccwpck_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/compat */ | ||
/******/ | ||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// ESM COMPAT FLAG | ||
__nccwpck_require__.r(__webpack_exports__); | ||
|
||
;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js | ||
var x = 'x'; | ||
|
||
;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js | ||
|
||
console.log(x); | ||
|
||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; | ||
console.log(x); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you didn't decide to preserve the extension of the input file?
I would expect this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Style we do keep the extension so that
.cjs
->.cjs
and.mjs
->.mjs
. The issue with.js
is that it will be read by webpack as supporting both CJS and ESM, so isn't enough information on its own, hence the boundary check.