@typed/content-hash
Version:
Content hash a directory of HTML/JS/CSS files and other static assets
28 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createResolveTsConfigPaths = void 0;
const function_1 = require("fp-ts/function");
const Option_1 = require("fp-ts/Option");
const tsconfig_paths_1 = require("tsconfig-paths");
const mainFields = ['module', 'jsnext:main', 'browser', 'main'];
const PATH_STAR_REGEX = /\/?\*$/;
const extensions = ['.js', '.jsx', '.ts', '.d.ts', '.d.ts.map', '.json'];
function createResolveTsConfigPaths({ compilerOptions, }) {
const { baseUrl, paths = {} } = compilerOptions;
const pathsKeys = Object.keys(paths);
const pathsKeysWithoutStars = pathsKeys.map((key) => key.replace(PATH_STAR_REGEX, ''));
const canMatchPath = baseUrl && pathsKeys.length > 0;
const matchPath = canMatchPath ? (0, tsconfig_paths_1.createMatchPath)(baseUrl, paths, Array.from(mainFields)) : null;
const resolvePath = matchPath
? (specifier) => (0, function_1.pipe)(matchPath(specifier, undefined, undefined, extensions), Option_1.fromNullable)
: (0, function_1.constant)(Option_1.none);
const isInPaths = canMatchPath
? (moduleSpecifier) => pathsKeysWithoutStars.some((x) => moduleSpecifier.startsWith(x))
: function_1.constFalse;
return {
resolvePath,
isInPaths,
};
}
exports.createResolveTsConfigPaths = createResolveTsConfigPaths;
//# sourceMappingURL=resolveTsConfigPaths.js.map