prisma-laravel-migrate 0.1.13 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +2 -1
- package/dist/cli/generate.js +1 -7
- package/dist/utils/config.js +69 -0
- package/dist/utils/loadSharedCfg.js +2 -1
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -4,7 +4,8 @@ import fs from 'fs/promises';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { existsSync, readdirSync } from 'fs';
|
|
7
|
-
import { loadConfig
|
|
7
|
+
import { loadConfig } from '../utils/config.js';
|
|
8
|
+
import { runGenerators } from './generate.js';
|
|
8
9
|
const cli = new Command();
|
|
9
10
|
cli
|
|
10
11
|
.name('prisma-laravel-cli')
|
package/dist/cli/generate.js
CHANGED
|
@@ -6,13 +6,7 @@ import fs from 'fs/promises';
|
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { spawn } from "child_process";
|
|
8
8
|
import * as dmf from '@prisma/internals';
|
|
9
|
-
import {
|
|
10
|
-
// helper once:
|
|
11
|
-
export async function loadConfig(configPath) {
|
|
12
|
-
const url = pathToFileURL(configPath).href; // ✅ file:///C:/...
|
|
13
|
-
const mod = await import(url);
|
|
14
|
-
return (mod.default ?? mod); // works for CJS or ESM
|
|
15
|
-
}
|
|
9
|
+
import { loadConfig } from "../utils/config.js";
|
|
16
10
|
// utility: load/merge ALL *.prisma files under prisma/ (schema first, then the rest)
|
|
17
11
|
async function loadMergedDatamodel(schemaPrismaPath) {
|
|
18
12
|
const schemaDir = path.dirname(schemaPrismaPath);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// loaders/config.ts
|
|
2
|
+
import { pathToFileURL } from "url";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { extname, dirname, resolve } from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
/** find nearest package.json and read its "type" (defaults to "commonjs") */
|
|
7
|
+
function getNearestPkgType(fromPath) {
|
|
8
|
+
try {
|
|
9
|
+
let dir = dirname(fromPath);
|
|
10
|
+
while (true) {
|
|
11
|
+
const pj = resolve(dir, "package.json");
|
|
12
|
+
if (fs.existsSync(pj)) {
|
|
13
|
+
const type = JSON.parse(fs.readFileSync(pj, "utf8")).type;
|
|
14
|
+
return type === "module" ? "module" : "commonjs";
|
|
15
|
+
}
|
|
16
|
+
const up = dirname(dir);
|
|
17
|
+
if (up === dir)
|
|
18
|
+
break;
|
|
19
|
+
dir = up;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
return "commonjs";
|
|
24
|
+
}
|
|
25
|
+
// simple singleton cache to avoid double-loading the same file concurrently
|
|
26
|
+
const configCache = new Map();
|
|
27
|
+
async function loadConfigUniversal(absPath) {
|
|
28
|
+
const key = absPath;
|
|
29
|
+
if (configCache.has(key))
|
|
30
|
+
return configCache.get(key);
|
|
31
|
+
const promise = (async () => {
|
|
32
|
+
const ext = extname(absPath).toLowerCase();
|
|
33
|
+
const projType = getNearestPkgType(absPath);
|
|
34
|
+
const asUrl = pathToFileURL(absPath).href;
|
|
35
|
+
const req = createRequire(import.meta.url);
|
|
36
|
+
// Explicit extensions win:
|
|
37
|
+
if (ext === ".mjs") {
|
|
38
|
+
const mod = await import(asUrl);
|
|
39
|
+
return mod.default ?? mod;
|
|
40
|
+
}
|
|
41
|
+
if (ext === ".cjs") {
|
|
42
|
+
const mod = req(absPath);
|
|
43
|
+
return mod.default ?? mod;
|
|
44
|
+
}
|
|
45
|
+
// .js is ambiguous: respect package.json "type"
|
|
46
|
+
if (projType === "module") {
|
|
47
|
+
// ESM project: load as ESM
|
|
48
|
+
const mod = await import(asUrl);
|
|
49
|
+
return mod.default ?? mod;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// CJS project: load via require
|
|
53
|
+
const mod = req(absPath);
|
|
54
|
+
return mod.default ?? mod;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
configCache.set(key, promise);
|
|
58
|
+
try {
|
|
59
|
+
const cfg = await promise;
|
|
60
|
+
return cfg;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
// keep it cached for this process; remove if you prefer one-shot
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function loadConfig(configPath) {
|
|
67
|
+
return await loadConfigUniversal(configPath); // works for CJS or ESM
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// utils/loadSharedCfg.ts
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
4
5
|
/** ---------------- shared-config loader ---------------- */
|
|
5
6
|
export async function loadSharedConfig(schemaDir) {
|
|
6
7
|
const envOverride = process.env.PRISMA_LARAVEL_CFG;
|
|
@@ -9,7 +10,7 @@ export async function loadSharedConfig(schemaDir) {
|
|
|
9
10
|
console.log("Loading shared config from - " + cfgPath);
|
|
10
11
|
try {
|
|
11
12
|
await fs.accessSync(cfgPath);
|
|
12
|
-
const mod = await
|
|
13
|
+
const mod = await loadConfig(cfgPath);
|
|
13
14
|
return (mod.default ?? mod);
|
|
14
15
|
}
|
|
15
16
|
catch (err) {
|