@builder.io/dev-tools
Version:
Builder.io Visual CMS Devtools
71 lines (66 loc) • 2.67 kB
JavaScript
var version = process.version;
var [majorVersion, minorVersion] = version.replace("v", "").split(".");
if (Number(majorVersion) < 18) {
console.error(
"Builder.io Dev Tools requires Node.js 18.11 or higher. You are currently running Node.js " +
version,
);
process.exit(1);
} else if (Number(majorVersion) === 18) {
if (Number(minorVersion) < 4) {
console.error(
"Builder.io Dev Tools requires Node.js 18.4 or higher. You are currently running Node.js" +
version,
);
process.exit(1);
} else if (Number(minorVersion) < 11) {
console.error(
"Node.js 18.11 or higher is REQUIRED. From Node 18.0.0 to 18.11.0, there is a bug preventing correct behaviour of Builder.io. You are currently running Node.js " +
version,
);
}
}
// Filter out any PATH entries that contain "builder-electron-node-bin"
// This prevents fake node paths from the CLI caller from being passed through
if (process.env.PATH) {
const pathSeparator = process.platform === "win32" ? ";" : ":";
const pathEntries = process.env.PATH.split(pathSeparator);
const filteredPaths = pathEntries.filter(
(pathEntry) => !pathEntry.includes("builder-electron-node-bin"),
);
process.env.PATH = filteredPaths.join(pathSeparator);
}
// Ensure File global is available for undici compatibility
// This is needed when running via npx with local paths where dependencies
// might resolve from parent node_modules with different undici versions
// undici v7+ requires File to be available, and it checks for it at module load time
if (typeof globalThis.File === "undefined") {
try {
// In Node.js 20+, File is available from node:buffer
const { File } = require("node:buffer");
globalThis.File = File;
} catch (e) {
console.error("Error importing File from node:buffer", e);
// Fallback: create a minimal File polyfill for undici compatibility
// This is a basic implementation that should satisfy undici's type checks
globalThis.File = class File extends Blob {
constructor(chunks, name, options) {
super(chunks, options);
this.name = name || "";
this.lastModified = options?.lastModified || Date.now();
}
};
}
} else {
// Ensure File is explicitly set in globalThis even if it already exists
// This helps with module resolution timing issues when using npx with local paths
try {
const { File } = require("node:buffer");
globalThis.File = File;
} catch (e) {
console.error("Error importing File from node:buffer", e);
// If we can't import it, the existing global File should be sufficient
}
}
require("./index.cjs");