\href{https://www.npmjs.com/package/ts-pnp}{\texttt{ }} \href{https://www.npmjs.com/package/ts-pnp}{\texttt{ }}

{\itshape This plugin is also available for Webpack (\href{https://github.com/arcanis/pnp-webpack-plugin}{\texttt{ pnp-\/webpack-\/plugin}}), Jest (\href{https://github.com/arcanis/jest-pnp-resolver}{\texttt{ jest-\/pnp-\/resolver}}), and Rollup (\href{https://github.com/arcanis/rollup-plugin-pnp-resolve}{\texttt{ rollup-\/plugin-\/pnp-\/resolve}})}\hypertarget{md_sfcode_node_modules_ts_pnp_README_autotoc_md30676}{}\doxysection{Installation}\label{md_sfcode_node_modules_ts_pnp_README_autotoc_md30676}

\begin{DoxyCode}{0}
\DoxyCodeLine{yarn add -\/D ts-\/pnp }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ts_pnp_README_autotoc_md30677}{}\doxysection{Usage}\label{md_sfcode_node_modules_ts_pnp_README_autotoc_md30677}
$\ast$\+Note that {\ttfamily ts-\/pnp} is a low-\/level package -\/ you shouldn\textquotesingle{}t have to use it unless you\textquotesingle{}re writing a TS compiler host. If you just want to write Type\+Script and have it Just Work™, take a look at \href{https://github.com/arcanis/pnp-webpack-plugin\#ts-loader-integration}{\texttt{ {\ttfamily pnp-\/webpack-\/plugin}}} instead.$\ast$

This package exports a function that can be used to implement the \href{https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API\#customizing-module-resolution}{\texttt{ {\ttfamily resolve\+Module\+Name} hook from {\ttfamily Compiler\+Host}}}. It mimics the interface from the one you\textquotesingle{}d typically use and, as all other PnP plugins, works just fine whether your application is actually running under PnP or not.


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{resolveModuleName\} from 'ts-\/pnp';}
\DoxyCodeLine{import * as ts from 'typescript';}
\DoxyCodeLine{}
\DoxyCodeLine{function createCompilerHost(}
\DoxyCodeLine{  compilerOptions: ts.CompilerOptions,}
\DoxyCodeLine{): ts.CompilerHost \{}
\DoxyCodeLine{  const compilerHost = \{}
\DoxyCodeLine{    resolveModuleNames,}
\DoxyCodeLine{    resolveTypeReferenceDirectives,}
\DoxyCodeLine{  \};}
\DoxyCodeLine{}
\DoxyCodeLine{  return compilerHost;}
\DoxyCodeLine{}
\DoxyCodeLine{  function resolveModuleNames(moduleNames: string[], containingFile: string) \{}
\DoxyCodeLine{    return moduleNames.map(moduleName => \{}
\DoxyCodeLine{      return resolveModuleName(moduleName, containingFile, compilerOptions, compilerHost, ts.resolveModuleName).resolvedModule;}
\DoxyCodeLine{    \});}
\DoxyCodeLine{  \}}
\DoxyCodeLine{}
\DoxyCodeLine{  function resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string) \{}
\DoxyCodeLine{    return typeDirectiveNames.map(typeDirectiveName => \{}
\DoxyCodeLine{      return resolveModuleName(typeDirectiveName, containingFile, compilerOptions, compilerHost, ts.resolveTypeReferenceDirective).resolvedTypeReferenceDirective;}
\DoxyCodeLine{    \});}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ts_pnp_README_autotoc_md30678}{}\doxysection{License (\+MIT)}\label{md_sfcode_node_modules_ts_pnp_README_autotoc_md30678}
\begin{quote}
{\bfseries{Copyright © 2016 Maël Nison}}

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \char`\"{}\+Software\char`\"{}), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions\+:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED \char`\"{}\+AS IS\char`\"{}, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \end{quote}
