Skip to main content

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 the package.json, it uses the corresponding main or module file path as the root.

    • If there is no main or module then it uses the current working directory as the root, while retaining the matching CommonJS or ESM based on the type
  • 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

fieldsresolved as
type=commonjs && mainCommonJS
type=commonjs && moduleCommonJS
type=module && mainESM
type=module && moduleESM
type=undefined && mainCommonJS
type=undefined && moduleESM
no package.json on cwdCommonJS

Returns

RootData

The root data object containing the root path and the type of the project.

Source

projects/pieces/src/lib/internal/RootScan.ts:77