Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 53 additions & 14 deletions .ado/scripts/npmAddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// @ts-check

const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const os = require("os");

const username = process.argv[2];
const password = process.argv[3];
Expand All @@ -23,18 +26,54 @@ if (!email) {
process.exit(1);
}

const child = child_process.exec(`npm adduser${registry? (' --registry ' + registry) :''}` );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

child.stdin.write waits for prompts that never properly complete , for node 22 and verdaccio and its not itermittent in nature hence added non-interactive approach using npm config set commands to set authentication


child.stdout.on("data", d => {
const data = d.toString();
process.stdout.write(d + "\n");
if (data.match(/username/i)) {
child.stdin.write(username + "\n");
} else if (data.match(/password/i)) {
child.stdin.write(password + "\n");
} else if (data.match(/email/i)) {
child.stdin.write(email + "\n");
} else if (data.match(/logged in as/i)) {
child.stdin.end();
}
const registryUrl = registry || "http://localhost:4873";

// First set the registry
console.log(`Setting npm registry to ${registryUrl}`);
const setRegistry = child_process.spawnSync('npm', ['config', 'set', 'registry', registryUrl], {
stdio: 'inherit',
shell: true
});

if (setRegistry.status !== 0) {
console.error('Failed to set registry');
process.exit(1);
}

// Create auth token for verdaccio
const authString = Buffer.from(`${username}:${password}`).toString('base64');
const registryPath = registryUrl.replace(/^https?:/, '');

// Set auth in npm config
console.log('Setting authentication...');
const setAuth = child_process.spawnSync('npm', ['config', 'set', `${registryPath}/:_auth`, authString], {
stdio: 'inherit',
shell: true
});

if (setAuth.status !== 0) {
console.error('Failed to set auth');
process.exit(1);
}

// Set email
const setEmail = child_process.spawnSync('npm', ['config', 'set', 'email', email], {
stdio: 'inherit',
shell: true
});

// Verify authentication
console.log('Verifying authentication...');
const whoami = child_process.spawnSync('npm', ['whoami', '--registry', registryUrl], {
encoding: 'utf8',
shell: true
});

if (whoami.status === 0 && whoami.stdout.trim()) {
console.log(`Logged in as ${whoami.stdout.trim()} on ${registryUrl}`);
process.exit(0);
} else {
console.error('Authentication verification failed');
if (whoami.stderr) console.error('Error:', whoami.stderr);
process.exit(1);
}
6 changes: 3 additions & 3 deletions .ado/windows-vs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ parameters:
default:
Small:
name: rnw-pool-2
demands: ImageOverride -equals rnw-img-vs2022-node18
demands: ImageOverride -equals rnw-img-vs2022-node22
Medium:
name: rnw-pool-4
demands: ImageOverride -equals rnw-img-vs2022-node18
demands: ImageOverride -equals rnw-img-vs2022-node22
Large:
name: rnw-pool-8
demands: ImageOverride -equals rnw-img-vs2022-node18
demands: ImageOverride -equals rnw-img-vs2022-node22

stages:
- template: stages.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "replace npm commands with yarn to solve connection issue npm 10.5.1",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
28 changes: 14 additions & 14 deletions vnext/Scripts/creaternwapp.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ if not "%part%"=="" (
:loopend

if %USE_VERDACCIO% equ 1 (
@echo creaternwapp.cmd: Setting npm to use verdaccio at http://localhost:4873
call npm config set registry http://localhost:4873
@echo creaternwapp.cmd: Setting yarn to use verdaccio at http://localhost:4873
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all npm commands and replaced with yarn equivalent as workaround for npm 10.5.1 has a bug with Verdaccio that causes ECONNREFUSED errors particular to node version >= 21 ( we updated to 22) .

call yarn config set registry http://localhost:4873
)

if %LINK_RNW% equ 1 (
@echo creaternwapp.cmd Determining versions from local RNW repo at %RNW_ROOT%
for /f "delims=" %%a in ('npm show "%RNW_ROOT%\vnext" devDependencies.react') do @set R_VERSION=%%a
for /f "delims=" %%a in ('npm show "%RNW_ROOT%\vnext" devDependencies.react-native') do @set RN_VERSION=%%a
for /f "delims=" %%a in ('npm show "%RNW_ROOT%\vnext" version') do @set RNW_VERSION=%%a
for /f "delims=" %%a in ('npm show "%RNW_ROOT%\vnext" dependencies.@react-native-community/cli') do @set RNCLI_VERSION=%%a
for /f "delims=" %%a in ('yarn info "%RNW_ROOT%\vnext" devDependencies.react --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty devDependencies | Select-Object -ExpandProperty react"') do @set R_VERSION=%%a
for /f "delims=" %%a in ('yarn info "%RNW_ROOT%\vnext" devDependencies.react-native --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty devDependencies | Select-Object -ExpandProperty 'react-native'"') do @set RN_VERSION=%%a
for /f "delims=" %%a in ('yarn info "%RNW_ROOT%\vnext" version --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data"') do @set RNW_VERSION=%%a
for /f "delims=" %%a in ('yarn info "%RNW_ROOT%\vnext" dependencies.@react-native-community/cli --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty dependencies | Select-Object -ExpandProperty '@react-native-community/cli'"') do @set RNCLI_VERSION=%%a
)

if "%RNW_VERSION%"=="" (
Expand All @@ -90,31 +90,31 @@ if "%RNW_VERSION%"=="" (

if "%RN_VERSION%"=="" (
@echo creaternwapp.cmd Determining react-native version from react-native-windows dependency
for /f "delims=" %%a in ('npm show react-native-windows@%RNW_VERSION% devDependencies.react-native') do @set RN_VERSION=%%a
for /f "delims=" %%a in ('yarn info react-native-windows@%RNW_VERSION% devDependencies.react-native --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty devDependencies | Select-Object -ExpandProperty 'react-native'"') do @set RN_VERSION=%%a
)

if "%RNCLI_VERSION%"=="" (
@echo creaternwapp.cmd Determining @react-native-community/cli version from react-native-windows dependency
for /f "delims=" %%a in ('npm show react-native-windows@%RNW_VERSION% dependencies.@react-native-community/cli') do @set RNCLI_VERSION=%%a
for /f "delims=" %%a in ('yarn info react-native-windows@%RNW_VERSION% dependencies.@react-native-community/cli --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty dependencies | Select-Object -ExpandProperty '@react-native-community/cli'"') do @set RNCLI_VERSION=%%a
)

if "%R_VERSION%"=="" (
@echo creaternwapp.cmd Determining react version from react-native-windows dependency
for /f "delims=" %%a in ('npm show react-native-windows@%RNW_VERSION% devDependencies.react') do @set R_VERSION=%%a
for /f "delims=" %%a in ('yarn info react-native-windows@%RNW_VERSION% devDependencies.react --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data | Select-Object -ExpandProperty devDependencies | Select-Object -ExpandProperty react"') do @set R_VERSION=%%a
)

@echo creaternwapp.cmd Determining concrete versions for react@%R_VERSION%, react-native@%RN_VERSION%, @react-native-community/cli@%RNCLI_VERSION%, and react-native-windows@%RNW_VERSION%
for /f "delims=" %%a in ('npm show react-native-windows@%RNW_VERSION% version') do @set RNW_VERSION=%%a
for /f "delims=" %%a in ('npm show react-native@%RN_VERSION% version') do @set RN_VERSION=%%a
for /f "delims=" %%a in ('npm show @react-native-community/cli@%RNCLI_VERSION% version') do @set RNCLI_VERSION=%%a
for /f "delims=" %%a in ('npm show react@%R_VERSION% version') do @set R_VERSION=%%a
for /f "delims=" %%a in ('yarn info react-native-windows@%RNW_VERSION% version --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data"') do @set RNW_VERSION=%%a
for /f "delims=" %%a in ('yarn info react-native@%RN_VERSION% version --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data"') do @set RN_VERSION=%%a
for /f "delims=" %%a in ('yarn info @react-native-community/cli@%RNCLI_VERSION% version --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data"') do @set RNCLI_VERSION=%%a
for /f "delims=" %%a in ('yarn info react@%R_VERSION% version --json ^| powershell -Command "$input | ConvertFrom-Json | Select-Object -ExpandProperty data"') do @set R_VERSION=%%a

@echo creaternwapp.cmd Creating RNW app "%APP_NAME%" with react@%R_VERSION%, react-native@%RN_VERSION%, and react-native-windows@%RNW_VERSION%

set RNCLI_TEMPLATE=
if not "x%RN_VERSION:nightly=%"=="x%RN_VERSION%" (
@echo creaternwapp.cmd Override @react-native-community/template version
set RNCLI_TEMPLATE=--template "@react-native-community/template@^%RN_VERSION:~0,4%.0-"
set RNCLI_TEMPLATE=--template "@react-native-community/template@%RN_VERSION:~0,4%.0-"
)

@echo creaternwapp.cmd: Creating base RN app project with: npx --yes @react-native-community/cli@latest init %APP_NAME% --version %RN_VERSION% %RNCLI_TEMPLATE% --verbose --skip-install --install-pods false --skip-git-init true
Expand Down
Loading