1- import * as core from '@actions/core'
2- import * as exec from '@actions/exec'
1+ import { info , debug , warning , saveState , setOutput , addPath } from '@actions/core'
2+ import { exec , getExecOutput } from '@actions/exec'
33import type { Inputs } from './types.js'
44import {
55 PACKAGE_NAME ,
6- NPM_REGISTRY ,
76 GITHUB_REGISTRY ,
87 State ,
98 Outputs ,
@@ -12,7 +11,7 @@ import {
1211export async function installVitePlus ( inputs : Inputs ) : Promise < void > {
1312 const { version, registry, githubToken } = inputs
1413
15- core . info ( `Installing ${ PACKAGE_NAME } @${ version } from ${ registry } registry...` )
14+ info ( `Installing ${ PACKAGE_NAME } @${ version } from ${ registry } registry...` )
1615
1716 // Validate GitHub token if using GitHub registry
1817 if ( registry === 'github' && ! githubToken ) {
@@ -26,30 +25,33 @@ export async function installVitePlus(inputs: Inputs): Promise<void> {
2625 const packageSpec =
2726 version === 'latest' ? PACKAGE_NAME : `${ PACKAGE_NAME } @${ version } `
2827
29- const registryUrl = registry === 'github' ? GITHUB_REGISTRY : NPM_REGISTRY
30-
31- // Run npm install -g
32- const args = [ 'install' , '-g' , packageSpec , `--registry=${ registryUrl } ` ]
33-
34- core . debug ( `Running: npm ${ args . join ( ' ' ) } ` )
28+ const args = [ 'install' , '-g' , packageSpec ]
3529
3630 // Set up environment for installation
31+ // Use environment variables instead of writing to .npmrc to prevent token theft
3732 const env : Record < string , string > = { }
3833 for ( const [ key , value ] of Object . entries ( process . env ) ) {
3934 if ( value !== undefined ) {
4035 env [ key ] = value
4136 }
4237 }
4338
44- // Configure registry auth for GitHub
39+ // Configure scoped registry for GitHub Package Registry via environment variables
40+ // This allows @voidzero -dev packages from GitHub while other packages use npm
4541 if ( registry === 'github' && githubToken ) {
46- env . NODE_AUTH_TOKEN = githubToken
42+ debug ( 'Configuring @voidzero-dev scoped registry for GitHub Package Registry' )
43+
44+ // npm reads environment variables in the format: npm_config_<key>
45+ // For scoped registry: @voidzero -dev:registry -> npm_config_@voidzero-dev:registry
46+ env [ 'npm_config_@voidzero-dev:registry' ] = GITHUB_REGISTRY
47+
48+ // For auth token: //npm.pkg.github.com/:_authToken -> npm_config_//npm.pkg.github.com/:_authToken
49+ env [ 'npm_config_//npm.pkg.github.com/:_authToken' ] = githubToken
4750 }
4851
49- const exitCode = await exec . exec ( 'npm' , args , {
50- env,
51- silent : false ,
52- } )
52+ debug ( `Running: npm ${ args . join ( ' ' ) } ` )
53+
54+ const exitCode = await exec ( 'npm' , args , { env } )
5355
5456 if ( exitCode !== 0 ) {
5557 throw new Error (
@@ -59,26 +61,26 @@ export async function installVitePlus(inputs: Inputs): Promise<void> {
5961
6062 // Verify installation and get version
6163 const installedVersion = await getInstalledVersion ( )
62- core . info ( `Successfully installed ${ PACKAGE_NAME } @${ installedVersion } ` )
64+ info ( `Successfully installed ${ PACKAGE_NAME } @${ installedVersion } ` )
6365
6466 // Save state for outputs
65- core . saveState ( State . InstalledVersion , installedVersion )
66- core . setOutput ( Outputs . Version , installedVersion )
67+ saveState ( State . InstalledVersion , installedVersion )
68+ setOutput ( Outputs . Version , installedVersion )
6769
6870 // Ensure global bin is in PATH
6971 await ensureGlobalBinInPath ( )
7072}
7173
7274async function getInstalledVersion ( ) : Promise < string > {
7375 try {
74- const result = await exec . getExecOutput ( 'vp' , [ '--version' ] , {
76+ const result = await getExecOutput ( 'vp' , [ '--version' ] , {
7577 silent : true ,
7678 } )
7779 return result . stdout . trim ( )
7880 } catch {
7981 // Fallback: check npm list
8082 try {
81- const result = await exec . getExecOutput (
83+ const result = await getExecOutput (
8284 'npm' ,
8385 [ 'list' , '-g' , PACKAGE_NAME , '--depth=0' , '--json' ] ,
8486 { silent : true }
@@ -95,15 +97,15 @@ async function getInstalledVersion(): Promise<string> {
9597
9698async function ensureGlobalBinInPath ( ) : Promise < void > {
9799 try {
98- const result = await exec . getExecOutput ( 'npm' , [ 'bin' , '-g' ] , {
100+ const result = await getExecOutput ( 'npm' , [ 'bin' , '-g' ] , {
99101 silent : true ,
100102 } )
101103 const globalBin = result . stdout . trim ( )
102104 if ( globalBin && ! process . env . PATH ?. includes ( globalBin ) ) {
103- core . addPath ( globalBin )
104- core . debug ( `Added ${ globalBin } to PATH` )
105+ addPath ( globalBin )
106+ debug ( `Added ${ globalBin } to PATH` )
105107 }
106108 } catch ( error ) {
107- core . warning ( `Could not determine global npm bin path: ${ error } ` )
109+ warning ( `Could not determine global npm bin path: ${ error } ` )
108110 }
109111}
0 commit comments