Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
esm: Treat all non-nullish values the same
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrems committed Jul 4, 2019
1 parent c86a017 commit 29df8a0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ import feature from 'es-module-package/features/x.js';
If a package has no exports, setting `"exports": false` can be used instead of
`"exports": {}` to indicate the package does not intent for submodules to be
exposed.
This is just a convention that works because `false`, just like `{}`, has no
iterable own properties.

## <code>import</code> Specifiers

Expand Down
3 changes: 1 addition & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,7 @@ Maybe<const PackageConfig*> GetPackageConfig(Environment* env,
Persistent<Value> exports;
if (pkg_json->Get(env->context(),
env->exports_string()).ToLocal(&exports_v) &&
(exports_v->IsObject() ||
(exports_v->IsBoolean() && exports_v->IsFalse()))) {
!exports_v->IsNullOrUndefined()) {
exports.Reset(env->isolate(), exports_v);

auto entry = env->package_json_cache.emplace(path,
Expand Down
7 changes: 6 additions & 1 deletion test/es-module/test-esm-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mustCall } from '../common/index.mjs';
import { ok, strictEqual } from 'assert';

import { asdf, asdf2 } from '../fixtures/pkgexports.mjs';
import { loadMissing } from '../fixtures/pkgexports-missing.mjs';
import { loadMissing, loadFromNumber } from '../fixtures/pkgexports-missing.mjs';

strictEqual(asdf, 'asdf');
strictEqual(asdf2, 'asdf');
Expand All @@ -13,3 +13,8 @@ loadMissing().catch(mustCall((err) => {
ok(err.message.toString().startsWith('Package exports'));
ok(err.message.toString().indexOf('do not define a \'./missing\' subpath'));
}));

loadFromNumber().catch(mustCall((err) => {
ok(err.message.toString().startsWith('Package exports'));
ok(err.message.toString().indexOf('do not define a \'./missing\' subpath'));
}));
1 change: 1 addition & 0 deletions test/fixtures/node_modules/pkgexports-number/hidden.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/node_modules/pkgexports-number/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion test/fixtures/pkgexports-missing.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function loadMissing () {
export function loadMissing() {
return import('pkgexports/missing');
}

export function loadFromNumber() {
return import('pkgexports-number/hidden.js');
}

0 comments on commit 29df8a0

Please sign in to comment.