@lark-apaas/express-datapaas 0.0.1 → 0.0.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/package.json +2 -2
- package/scripts/apply-patch.js +52 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/express-datapaas",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Drizzle ORM + PostgreSQL with RLS support for Express",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup",
|
|
37
|
-
"postinstall": "
|
|
37
|
+
"postinstall": "node scripts/apply-patch.js",
|
|
38
38
|
"apply-patch": "node scripts/apply-patch.js",
|
|
39
39
|
"dev": "tsup --watch",
|
|
40
40
|
"clean": "rm -rf dist",
|
package/scripts/apply-patch.js
CHANGED
|
@@ -1,19 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import fs from "fs";
|
|
3
5
|
import path from "path";
|
|
4
6
|
import { fileURLToPath } from "url";
|
|
5
7
|
|
|
6
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
9
|
const sdkRoot = path.resolve(__dirname, "..");
|
|
8
|
-
const
|
|
10
|
+
const patchDir = path.resolve(sdkRoot, "patches");
|
|
11
|
+
const esmRequire = createRequire(import.meta.url);
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 通过 Node 模块解析定位 drizzle-orm 所在的 node_modules 父目录。
|
|
15
|
+
* 兼容 npm(扁平)、yarn(扁平)、pnpm(隔离 + symlink)。
|
|
16
|
+
*
|
|
17
|
+
* 注意:drizzle-orm 的 exports 字段未导出 ./package.json,
|
|
18
|
+
* 因此使用 resolve("drizzle-orm") 获取入口文件路径,
|
|
19
|
+
* 再通过 "node_modules/drizzle-orm/" marker 截取 hostRoot。
|
|
20
|
+
*/
|
|
21
|
+
function resolveHostRoot() {
|
|
22
|
+
const resolved = fs.realpathSync(esmRequire.resolve("drizzle-orm"));
|
|
23
|
+
// resolved: .../node_modules/drizzle-orm/index.cjs (npm/yarn)
|
|
24
|
+
// 或: .../.pnpm/drizzle-orm@0.44.6/node_modules/drizzle-orm/index.cjs (pnpm)
|
|
25
|
+
const marker = `${path.sep}node_modules${path.sep}drizzle-orm${path.sep}`;
|
|
26
|
+
const idx = resolved.lastIndexOf(marker);
|
|
27
|
+
if (idx === -1) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Cannot locate node_modules/drizzle-orm in resolved path: ${resolved}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return resolved.substring(0, idx);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 解析 patch-package CLI 入口的绝对路径,避免依赖 npx 在错误 cwd 下查找。
|
|
37
|
+
*/
|
|
38
|
+
function resolvePatchBin() {
|
|
39
|
+
const pkgPath = esmRequire.resolve("patch-package/package.json");
|
|
40
|
+
const pkgDir = path.dirname(pkgPath);
|
|
41
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
42
|
+
const bin =
|
|
43
|
+
typeof pkg.bin === "string" ? pkg.bin : pkg.bin["patch-package"];
|
|
44
|
+
return path.resolve(pkgDir, bin);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ── main ──
|
|
48
|
+
const hostRoot = resolveHostRoot();
|
|
49
|
+
const patchBin = resolvePatchBin();
|
|
50
|
+
|
|
51
|
+
// patch-package 要求 --patch-dir 为相对路径(相对于 cwd)
|
|
52
|
+
const relativePatchDir = path.relative(hostRoot, patchDir);
|
|
53
|
+
|
|
54
|
+
console.log(`[patch] host root : ${hostRoot}`);
|
|
55
|
+
console.log(`[patch] patch-package : ${patchBin}`);
|
|
56
|
+
console.log(`[patch] patch dir : ${patchDir} (relative: ${relativePatchDir})`);
|
|
11
57
|
|
|
12
58
|
try {
|
|
13
|
-
execSync(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
);
|
|
59
|
+
execSync(`node "${patchBin}" --patch-dir "${relativePatchDir}"`, {
|
|
60
|
+
stdio: "inherit",
|
|
61
|
+
cwd: hostRoot,
|
|
62
|
+
});
|
|
17
63
|
console.log("[patch] drizzle-orm patched ✅");
|
|
18
64
|
} catch (err) {
|
|
19
65
|
console.error("[patch] Failed to apply drizzle-orm patch ❌", err);
|