UNPKG

@storm-software/esbuild

Version:

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

60 lines (55 loc) 3.33 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunkOBGZSXTJcjs = require('../chunk-OBGZSXTJ.cjs'); // src/plugins/resolve-paths.ts var _correctpaths = require('@storm-software/config-tools/utilities/correct-paths'); var _filepathutils = require('@storm-software/config-tools/utilities/file-path-utils'); var _path = require('path'); var _path2 = _interopRequireDefault(_path); function resolvePathsConfig(options, cwd, projectRoot) { if (_optionalChain([options, 'optionalAccess', _ => _.compilerOptions, 'optionalAccess', _2 => _2.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 ? _correctpaths.joinPaths.call(void 0, cwd, projectRoot, options.extends) : _correctpaths.joinPaths.call(void 0, cwd, options.extends) ); const extendsDir = _path2.default.dirname(extendsPath); const extendsConfig = _chunkOBGZSXTJcjs.__require.call(void 0, extendsPath); return resolvePathsConfig(extendsConfig, extendsDir); } return []; } var resolvePathsPlugin = (context) => ({ name: "storm:resolve-paths", setup(build) { const parentTsConfig = build.initialOptions.tsconfig ? _chunkOBGZSXTJcjs.__require.call(void 0, _correctpaths.joinPaths.call(void 0, context.workspaceConfig.workspaceRoot, build.initialOptions.tsconfig.replace( context.workspaceConfig.workspaceRoot, "" ) )) : _chunkOBGZSXTJcjs.__require.call(void 0, _correctpaths.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', _3 => _3.initialOptions, 'access', _4 => _4.external, 'optionalAccess', _5 => _5.includes, 'call', _6 => _6(args.path)])) { return { path: args.path, external: true }; } let resolvedPath = resolvedTsPaths[args.path][0]; if (resolvedPath.endsWith(".ts") || resolvedPath.endsWith(".tsx")) { resolvedPath = _filepathutils.findFilePath.call(void 0, resolvedPath); } return { path: _correctpaths.joinPaths.call(void 0, resolvedPath, "index.ts") }; }); } }); exports.resolvePathsPlugin = resolvePathsPlugin;