com.jimuwd.xian.registry-proxy 1.1.21 → 1.1.24
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/client/yarn-install.js +95 -85
- package/dist/models.d.ts +34 -0
- package/dist/models.js +1 -0
- package/dist/server/index.js +4 -49
- package/dist/server/serverConfigReader.d.ts +8 -0
- package/dist/server/serverConfigReader.js +29 -0
- package/dist/utils/configFileReader.d.ts +13 -0
- package/dist/utils/configFileReader.js +35 -0
- package/dist/utils/logger.js +3 -3
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import { execa } from 'execa';
|
|
6
6
|
import findProjectRoot from "../utils/findProjectRoot.js";
|
|
7
7
|
import { isPortConnectable } from "../utils/portTester.js";
|
|
8
|
+
import { readYarnConfig } from "../utils/configFileReader.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';
|
|
@@ -63,105 +64,114 @@ function registerSignalHandler(handler) {
|
|
|
63
64
|
// Main implementation
|
|
64
65
|
async function main() {
|
|
65
66
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
await startLocalRegistryProxyServerAndYarnInstallWithoutCleanup();
|
|
68
|
+
await cleanup(0);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error('Error:', err instanceof Error ? err.message : String(err));
|
|
72
|
+
await cleanup(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function startLocalRegistryProxyServerAndYarnInstallWithoutCleanup() {
|
|
76
|
+
// Find project root as base dir to get config file and other tmp files.
|
|
77
|
+
const INSTALLATION_ROOT = await findProjectRoot();
|
|
78
|
+
const LOCK_FILE = path.join(INSTALLATION_ROOT, LOCK_FILE_NAME);
|
|
79
|
+
const PORT_FILE = path.join(INSTALLATION_ROOT, PORT_FILE_NAME);
|
|
80
|
+
// Check for existing lock file
|
|
81
|
+
try {
|
|
82
|
+
await fs.access(LOCK_FILE);
|
|
83
|
+
console.log(`Custom install script is already running (lock file ${LOCK_FILE} exists).`);
|
|
84
|
+
console.log(`If this is unexpected, please remove ${LOCK_FILE} and try again.`);
|
|
85
|
+
return cleanup(0);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
}
|
|
89
|
+
// Create lock file
|
|
90
|
+
await fs.writeFile(LOCK_FILE, process.pid.toString());
|
|
91
|
+
registerCleanup(async () => {
|
|
71
92
|
try {
|
|
72
|
-
await fs.
|
|
73
|
-
console.log(`Custom install script is already running (lock file ${LOCK_FILE} exists).`);
|
|
74
|
-
console.log(`If this is unexpected, please remove ${LOCK_FILE} and try again.`);
|
|
75
|
-
return cleanup(0);
|
|
93
|
+
await fs.unlink(LOCK_FILE);
|
|
76
94
|
}
|
|
77
|
-
catch {
|
|
95
|
+
catch (err) { //cleanup程序不要抛出任何异常
|
|
96
|
+
console.error(`Failed to delete lock file: ${LOCK_FILE}`, err);
|
|
78
97
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
});
|
|
99
|
+
// Change to project root
|
|
100
|
+
process.chdir(INSTALLATION_ROOT);
|
|
101
|
+
// Start registry proxy
|
|
102
|
+
console.log(`Starting registry-proxy@${REGISTRY_PROXY_VERSION} in the background...`);
|
|
103
|
+
// 提示:这里借助了execa调用"yarn dlx"后台运行registry proxy server的功能,没有直接使用本地ts函数调用的方式启动本地代理服务器,因为后者不太容易达到后台运行的效果。
|
|
104
|
+
proxyProcess = execa('yarn', [
|
|
105
|
+
'dlx', '-p', `com.jimuwd.xian.registry-proxy@${REGISTRY_PROXY_VERSION}`,
|
|
106
|
+
'registry-proxy',
|
|
107
|
+
'.registry-proxy.yml',
|
|
108
|
+
'.yarnrc.yml',
|
|
109
|
+
path.join(process.env.HOME || '', '.yarnrc.yml'),
|
|
110
|
+
/*之前是写死的静态端口40061,它有个缺点就是本地无法为多个项目工程并发执行yarn-install,现改为使用随机可用端口作为本地代理服务器端口,传'0'/''空串即可*/ '0'
|
|
111
|
+
], {
|
|
112
|
+
detached: true,
|
|
113
|
+
stdio: 'inherit'
|
|
114
|
+
});
|
|
115
|
+
registerCleanup(async (_exitCode) => {
|
|
116
|
+
if (proxyProcess && !proxyProcess.killed) {
|
|
117
|
+
console.log('Stopping proxy server...');
|
|
82
118
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.error(`Failed to delete lock file: ${LOCK_FILE}`, err);
|
|
119
|
+
proxyProcess.kill('SIGTERM');
|
|
120
|
+
await proxyProcess;
|
|
121
|
+
console.log('Proxy server stopped.');
|
|
87
122
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
process.chdir(INSTALLATION_ROOT);
|
|
91
|
-
// Start registry proxy
|
|
92
|
-
console.log(`Starting registry-proxy@${REGISTRY_PROXY_VERSION} in the background...`);
|
|
93
|
-
// 提示:这里借助了execa调用"yarn dlx"后台运行registry proxy server的功能,没有直接使用本地ts函数调用的方式启动本地代理服务器,因为后者不太容易达到后台运行的效果。
|
|
94
|
-
proxyProcess = execa('yarn', [
|
|
95
|
-
'dlx', '-p', `com.jimuwd.xian.registry-proxy@${REGISTRY_PROXY_VERSION}`,
|
|
96
|
-
'registry-proxy',
|
|
97
|
-
'.registry-proxy.yml',
|
|
98
|
-
'.yarnrc.yml',
|
|
99
|
-
path.join(process.env.HOME || '', '.yarnrc.yml'),
|
|
100
|
-
/*之前是写死的静态端口40061,它有个缺点就是本地无法为多个项目工程并发执行yarn-install,现改为使用随机可用端口作为本地代理服务器端口,传'0'/''空串即可*/ '0'
|
|
101
|
-
], {
|
|
102
|
-
detached: true,
|
|
103
|
-
stdio: 'inherit'
|
|
104
|
-
});
|
|
105
|
-
registerCleanup(async (exitCode) => {
|
|
106
|
-
if (proxyProcess && !proxyProcess.killed) {
|
|
107
|
-
console.log('Stopping proxy server...');
|
|
108
|
-
try {
|
|
109
|
-
proxyProcess.kill('SIGTERM');
|
|
110
|
-
await proxyProcess;
|
|
111
|
-
console.log('Proxy server stopped.');
|
|
112
|
-
}
|
|
113
|
-
catch (err) { // cleanup程序不要抛出异常
|
|
114
|
-
console.error('Proxy server stopping with error', err);
|
|
115
|
-
}
|
|
123
|
+
catch (err) { // cleanup程序不要抛出异常
|
|
124
|
+
console.error('Proxy server stopping with error', err);
|
|
116
125
|
}
|
|
117
|
-
});
|
|
118
|
-
// Wait for proxy to start
|
|
119
|
-
console.log('Waiting for proxy server to start (up to 30 seconds)...');
|
|
120
|
-
const fileExists = await waitForFile(PORT_FILE, MAX_WAIT_TIME_MS);
|
|
121
|
-
if (!fileExists) {
|
|
122
|
-
throw new Error(`Proxy server failed to create port file after ${MAX_WAIT_TIME_MS / 1000} seconds`);
|
|
123
|
-
}
|
|
124
|
-
const PROXY_PORT = await readPortFile(PORT_FILE);
|
|
125
|
-
const portConnectable = await isPortConnectable(PROXY_PORT);
|
|
126
|
-
if (!portConnectable) {
|
|
127
|
-
throw new Error(`Proxy server not listening on port ${PROXY_PORT}`);
|
|
128
126
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
});
|
|
128
|
+
// Wait for proxy to start
|
|
129
|
+
console.log('Waiting for proxy server to start (up to 30 seconds)...');
|
|
130
|
+
const fileExists = await waitForFile(PORT_FILE, MAX_WAIT_TIME_MS);
|
|
131
|
+
if (!fileExists) {
|
|
132
|
+
throw new Error(`Proxy server failed to create port file after ${MAX_WAIT_TIME_MS / 1000} seconds`);
|
|
133
|
+
}
|
|
134
|
+
const PROXY_PORT = await readPortFile(PORT_FILE);
|
|
135
|
+
const portConnectable = await isPortConnectable(PROXY_PORT);
|
|
136
|
+
if (!portConnectable) {
|
|
137
|
+
throw new Error(`Proxy server not listening on port ${PROXY_PORT}`);
|
|
138
|
+
}
|
|
139
|
+
// Configure yarn
|
|
140
|
+
const { exitCode, stdout } = await execa('yarn', ['config', 'get', 'npmRegistryServer']);
|
|
141
|
+
const npmRegistryServer = (exitCode === 0 && stdout) ? stdout.trim() : undefined;
|
|
142
|
+
const localNpmRegistryServer = (await readYarnConfig('.yarnrc.yml')).npmRegistryServer;
|
|
143
|
+
if (localNpmRegistryServer && localNpmRegistryServer === npmRegistryServer)
|
|
144
|
+
console.log("Using npmRegistryServer value in project local .yarnrc.yml config file.");
|
|
145
|
+
else
|
|
146
|
+
console.log("Using npmRegistryServer value in global config file.");
|
|
147
|
+
await execa('yarn', ['config', 'set', 'npmRegistryServer', `http://127.0.0.1:${PROXY_PORT}`]);
|
|
148
|
+
console.log(`Set npmRegistryServer to http://127.0.0.1:${PROXY_PORT}`);
|
|
149
|
+
registerCleanup(async () => {
|
|
150
|
+
try {
|
|
151
|
+
//if (npmRegistryServer) {//不能用这个变量来恢复为原来的 npmRegistryServer,因为它可能是全局配置~/.yarnrc.yml内的配置值或yarn工具官方默认值,而非本地.yarnrc.yml配置值。
|
|
152
|
+
if (localNpmRegistryServer && localNpmRegistryServer.trim()) { //恢复为本地配置文件原来的 npmRegistryServer 配置值
|
|
153
|
+
await execa('yarn', ['config', 'set', 'npmRegistryServer', localNpmRegistryServer]);
|
|
154
|
+
console.log(`Recover npmRegistryServer to ${localNpmRegistryServer}`);
|
|
144
155
|
}
|
|
145
|
-
|
|
146
|
-
|
|
156
|
+
else { //原来本地配置文件中没有npmRegistryServer,则重置npmRegistryServer
|
|
157
|
+
await execa('yarn', ['config', 'unset', 'npmRegistryServer']);
|
|
158
|
+
console.log(`Unset npmRegistryServer.`);
|
|
147
159
|
}
|
|
148
|
-
});
|
|
149
|
-
// Run yarn install
|
|
150
|
-
console.log('Running yarn install...');
|
|
151
|
-
try {
|
|
152
|
-
await execa('yarn', ['install'], { stdio: 'inherit' });
|
|
153
160
|
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
|
|
161
|
+
catch (err) { //cleanup程序不要抛出异常
|
|
162
|
+
console.error('Recover yarn config npmRegistryServer error.', err);
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
});
|
|
165
|
+
// Run yarn install
|
|
166
|
+
console.log('Running yarn install...');
|
|
167
|
+
try {
|
|
168
|
+
await execa('yarn', ['install'], { stdio: 'inherit' });
|
|
160
169
|
}
|
|
161
170
|
catch (err) {
|
|
162
|
-
|
|
163
|
-
await cleanup(1);
|
|
171
|
+
throw new Error('yarn install failed');
|
|
164
172
|
}
|
|
173
|
+
// Success
|
|
174
|
+
console.info("Yarn install with local registry-proxy server success.");
|
|
165
175
|
}
|
|
166
176
|
// 当前模块是否是直接运行的入口文件,而不是被其他模块导入的
|
|
167
177
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
interface RegistryConfig {
|
|
2
|
+
npmAuthToken?: string;
|
|
3
|
+
}
|
|
4
|
+
interface HttpsConfig {
|
|
5
|
+
key: string;
|
|
6
|
+
cert: string;
|
|
7
|
+
}
|
|
8
|
+
interface ProxyConfig {
|
|
9
|
+
registries: Record<string, RegistryConfig | null>;
|
|
10
|
+
https?: HttpsConfig;
|
|
11
|
+
basePath?: string;
|
|
12
|
+
}
|
|
13
|
+
interface YarnConfig {
|
|
14
|
+
npmRegistryServer?: string | null | undefined;
|
|
15
|
+
npmRegistries?: Record<string, RegistryConfig | null>;
|
|
16
|
+
}
|
|
17
|
+
interface RegistryInfo {
|
|
18
|
+
normalizedRegistryUrl: string;
|
|
19
|
+
token?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ProxyInfo {
|
|
22
|
+
registries: RegistryInfo[];
|
|
23
|
+
https?: HttpsConfig;
|
|
24
|
+
basePath?: string;
|
|
25
|
+
}
|
|
26
|
+
interface PackageVersion {
|
|
27
|
+
dist?: {
|
|
28
|
+
tarball?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface PackageData {
|
|
32
|
+
versions?: Record<string, PackageVersion>;
|
|
33
|
+
}
|
|
34
|
+
export { RegistryConfig, HttpsConfig, ProxyConfig, YarnConfig, RegistryInfo, ProxyInfo, PackageVersion, PackageData };
|
package/dist/models.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/server/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import http, { createServer } from 'node:http';
|
|
3
3
|
import https, { createServer as createHttpsServer } from 'node:https';
|
|
4
|
-
import {
|
|
5
|
-
import { load } from 'js-yaml';
|
|
4
|
+
import { promises as fsPromises, readFileSync } from 'node:fs';
|
|
6
5
|
import fetch from 'node-fetch';
|
|
7
6
|
import { homedir } from 'os';
|
|
8
|
-
import { join
|
|
7
|
+
import { join } from 'path';
|
|
9
8
|
import { URL } from 'url';
|
|
10
9
|
import logger from "../utils/logger.js";
|
|
11
10
|
import ConcurrencyLimiter from "../utils/ConcurrencyLimiter.js";
|
|
12
11
|
import { gracefulShutdown, registerProcessShutdownHook } from "./gracefullShutdown.js";
|
|
13
12
|
import { writePortFile } from "../port.js";
|
|
14
13
|
import resolveEnvValue from "../utils/resolveEnvValue.js";
|
|
15
|
-
|
|
14
|
+
import { readYarnConfig, resolvePath, } from "../utils/configFileReader.js";
|
|
15
|
+
import { readProxyConfig, } from "./serverConfigReader.js";
|
|
16
16
|
// 整个registry-proxy server实例 使用的全局限流器
|
|
17
17
|
const LIMITER = new ConcurrencyLimiter(5);
|
|
18
18
|
function removeEndingSlashAndForceStartingSlash(str) {
|
|
@@ -44,9 +44,6 @@ function normalizeUrl(httpOrHttpsUrl) {
|
|
|
44
44
|
throw new Error(`Invalid URL: ${httpOrHttpsUrl}`, { cause: e });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
function resolvePath(path) {
|
|
48
|
-
return path.startsWith('~/') ? join(homedir(), path.slice(2)) : resolve(path);
|
|
49
|
-
}
|
|
50
47
|
function removeRegistryPrefix(tarballUrl, registries) {
|
|
51
48
|
const normalizedTarball = normalizeUrl(tarballUrl);
|
|
52
49
|
const normalizedRegistries = registries
|
|
@@ -59,48 +56,6 @@ function removeRegistryPrefix(tarballUrl, registries) {
|
|
|
59
56
|
}
|
|
60
57
|
throw new Error(`Can't find tarball url ${tarballUrl} does not match given registries ${normalizedRegistries}`);
|
|
61
58
|
}
|
|
62
|
-
/**
|
|
63
|
-
* 读取yml配置文件得到配置值对象{@link ProxyConfig}
|
|
64
|
-
* @note 本读取操作不会解析环境变量值
|
|
65
|
-
* @param proxyConfigPath 配置文件路径
|
|
66
|
-
*/
|
|
67
|
-
async function readProxyConfig(proxyConfigPath = './.registry-proxy.yml') {
|
|
68
|
-
let config = undefined;
|
|
69
|
-
const resolvedPath = resolvePath(proxyConfigPath);
|
|
70
|
-
try {
|
|
71
|
-
const content = await readFile(resolvedPath, 'utf8');
|
|
72
|
-
config = load(content);
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
logger.error(`Failed to load proxy config from ${resolvedPath}:`, e);
|
|
76
|
-
await gracefulShutdown();
|
|
77
|
-
}
|
|
78
|
-
if (!config?.registries) {
|
|
79
|
-
logger.error('Missing required "registries" field in config');
|
|
80
|
-
await gracefulShutdown();
|
|
81
|
-
}
|
|
82
|
-
return config;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 读取yml配置文件为yml对象
|
|
86
|
-
* @param path yml文件路径
|
|
87
|
-
*/
|
|
88
|
-
async function readYarnConfig(path) {
|
|
89
|
-
try {
|
|
90
|
-
if (existsSync(path)) {
|
|
91
|
-
const content = await readFile(resolvePath(path), 'utf8');
|
|
92
|
-
return load(content);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
logger.info(`Skip reading ${path}, because it does not exist.`);
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
logger.warn(`Failed to load Yarn config from ${path}:`, e);
|
|
101
|
-
return {};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
59
|
async function loadProxyInfo(proxyConfigPath = './.registry-proxy.yml', localYarnConfigPath = './.yarnrc.yml', globalYarnConfigPath = join(homedir(), '.yarnrc.yml')) {
|
|
105
60
|
const [proxyConfig, localYarnConfig, globalYarnConfig] = await Promise.all([
|
|
106
61
|
readProxyConfig(proxyConfigPath),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ProxyConfig } from "../models.js";
|
|
2
|
+
/**
|
|
3
|
+
* 读取yml配置文件得到配置值对象{@link ProxyConfig}
|
|
4
|
+
* @note 本读取操作不会解析环境变量值
|
|
5
|
+
* @param proxyConfigPath 配置文件路径
|
|
6
|
+
*/
|
|
7
|
+
declare function readProxyConfig(proxyConfigPath?: string): Promise<ProxyConfig>;
|
|
8
|
+
export { readProxyConfig };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { load } from "js-yaml";
|
|
2
|
+
import { promises as fsPromises } from 'node:fs';
|
|
3
|
+
import { gracefulShutdown } from "./gracefullShutdown.js";
|
|
4
|
+
import { resolvePath } from "../utils/configFileReader.js";
|
|
5
|
+
import logger from "../utils/logger.js";
|
|
6
|
+
const { readFile } = fsPromises;
|
|
7
|
+
/**
|
|
8
|
+
* 读取yml配置文件得到配置值对象{@link ProxyConfig}
|
|
9
|
+
* @note 本读取操作不会解析环境变量值
|
|
10
|
+
* @param proxyConfigPath 配置文件路径
|
|
11
|
+
*/
|
|
12
|
+
async function readProxyConfig(proxyConfigPath = './.registry-proxy.yml') {
|
|
13
|
+
let config = undefined;
|
|
14
|
+
const resolvedPath = resolvePath(proxyConfigPath);
|
|
15
|
+
try {
|
|
16
|
+
const content = await readFile(resolvedPath, 'utf8');
|
|
17
|
+
config = load(content);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
logger.error(`Failed to load proxy config from ${resolvedPath}:`, e);
|
|
21
|
+
await gracefulShutdown();
|
|
22
|
+
}
|
|
23
|
+
if (!config?.registries) {
|
|
24
|
+
logger.error('Missing required "registries" field in config');
|
|
25
|
+
await gracefulShutdown();
|
|
26
|
+
}
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
export { readProxyConfig };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { YarnConfig } from "../models.js";
|
|
2
|
+
/**
|
|
3
|
+
* 读取yml配置文件为yml对象
|
|
4
|
+
* @note 如果配置文件不存在,那么返回空对象,不抛异常。
|
|
5
|
+
* @param path yml文件路径
|
|
6
|
+
*/
|
|
7
|
+
declare function readYarnConfig(path: string): Promise<YarnConfig>;
|
|
8
|
+
/**
|
|
9
|
+
* 标准化处理路径值
|
|
10
|
+
* @param path
|
|
11
|
+
*/
|
|
12
|
+
declare function resolvePath(path: string): string;
|
|
13
|
+
export { readYarnConfig, resolvePath, };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { load } from "js-yaml";
|
|
2
|
+
import { join, resolve } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { existsSync, promises as fsPromises } from 'node:fs';
|
|
5
|
+
import logger from "./logger.js";
|
|
6
|
+
const { readFile } = fsPromises;
|
|
7
|
+
/**
|
|
8
|
+
* 读取yml配置文件为yml对象
|
|
9
|
+
* @note 如果配置文件不存在,那么返回空对象,不抛异常。
|
|
10
|
+
* @param path yml文件路径
|
|
11
|
+
*/
|
|
12
|
+
async function readYarnConfig(path) {
|
|
13
|
+
try {
|
|
14
|
+
if (existsSync(path)) {
|
|
15
|
+
const content = await readFile(resolvePath(path), 'utf8');
|
|
16
|
+
return load(content);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
logger.info(`Skip reading ${path}, because it does not exist.`);
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger.warn(`Failed to load Yarn config from ${path}:`, e);
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 标准化处理路径值
|
|
30
|
+
* @param path
|
|
31
|
+
*/
|
|
32
|
+
function resolvePath(path) {
|
|
33
|
+
return path.startsWith('~/') ? join(homedir(), path.slice(2)) : resolve(path);
|
|
34
|
+
}
|
|
35
|
+
export { readYarnConfig, resolvePath, };
|
package/dist/utils/logger.js
CHANGED
|
@@ -15,10 +15,10 @@ const PREFIX = {
|
|
|
15
15
|
};
|
|
16
16
|
// 代理服务器专用日志
|
|
17
17
|
const logger = {
|
|
18
|
-
info: (...args) =>
|
|
19
|
-
success: (...args) =>
|
|
18
|
+
info: (...args) => { },
|
|
19
|
+
success: (...args) => { },
|
|
20
20
|
error: (...args) => console.error(`${PREFIX.error}`, ...args),
|
|
21
|
-
warn: (...args) =>
|
|
21
|
+
warn: (...args) => { },
|
|
22
22
|
debug: (...args) => process.env.DEBUG && console.debug(`${PREFIX.debug}`, ...args)
|
|
23
23
|
};
|
|
24
24
|
export default logger;
|