Package JSON
Helper functions for working with package.json files.
Functions
getPackageJSON()
function getPackageJSON(filePathOrDirPath): Record<string, unknown>
Helper function to synchronously get a "package.json" file as an object. This will throw an error if the "package.json" file cannot be found or is otherwise invalid.
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPath | undefined | string | Either the path to a "package.json" file or the path to a directory which contains a "package.json" file. If undefined is passed, the current working directory will be used. |
Returns
Record
<string
, unknown
>
Defined in
packages/complete-node/src/functions/packageJSON.ts:29
getPackageJSONAsync()
function getPackageJSONAsync(filePathOrDirPath): Promise<Record<string, unknown>>
Helper function to asynchronously get a "package.json" file as an object. This will throw an error if the "package.json" file cannot be found or is otherwise invalid.
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPath | undefined | string | Either the path to a "package.json" file or the path to a directory which contains a "package.json" file. If undefined is passed, the current working directory will be used. |
Returns
Promise
<Record
<string
, unknown
>>
Defined in
packages/complete-node/src/functions/packageJSON.ts:52
getPackageJSONDependencies()
function getPackageJSONDependencies(filePathOrDirPathOrRecord, dependencyType): Record<string, string> | undefined
Helper function to synchronously get the "dependencies" or "devDependencies" or
"peerDependencies" field from a "package.json" file. If the corresponding field does not exist,
undefined
will be returned.
This will throw an error if the "package.json" file cannot be found or is otherwise invalid.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
filePathOrDirPathOrRecord | undefined | string | Readonly <Record <string , unknown >> | undefined | Either the path to a "package.json" file, the path to a directory which contains a "package.json" file, or a parsed JavaScript object from a JSON file. If undefined is passed, the current working directory will be used. |
dependencyType | DependencyType | "dependencies" | Optional. The specific dependencies field to get. Defaults to "dependencies". |
Returns
Record
<string
, string
> | undefined
Defined in
packages/complete-node/src/functions/packageJSON.ts:81
getPackageJSONDependenciesAsync()
function getPackageJSONDependenciesAsync(filePathOrDirPathOrRecord, dependencyType): Promise<Record<string, string> | undefined>
Helper function to asynchronously get the "dependencies" or "devDependencies" or
"peerDependencies" field from a "package.json" file. If the corresponding field does not exist,
undefined
will be returned.
This will throw an error if the "package.json" file cannot be found or is otherwise invalid.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
filePathOrDirPathOrRecord | undefined | string | Readonly <Record <string , unknown >> | undefined | Either the path to a "package.json" file, the path to a directory which contains a "package.json" file, or a parsed JavaScript object from a JSON file. If undefined is passed, the current working directory will be used. |
dependencyType | DependencyType | "dependencies" | Optional. The specific dependencies field to get. Defaults to "dependencies". |
Returns
Promise
<Record
<string
, string
> | undefined
>
Defined in
packages/complete-node/src/functions/packageJSON.ts:110
getPackageJSONField()
function getPackageJSONField(filePathOrDirPathOrRecord, fieldName): string | undefined
Helper function to synchronously get an arbitrary string field from a "package.json" file. If the
field does not exist, undefined
will be returned. This will throw an error if the
"package.json" file cannot be found or the field is not a string.
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPathOrRecord | undefined | string | Readonly <Record <string , unknown >> | Either the path to a "package.json" file, the path to a directory which contains a "package.json" file, or a parsed JavaScript object from a JSON file. If undefined is passed, the current working directory will be used. |
fieldName | string | The name of the field to retrieve. |
Returns
string
| undefined
Defined in
packages/complete-node/src/functions/packageJSON.ts:162
getPackageJSONFieldAsync()
function getPackageJSONFieldAsync(filePathOrDirPathOrRecord, fieldName): Promise<string | undefined>
Helper function to asynchronously get an arbitrary string field from a "package.json" file. If
the field does not exist, undefined
will be returned. This will throw an error if the
"package.json" file cannot be found or the field is not a string.
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPathOrRecord | undefined | string | Readonly <Record <string , unknown >> | Either the path to a "package.json" file, the path to a directory which contains a "package.json" file, or a parsed JavaScript object from a JSON file. If undefined is passed, the current working directory will be used. |
fieldName | string | The name of the field to retrieve. |
Returns
Promise
<string
| undefined
>
Defined in
packages/complete-node/src/functions/packageJSON.ts:208
getPackageJSONFieldMandatory()
function getPackageJSONFieldMandatory(filePathOrDirPathOrRecord, fieldName): string
Helper function to synchronously get an arbitrary string field from a "package.json" file. This will throw an error if the "package.json" file cannot be found or the field does not exist or the field is not a string.
Also see the getPackageJSONField
function.
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPathOrRecord | undefined | string | Readonly <Record <string , unknown >> | Either the path to a "package.json" file, the path to a directory which contains a "package.json" file, or a parsed JavaScript object from a JSON file. If undefined is passed, the current working directory will be used. |
fieldName | string | The name of the field to retrieve. |
Returns
string
Defined in
packages/complete-node/src/functions/packageJSON.ts:256
getPackageJSONFieldsMandatory()
function getPackageJSONFieldsMandatory<T>(filePathOrDirPath, ...fieldNames): Record<T, string>
Helper function to synchronously get N arbitrary string fields from a "package.json" file. This will throw an error if the "package.json" file cannot be found or any of the fields do not exist or any of the fields are not strings.
Also see the getPackageJSONFieldMandatory
function.
Type Parameters
Type Parameter |
---|
T extends string |
Parameters
Parameter | Type | Description |
---|---|---|
filePathOrDirPath | undefined | string | Either the path to a "package.json" file or the path to a directory which contains a "package.json" file. If undefined is passed, the current working directory will be used. |
...fieldNames | readonly T [] | The names of the fields to retrieve. |