{"_id":"@alloc/tsconfig-paths","_rev":"1-9287f7d114f5ecd04ba9741589866819","name":"@alloc/tsconfig-paths","dist-tags":{"latest":"3.8.0"},"versions":{"3.8.0":{"name":"@alloc/tsconfig-paths","version":"3.8.0","description":"Load node modules according to tsconfig paths, in run-time or via API.","main":"lib/index.js","types":"lib/index","author":{"name":"Jonas Kello"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/dividab/tsconfig-paths.git"},"devDependencies":{"@types/chai":"^4.1.4","@types/deepmerge":"^1.3.2","@types/minimist":"^1.2.0","@types/mocha":"^5.2.3","@types/node":"^6.0.54","@types/strip-bom":"^3.0.0","@types/strip-json-comments":"^0.0.30","chai":"^4.1.2","codecov":"^3.1.0","husky":"^0.14.3","lint-staged":"^4.3.0","mocha":"^5.2.0","nyc":"^11.4.1","prettier":"1.7.4","rimraf":"^2.6.2","shelljs":"^0.7.5","ts-node":"^7.0.0","tslint":"^5.8.0","typescript":"^2.4.1"},"dependencies":{"@types/json5":"^0.0.29","deepmerge":"^2.0.1","json5":"^1.0.1","minimist":"^1.2.0","strip-bom":"^3.0.0"},"scripts":{"start":"cd src && ts-node index.ts","example:node":"yarn build && cd ./example/node && ts-node -r ../register.js main.ts","example:project":"yarn build && ts-node -r ./register.js -P ./example/project/tsconfig.json ./example/project/main.ts","example:api":"cd example/api && ts-node main.ts","example:perf":"cd example/perf && ts-node main.ts","test":"mocha","build":"rimraf lib && tsc -p src","build:test":"rimraf ./test/js_out && tsc -p test","lint":"tslint './{src,tests}/**/*.ts{,x}'","verify":"yarn build && yarn lint && yarn coverage","coverage":"rimraf coverage .nyc_output && nyc yarn test","report-coverage":"codecov -f coverage/*.json","precommit":"lint-staged","publish:major":"yarn build && node scripts/publish.js major","publish:minor":"yarn build && node scripts/publish.js minor","publish:patch":"yarn build && node scripts/publish.js patch"},"lint-staged":{"*.ts":["tslint","prettier --write","git add"]},"gitHead":"44f383788c12d532b0c46dce81934483f73eefc7","bugs":{"url":"https://github.com/dividab/tsconfig-paths/issues"},"homepage":"https://github.com/dividab/tsconfig-paths#readme","_id":"@alloc/tsconfig-paths@3.8.0","_nodeVersion":"11.10.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-pL1Ki1Id3EJ1SSaa5ycRMOTvJJkQD3+wFmMmFqAa98hMzQ6NpwS5qUELs9oYSIWnb7v7EHjzyRwqgmrPm/+s1w==","shasum":"fb3ce0b0735f98392e8fb480f78a529c61ddedbf","tarball":"https://registry.npmjs.org/@alloc/tsconfig-paths/-/tsconfig-paths-3.8.0.tgz","fileCount":38,"unpackedSize":81100,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdArrCCRA9TVsSAnZWagAAwvgP/iw0uTY/N1hqixUwphk/\nDRbddFr9EJT7HBZzSvZKtXfELgahr+jYGy+GVyhb17+j4lqWqrwJJba1Do+E\nRq4p+wfPU07A44RrPiUofF5i3vWvppTgBd1UE39Sgujw+w8VCarVwLa3Y3ag\nis1fFaYIeQmnXKecAEBOYP1/dqizLgmqar75fAGfIa2nZm3SeTHiNmQye/jm\nk/F5x+fFiSt6r0agtYJiUUy8h9Vjm7Om93I+6CiE841UqGej2j6QGWJBT6ro\nO1tLj8Pm4R9pKATL9XzJI0abatSujtYqBfVrt3O+ddz4JEj944bF7sbciw2A\nQlg38we3bft8ZOb0p8Ne2PBZ4162Yz3Hi1DX5eHW5UmE+ua0E0J0IVwafloE\nzNWDUI3SdXHPVUVaIKaZp3H/AFUYt+I1qYDHdoMXxE8exntXZKGgWaB6Nxju\nH05ntiUPnt3ZoGdcwA34xk96/NAsKe7LTnYd/b6qRvgxaTOc1oIxHzOUAqHU\nbM40qTnxir6jLZ1sY8WWDDQx9JN2a7ePiq96pF0LuDUKBLzVunQM6RtMA4qp\nLaxmzTtH2L2+PY0EwAd2k5cAZNOlD9w6DBpMIxTwnqrxnhPCftBqimwmQNxm\ncutnmtbUweXMVBejb9gQl0yDMNMV48VcLKD35eUGrezqp9ixCgZXFsFqgC93\nijNR\r\n=8Rio\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCTS+sVmHmijF+pcU2cMBHJuZsidXsTIFvt4sR969/K8wIgGPK+3Sep6FP/cmjW8OoQUulty3EIK8PMsWza53ul2/E="}]},"maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"_npmUser":{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tsconfig-paths_3.8.0_1560459969089_0.721880966337207"},"_hasShrinkwrap":false}},"time":{"created":"2019-06-13T21:06:08.906Z","3.8.0":"2019-06-13T21:06:09.270Z","modified":"2022-04-04T13:33:44.045Z"},"maintainers":[{"name":"aleclarson","email":"alec.stanford.larson@gmail.com"}],"description":"Load node modules according to tsconfig paths, in run-time or via API.","homepage":"https://github.com/dividab/tsconfig-paths#readme","repository":{"type":"git","url":"git+https://github.com/dividab/tsconfig-paths.git"},"author":{"name":"Jonas Kello"},"bugs":{"url":"https://github.com/dividab/tsconfig-paths/issues"},"license":"MIT","readme":"# tsconfig-paths\n\n[![npm version][version-image]][version-url]\n[![travis build][travis-image]][travis-url]\n[![Coverage Status][codecov-image]][codecov-url]\n[![MIT license][license-image]][license-url]\n[![code style: prettier][prettier-image]][prettier-url]\n\nUse this to load modules whose location is specified in the `paths` section of `tsconfig.json`. Both loading at run-time and via API are supported.\n\nTypescript by default mimics the Node.js runtime resolution strategy of modules. But it also allows the use of [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html) which allows arbitrary module paths (that doesn't start with \"/\" or \".\") to be specified and mapped to physical paths in the filesystem. The typescript compiler can resolve these paths from `tsconfig` so it will compile OK. But if you then try to execute the compiled files with node (or ts-node), it will only look in the `node_modules` folders all the way up to the root of the filesystem and thus will not find the modules specified by `paths` in `tsconfig`.\n\nIf you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` and convert node's module loading calls into to physcial file paths that node can load.\n\n## How to install\n\n```\nyarn add --dev tsconfig-paths\n```\n\nor\n\n```\nnpm install --save-dev tsconfig-paths\n```\n\n## How to use\n\n### With node\n\n`node -r tsconfig-paths/register main.js`\n\n### With ts-node\n\n`ts-node -r tsconfig-paths/register main.ts`\n\nIf `process.env.TS_NODE_PROJECT` is set it will be used to resolved tsconfig.json\n\n### With webpack\n\nFor webpack please use the [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin).\n\n### With mocha and ts-node\n\nAs of Mocha >= 4.0.0 the `--compiler` was [deprecated](https://github.com/mochajs/mocha/wiki/compilers-deprecation). Instead `--require` should be used. You also have to specify a glob that includes `.ts` files because mocha looks after files with `.js` extension by default.\n\n```bash\nmocha -r ts-node/register -r tsconfig-paths/register \"test/**/*.ts\"\n```\n\n### With other commands\n\nAs long as the command has something similar to a `--require` option that can load a module before it starts, tsconfig-paths should be able to work with it.\n\n## Bootstraping with explicit params\n\nIf you want more granular control over tsconfig-paths you can bootstrap it. This can be useful if you for instance have compiled with `tsc` to another directory where `tsconfig.json` doesn't exists.\n\n```javascript\nconst tsConfig = require(\"./tsconfig.json\");\nconst tsConfigPaths = require(\"tsconfig-paths\");\n\nconst baseUrl = \"./\"; // Either absolute or relative path. If relative it's resolved to current working directory.\nconst cleanup = tsConfigPaths.register({\n  baseUrl,\n  paths: tsConfig.compilerOptions.paths\n});\n\n// When path registration is no longer needed\ncleanup();\n```\n\nThen run with:\n\n`node -r ./tsconfig-paths-bootstrap.js main.js`\n\n## Configuration Options\n\nYou can set options by passing them before the script path, via programmatic usage or via environment variables.\n\n```bash\nts-node --project customLocation/tsconfig.json -r tsconfig-paths/register \"test/**/*.ts\"\n```\n\n### CLI and Programmatic Options\n\n_Environment variable denoted in parentheses._\n\n- `-P, --project [path]` Path to TypeScript JSON project file (`TS_NODE_PROJECT`)\n\n## Config loading process\n\n1.  Use explicit params passed to register\n2.  Use `process.env.TS_NODE_PROJECT` to resolve tsConfig.json and the specified baseUrl and paths.\n3.  Resolves tsconfig.json from current working directory and the specified baseUrl and paths.\n\n## Programmatic use\n\nThe public API consists of these functions:\n\n- [register](#register)\n- [loadConfig](#loadConfig)\n- [createMatchPath](#createMatchPath) / [createMatchPathAsync](#createMatchPathAsync)\n- [matchFromAbsolutePaths](#matchFromAbsolutePaths) / [matchFromAbsolutePathsAsync](#matchFromAbsolutePathsAsync)\n\n### register\n\n```typescript\nexport interface ExplicitParams {\n  baseUrl: string;\n  paths: { [key: string]: Array<string> };\n  mainFields?: Array<string>;\n  addMatchAll?: boolean;\n}\n\n/**\n * Installs a custom module load function that can adhere to paths in tsconfig.\n */\nexport function register(explicitParams: ExplicitParams): () => void;\n```\n\nThis function will patch the node's module loading so it will look for modules in paths specified by tsconfig.json.\nA function is returned for you to reinstate Node's original module loading.\n\n### loadConfig\n\n```typescript\nexport function loadConfig(cwd: string = process.cwd()): ConfigLoaderResult;\n\nexport type ConfigLoaderResult =\n  | ConfigLoaderSuccessResult\n  | ConfigLoaderFailResult;\n\nexport interface ConfigLoaderSuccessResult {\n  resultType: \"success\";\n  absoluteBaseUrl: string;\n  paths: { [key: string]: Array<string> };\n}\n\nexport interface ConfigLoaderFailResult {\n  resultType: \"failed\";\n  message: string;\n}\n```\n\nThis function loads the tsconfig.json. It will start searching from the specified `cwd` directory.\n\n### createMatchPath\n\n```typescript\n/**\n * Function that can match a path\n */\nexport interface MatchPath {\n  (\n    requestedModule: string,\n    readJson?: Filesystem.ReadJsonSync,\n    fileExists?: (name: string) => boolean,\n    extensions?: ReadonlyArray<string>\n  ): string | undefined;\n}\n\n/**\n * Creates a function that can resolve paths according to tsconfig paths property.\n * @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.\n * @param paths The paths as specified in tsconfig.\n * @param mainFields A list of package.json field names to try when resolving module files.\n * @param addMatchAll Add a match-all \"*\" rule if none is present\n * @returns a function that can resolve paths.\n */\nexport function createMatchPath(\n  absoluteBaseUrl: string,\n  paths: { [key: string]: Array<string> },\n  mainFields: string[] = [\"main\"],\n  addMatchAll: boolean = true\n): MatchPath {\n```\n\nThe `createMatchPath` function will create a function that can match paths. It accepts `baseUrl` and `paths` directly as they are specified in tsconfig and will handle resolving paths to absolute form. The created function has the signare specified by the type `MatchPath` above.\n\n### matchFromAbsolutePaths\n\n```typescript\n/**\n * Finds a path from tsconfig that matches a module load request.\n * @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.\n * @param requestedModule The required module name.\n * @param readJson Function that can read json from a path (useful for testing).\n * @param fileExists Function that checks for existance of a file at a path (useful for testing).\n * @param extensions File extensions to probe for (useful for testing).\n * @param mainFields A list of package.json field names to try when resolving module files.\n * @returns the found path, or undefined if no path was found.\n */\nexport function matchFromAbsolutePaths(\n  absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>,\n  requestedModule: string,\n  readJson: Filesystem.ReadJsonSync = Filesystem.readJsonFromDiskSync,\n  fileExists: Filesystem.FileExistsSync = Filesystem.fileExistsSync,\n  extensions: Array<string> = Object.keys(require.extensions),\n  mainFields: string[] = [\"main\"]\n): string | undefined {\n```\n\nThis function is lower level and requries that the paths as already been resolved to absolute form and sorted in correct order into an array.\n\n### createMatchPathAsync\n\nThis is the async version of `createMatchPath`. It has the same signature but with a callback parameter for the result.\n\n### matchFromAbsolutePathsAsync\n\nThis is the async version of `matchFromAbsolutePaths`. It has the same signature but with a callback parameter for the result.\n\n[version-image]: https://img.shields.io/npm/v/tsconfig-paths.svg?style=flat\n[version-url]: https://www.npmjs.com/package/tsconfig-paths\n[travis-image]: https://travis-ci.com/dividab/tsconfig-paths.svg?branch=master&style=flat\n[travis-url]: https://travis-ci.com/dividab/tsconfig-paths\n[codecov-image]: https://codecov.io/gh/dividab/tsconfig-paths/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/dividab/tsconfig-paths\n[license-image]: https://img.shields.io/github/license/dividab/tsconfig-paths.svg?style=flat\n[license-url]: https://opensource.org/licenses/MIT\n[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg\n[prettier-url]: https://github.com/prettier/prettier\n","readmeFilename":"README.md"}