Find the package.json file, either from a TypeScript file somewhere not
in a 'dist' folder, or a built and/or installed 'dist' folder.
Note: this only works if you build your code into './dist', and that the
source path does not also contain 'dist'! If you don't build into
'./dist', or if you have files at ./src/dist/dist.ts, then this will
not work properly!
The default pathFromSrc option assumes that the calling code lives one
folder below the root of the package. Otherwise, it must be specified.
Find the package.json file, either from a TypeScript file somewhere not in a 'dist' folder, or a built and/or installed 'dist' folder.
Note: this only works if you build your code into
'./dist'
, and that the source path does not also contain'dist'
! If you don't build into'./dist'
, or if you have files at./src/dist/dist.ts
, then this will not work properly!The default
pathFromSrc
option assumes that the calling code lives one folder below the root of the package. Otherwise, it must be specified.Example:
If the caller is deeper within the project source, then you must provide the appropriate fallback path:
When running from CommmonJS, use
__filename
instead ofimport.meta.url