Skip to content

Commit 3205b19

Browse files
authored
lib: remove aix directory case for package reader
PR-URL: #48605 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent d9438cc commit 3205b19

File tree

4 files changed

+12
-56
lines changed

4 files changed

+12
-56
lines changed

lib/internal/modules/package_json_reader.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const { kEmptyObject, setOwnProperty } = require('internal/util');
1515
const { fileURLToPath, pathToFileURL } = require('internal/url');
1616

1717
const cache = new SafeMap();
18-
const isAIX = process.platform === 'aix';
1918

2019
let manifest;
2120

@@ -45,10 +44,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) {
4544
return cache.get(jsonPath);
4645
}
4746

48-
const {
49-
0: string,
50-
1: containsKeys,
51-
} = internalModuleReadJSON(
47+
const string = internalModuleReadJSON(
5248
toNamespacedPath(jsonPath),
5349
);
5450
const result = {
@@ -62,14 +58,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) {
6258
imports: undefined,
6359
};
6460

65-
// Folder read operation succeeds in AIX.
66-
// For libuv change, see https://github.com/libuv/libuv/pull/2025.
67-
// https://github.com/nodejs/node/pull/48477#issuecomment-1604586650
68-
// TODO(anonrig): Follow-up on this change and remove it since it is a
69-
// semver-major change.
70-
const isResultValid = isAIX && !isESM ? containsKeys : string !== undefined;
71-
72-
if (isResultValid) {
61+
if (string !== undefined) {
7362
let parsed;
7463
try {
7564
parsed = JSONParse(string);

src/node_file.cc

+2-38
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ namespace fs {
5757

5858
using v8::Array;
5959
using v8::BigInt;
60-
using v8::Boolean;
6160
using v8::Context;
6261
using v8::EscapableHandleScope;
6362
using v8::Function;
@@ -1035,15 +1034,13 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10351034
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
10361035

10371036
if (strlen(*path) != path.length()) {
1038-
args.GetReturnValue().Set(Array::New(isolate));
10391037
return; // Contains a nul byte.
10401038
}
10411039
uv_fs_t open_req;
10421040
const int fd = uv_fs_open(loop, &open_req, *path, O_RDONLY, 0, nullptr);
10431041
uv_fs_req_cleanup(&open_req);
10441042

10451043
if (fd < 0) {
1046-
args.GetReturnValue().Set(Array::New(isolate));
10471044
return;
10481045
}
10491046

@@ -1070,7 +1067,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10701067
uv_fs_req_cleanup(&read_req);
10711068

10721069
if (numchars < 0) {
1073-
args.GetReturnValue().Set(Array::New(isolate));
10741070
return;
10751071
}
10761072
offset += numchars;
@@ -1082,42 +1078,10 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10821078
}
10831079
const size_t size = offset - start;
10841080

1085-
// TODO(anonrig): Follow-up on removing the following changes for AIX.
1086-
char* p = &chars[start];
1087-
char* pe = &chars[size];
1088-
char* pos[2];
1089-
char** ppos = &pos[0];
1090-
1091-
while (p < pe) {
1092-
char c = *p++;
1093-
if (c == '\\' && p < pe && *p == '"') p++;
1094-
if (c != '"') continue;
1095-
*ppos++ = p;
1096-
if (ppos < &pos[2]) continue;
1097-
ppos = &pos[0];
1098-
1099-
char* s = &pos[0][0];
1100-
char* se = &pos[1][-1]; // Exclude quote.
1101-
size_t n = se - s;
1102-
1103-
if (n == 4) {
1104-
if (0 == memcmp(s, "main", 4)) break;
1105-
if (0 == memcmp(s, "name", 4)) break;
1106-
if (0 == memcmp(s, "type", 4)) break;
1107-
} else if (n == 7) {
1108-
if (0 == memcmp(s, "exports", 7)) break;
1109-
if (0 == memcmp(s, "imports", 7)) break;
1110-
}
1111-
}
1112-
1113-
Local<Value> return_value[] = {
1081+
args.GetReturnValue().Set(
11141082
String::NewFromUtf8(
11151083
isolate, &chars[start], v8::NewStringType::kNormal, size)
1116-
.ToLocalChecked(),
1117-
Boolean::New(isolate, p < pe ? true : false)};
1118-
1119-
args.GetReturnValue().Set(
1120-
Array::New(isolate, return_value, arraysize(return_value)));
1084+
.ToLocalChecked());
11211085
}
11221086

11231087
// Used to speed up module loading. Returns 0 if the path refers to

test/parallel/test-module-binding.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const { readFileSync } = require('fs');
99
const { strictEqual, deepStrictEqual } = require('assert');
1010

1111
{
12-
strictEqual(internalModuleReadJSON('nosuchfile')[0], undefined);
12+
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
1313
}
1414
{
15-
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt'))[0], '');
15+
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '');
1616
}
1717
{
18-
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt'))[0], '');
18+
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '');
1919
}
2020
{
2121
const filename = fixtures.path('require-bin/package.json');
22-
const returnValue = JSON.parse(internalModuleReadJSON(filename)[0]);
22+
const returnValue = JSON.parse(internalModuleReadJSON(filename));
2323
const file = JSON.parse(readFileSync(filename, 'utf-8'));
2424
const expectedValue = filterOwnProperties(file, ['name', 'main', 'exports', 'imports', 'type']);
2525
deepStrictEqual({

test/parallel/test-module-loading-error.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ assert.throws(
8484
message: 'The argument \'id\' must be a non-empty string. Received \'\''
8585
});
8686

87+
// Folder read operation succeeds in AIX.
88+
// For libuv change, see https://github.com/libuv/libuv/pull/2025.
89+
// https://github.com/nodejs/node/pull/48477#issuecomment-1604586650
8790
assert.throws(
8891
() => { require('../fixtures/packages/is-dir'); },
89-
{
92+
common.isAIX ? { code: 'ERR_INVALID_PACKAGE_CONFIG' } : {
9093
code: 'MODULE_NOT_FOUND',
9194
message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/
9295
}

0 commit comments

Comments
 (0)