ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / third_party / tsconfig-loader.js
Source Blame History 103 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var tsconfig_loader_exports = {};
f7eb47b… lmata 30 __export(tsconfig_loader_exports, {
f7eb47b… lmata 31 loadTsConfig: () => loadTsConfig
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(tsconfig_loader_exports);
f7eb47b… lmata 34 var import_path = __toESM(require("path"));
f7eb47b… lmata 35 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 36 var import_utilsBundle = require("../utilsBundle");
f7eb47b… lmata 37 function loadTsConfig(configPath) {
f7eb47b… lmata 38 try {
f7eb47b… lmata 39 const references = [];
f7eb47b… lmata 40 const config = innerLoadTsConfig(configPath, references);
f7eb47b… lmata 41 return [config, ...references];
f7eb47b… lmata 42 } catch (e) {
f7eb47b… lmata 43 throw new Error(`Failed to load tsconfig file at ${configPath}:
f7eb47b… lmata 44 ${e.message}`);
f7eb47b… lmata 45 }
f7eb47b… lmata 46 }
f7eb47b… lmata 47 function resolveConfigFile(baseConfigFile, referencedConfigFile) {
f7eb47b… lmata 48 if (!referencedConfigFile.endsWith(".json"))
f7eb47b… lmata 49 referencedConfigFile += ".json";
f7eb47b… lmata 50 const currentDir = import_path.default.dirname(baseConfigFile);
f7eb47b… lmata 51 let resolvedConfigFile = import_path.default.resolve(currentDir, referencedConfigFile);
f7eb47b… lmata 52 if (referencedConfigFile.includes("/") && referencedConfigFile.includes(".") && !import_fs.default.existsSync(resolvedConfigFile))
f7eb47b… lmata 53 resolvedConfigFile = import_path.default.join(currentDir, "node_modules", referencedConfigFile);
f7eb47b… lmata 54 return resolvedConfigFile;
f7eb47b… lmata 55 }
f7eb47b… lmata 56 function innerLoadTsConfig(configFilePath, references, visited = /* @__PURE__ */ new Map()) {
f7eb47b… lmata 57 if (visited.has(configFilePath))
f7eb47b… lmata 58 return visited.get(configFilePath);
f7eb47b… lmata 59 let result = {
f7eb47b… lmata 60 tsConfigPath: configFilePath
f7eb47b… lmata 61 };
f7eb47b… lmata 62 visited.set(configFilePath, result);
f7eb47b… lmata 63 if (!import_fs.default.existsSync(configFilePath))
f7eb47b… lmata 64 return result;
f7eb47b… lmata 65 const configString = import_fs.default.readFileSync(configFilePath, "utf-8");
f7eb47b… lmata 66 const cleanedJson = StripBom(configString);
f7eb47b… lmata 67 const parsedConfig = import_utilsBundle.json5.parse(cleanedJson);
f7eb47b… lmata 68 const extendsArray = Array.isArray(parsedConfig.extends) ? parsedConfig.extends : parsedConfig.extends ? [parsedConfig.extends] : [];
f7eb47b… lmata 69 for (const extendedConfig of extendsArray) {
f7eb47b… lmata 70 const extendedConfigPath = resolveConfigFile(configFilePath, extendedConfig);
f7eb47b… lmata 71 const base = innerLoadTsConfig(extendedConfigPath, references, visited);
f7eb47b… lmata 72 Object.assign(result, base, { tsConfigPath: configFilePath });
f7eb47b… lmata 73 }
f7eb47b… lmata 74 if (parsedConfig.compilerOptions?.allowJs !== void 0)
f7eb47b… lmata 75 result.allowJs = parsedConfig.compilerOptions.allowJs;
f7eb47b… lmata 76 if (parsedConfig.compilerOptions?.paths !== void 0) {
f7eb47b… lmata 77 result.paths = {
f7eb47b… lmata 78 mapping: parsedConfig.compilerOptions.paths,
f7eb47b… lmata 79 pathsBasePath: import_path.default.dirname(configFilePath)
f7eb47b… lmata 80 };
f7eb47b… lmata 81 }
f7eb47b… lmata 82 if (parsedConfig.compilerOptions?.baseUrl !== void 0) {
f7eb47b… lmata 83 result.absoluteBaseUrl = import_path.default.resolve(import_path.default.dirname(configFilePath), parsedConfig.compilerOptions.baseUrl);
f7eb47b… lmata 84 }
f7eb47b… lmata 85 for (const ref of parsedConfig.references || [])
f7eb47b… lmata 86 references.push(innerLoadTsConfig(resolveConfigFile(configFilePath, ref.path), references, visited));
f7eb47b… lmata 87 if (import_path.default.basename(configFilePath) === "jsconfig.json" && result.allowJs === void 0)
f7eb47b… lmata 88 result.allowJs = true;
f7eb47b… lmata 89 return result;
f7eb47b… lmata 90 }
f7eb47b… lmata 91 function StripBom(string) {
f7eb47b… lmata 92 if (typeof string !== "string") {
f7eb47b… lmata 93 throw new TypeError(`Expected a string, got ${typeof string}`);
f7eb47b… lmata 94 }
f7eb47b… lmata 95 if (string.charCodeAt(0) === 65279) {
f7eb47b… lmata 96 return string.slice(1);
f7eb47b… lmata 97 }
f7eb47b… lmata 98 return string;
f7eb47b… lmata 99 }
f7eb47b… lmata 100 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 101 0 && (module.exports = {
f7eb47b… lmata 102 loadTsConfig
f7eb47b… lmata 103 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button