From 3205b1936a5c3c21b0c8c568a57b0d2bada366b1 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 7 Jul 2023 11:31:33 -0400 Subject: [PATCH] lib: remove aix directory case for package reader PR-URL: https://github.com/nodejs/node/pull/48605 Reviewed-By: Antoine du Hamel Reviewed-By: Rafael Gonzaga --- lib/internal/modules/package_json_reader.js | 15 ++------ src/node_file.cc | 40 ++------------------- test/parallel/test-module-binding.js | 8 ++--- test/parallel/test-module-loading-error.js | 5 ++- 4 files changed, 12 insertions(+), 56 deletions(-) diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index 0572147d5e5897..c4afd159ebdb63 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -15,7 +15,6 @@ const { kEmptyObject, setOwnProperty } = 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 49674385297c7a..fbcde2fb9b2788 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -57,7 +57,6 @@ namespace fs { using v8::Array; using v8::BigInt; -using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; using v8::Function; @@ -1035,7 +1034,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; @@ -1043,7 +1041,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { uv_fs_req_cleanup(&open_req); if (fd < 0) { - args.GetReturnValue().Set(Array::New(isolate)); return; } @@ -1070,7 +1067,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; @@ -1082,42 +1078,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..d56e696942430b 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -84,9 +84,12 @@ assert.throws( message: 'The argument \'id\' must be a non-empty string. Received \'\'' }); +// 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 assert.throws( () => { require('../fixtures/packages/is-dir'); }, - { + common.isAIX ? { code: 'ERR_INVALID_PACKAGE_CONFIG' } : { code: 'MODULE_NOT_FOUND', message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/ }