Function: parseRootData()
parseRootData():
RootData
Retrieves the root data of the project.
This function reads the package.json
file in the current working directory and determines the root path and type
of the project.
-
If the
package.json
file is not found or cannot be parsed, it assumes the project is using CommonJS and the current working directory is used as the root -
If the project
type
is specified as"commonjs"
or"module"
in thepackage.json
, it uses the correspondingmain
ormodule
file path as the root.- If there is no
main
ormodule
then it uses the current working directory as the root, while retaining the matchingCommonJS
orESM
based on thetype
- If there is no
-
If the main or module file path is not specified, it uses the current working directory as the root.
The following table shows how different situations resolve to different root data
fields | resolved as |
---|---|
type=commonjs && main | CommonJS |
type=commonjs && module | CommonJS |
type=module && main | ESM |
type=module && module | ESM |
type=undefined && main | CommonJS |
type=undefined && module | ESM |
no package.json on cwd | CommonJS |
Returns
The root data object containing the root path and the type of the project.