Function: parseRootData()
parseRootData():
RootData
Defined in: projects/pieces/src/lib/internal/RootScan.ts:77
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.jsonfile 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
typeis specified as"commonjs"or"module"in thepackage.json, it uses the correspondingmainormodulefile path as the root.- If there is no
mainormodulethen it uses the current working directory as the root, while retaining the matchingCommonJSorESMbased 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.