@@ -2,12 +2,64 @@ import { createReadStream, lstat, readFileSync, statSync } from 'fs-extra'
22import glob from 'globby'
33import { join } from 'path'
44import { reject } from 'ramda'
5+ import { PassThrough } from 'stream'
56import { BatchStream } from '../typings/types'
67
8+ /**
9+ * Expands environment variables in .npmrc file content
10+ * @param content The original .npmrc file content
11+ * @returns The content with environment variables expanded
12+ */
13+ const expandEnvironmentVariables = ( content : string ) : string => {
14+ return content . replace ( / \$ \{ ( [ ^ } ] + ) \} / g, ( _ , envVar ) => {
15+ const value = process . env [ envVar ]
16+ if ( value === undefined ) {
17+ throw new Error ( `Environment variable ${ envVar } is not defined` )
18+ }
19+ return value
20+ } )
21+ }
22+
23+ /**
24+ * Creates a stream from a string
25+ * @param str The string to convert to a stream
26+ * @returns A readable stream
27+ */
28+ const stringToStream = ( str : string ) => {
29+ const stream = new PassThrough ( )
30+ stream . end ( str )
31+ return stream
32+ }
33+
734export const createPathToFileObject = ( root : string , prefix = '' ) => {
835 return ( path : string ) : BatchStream => {
936 const realAbsolutePath = join ( root , path )
1037 const stats = statSync ( realAbsolutePath )
38+
39+ // Check if this is a .npmrc file that needs environment variable expansion
40+ if ( path . endsWith ( '.npmrc' ) ) {
41+ try {
42+ const originalContent = readFileSync ( realAbsolutePath , 'utf8' )
43+ const expandedContent = expandEnvironmentVariables ( originalContent )
44+ const expandedStream = stringToStream ( expandedContent )
45+
46+ return {
47+ path : join ( prefix , path ) ,
48+ content : expandedStream ,
49+ byteSize : Buffer . byteLength ( expandedContent , 'utf8' ) ,
50+ }
51+ } catch ( error ) {
52+ // If environment variable expansion fails, fall back to original file
53+ console . warn ( `Warning: Failed to expand environment variables in ${ path } : ${ error . message } ` )
54+ return {
55+ path : join ( prefix , path ) ,
56+ content : createReadStream ( realAbsolutePath ) ,
57+ byteSize : stats . size ,
58+ }
59+ }
60+ }
61+
62+ // For all other files, use the original behavior
1163 return {
1264 path : join ( prefix , path ) ,
1365 content : createReadStream ( realAbsolutePath ) ,
@@ -52,7 +104,7 @@ export class ProjectFilesManager {
52104 }
53105
54106 public async getLocalFiles ( test = false ) : Promise < string [ ] > {
55- const files : string [ ] = await glob ( [ 'manifest.json' , 'policies.json' , 'node/.*' , 'react/.*' ] , {
107+ const files : string [ ] = await glob ( [ 'manifest.json' , 'policies.json' , '.npmrc' , ' node/.*', 'react/.*' ] , {
56108 cwd : this . root ,
57109 follow : true ,
58110 ignore : this . getIgnoredPaths ( test ) ,
0 commit comments