Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup: remove changes for get full packagejson
  • Loading branch information
JakobJingleheimer committed Sep 30, 2024
commit 6ddf9abacbd40e8cfe68bcbaa7d2868db026bf4b
17 changes: 6 additions & 11 deletions lib/internal/modules/package_json_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ const { resolve, sep } = require('path');
const { kEmptyObject } = require('internal/util');

/**
* @typedef {import('typings/internalBinding/modules').FullPackageConfig} FullPackageConfig
* @typedef {import('typings/internalBinding/modules').PackageConfig} PackageConfig
* @typedef {import('typings/internalBinding/modules').SerializedPackageConfig} SerializedPackageConfig
*/

/**
* @param {string} path
* @param {SerializedPackageConfig} contents
* @param {boolean} everything
* @returns {everything extends true ? FullPackageConfig : PackageConfig}
* @returns {PackageConfig}
*/
function deserializePackageJSON(path, contents, everything = false) {
function deserializePackageJSON(path, contents) {
if (contents === undefined) {
return {
__proto__: null,
Expand Down Expand Up @@ -71,7 +69,6 @@ function deserializePackageJSON(path, contents, everything = false) {
ObjectDefineProperty(this, 'exports', { __proto__: null, value });
return this.exports;
},
...(everything && contents[6]),
};
}

Expand Down Expand Up @@ -113,17 +110,16 @@ function readPackage(requestPath) {
* Get the nearest parent package.json file from a given path.
* Return the package.json data and the path to the package.json file, or undefined.
* @param {string} checkPath The path to start searching from.
* @param {boolean} everything Whether to include unrecognised fields.
* @returns {undefined | {data: PackageConfig, path: string}}
*/
function getNearestParentPackageJSON(checkPath, everything = false) {
function getNearestParentPackageJSON(checkPath) {
const result = modulesBinding.getNearestParentPackageJSON(checkPath);

if (result === undefined) {
return undefined;
}

const data = deserializePackageJSON(checkPath, result, everything);
const data = deserializePackageJSON(checkPath, result);

// Path should be the root folder of the matched package.json
// For example for ~/path/package.json, it should be ~/path
Expand All @@ -144,14 +140,13 @@ function findNearestPackageJSON(origin) {
/**
* Returns the package configuration for the given resolved URL.
* @param {URL | string} resolved - The resolved URL.
* @param {boolean} everything - Whether to include unrecognised fields.
* @returns {PackageConfig} - The package configuration.
*/
function getPackageScopeConfig(resolved, everything = false) {
function getPackageScopeConfig(resolved) {
const result = modulesBinding.getPackageScopeConfig(`${resolved}`);

if (ArrayIsArray(result)) {
return deserializePackageJSON(`${resolved}`, result, everything);
return deserializePackageJSON(`${resolved}`, result);
}

// This means that the response is a string
Expand Down
2 changes: 0 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
getCompileCacheDir,
} = require('internal/modules/helpers');
const {
getPackageScopeConfig,
findNearestPackageJSON,
} = require('internal/modules/package_json_reader');

Expand All @@ -23,6 +22,5 @@ Module.enableCompileCache = enableCompileCache;
Module.flushCompileCache = flushCompileCache;

Module.getCompileCacheDir = getCompileCacheDir;
Module.getPackageScopeConfig = getPackageScopeConfig;
Module.findNearestPackageJSON = findNearestPackageJSON;
module.exports = Module;
3 changes: 0 additions & 3 deletions typings/internalBinding/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export type PackageConfig = {
exports?: string | string[] | Record<string, unknown>
imports?: string | string[] | Record<string, unknown>
}
export type FullPackageConfig = PackageConfig & {
[key: string]: unknown,
}
export type SerializedPackageConfig = [
PackageConfig['name'],
PackageConfig['main'],
Expand Down