MCPcopy
hub / github.com/angular/angular / pathPlugin

Function pathPlugin

tools/bazel/rollup/path-plugin.cjs:13–47  ·  view source on GitHub ↗
({tsconfigPath})

Source from the content-addressed store, hash-verified

11const {parseTsconfig, createPathsMatcher} = require('get-tsconfig');
12
13function pathPlugin({tsconfigPath}) {
14 if (tsconfigPath === undefined) {
15 throw Error('A path tsconfig file must be provided.');
16 }
17 const fullTsconfigPath = join(process.cwd(), tsconfigPath);
18 const tsconfig = parseTsconfig(fullTsconfigPath);
19 const pathMappingMatcher = createPathsMatcher({config: tsconfig, path: fullTsconfigPath});
20 return {
21 name: 'paths',
22 resolveId: (source) => {
23 /**
24 * A list containing all of the potential paths which match the provided source based
25 * on the paths field from the tsconfig.
26 */
27 const matchedSources = pathMappingMatcher(source);
28 if (matchedSources.length == 0) {
29 return null;
30 }
31 // We need to check each matched source to see if it loads at the path directly, or is
32 // a directory with an index.js file to import.
33 for (let matchedSource of matchedSources) {
34 const indexPath = join(matchedSource, 'index.js');
35 if (existsSync(indexPath) && statSync(indexPath).isFile) {
36 return {id: indexPath};
37 }
38 const filePath = matchedSource + '.js';
39 if (existsSync(filePath) && statSync(filePath).isFile) {
40 return {id: filePath};
41 }
42 }
43
44 throw Error(`Cannot find ${source}\nLocations checked:\n-${matchedSources.join('\n')}`);
45 },
46 };
47}
48
49module.exports = {pathPlugin};

Callers 2

rollup.config.jsFile · 0.85
rollup.config.jsFile · 0.85

Calls 3

ErrorInterface · 0.85
joinFunction · 0.85
joinMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…