| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9e6054e commit bb09b4d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,8 +174,8 @@ function getPackageScopeConfig(resolved) { | |||
| 174 | 174 | * @param {URL} url - The URL to get the package type for. | |
| 175 | 175 | */ | |
| 176 | 176 | function getPackageType(url) { | |
| 177 | - // TODO(@anonrig): Write a C++ function that returns only "type". | ||
| 178 | - return getPackageScopeConfig(url).type; | ||
| 177 | + const type = modulesBinding.getPackageType(`${url}`); | ||
| 178 | + return type ?? 'none'; | ||
| 179 | 179 | } | |
| 180 | 180 | ||
| 181 | 181 | const invalidPackageNameRegEx = /^\.|%|\\/; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -398,6 +398,7 @@ void BindingData::GetNearestParentPackageJSONType( | |||
| 398 | 398 | args.GetReturnValue().Set(value); | |
| 399 | 399 | } | |
| 400 | 400 | ||
| 401 | + template <bool return_only_type> | ||
| 401 | 402 | void BindingData::GetPackageScopeConfig( | |
| 402 | 403 | const FunctionCallbackInfo<Value>& args) { | |
| 403 | 404 | CHECK_GE(args.Length(), 1); | |
@@ -436,7 +437,15 @@ void BindingData::GetPackageScopeConfig( | |||
| 436 | 437 | error_context.specifier = resolved.ToString(); | |
| 437 | 438 | auto package_json = GetPackageJSON(realm, *file_url, &error_context); | |
| 438 | 439 | if (package_json != nullptr) { | |
| 439 | - return args.GetReturnValue().Set(package_json->Serialize(realm)); | ||
| 440 | + if constexpr (return_only_type) { | ||
| 441 | + Local<Value> value; | ||
| 442 | + if (ToV8Value(realm->context(), package_json->type).ToLocal(&value)) { | ||
| 443 | + args.GetReturnValue().Set(value); | ||
| 444 | + } | ||
| 445 | + return; | ||
| 446 | + } else { | ||
| 447 | + return args.GetReturnValue().Set(package_json->Serialize(realm)); | ||
| 448 | + } | ||
| 440 | 449 | } | |
| 441 | 450 | ||
| 442 | 451 | auto last_href = std::string(package_json_url->get_href()); | |
@@ -454,6 +463,12 @@ void BindingData::GetPackageScopeConfig( | |||
| 454 | 463 | } | |
| 455 | 464 | } | |
| 456 | 465 | ||
| 466 | + if constexpr (return_only_type) { | ||
| 467 | + return; | ||
| 468 | + } | ||
| 469 | + | ||
| 470 | + // If the package.json could not be found return a string containing a path | ||
| 471 | + // to the non-existent package.json file in the initial requested location | ||
| 457 | 472 | auto package_json_url_as_path = | |
| 458 | 473 | url::FileURLToPath(realm->env(), *package_json_url); | |
| 459 | 474 | CHECK(package_json_url_as_path); | |
@@ -526,7 +541,9 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 526 | 541 | target, | |
| 527 | 542 | "getNearestParentPackageJSON", | |
| 528 | 543 | GetNearestParentPackageJSON); | |
| 529 | - SetMethod(isolate, target, "getPackageScopeConfig", GetPackageScopeConfig); | ||
| 544 | + SetMethod( | ||
| 545 | + isolate, target, "getPackageScopeConfig", GetPackageScopeConfig<false>); | ||
| 546 | + SetMethod(isolate, target, "getPackageType", GetPackageScopeConfig<true>); | ||
| 530 | 547 | SetMethod(isolate, target, "enableCompileCache", EnableCompileCache); | |
| 531 | 548 | SetMethod(isolate, target, "getCompileCacheDir", GetCompileCacheDir); | |
| 532 | 549 | SetMethod(isolate, target, "flushCompileCache", FlushCompileCache); | |
@@ -559,7 +576,8 @@ void BindingData::RegisterExternalReferences( | |||
| 559 | 576 | registry->Register(ReadPackageJSON); | |
| 560 | 577 | registry->Register(GetNearestParentPackageJSONType); | |
| 561 | 578 | registry->Register(GetNearestParentPackageJSON); | |
| 562 | - registry->Register(GetPackageScopeConfig); | ||
| 579 | + registry->Register(GetPackageScopeConfig<false>); | ||
| 580 | + registry->Register(GetPackageScopeConfig<true>); | ||
| 563 | 581 | registry->Register(EnableCompileCache); | |
| 564 | 582 | registry->Register(GetCompileCacheDir); | |
| 565 | 583 | registry->Register(FlushCompileCache); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,7 @@ class BindingData : public SnapshotableObject { | |||
| 59 | 59 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 60 | 60 | static void GetNearestParentPackageJSONType( | |
| 61 | 61 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 62 | + template <bool return_only_type> | ||
| 62 | 63 | static void GetPackageScopeConfig( | |
| 63 | 64 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 64 | 65 | static void GetPackageJSONScripts( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,5 +26,8 @@ export interface ModulesBinding { | |||
| 26 | 26 | getNearestRawParentPackageJSON(origin: URL['pathname']): [ReturnType<JSON['stringify']>, DeserializedPackageConfig['path']] | undefined | |
| 27 | 27 | getNearestParentPackageJSONType(path: string): PackageConfig['type'] | |
| 28 | 28 | getPackageScopeConfig(path: string): SerializedPackageConfig | undefined | |
| 29 | - getPackageJSONScripts(): string | undefined | ||
| 29 | + getPackageType(path: string): PackageConfig['type'] | undefined | ||
| 30 | + enableCompileCache(path?: string): { status: number, message?: string, directory?: string } | ||
| 31 | + getCompileCacheDir(): string | undefined | ||
| 32 | + flushCompileCache(keepDeserializedCache?: boolean): void | ||
| 30 | 33 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments