-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
esm: Add support for pjson cache and main without extensions #18728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f14420e
adfe1ac
ebdb3cb
5855e5c
05c9941
2d6d4e6
a06db2d
081aab4
ed9df8a
8b4d85f
4468e2c
b4dc802
9f7aabd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -610,6 +610,7 @@ class Environment { | |
|
|
||
| struct PackageConfig { | ||
| bool exists; | ||
| bool is_valid; | ||
| bool has_main; | ||
| std::string main; | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would still be nice if these were const.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell getting this to work would mean inlining the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (as in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first case didn't work unfortunately. In the second case it would need to be a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I managed to get the |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -495,7 +495,10 @@ Maybe<uv_file> CheckFile(const std::string& path, | |
|
|
||
| const Environment::PackageConfig& GetPackageConfig(Environment* env, | ||
| const std::string path) { | ||
| static const Environment::PackageConfig kEmptyPackage = { false, false, "" }; | ||
| static const Environment::PackageConfig kEmptyPackage = | ||
| { false, true, false, "" }; | ||
| static const Environment::PackageConfig kInvalidPackage = | ||
| { true, false, false, "" }; | ||
|
|
||
| auto existing = env->package_json_cache.find(path); | ||
| if (existing != env->package_json_cache.end()) | ||
|
|
@@ -528,11 +531,9 @@ const Environment::PackageConfig& GetPackageConfig(Environment* env, | |
| Local<Value> pkg_json_v; | ||
| Local<Object> pkg_json; | ||
|
|
||
| // TODO: Invalid package.json MUST THROW the resolve | ||
| // currently this will just silently ignore | ||
| if (!JSON::Parse(env->context(), src).ToLocal(&pkg_json_v) || | ||
| !pkg_json_v->ToObject(env->context()).ToLocal(&pkg_json)) | ||
| return kEmptyPackage; | ||
| return env->package_json_cache[path] = kInvalidPackage; | ||
|
|
||
| Local<Value> pkg_main; | ||
| bool has_main = false; | ||
|
|
@@ -544,7 +545,7 @@ const Environment::PackageConfig& GetPackageConfig(Environment* env, | |
| main_std = std::string(*main_utf8, main_utf8.length()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use |
||
| } | ||
|
|
||
| Environment::PackageConfig pjson = { true, has_main, main_std }; | ||
| Environment::PackageConfig pjson = { true, true, has_main, main_std }; | ||
| return env->package_json_cache[path] = pjson; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return either a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not shown here, but this issue is addressed and const PackageConfig& is returned. |
||
|
|
||
|
|
@@ -583,7 +584,9 @@ Maybe<URL> ResolveMain(Environment* env, const URL& search) { | |
|
|
||
| const Environment::PackageConfig& pjson = | ||
| GetPackageConfig(env, pkg.ToFilePath()); | ||
| if (!pjson.exists || !pjson.has_main) { | ||
| // Note invalid package.json should throw in resolver | ||
| // currently we silently ignore which is incorrect | ||
| if (!pjson.exists || !pjson.is_valid || !pjson.has_main) { | ||
| return Nothing<URL>(); | ||
| } | ||
| if (!ShouldBeTreatedAsRelativeOrAbsolutePath(pjson.main)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PackageConfig should probably live in the
node::loadernamespace, like ModuleWrap.