From 400967ecb97425a9202139832fae5432d29bd2ec Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 29 Jun 2023 15:38:29 -0400 Subject: [PATCH] lib: remove aix directory case for package reader --- lib/internal/modules/package_json_reader.js | 15 ++------ src/node_file.cc | 39 ++------------------- test/parallel/test-module-binding.js | 8 ++--- test/parallel/test-module-loading-error.js | 19 ++++++---- 4 files changed, 20 insertions(+), 61 deletions(-) diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index c6377faae6f5a8..114bfb18faf44b 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -15,7 +15,6 @@ const { kEmptyObject } = require('internal/util'); const { fileURLToPath, pathToFileURL } = require('internal/url'); const cache = new SafeMap(); -const isAIX = process.platform === 'aix'; let manifest; @@ -45,10 +44,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { return cache.get(jsonPath); } - const { - 0: string, - 1: containsKeys, - } = internalModuleReadJSON( + const string = internalModuleReadJSON( toNamespacedPath(jsonPath), ); const result = { @@ -62,14 +58,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { imports: undefined, }; - // Folder read operation succeeds in AIX. - // For libuv change, see https://github.com/libuv/libuv/pull/2025. - // https://github.com/nodejs/node/pull/48477#issuecomment-1604586650 - // TODO(anonrig): Follow-up on this change and remove it since it is a - // semver-major change. - const isResultValid = isAIX && !isESM ? containsKeys : string !== undefined; - - if (isResultValid) { + if (string !== undefined) { let parsed; try { parsed = JSONParse(string); diff --git a/src/node_file.cc b/src/node_file.cc index 66a7a8f55dd4f1..b72439a4d37047 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1032,7 +1032,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { env, permission::PermissionScope::kFileSystemRead, path.ToStringView()); if (strlen(*path) != path.length()) { - args.GetReturnValue().Set(Array::New(isolate)); return; // Contains a nul byte. } uv_fs_t open_req; @@ -1040,7 +1039,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { uv_fs_req_cleanup(&open_req); if (fd < 0) { - args.GetReturnValue().Set(Array::New(isolate)); return; } @@ -1067,7 +1065,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { uv_fs_req_cleanup(&read_req); if (numchars < 0) { - args.GetReturnValue().Set(Array::New(isolate)); return; } offset += numchars; @@ -1079,42 +1076,10 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { } const size_t size = offset - start; - // TODO(anonrig): Follow-up on removing the following changes for AIX. - char* p = &chars[start]; - char* pe = &chars[size]; - char* pos[2]; - char** ppos = &pos[0]; - - while (p < pe) { - char c = *p++; - if (c == '\\' && p < pe && *p == '"') p++; - if (c != '"') continue; - *ppos++ = p; - if (ppos < &pos[2]) continue; - ppos = &pos[0]; - - char* s = &pos[0][0]; - char* se = &pos[1][-1]; // Exclude quote. - size_t n = se - s; - - if (n == 4) { - if (0 == memcmp(s, "main", 4)) break; - if (0 == memcmp(s, "name", 4)) break; - if (0 == memcmp(s, "type", 4)) break; - } else if (n == 7) { - if (0 == memcmp(s, "exports", 7)) break; - if (0 == memcmp(s, "imports", 7)) break; - } - } - - Local return_value[] = { + args.GetReturnValue().Set( String::NewFromUtf8( isolate, &chars[start], v8::NewStringType::kNormal, size) - .ToLocalChecked(), - Boolean::New(isolate, p < pe ? true : false)}; - - args.GetReturnValue().Set( - Array::New(isolate, return_value, arraysize(return_value))); + .ToLocalChecked()); } // Used to speed up module loading. Returns 0 if the path refers to diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js index 47170785434099..d7f76d6ef5b153 100644 --- a/test/parallel/test-module-binding.js +++ b/test/parallel/test-module-binding.js @@ -9,17 +9,17 @@ const { readFileSync } = require('fs'); const { strictEqual, deepStrictEqual } = require('assert'); { - strictEqual(internalModuleReadJSON('nosuchfile')[0], undefined); + strictEqual(internalModuleReadJSON('nosuchfile'), undefined); } { - strictEqual(internalModuleReadJSON(fixtures.path('empty.txt'))[0], ''); + strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), ''); } { - strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt'))[0], ''); + strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), ''); } { const filename = fixtures.path('require-bin/package.json'); - const returnValue = JSON.parse(internalModuleReadJSON(filename)[0]); + const returnValue = JSON.parse(internalModuleReadJSON(filename)); const file = JSON.parse(readFileSync(filename, 'utf-8')); const expectedValue = filterOwnProperties(file, ['name', 'main', 'exports', 'imports', 'type']); deepStrictEqual({ diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index 8cbe8b2c675663..f6ff03672fb257 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -84,10 +84,15 @@ assert.throws( message: 'The argument \'id\' must be a non-empty string. Received \'\'' }); -assert.throws( - () => { require('../fixtures/packages/is-dir'); }, - { - code: 'MODULE_NOT_FOUND', - message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/ - } -); +// Folder read operation succeeds in AIX. +// For libuv change, see https://github.com/libuv/libuv/pull/2025. +// https://github.com/nodejs/node/pull/48477#issuecomment-1604586650 +if (process.platform !== 'aix') { + assert.throws( + () => { require('../fixtures/packages/is-dir'); }, + { + code: 'MODULE_NOT_FOUND', + message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/ + } + ); +}