UNPKG

@storm-software/esbuild

Version:

A package containing `esbuild` utilities for building Storm Software libraries and applications

86 lines (75 loc) 4.36 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkI7VU53I5cjs = require('../chunk-I7VU53I5.cjs'); var _chunkJG7MZJV2cjs = require('../chunk-JG7MZJV2.cjs'); // src/plugins/resolve-paths.ts _chunkJG7MZJV2cjs.init_cjs_shims.call(void 0, ); // ../config-tools/src/utilities/file-path-utils.ts _chunkJG7MZJV2cjs.init_cjs_shims.call(void 0, ); function findFileName(filePath, { requireExtension, withExtension } = {}) { const result = _nullishCoalesce(_optionalChain([_chunkI7VU53I5cjs.normalizeWindowsPath.call(void 0, filePath), 'optionalAccess', _ => _.split, 'call', _2 => _2(_optionalChain([filePath, 'optionalAccess', _3 => _3.includes, 'call', _4 => _4("\\")]) ? "\\" : "/"), 'optionalAccess', _5 => _5.pop, 'call', _6 => _6()]), () => ( "")); if (requireExtension === true && !result.includes(".")) { return ""; } if (withExtension === false && result.includes(".")) { return result.split(".").slice(-1).join(".") || ""; } return result; } function findFilePath(filePath) { const normalizedPath = _chunkI7VU53I5cjs.normalizeWindowsPath.call(void 0, filePath); return normalizedPath.replace( findFileName(normalizedPath, { requireExtension: true }), "" ); } // src/plugins/resolve-paths.ts var _path = require('path'); var _path2 = _interopRequireDefault(_path); function resolvePathsConfig(options, cwd, projectRoot) { if (_optionalChain([options, 'optionalAccess', _7 => _7.compilerOptions, 'optionalAccess', _8 => _8.paths])) { const paths = Object.entries(options.compilerOptions.paths); const resolvedPaths = paths.map(([key, paths2]) => { return [key, paths2.map((v) => _path2.default.resolve(cwd, v))]; }); return Object.fromEntries(resolvedPaths); } if (options.extends) { const extendsPath = _path2.default.resolve( projectRoot ? _chunkI7VU53I5cjs.joinPaths.call(void 0, cwd, projectRoot, options.extends) : _chunkI7VU53I5cjs.joinPaths.call(void 0, cwd, options.extends) ); const extendsDir = _path2.default.dirname(extendsPath); const extendsConfig = _chunkJG7MZJV2cjs.__require.call(void 0, extendsPath); return resolvePathsConfig(extendsConfig, extendsDir); } return []; } var resolvePathsPlugin = (context) => ({ name: "storm:resolve-paths", setup(build) { const parentTsConfig = build.initialOptions.tsconfig ? _chunkJG7MZJV2cjs.__require.call(void 0, _chunkI7VU53I5cjs.joinPaths.call(void 0, context.workspaceConfig.workspaceRoot, build.initialOptions.tsconfig.replace( context.workspaceConfig.workspaceRoot, "" ) )) : _chunkJG7MZJV2cjs.__require.call(void 0, _chunkI7VU53I5cjs.joinPaths.call(void 0, context.workspaceConfig.workspaceRoot, "tsconfig.json")); const resolvedTsPaths = resolvePathsConfig( parentTsConfig, context.workspaceConfig.workspaceRoot, context.options.projectRoot ); const packagesRegex = new RegExp( `^(${Object.keys(resolvedTsPaths).join("|")})$` ); build.onResolve({ filter: packagesRegex }, (args) => { if (_optionalChain([build, 'access', _9 => _9.initialOptions, 'access', _10 => _10.external, 'optionalAccess', _11 => _11.includes, 'call', _12 => _12(args.path)])) { return { path: args.path, external: true }; } let resolvedPath = resolvedTsPaths[args.path][0]; if (resolvedPath.endsWith(".ts") || resolvedPath.endsWith(".tsx")) { resolvedPath = findFilePath(resolvedPath); } return { path: _chunkI7VU53I5cjs.joinPaths.call(void 0, resolvedPath, "index.ts") }; }); } }); exports.resolvePathsPlugin = resolvePathsPlugin;