com.jimuwd.xian.registry-proxy 1.0.131 → 1.0.132

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.
@@ -5,6 +5,7 @@ import path from 'node:path';
5
5
  import { execa } from 'execa';
6
6
  import net from 'node:net';
7
7
  import { fileURLToPath } from 'node:url';
8
+ import findProjectRoot from "../utils/findProjectRoot.js";
8
9
  // Constants
9
10
  const REGISTRY_PROXY_VERSION = process.env.REGISTRY_PROXY_VERSION || 'latest';
10
11
  const LOCK_FILE_NAME = '.registry-proxy-install.lock';
@@ -17,19 +18,6 @@ let cleanupHandlers = [];
17
18
  let signalHandlers = [];
18
19
  // Helper functions
19
20
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
20
- async function findProjectRoot(startDir = process.cwd()) {
21
- let dir = startDir;
22
- while (dir !== '/') {
23
- try {
24
- await fs.access(path.join(dir, 'package.json'));
25
- return dir;
26
- }
27
- catch {
28
- dir = path.dirname(dir);
29
- }
30
- }
31
- throw new Error('Could not find project root (package.json not found)');
32
- }
33
21
  async function isPortAvailable(port) {
34
22
  return new Promise(resolve => {
35
23
  const server = net.createServer();
@@ -53,6 +41,10 @@ async function waitForFile(filePath, timeoutMs) {
53
41
  }
54
42
  return false;
55
43
  }
44
+ /**
45
+ * 读取约定的端口文件内容
46
+ * @param filePath 由server端启动时生成的端口文件路径
47
+ */
56
48
  async function readPortFile(filePath) {
57
49
  const content = await fs.readFile(filePath, 'utf-8');
58
50
  const port = parseInt(content.trim(), 10);
@@ -94,10 +86,10 @@ function registerSignalHandler(handler) {
94
86
  // Main implementation
95
87
  async function main() {
96
88
  try {
97
- // Find project root
98
- const PROJECT_ROOT = await findProjectRoot();
99
- const LOCK_FILE = path.join(PROJECT_ROOT, LOCK_FILE_NAME);
100
- const PORT_FILE = path.join(PROJECT_ROOT, PORT_FILE_NAME);
89
+ // Find project root as base dir to get config file and other tmp files.
90
+ const INSTALLATION_ROOT = await findProjectRoot();
91
+ const LOCK_FILE = path.join(INSTALLATION_ROOT, LOCK_FILE_NAME);
92
+ const PORT_FILE = path.join(INSTALLATION_ROOT, PORT_FILE_NAME);
101
93
  // Check for existing lock file
102
94
  try {
103
95
  await fs.access(LOCK_FILE);
@@ -117,12 +109,13 @@ async function main() {
117
109
  }
118
110
  });
119
111
  // Change to project root
120
- process.chdir(PROJECT_ROOT);
112
+ process.chdir(INSTALLATION_ROOT);
121
113
  // Start registry proxy
122
114
  console.log(`Starting registry-proxy@${REGISTRY_PROXY_VERSION} in the background...`);
123
115
  proxyProcess = execa('yarn', [
124
116
  'dlx',
125
117
  `com.jimuwd.xian.registry-proxy@${REGISTRY_PROXY_VERSION}`,
118
+ 'registry-proxy',
126
119
  '.registry-proxy.yml',
127
120
  '.yarnrc.yml',
128
121
  path.join(process.env.HOME || '', '.yarnrc.yml'),
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 获取以package.json为基准的工程路径
3
+ * @param startDir 起点路径,由此向上逐级搜索package.json文件直到找到其路径作为工程基础路径值返回
4
+ */
5
+ export default function findProjectRoot(startDir?: string): Promise<string>;
@@ -0,0 +1,19 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ /**
4
+ * 获取以package.json为基准的工程路径
5
+ * @param startDir 起点路径,由此向上逐级搜索package.json文件直到找到其路径作为工程基础路径值返回
6
+ */
7
+ export default async function findProjectRoot(startDir = process.cwd()) {
8
+ let dir = startDir;
9
+ while (dir !== '/') {
10
+ try {
11
+ await fs.access(path.join(dir, 'package.json'));
12
+ return dir;
13
+ }
14
+ catch {
15
+ dir = path.dirname(dir);
16
+ }
17
+ }
18
+ throw new Error('Could not find project root (package.json not found)');
19
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.131",
3
+ "version": "1.0.132",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/server/index.js",
7
7
  "bin": {
8
- "registry-proxy": "dist/server/index.js"
8
+ "registry-proxy": "dist/server/index.js",
9
+ "yarn-install": "dist/client/yarn-install.js"
9
10
  },
10
11
  "files": [
11
12
  "dist"