com.jimuwd.xian.registry-proxy 1.1.24 → 1.1.25
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 +14 -15
- package/package.json +1 -1
|
@@ -99,14 +99,13 @@ async function startLocalRegistryProxyServerAndYarnInstallWithoutCleanup() {
|
|
|
99
99
|
// Change to project root
|
|
100
100
|
process.chdir(INSTALLATION_ROOT);
|
|
101
101
|
// Start registry proxy
|
|
102
|
-
console.log(`Starting registry-proxy@${REGISTRY_PROXY_VERSION} in the background...`);
|
|
102
|
+
console.log(`Starting registry-proxy@${REGISTRY_PROXY_VERSION} local server in the background...`);
|
|
103
103
|
// 提示:这里借助了execa调用"yarn dlx"后台运行registry proxy server的功能,没有直接使用本地ts函数调用的方式启动本地代理服务器,因为后者不太容易达到后台运行的效果。
|
|
104
104
|
proxyProcess = execa('yarn', [
|
|
105
|
-
'dlx', '-p', `com.jimuwd.xian.registry-proxy@${REGISTRY_PROXY_VERSION}`,
|
|
106
|
-
'registry-proxy',
|
|
107
|
-
'.
|
|
108
|
-
'.yarnrc.yml',
|
|
109
|
-
path.join(process.env.HOME || '', '.yarnrc.yml'),
|
|
105
|
+
'dlx', '-p', `com.jimuwd.xian.registry-proxy@${REGISTRY_PROXY_VERSION}`, 'registry-proxy',
|
|
106
|
+
/*是不是可以传空,让server使用默认值?*/ '.registry-proxy.yml',
|
|
107
|
+
/*是不是可以传空,让server使用默认值?*/ '.yarnrc.yml',
|
|
108
|
+
/*是不是可以传空,让server使用默认值?*/ path.join(process.env.HOME || '', '.yarnrc.yml'),
|
|
110
109
|
/*之前是写死的静态端口40061,它有个缺点就是本地无法为多个项目工程并发执行yarn-install,现改为使用随机可用端口作为本地代理服务器端口,传'0'/''空串即可*/ '0'
|
|
111
110
|
], {
|
|
112
111
|
detached: true,
|
|
@@ -114,14 +113,14 @@ async function startLocalRegistryProxyServerAndYarnInstallWithoutCleanup() {
|
|
|
114
113
|
});
|
|
115
114
|
registerCleanup(async (_exitCode) => {
|
|
116
115
|
if (proxyProcess && !proxyProcess.killed) {
|
|
117
|
-
console.log('Stopping proxy server...');
|
|
116
|
+
console.log('Stopping registry-proxy local server...');
|
|
118
117
|
try {
|
|
119
118
|
proxyProcess.kill('SIGTERM');
|
|
120
119
|
await proxyProcess;
|
|
121
|
-
console.log('
|
|
120
|
+
console.log('Registry-proxy local server stopped.');
|
|
122
121
|
}
|
|
123
122
|
catch (err) { // cleanup程序不要抛出异常
|
|
124
|
-
console.error('
|
|
123
|
+
console.error('Registry-proxy local server stopping with error', err);
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
});
|
|
@@ -139,23 +138,23 @@ async function startLocalRegistryProxyServerAndYarnInstallWithoutCleanup() {
|
|
|
139
138
|
// Configure yarn
|
|
140
139
|
const { exitCode, stdout } = await execa('yarn', ['config', 'get', 'npmRegistryServer']);
|
|
141
140
|
const npmRegistryServer = (exitCode === 0 && stdout) ? stdout.trim() : undefined;
|
|
142
|
-
const localNpmRegistryServer = (await readYarnConfig('.yarnrc.yml')).npmRegistryServer;
|
|
141
|
+
const localNpmRegistryServer = (await readYarnConfig('.yarnrc.yml')).npmRegistryServer?.trim();
|
|
143
142
|
if (localNpmRegistryServer && localNpmRegistryServer === npmRegistryServer)
|
|
144
|
-
console.log(
|
|
143
|
+
console.log(`Using npmRegistryServer value in project local .yarnrc.yml: ${localNpmRegistryServer}`);
|
|
145
144
|
else
|
|
146
|
-
console.log(
|
|
145
|
+
console.log(`Using npmRegistryServer value in ${path.join(process.env.HOME || '', '.yarnrc.yml')}: ${npmRegistryServer}`);
|
|
147
146
|
await execa('yarn', ['config', 'set', 'npmRegistryServer', `http://127.0.0.1:${PROXY_PORT}`]);
|
|
148
147
|
console.log(`Set npmRegistryServer to http://127.0.0.1:${PROXY_PORT}`);
|
|
149
148
|
registerCleanup(async () => {
|
|
150
149
|
try {
|
|
151
150
|
//if (npmRegistryServer) {//不能用这个变量来恢复为原来的 npmRegistryServer,因为它可能是全局配置~/.yarnrc.yml内的配置值或yarn工具官方默认值,而非本地.yarnrc.yml配置值。
|
|
152
|
-
if (localNpmRegistryServer
|
|
151
|
+
if (localNpmRegistryServer) { //恢复为本地配置文件原来的 npmRegistryServer 配置值
|
|
153
152
|
await execa('yarn', ['config', 'set', 'npmRegistryServer', localNpmRegistryServer]);
|
|
154
|
-
console.log(`Recover npmRegistryServer to ${localNpmRegistryServer}
|
|
153
|
+
console.log(`Recover npmRegistryServer to ${localNpmRegistryServer} in local '.yarnrc.yml'.`);
|
|
155
154
|
}
|
|
156
155
|
else { //原来本地配置文件中没有npmRegistryServer,则重置npmRegistryServer
|
|
157
156
|
await execa('yarn', ['config', 'unset', 'npmRegistryServer']);
|
|
158
|
-
console.log(`Unset npmRegistryServer.`);
|
|
157
|
+
console.log(`Unset npmRegistryServer value in local '.yarnrc.yml'.`);
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
catch (err) { //cleanup程序不要抛出异常
|