Skip to content

Commit 864b98a

Browse files
fixup: add exists to DeserializedPackageConfig
1 parent eed739c commit 864b98a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/internal/modules/package_json_reader.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function deserializePackageJSON(path, contents) {
4040
__proto__: null,
4141
type: 'none', // Ignore unknown types for forwards compatibility
4242
},
43+
exists: false,
4344
path,
4445
};
4546
}
@@ -78,6 +79,7 @@ function deserializePackageJSON(path, contents) {
7879
},
7980
}),
8081
},
82+
exists: true,
8183
path: pjsonPath,
8284
};
8385
}
@@ -112,7 +114,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) {
112114
return {
113115
__proto__: null,
114116
...result.data,
115-
exists: result.data !== 'none',
117+
exists: result.exists,
116118
pjsonPath: result.path,
117119
};
118120
}
@@ -164,6 +166,7 @@ function getNearestParentPackageJSON(startLocation, everything = false) {
164166
__proto__: null,
165167
...JSONParse(result?.[0]),
166168
},
169+
exists: true,
167170
path: result?.[1],
168171
};
169172
}
@@ -189,10 +192,12 @@ function getPackageScopeConfig(resolved) {
189192
const result = modulesBinding.getPackageScopeConfig(`${resolved}`);
190193

191194
if (ArrayIsArray(result)) {
192-
const { data, path } = deserializePackageJSON(`${resolved}`, result);
195+
const { data, exists, path } = deserializePackageJSON(`${resolved}`, result);
196+
193197
return {
194198
__proto__: null,
195199
...data,
200+
exists,
196201
pjsonPath: path,
197202
};
198203
}

test/parallel/test-get-package-json.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const pkgType = 'module'; // a non-default value
3131

3232
assert.deepStrictEqual(pkg, {
3333
path: path.join(pathToDir, 'package.json'),
34+
exists: true,
3435
data: {
3536
__proto__: null,
3637
name: pkgName,
@@ -45,6 +46,7 @@ const pkgType = 'module'; // a non-default value
4546

4647
assert.deepStrictEqual(pkg, {
4748
path: path.join(pathToDir, 'package.json'),
49+
exists: true,
4850
data: {
4951
__proto__: null,
5052
name: pkgName,
@@ -59,6 +61,7 @@ const pkgType = 'module'; // a non-default value
5961

6062
assert.deepStrictEqual(pkg, {
6163
path: path.join(pathToDir, 'package.json'),
64+
exists: true,
6265
data: {
6366
__proto__: null,
6467
name: pkgName,
@@ -74,6 +77,7 @@ const pkgType = 'module'; // a non-default value
7477

7578
assert.deepStrictEqual(pkg, {
7679
path: path.join(pathToDir, 'package.json'),
80+
exists: true,
7781
data: {
7882
__proto__: null,
7983
name: pkgName,
@@ -92,6 +96,7 @@ const pkgType = 'module'; // a non-default value
9296

9397
assert.deepStrictEqual(pkg, {
9498
path: path.join(pathToDir, 'package.json'),
99+
exists: true,
95100
data: {
96101
__proto__: null,
97102
name: pkgName,

typings/internalBinding/modules.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export type FullPackageConfig = RecognizedPackageConfig & {
1010
[key: string]: unknown,
1111
}
1212
export type DeserializedPackageConfig<everything = false> = {
13-
data: everything extends true ? FullPackageConfig : RecognizedPackageConfig
13+
data: everything extends true ? FullPackageConfig : RecognizedPackageConfig,
14+
exists: boolean,
1415
path: URL['pathname'],
1516
}
1617
export type SerializedPackageConfig = [

0 commit comments

Comments
 (0)