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