| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -426,8 +426,16 @@ void BindingData::GetPackageScopeConfig( | |||
| 426 | 426 | url::ThrowInvalidURL(realm->env(), resolved.ToStringView(), std::nullopt); | |
| 427 | 427 | return; | |
| 428 | 428 | } | |
| 429 | + BufferValue file_path_buf(realm->isolate(), | ||
| 430 | + String::NewFromUtf8(realm->isolate(), | ||
| 431 | + file_url->c_str(), | ||
| 432 | + NewStringType::kInternalized, | ||
| 433 | + file_url->size()) | ||
| 434 | + .ToLocalChecked()); | ||
| 435 | + ToNamespacedPath(realm->env(), &file_path_buf); | ||
| 429 | 436 | error_context.specifier = resolved.ToString(); | |
| 430 | - auto package_json = GetPackageJSON(realm, *file_url, &error_context); | ||
| 437 | + auto package_json = | ||
| 438 | + GetPackageJSON(realm, file_path_buf.ToStringView(), &error_context); | ||
| 431 | 439 | if (package_json != nullptr) { | |
| 432 | 440 | if constexpr (return_only_type) { | |
| 433 | 441 | Local<Value> value; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ describe('long path on Windows', () => { | |||
| 60 | 60 | tmpdir.refresh(); | |
| 61 | 61 | ||
| 62 | 62 | fs.mkdirSync(packageDirPath); | |
| 63 | - fs.writeFileSync(packageJSPath, ''); | ||
| 63 | + fs.writeFileSync(packageJSPath, '{}'); | ||
| 64 | 64 | fs.writeFileSync(indexJSPath, ''); | |
| 65 | 65 | ||
| 66 | 66 | const packageJsonUrl = pathToFileURL( | |
@@ -83,7 +83,7 @@ describe('long path on Windows', () => { | |||
| 83 | 83 | tmpdir.refresh(); | |
| 84 | 84 | ||
| 85 | 85 | fs.mkdirSync(packageDirPath); | |
| 86 | - fs.writeFileSync(packageJSPath, ''); | ||
| 86 | + fs.writeFileSync(packageJSPath, '{}'); | ||
| 87 | 87 | fs.writeFileSync(indexJSPath, ''); | |
| 88 | 88 | ||
| 89 | 89 | const packageJsonUrl = pathToFileURL( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 1 | + // Regression test for https://github.com/nodejs/node/issues/62043 | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + if (!common.isWindows) { | ||
| 6 | + common.skip('this test is Windows-specific.'); | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + const fs = require('fs'); | ||
| 10 | + const { createRequire } = require('module'); | ||
| 11 | + const path = require('path'); | ||
| 12 | + const tmpdir = require('../common/tmpdir'); | ||
| 13 | + | ||
| 14 | + tmpdir.refresh(); | ||
| 15 | + | ||
| 16 | + const TARGET = 260; // Shortest length that used to trigger the bug | ||
| 17 | + const fixedLen = tmpdir.path.length + 2 + 'package.json'.length; | ||
| 18 | + const dirNameLen = Math.max(TARGET - fixedLen, 1); | ||
| 19 | + | ||
| 20 | + const dir = path.join(tmpdir.path, 'a'.repeat(dirNameLen)); | ||
| 21 | + const depDir = path.join(dir, 'node_modules', 'dep'); | ||
| 22 | + const packageJsonPath = path.join(dir, 'package.json'); | ||
| 23 | + | ||
| 24 | + fs.mkdirSync(depDir, { recursive: true }); | ||
| 25 | + fs.writeFileSync( | ||
| 26 | + packageJsonPath, | ||
| 27 | + JSON.stringify({ imports: { '#foo': './foo.mjs' } }), | ||
| 28 | + ); | ||
| 29 | + fs.writeFileSync(path.join(dir, 'foo.mjs'), 'export default 1;\n'); | ||
| 30 | + fs.writeFileSync( | ||
| 31 | + path.join(depDir, 'package.json'), | ||
| 32 | + JSON.stringify({ name: 'dep', exports: { '.': './index.mjs' } }), | ||
| 33 | + ); | ||
| 34 | + fs.writeFileSync(path.join(depDir, 'index.mjs'), 'export default 1;\n'); | ||
| 35 | + | ||
| 36 | + const req = createRequire(path.join(dir, '_.mjs')); | ||
| 37 | + | ||
| 38 | + // Both resolves should succeed without throwing | ||
| 39 | + req.resolve('dep'); | ||
| 40 | + req.resolve('#foo'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments