@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
22import type { RadioChangeEvent } from "antd" ;
33import { Input , Radio , Space , Spin } from "antd" ;
44import { Command } from "@tauri-apps/api/shell" ;
5+ import { platform } from "@tauri-apps/api/os" ;
56
67const Npm : React . FC = ( ) => {
78 const [ customUrl , setCustomUrl ] = useState < string > ( "" ) ;
@@ -50,9 +51,16 @@ const Npm: React.FC = () => {
5051 const [ value , setValue ] = useState < string > ( "" ) ;
5152 const [ url , setUrl ] = useState < string > ( "" ) ;
5253
54+ async function getNpmProgram ( ) {
55+ const platformName = await platform ( ) ;
56+ return / ^ w i n / i. test ( platformName ) ? "run-npm.cmd" : "run-npm" ;
57+ }
58+
5359 function getUrl ( ) : Promise < string > {
54- return new Promise < string > ( ( resolve ) => {
55- const command = new Command ( "run-npm" , [ "config" , "get" , "registry" ] ) ;
60+ return new Promise < string > ( async ( resolve ) => {
61+ const platformName = await platform ( ) ;
62+ const program = / ^ w i n / i. test ( platformName ) ? "run-npm-cmd" : "run-npm" ;
63+ const command = new Command ( program , [ "config" , "get" , "registry" ] ) ;
5664 let url = "" ;
5765
5866 command . stdout . on ( "data" , ( line ) => {
@@ -68,6 +76,12 @@ const Npm: React.FC = () => {
6876 } ) ;
6977 }
7078
79+ async function writeUrlToFile ( url : string ) {
80+ const program = await getNpmProgram ( ) ;
81+ const command = new Command ( program , [ "config" , "set" , "registry" , url ] ) ;
82+ await command . spawn ( ) ;
83+ }
84+
7185 const initRadio = ( ) => {
7286 const option = npmOptions . find (
7387 ( option ) =>
@@ -110,11 +124,6 @@ const Npm: React.FC = () => {
110124 ) ;
111125 }
112126
113- async function writeUrlToFile ( url : string ) {
114- const command = new Command ( "run-npm" , [ "config" , "set" , "registry" , url ] ) ;
115- await command . spawn ( ) ;
116- }
117-
118127 const onChange = async ( e : RadioChangeEvent ) => {
119128 let checkedValue = e . target . value ;
120129 setValue ( checkedValue ) ;
0 commit comments