everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
55 lines (53 loc) • 2.06 kB
JavaScript
const require_core = require('./core.cjs');
let node_fs = require("node:fs");
let node_path = require("node:path");
let node_url = require("node:url");
//#region src/db/identity.ts
/**
* Walk up from a directory to the nearest ancestor containing a package.json.
* Returns the start directory when none is found.
*/
function findWorkspaceDir(startDir) {
let current = startDir;
for (let i = 0; i < 15; i++) {
if ((0, node_fs.existsSync)((0, node_path.join)(current, "package.json"))) return current;
const parent = (0, node_path.dirname)(current);
if (parent === current) break;
current = parent;
}
return startDir;
}
/**
* Derive workspace identity from a workspace directory.
*/
function workspaceIdentityFromWorkspaceDir(dir) {
const workspaceDir = findWorkspaceDir(dir);
const slug = require_core.getMigrationSlug(workspaceDir);
return {
slug,
secretName: require_core.getDatabaseUrlSecretName(slug),
journal: require_core.getMigrationStorage(slug),
workspaceDir
};
}
/**
* Derive workspace identity from a module's own location.
*
* This is the primitive for drizzle.config.ts files: `import.meta.url` is the
* one module-identity fact that survives every config loader we run under —
* real ESM (Node/Bun) and drizzle-kit's bundled tsx CJS transform (which
* defines `import.meta.url` but NOT `import.meta.dirname`, leaving that
* `undefined` in evaluated configs).
*
* Pass the member expression itself (`workspaceIdentityFromModuleUrl(import.meta.url)`)
* so the transform substitutes the value; do not pass the `import.meta` object.
*/
function workspaceIdentityFromModuleUrl(moduleUrl) {
const modulePath = moduleUrl.startsWith("file:") ? (0, node_url.fileURLToPath)(moduleUrl) : moduleUrl;
return workspaceIdentityFromWorkspaceDir((0, node_path.dirname)(modulePath));
}
//#endregion
exports.findWorkspaceDir = findWorkspaceDir;
exports.workspaceIdentityFromModuleUrl = workspaceIdentityFromModuleUrl;
exports.workspaceIdentityFromWorkspaceDir = workspaceIdentityFromWorkspaceDir;
//# sourceMappingURL=identity.cjs.map