UNPKG

@vis.gl/dev-tools

Version:

Dev tools for vis.gl frameworks

198 lines (191 loc) 6.8 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // dist/index.js var dist_exports = {}; __export(dist_exports, { getOcularConfig: () => getOcularConfig }); module.exports = __toCommonJS(dist_exports); // dist/helpers/get-ocular-config.js var import_fs3 = __toESM(require("fs"), 1); var import_path3 = require("path"); // dist/helpers/aliases.js var import_path2 = require("path"); var import_fs2 = __toESM(require("fs"), 1); // dist/utils/utils.js var import_fs = __toESM(require("fs"), 1); var import_path = require("path"); var import_node_url = require("node:url"); var import_child_process = require("child_process"); var import_meta = {}; var ocularRoot = function() { let dir; try { dir = __dirname; } catch { dir = (0, import_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url)); } return (0, import_path.resolve)(dir, "../.."); }(); function shallowMerge(base, override) { for (const key in override) { if (base[key] && typeof base[key] === "object") { Object.assign(base[key], override[key]); } else { base[key] = override[key]; } } return base; } function getValidPath(...resolveOrder) { for (const path of resolveOrder) { if (import_fs.default.existsSync(path)) { return path; } } return null; } // dist/helpers/aliases.js function getModuleInfo(path) { if (import_fs2.default.lstatSync(path).isDirectory()) { try { const packageInfoText = import_fs2.default.readFileSync((0, import_path2.resolve)(path, "package.json"), "utf-8"); const packageInfo = JSON.parse(packageInfoText); return { name: packageInfo.name, path, packageInfo }; } catch (err) { } } return null; } function getSubmodules(packageRoot) { const submodules = {}; const parentPath = (0, import_path2.resolve)(packageRoot, "./modules"); if (import_fs2.default.existsSync(parentPath)) { import_fs2.default.readdirSync(parentPath).forEach((item) => { const itemPath = (0, import_path2.resolve)(parentPath, item); const moduleInfo = getModuleInfo(itemPath); if (moduleInfo) { submodules[moduleInfo.name] = moduleInfo; } }); } else { const moduleInfo = getModuleInfo(packageRoot); if (moduleInfo) { submodules[moduleInfo.name] = moduleInfo; } } return submodules; } function getAliases(mode, packageRoot = process.env.PWD) { const aliases = {}; const submodules = getSubmodules(packageRoot); for (const moduleName in submodules) { const { path } = submodules[moduleName]; const testPath = (0, import_path2.resolve)(path, "test"); if (import_fs2.default.existsSync(testPath)) { aliases[`${moduleName}/test`] = testPath; } if (mode === "dist") { aliases[moduleName] = getValidPath((0, import_path2.resolve)(path, "dist/es5"), (0, import_path2.resolve)(path, "dist/esm"), (0, import_path2.resolve)(path, "dist")); } else { aliases[moduleName] = (0, import_path2.resolve)(path, "src"); } } return aliases; } // dist/helpers/get-ocular-config.js async function getOcularConfig(options = {}) { var _a, _b; const packageRoot = options.root || process.env.PWD; const IS_MONOREPO = import_fs3.default.existsSync((0, import_path3.resolve)(packageRoot, "./modules")); const userConfig = await getUserConfig(packageRoot); const config = { root: packageRoot, ocularPath: ocularRoot, esm: ((_a = getModuleInfo(packageRoot)) == null ? void 0 : _a.packageInfo.type) === "module", bundle: { globals: {} }, typescript: { project: "tsconfig.json" }, lint: { paths: IS_MONOREPO ? ["modules"] : ["src"], extensions: ["js", "mjs", "jsx", "ts", "tsx", "d.ts"] }, coverage: { test: "node" }, aliases: {}, entry: { test: "test/index.ts", "test-browser": "test/index.html", bench: "test/bench/index.ts", "bench-browser": "test/bench/index.html", size: ["test/size.ts"] }, vite: { version: 4, configPath: getValidPath((0, import_path3.resolve)(packageRoot, "./vite.config.js"), (0, import_path3.resolve)(packageRoot, "./vite.config.cjs"), (0, import_path3.resolve)(ocularRoot, "dist/configuration/vite.config.js")) } }; shallowMerge(config, userConfig); if (typeof ((_b = userConfig.entry) == null ? void 0 : _b.size) === "string") { userConfig.entry.size = [userConfig.entry.size]; } const aliasMode = options.aliasMode || "src"; Object.assign(config.aliases, getAliases(aliasMode, packageRoot)); if (aliasMode && !aliasMode.includes("browser")) { Object.assign(config.aliases, userConfig.nodeAliases); } return config; } async function getUserConfig(packageRoot) { const userConfigPath = getValidPath( (0, import_path3.resolve)(packageRoot, "./.ocularrc.js"), (0, import_path3.resolve)(packageRoot, "./.ocularrc.cjs"), (0, import_path3.resolve)(packageRoot, "./.ocular.config.js"), (0, import_path3.resolve)(packageRoot, "./.ocular.config.cjs"), // deprecated (0, import_path3.resolve)(packageRoot, "./ocular-dev-tools.config.js") ); if (userConfigPath) { const userConfigModule = await import(userConfigPath); if ("default" in userConfigModule) { return userConfigModule.default; } return userConfigModule; } throw new Error("No valid user config found"); } //# sourceMappingURL=index.cjs.map