Skip to content

Commit 00710b9

Browse files
authored
fix(js): fix verdaccio windows for registry (#27350)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #27135
1 parent d6a0cfb commit 00710b9

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

packages/js/src/executors/verdaccio/verdaccio.impl.ts

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ function setupNpm(options: VerdaccioExecutorSchema) {
146146

147147
try {
148148
scopes.forEach((scope) => {
149-
const scopeName = scope ? `${scope}:` : '';
149+
const registryName = scope ? `${scope}:registry` : 'registry';
150150
try {
151151
npmRegistryPaths.push(
152152
execSync(
153-
`npm config get '${scopeName}registry' --location ${options.location}`,
153+
`npm config get ${registryName} --location ${options.location}`,
154154
{ env }
155155
)
156156
?.toString()
157157
?.trim()
158158
?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
159159
);
160160
execSync(
161-
`npm config set '${scopeName}registry' http://localhost:${options.port}/ --location ${options.location}`,
161+
`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`,
162162
{ env }
163163
);
164164

@@ -168,11 +168,11 @@ function setupNpm(options: VerdaccioExecutorSchema) {
168168
);
169169

170170
logger.info(
171-
`Set npm ${scopeName}registry to http://localhost:${options.port}/`
171+
`Set npm ${registryName} to http://localhost:${options.port}/`
172172
);
173173
} catch (e) {
174174
throw new Error(
175-
`Failed to set npm ${scopeName}registry to http://localhost:${options.port}/: ${e.message}`
175+
`Failed to set npm ${registryName} to http://localhost:${options.port}/: ${e.message}`
176176
);
177177
}
178178
});
@@ -186,30 +186,29 @@ function setupNpm(options: VerdaccioExecutorSchema) {
186186
?.toString()
187187
?.trim()
188188
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
189-
if (
190-
npmRegistryPaths.length > 0 &&
191-
currentNpmRegistryPath.includes('localhost')
192-
) {
193-
scopes.forEach((scope, index) => {
194-
const scopeName = scope ? `${scope}:` : '';
195-
189+
scopes.forEach((scope, index) => {
190+
const registryName = scope ? `${scope}:registry` : 'registry';
191+
if (
192+
npmRegistryPaths[index] &&
193+
currentNpmRegistryPath.includes('localhost')
194+
) {
196195
execSync(
197-
`npm config set '${scopeName}registry' ${npmRegistryPaths[index]} --location ${options.location}`,
196+
`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`,
198197
{ env }
199198
);
200199
logger.info(
201-
`Reset npm ${scopeName}registry to ${npmRegistryPaths[index]}`
200+
`Reset npm ${registryName} to ${npmRegistryPaths[index]}`
202201
);
203-
});
204-
} else {
205-
execSync(
206-
`npm config delete registry --location ${options.location}`,
207-
{
208-
env,
209-
}
210-
);
211-
logger.info('Cleared custom npm registry');
212-
}
202+
} else {
203+
execSync(
204+
`npm config delete ${registryName} --location ${options.location}`,
205+
{
206+
env,
207+
}
208+
);
209+
logger.info('Cleared custom npm registry');
210+
}
211+
});
213212
execSync(
214213
`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`,
215214
{ env }
@@ -319,33 +318,33 @@ function setupYarn(options: VerdaccioExecutorSchema) {
319318
?.toString()
320319
?.trim()
321320
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
322-
if (
323-
yarnRegistryPaths.length > 0 &&
324-
currentYarnRegistryPath.includes('localhost')
325-
) {
326-
scopes.forEach((scope, index) => {
327-
const scopeName = scope ? `${scope}:` : '';
328321

322+
scopes.forEach((scope, index) => {
323+
const registryName = scope
324+
? `${scope}:${registryConfigName}`
325+
: registryConfigName;
326+
327+
if (
328+
yarnRegistryPaths[index] &&
329+
currentYarnRegistryPath.includes('localhost')
330+
) {
329331
execSync(
330-
`yarn config set ${scopeName}${registryConfigName} ${yarnRegistryPaths[index]}` +
332+
`yarn config set ${registryName} ${yarnRegistryPaths[index]}` +
331333
(options.location === 'user' ? ' --home' : ''),
332334
{ env }
333335
);
334336
logger.info(
335-
`Reset yarn ${scopeName}${registryConfigName} to ${yarnRegistryPaths[index]}`
337+
`Reset yarn ${registryName} to ${yarnRegistryPaths[index]}`
336338
);
337-
});
338-
} else {
339-
execSync(
340-
`yarn config ${
341-
isYarnV1 ? 'delete' : 'unset'
342-
} ${registryConfigName}` +
343-
(options.location === 'user' ? ' --home' : ''),
344-
{ env }
345-
);
346-
logger.info(`Cleared custom yarn ${registryConfigName}`);
347-
}
348-
339+
} else {
340+
execSync(
341+
`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryName}` +
342+
(options.location === 'user' ? ' --home' : ''),
343+
{ env }
344+
);
345+
logger.info(`Cleared custom yarn ${registryConfigName}`);
346+
}
347+
});
349348
if (whitelistedLocalhost) {
350349
const currentWhitelist: Set<string> =
351350
getYarnUnsafeHttpWhitelist(isYarnV1);

0 commit comments

Comments
 (0)