@@ -223,6 +223,8 @@ PACKAGE_RESOLVE(_packageSpecifier_, _parentURL_)
223
223
> 1. Throw a _Module Not Found_ error.
224
224
> 1. Return _url_.
225
225
> 1. Otherwise,
226
+ > 1. If **HAS_ESM_PROPERTIES**(_pjson_) is *true*, then
227
+ > 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_, _pjson_).
226
228
> 1. Return the URL resolution of _packagePath_ in _packageURL_.
227
229
> 1. Throw a _Module Not Found_ error.
228
230
@@ -234,9 +236,58 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
234
236
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, returning
235
237
> *undefined* for no resolution.
236
238
> 1. Return _mainURL_.
237
- > 1. TODO: ESM main handling.
239
+ > 1. If _pjson.exports_ is a String, then
240
+ > 1. Return the URL of _pjson.exports_ within the parent path _packageURL_.
241
+ > 1. Assert: _pjson.exports_ is an Object.
242
+ > 1. If _pjson.exports["."]_ is a String, then
243
+ > 1. Let _target_ be _pjson.exports["."]_.
244
+ > 1. If **IS_VALID_EXPORTS_TARGET**(_target_) is **false**, then
245
+ > 1. Emit an _"Invalid Exports Target"_ warning.
246
+ > 1. Otherwise,
247
+ > 1. Return the URL of _pjson.exports.default_ within the parent path
248
+ > _packageURL_.
238
249
> 1. Return **null**.
239
250
251
+ PACKAGE_EXPORTS_RESOLVE(_packageURL_, _packagePath_, _pjson_)
252
+ > 1. Assert: _pjson_ is not **null**.
253
+ > 1. If _pjson.exports_ is a String, then
254
+ > 1. Throw a _Module Not Found_ error.
255
+ > 1. Assert: _pjson.exports_ is an Object.
256
+ > 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
257
+ > 1. If _packagePath_ is a key of _pjson.exports_, then
258
+ > 1. Let _target_ be the value of _pjson.exports[packagePath]_.
259
+ > 1. If **IS_VALID_EXPORTS_TARGET**(_target_) is **false**, then
260
+ > 1. Emit an _"Invalid Exports Target"_ warning.
261
+ > 1. Throw a _Module Not Found_ error.
262
+ > 1. Return the URL resolution of the concatenation of _packageURL_ and
263
+ > _target_.
264
+ > 1. Let _directoryKeys_ be the list of keys of _pjson.exports_ ending in
265
+ > _"/"_, sorted by length descending.
266
+ > 1. For each key _directory_ in _directoryKeys_, do
267
+ > 1. If _packagePath_ starts with _directory_, then
268
+ > 1. Let _target_ be the value of _pjson.exports[directory]_.
269
+ > 1. If **IS_VALID_EXPORTS_TARGET**(_target_) is **false** or _target_
270
+ > does not end in _"/"_, then
271
+ > 1. Emit an _"Invalid Exports Target"_ warning.
272
+ > 1. Continue the loop.
273
+ > 1. Let _subpath_ be the substring of _target_ starting at the index of
274
+ > the length of _directory_.
275
+ > 1. Return the URL resolution of the concatenation of _packageURL_,
276
+ > _target_ and _subpath_.
277
+ > 1. Throw a _Module Not Found_ error.
278
+
279
+ IS_VALID_EXPORTS_TARGET(_target_)
280
+ > 1. If _target_ is not a valid String, then
281
+ > 1. Return **false**.
282
+ > 1. If _target_ does not start with _"./"_, then
283
+ > 1. Return **false**.
284
+ > 1. If _target_ contains any _".."_ or _"."_ path segments, then
285
+ > 1. Return **false**.
286
+ > 1. If _target_ contains any percent-encoded characters for _"/"_ or _"\" _,
287
+ > then
288
+ > 1. Return **false**.
289
+ > 1. Return **true**.
290
+
240
291
**ESM_FORMAT(_url_)**
241
292
> 1. Assert: _url_ corresponds to an existing file.
242
293
> 1. Let _pjson_ be the result of **READ_PACKAGE_BOUNDARY**(_url_).
@@ -268,7 +319,9 @@ READ_JSON_FILE(_url_)
268
319
> 1. Return _pjson_.
269
320
270
321
HAS_ESM_PROPERTIES(_pjson_)
271
- > Note: To be specified.
322
+ > 1. If _pjson_ is not **null** and _pjson.exports_ is a String or Object, then
323
+ > 1. Return *true*.
324
+ > 1. Return *false*.
272
325
273
326
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
274
327
[` module .createRequireFromPath ()` ]: modules.html#modules_module_createrequirefrompath_filename
0 commit comments