jkrems / proposal-pkg-exports

Proposal for Bare Module Specifier Resolution in node.js
MIT License
130 stars 14 forks source link

Possible boolean value #25

Closed guybedford closed 5 years ago

guybedford commented 5 years ago

I've just been working out the interaction here with the "mode" spec ideas, and one thing that comes up then is that if we do allow the "main" to point to ".mjs" files, would we want "exports" to be able to be an empty object to get encapsulation:

{
  "main": "main.mjs",
  "exports": {}
}

A simpler form of the above might be just:

{
  "main": "main.mjs",
  "exports": false
}

where it is clear that is then a "frozen" package as it were.

It only really makes sense if the main field is kept with the mode proposal, but thought we should discuss it here first.

jkrems commented 5 years ago

Setting exports to false should work now and we have a test for it.

ljharb commented 5 years ago

(specifically, Object.assign/Object.keys semantics will be used, so any value without enumerable keys will be the same as {}, including false)

SMotaal commented 5 years ago

@ljharb Just to clarify… we're talking here about { "exports": false } not { "exports": "false" } as per op text, right?

The latter would assign/key as { 0: "f" … 4: "e" }… right?

ljharb commented 5 years ago

The former, yes. The latter is a valid string value for the field.

SMotaal commented 5 years ago

@guybedford do we want to revise the op text to read { "exports": false } not { … "false" } avoid confusion?

guybedford commented 5 years ago

Sure, have done that.