-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pnpmfile.cjs
More file actions
93 lines (81 loc) · 2.18 KB
/
Copy path.pnpmfile.cjs
File metadata and controls
93 lines (81 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// .pnpmfile.cjs — Redirect @connectum/* to local tarballs from Connectum/pack/
//
// Usage:
// pnpm install — uses published npm versions (no-op)
// CONNECTUM_LOCAL=1 pnpm install — uses local tarballs from pack/
//
// This file is committed to git. Symlinks in each example point here.
// The pack/ directory is populated by: cd connectum && pnpm run pack:all
"use strict";
const path = require("node:path");
const fs = require("node:fs");
const CONNECTUM_PACKAGES = [
"core",
"auth",
"interceptors",
"healthcheck",
"protoc-gen-catalog",
"reflection",
"cli",
"otel",
"testing",
"events",
"events-nats",
"events-kafka",
"events-redis",
"events-amqp",
];
// __dirname resolves to the real file location (examples/), not the symlink.
// So ../pack always resolves to Connectum/pack/.
const PACK_DIR = path.resolve(__dirname, "..", "pack");
/**
* Find a tarball for a given @connectum package name.
* Pattern: connectum-{name}-*.tgz (version-agnostic).
*/
function findTarball(name) {
const prefix = `connectum-${name}-`;
try {
const files = fs.readdirSync(PACK_DIR);
const match = files.find(
(f) => f.startsWith(prefix) && f.endsWith(".tgz"),
);
if (match) {
return path.join(PACK_DIR, match);
}
} catch {
// pack/ directory does not exist — skip silently
}
return null;
}
function readPackage(pkg) {
if (process.env.CONNECTUM_LOCAL !== "1") {
return pkg;
}
for (const name of CONNECTUM_PACKAGES) {
const scope = `@connectum/${name}`;
if (pkg.dependencies && pkg.dependencies[scope]) {
const tarball = findTarball(name);
if (tarball) {
pkg.dependencies[scope] = `file:${tarball}`;
}
}
if (pkg.devDependencies && pkg.devDependencies[scope]) {
const tarball = findTarball(name);
if (tarball) {
pkg.devDependencies[scope] = `file:${tarball}`;
}
}
if (pkg.peerDependencies && pkg.peerDependencies[scope]) {
const tarball = findTarball(name);
if (tarball) {
pkg.peerDependencies[scope] = `file:${tarball}`;
}
}
}
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};