solid-register
Version:
integrated package to run solid browser code in node
49 lines (48 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.config = exports.usesConditions = exports.conditions = exports.projectPath = void 0;
const path_1 = require("path");
const config = {
aliases: { solid: "dev" },
};
exports.config = config;
["jsdom", "happy-dom", "linkedom"].some((dom) => {
try {
require.resolve(dom);
config.dom = dom;
return true;
}
catch (e) {
return false;
}
});
const getPackageJson = () => {
let path = process.cwd();
while (path) {
try {
const packageJson = require((0, path_1.join)(path, "package.json"));
return [packageJson, path];
}
catch (e) {
/* package.json not loaded */
}
path = path.replace(/[\/\\][^/\\]+$/, "");
}
console.warn("\x1b[33m⚠️ package.json could not be found; maybe you're not in a project?\x1b[0m");
return [{}, "./"];
};
const [packageJson, projectPath] = getPackageJson();
exports.projectPath = projectPath;
Object.assign(config, packageJson?.["solid-register"]);
try {
Object.assign(config, require((0, path_1.join)(projectPath, "solid-register-config")));
}
catch (e) {
if ("code" in e && e.code !== "MODULE_NOT_FOUND") {
if (e instanceof Error) {
throw e;
}
}
}
exports.conditions = process.execArgv.reduce(([last, conditions], arg) => last === "--conditions" ? [arg, [...conditions, arg]] : [arg, conditions], ["", []])[1];
exports.usesConditions = exports.conditions.some((condition) => ["development", "browser", "node"].includes(condition));