MCPcopy
hub / github.com/ampproject/amphtml / readJsconfigPaths

Function readJsconfigPaths

build-system/babel-config/import-resolver.js:26–42  ·  view source on GitHub ↗

* Reads import paths from tsconfig.json. This file is used by VSCode for * Intellisense/auto-import. Rather than duplicate and require updating both * files, we can read from it directly. JSConfig format looks like: * { compilerOptions: { paths: { * '#foo/*': ['./src/foo/*'], * '#bar/*': ['

()

Source from the content-addressed store, hash-verified

24 * @return {!{[key: string]: string}}
25 */
26function readJsconfigPaths() {
27 if (!tsConfigPaths) {
28 const tsConfig = JSON.parse(fs.readFileSync(TSCONFIG_PATH, 'utf8'));
29 const aliasPaths = tsConfig.compilerOptions.paths;
30
31 const stripSuffix = (s) => s.replace(/\/\*$/, '');
32 // eslint-disable-next-line local/no-deep-destructuring
33 const aliases = Object.entries(aliasPaths).map(([alias, [dest]]) => [
34 stripSuffix(alias),
35 stripSuffix(dest),
36 ]);
37
38 tsConfigPaths = Object.fromEntries(aliases);
39 }
40
41 return tsConfigPaths;
42}
43
44/**
45 * Remap external modules that rely on React if building for Preact.

Callers 1

getImportResolverFunction · 0.85

Calls 3

stripSuffixFunction · 0.85
parseMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected