Skip to content

Commit

Permalink
fix(js): fix verdaccio windows for registry (#27350)
Browse files Browse the repository at this point in the history
<!-- 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
  • Loading branch information
xiongemi authored Aug 22, 2024
1 parent d6a0cfb commit 00710b9
Showing 1 changed file with 43 additions and 44 deletions.
87 changes: 43 additions & 44 deletions packages/js/src/executors/verdaccio/verdaccio.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ function setupNpm(options: VerdaccioExecutorSchema) {

try {
scopes.forEach((scope) => {
const scopeName = scope ? `${scope}:` : '';
const registryName = scope ? `${scope}:registry` : 'registry';
try {
npmRegistryPaths.push(
execSync(
`npm config get '${scopeName}registry' --location ${options.location}`,
`npm config get ${registryName} --location ${options.location}`,
{ env }
)
?.toString()
?.trim()
?.replace('\u001b[2K\u001b[1G', '') // strip out ansi codes
);
execSync(
`npm config set '${scopeName}registry' http://localhost:${options.port}/ --location ${options.location}`,
`npm config set ${registryName} http://localhost:${options.port}/ --location ${options.location}`,
{ env }
);

Expand All @@ -168,11 +168,11 @@ function setupNpm(options: VerdaccioExecutorSchema) {
);

logger.info(
`Set npm ${scopeName}registry to http://localhost:${options.port}/`
`Set npm ${registryName} to http://localhost:${options.port}/`
);
} catch (e) {
throw new Error(
`Failed to set npm ${scopeName}registry to http://localhost:${options.port}/: ${e.message}`
`Failed to set npm ${registryName} to http://localhost:${options.port}/: ${e.message}`
);
}
});
Expand All @@ -186,30 +186,29 @@ function setupNpm(options: VerdaccioExecutorSchema) {
?.toString()
?.trim()
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
if (
npmRegistryPaths.length > 0 &&
currentNpmRegistryPath.includes('localhost')
) {
scopes.forEach((scope, index) => {
const scopeName = scope ? `${scope}:` : '';

scopes.forEach((scope, index) => {
const registryName = scope ? `${scope}:registry` : 'registry';
if (
npmRegistryPaths[index] &&
currentNpmRegistryPath.includes('localhost')
) {
execSync(
`npm config set '${scopeName}registry' ${npmRegistryPaths[index]} --location ${options.location}`,
`npm config set ${registryName} ${npmRegistryPaths[index]} --location ${options.location}`,
{ env }
);
logger.info(
`Reset npm ${scopeName}registry to ${npmRegistryPaths[index]}`
`Reset npm ${registryName} to ${npmRegistryPaths[index]}`
);
});
} else {
execSync(
`npm config delete registry --location ${options.location}`,
{
env,
}
);
logger.info('Cleared custom npm registry');
}
} else {
execSync(
`npm config delete ${registryName} --location ${options.location}`,
{
env,
}
);
logger.info('Cleared custom npm registry');
}
});
execSync(
`npm config delete //localhost:${options.port}/:_authToken --location ${options.location}`,
{ env }
Expand Down Expand Up @@ -319,33 +318,33 @@ function setupYarn(options: VerdaccioExecutorSchema) {
?.toString()
?.trim()
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
if (
yarnRegistryPaths.length > 0 &&
currentYarnRegistryPath.includes('localhost')
) {
scopes.forEach((scope, index) => {
const scopeName = scope ? `${scope}:` : '';

scopes.forEach((scope, index) => {
const registryName = scope
? `${scope}:${registryConfigName}`
: registryConfigName;

if (
yarnRegistryPaths[index] &&
currentYarnRegistryPath.includes('localhost')
) {
execSync(
`yarn config set ${scopeName}${registryConfigName} ${yarnRegistryPaths[index]}` +
`yarn config set ${registryName} ${yarnRegistryPaths[index]}` +
(options.location === 'user' ? ' --home' : ''),
{ env }
);
logger.info(
`Reset yarn ${scopeName}${registryConfigName} to ${yarnRegistryPaths[index]}`
`Reset yarn ${registryName} to ${yarnRegistryPaths[index]}`
);
});
} else {
execSync(
`yarn config ${
isYarnV1 ? 'delete' : 'unset'
} ${registryConfigName}` +
(options.location === 'user' ? ' --home' : ''),
{ env }
);
logger.info(`Cleared custom yarn ${registryConfigName}`);
}

} else {
execSync(
`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryName}` +
(options.location === 'user' ? ' --home' : ''),
{ env }
);
logger.info(`Cleared custom yarn ${registryConfigName}`);
}
});
if (whitelistedLocalhost) {
const currentWhitelist: Set<string> =
getYarnUnsafeHttpWhitelist(isYarnV1);
Expand Down

0 comments on commit 00710b9

Please sign in to comment.