Skip to content

Commit a451d20

Browse files
committed
lib: remove aix directory case for package reader
1 parent 951da52 commit a451d20

File tree

4 files changed

+20
-62
lines changed

4 files changed

+20
-62
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 } = 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
@@ -54,7 +54,6 @@ namespace fs {
5454

5555
using v8::Array;
5656
using v8::BigInt;
57-
using v8::Boolean;
5857
using v8::Context;
5958
using v8::EscapableHandleScope;
6059
using v8::Function;
@@ -1032,15 +1031,13 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10321031
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
10331032

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

10421040
if (fd < 0) {
1043-
args.GetReturnValue().Set(Array::New(isolate));
10441041
return;
10451042
}
10461043

@@ -1067,7 +1064,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10671064
uv_fs_req_cleanup(&read_req);
10681065

10691066
if (numchars < 0) {
1070-
args.GetReturnValue().Set(Array::New(isolate));
10711067
return;
10721068
}
10731069
offset += numchars;
@@ -1079,42 +1075,10 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
10791075
}
10801076
const size_t size = offset - start;
10811077

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

11201084
// 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

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

87-
assert.throws(
88-
() => { require('../fixtures/packages/is-dir'); },
89-
{
90-
code: 'MODULE_NOT_FOUND',
91-
message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/
92-
}
93-
);
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
90+
if (process.platform !== 'aix') {
91+
assert.throws(
92+
() => { require('../fixtures/packages/is-dir'); },
93+
{
94+
code: 'MODULE_NOT_FOUND',
95+
message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/
96+
}
97+
);
98+
}

0 commit comments

Comments
 (0)