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

esm: scoped --type, cpp refactoring #57

Closed
wants to merge 37 commits into from

Conversation

guybedford
Copy link
Contributor

With the current implementation, there is an edge case of --type that doesn't quite work out.

Consider:

main.js

import './dep.js';

where dep.js is also an ECMAScript module.

Currently, node --type=module main.js will execute main.js as an ECMAScript module, but then when it loads dep.js it forgets the type flag and goes back to the old rules of CJS treatment, which is usually not the intention.

This PR fixes this case by having the top-level --type flag apply as a scope on the folder of the entry point.

I ended up refactoring the type errors and ESM_FORMAT implementation in the process, making both more consistent as a result while retaining the same implementation behaviours as previously. Moving ESM_FORMAT back into the C++ code in the process also fixes the TODO on the package.json cache sharing issue.

I've also updated the spec on how the --type flag works to reflect the above, and also fixed some spec bugs where it wasn't quite aligning with our implementation in that files without an extension that weren't the main were still being permitted.

guybedford and others added 30 commits March 7, 2019 09:06
Refs: nodejs/modules#180

PR-URL: nodejs#6
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Refs: nodejs/modules#180

PR-URL: nodejs#6
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Refs: nodejs/modules#180

PR-URL: nodejs#6
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Refs: nodejs/modules#180

PR-URL: nodejs#6
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: nodejs#6
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: nodejs#6
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@Fishrock123
Copy link
Contributor

I think I am in favor of less "virtual package json" magic, so... -0

@nodejs-ci nodejs-ci force-pushed the modules-lkgr branch 3 times, most recently from c7fa700 to d69f765 Compare March 21, 2019 08:06
@MylesBorins MylesBorins force-pushed the modules-lkgr branch 5 times, most recently from 335d584 to 9a343ce Compare March 21, 2019 19:09
@nodejs-ci nodejs-ci force-pushed the modules-lkgr branch 3 times, most recently from 3a00b51 to bc101f6 Compare March 24, 2019 08:06
@MylesBorins MylesBorins force-pushed the modules-lkgr branch 3 times, most recently from fd5b55a to 3a40599 Compare March 27, 2019 02:42
@guybedford guybedford closed this Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants