@@ -7,57 +7,18 @@ import { spawnSync } from 'child_process';
77 * Retrieve the path to the `npx` executable for interacting with the amplify gen2 cli.
88 * @returns the local `npx` executable path.
99 */
10- const getNpxPath = ( ) : string => {
11- console . log ( `DEBUG: process.platform is: ${ process . platform } ` ) ;
12- if ( process . platform === 'win32' ) {
13- const scriptRunnerPath = getScriptRunnerPath ( ) ;
14- console . log ( `DEBUG: getScriptRunnerPath() returned: ${ scriptRunnerPath } ` ) ;
15- const npxPath = scriptRunnerPath . replace ( 'node.exe' , 'npx.cmd' ) ;
16- console . log ( `DEBUG: Resolved npxPath for Windows: ${ npxPath } ` ) ;
17- return npxPath ;
18- } else {
19- console . log ( `DEBUG: Non-Windows platform; using 'npx'` ) ;
20- return 'npx' ;
21- }
22- } ;
10+ const getNpxPath = ( ) : string => ( process . platform === 'win32' ? getScriptRunnerPath ( ) . replace ( 'node.exe' , 'npx.cmd' ) : 'npx' ) ;
2311
2412/**
2513 * Retrieve the path to the `ampx` executable for interacting with the amplify gen2 cli.
2614 * @param cwd current working directory
2715 * @returns the local `ampx` executable path
16+ *
17+ * Note:
18+ * Use shell: true to properly execute the .cmd file on Windows
2819 */
29- const getAmpxPath = ( cwd : string ) : string => {
30- // Retrieve the path to npx
31- const npxPath = getNpxPath ( ) ;
32- console . log ( `DEBUG: Resolved npx path: ${ npxPath } ` ) ;
33-
34- // Execute the command to find 'ampx'
35- // Use shell: true to properly execute the .cmd file on Windows
36- const spawnResult = spawnSync ( npxPath , [ 'which' , 'ampx' ] , { cwd, env : process . env , stdio : 'pipe' , shell : true } ) ;
37-
38- // Log the entire result of spawnSync for inspection
39- console . log ( 'DEBUG: spawnSync result:' , spawnResult ) ;
40-
41- if ( spawnResult . error ) {
42- console . error ( 'DEBUG: spawnSync encountered an error:' , spawnResult . error ) ;
43- }
44-
45- // Log stderr if available
46- if ( spawnResult . stderr ) {
47- console . error ( 'DEBUG: spawnSync stderr:' , spawnResult . stderr . toString ( ) ) ;
48- }
49-
50- // Ensure stdout exists before converting to string
51- const stdout = spawnResult . stdout ;
52- if ( ! stdout ) {
53- console . error ( 'DEBUG: No stdout received from spawnSync.' ) ;
54- return '' ;
55- }
56-
57- const result = stdout . toString ( ) . trim ( ) ;
58- console . log ( `DEBUG: Parsed output: "${ result } "` ) ;
59- return result ;
60- } ;
20+ const getAmpxPath = ( cwd : string ) : string =>
21+ spawnSync ( getNpxPath ( ) , [ 'which' , 'ampx' ] , { cwd, env : process . env , stdio : 'pipe' , shell : true } ) . stdout . toString ( ) . trim ( ) ;
6122
6223const codegenPackagesInGen2 = [
6324 '@aws-amplify/graphql-generator' ,
0 commit comments