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

"exports" conditions semantics #665

Merged
merged 1 commit into from
Mar 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,24 @@ function ncc (
transpileOnly = false,
license = '',
target,
production = true,
Copy link
Member

Choose a reason for hiding this comment

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

Does node automatically consider 'production' exports?

Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be conditions: string[] instead

} = {}
) {
const cjsDeps = () => ({
mainFields: ["main"],
extensions: SUPPORTED_EXTENSIONS,
exportsFields: ["exports"],
importsFields: ["imports"],
conditionNames: ["require", "node", production ? "production" : "development"]
});
const esmDeps = () => ({
mainFields: ["main"],
extensions: SUPPORTED_EXTENSIONS,
exportsFields: ["exports"],
importsFields: ["imports"],
conditionNames: ["import", "node", production ? "production": "development"]
});

process.env.__NCC_OPTS = JSON.stringify({
quiet
});
Expand Down Expand Up @@ -221,6 +237,22 @@ function ncc (
},
resolve: {
extensions: SUPPORTED_EXTENSIONS,
exportsFields: ["exports"],
importsFields: ["imports"],
byDependency: {
wasm: esmDeps(),
esm: esmDeps(),
url: { preferRelative: true },
worker: { ...esmDeps(), preferRelative: true },
commonjs: cjsDeps(),
amd: cjsDeps(),
// for backward-compat: loadModule
loader: cjsDeps(),
// for backward-compat: Custom Dependency
unknown: cjsDeps(),
// for backward-compat: getResolve without dependencyType
undefined: cjsDeps()
},
// webpack defaults to `module` and `main`, but that's
// not really what node.js supports, so we reset it
mainFields: ["main"],
Expand Down
2 changes: 2 additions & 0 deletions test/unit/exports-nomodule/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { x } from 'x';
console.log(x);
1 change: 1 addition & 0 deletions test/unit/exports-nomodule/no.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var y = 'y';
1 change: 1 addition & 0 deletions test/unit/exports-nomodule/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var x = 'x';
34 changes: 34 additions & 0 deletions test/unit/exports-nomodule/output-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* 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__;
/******/ })()
;
34 changes: 34 additions & 0 deletions test/unit/exports-nomodule/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* 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__;
/******/ })()
;
12 changes: 12 additions & 0 deletions test/unit/exports-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "x",
"type": "module",
"exports": {
".": {
"module": "./no.js",
"default": {
"node": "./node.js"
}
}
}
}
2 changes: 2 additions & 0 deletions test/unit/exports-wildcard/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { y } from 'y/no';
console.log(y);
1 change: 1 addition & 0 deletions test/unit/exports-wildcard/no.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var x = 'x';
1 change: 1 addition & 0 deletions test/unit/exports-wildcard/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var y = 'y';
34 changes: 34 additions & 0 deletions test/unit/exports-wildcard/output-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* 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-wildcard/node.js
var y = 'y';

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js

console.log(y);

module.exports = __webpack_exports__;
/******/ })()
;
34 changes: 34 additions & 0 deletions test/unit/exports-wildcard/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* 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-wildcard/node.js
var y = 'y';

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js

console.log(y);

module.exports = __webpack_exports__;
/******/ })()
;
12 changes: 12 additions & 0 deletions test/unit/exports-wildcard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "y",
"type": "module",
"exports": {
"./*": {
"module": "./*.js",
"default": {
"node": "./*de.js"
}
}
}
}