-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda-nodejs): esbuild detection with Yarn 2 in PnP mode (#14739)
- Loading branch information
Showing
9 changed files
with
317 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/@aws-cdk/aws-lambda-nodejs/lib/esbuild-installation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { spawnSync } from 'child_process'; | ||
import { tryGetModuleVersion } from './util'; | ||
|
||
/** | ||
* An esbuild installation | ||
*/ | ||
export abstract class EsbuildInstallation { | ||
public static detect(): EsbuildInstallation | undefined { | ||
try { | ||
// Check local version first | ||
const version = tryGetModuleVersion('esbuild'); | ||
if (version) { | ||
return { | ||
isLocal: true, | ||
version, | ||
}; | ||
} | ||
|
||
// Fallback to a global version | ||
const esbuild = spawnSync('esbuild', ['--version']); | ||
if (esbuild.status === 0 && !esbuild.error) { | ||
return { | ||
isLocal: false, | ||
version: esbuild.stdout.toString().trim(), | ||
}; | ||
} | ||
return undefined; | ||
} catch (err) { | ||
return undefined; | ||
} | ||
} | ||
|
||
public abstract readonly isLocal: boolean; | ||
public abstract readonly version: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/@aws-cdk/aws-lambda-nodejs/lib/package-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
|
||
interface PackageManagerProps { | ||
readonly lockFile: string; | ||
readonly installCommand: string[]; | ||
readonly runCommand: string[]; | ||
} | ||
|
||
/** | ||
* A node package manager | ||
*/ | ||
export class PackageManager { | ||
public static NPM = new PackageManager({ | ||
lockFile: 'package-lock.json', | ||
installCommand: ['npm', 'install'], | ||
runCommand: ['npx', '--no-install'], | ||
}); | ||
|
||
public static YARN = new PackageManager({ | ||
lockFile: 'yarn.lock', | ||
installCommand: ['yarn', 'install'], | ||
runCommand: ['yarn', 'run'], | ||
}); | ||
|
||
public static fromLockFile(lockFilePath: string): PackageManager { | ||
const lockFile = path.basename(lockFilePath); | ||
|
||
switch (lockFile) { | ||
case PackageManager.NPM.lockFile: | ||
return PackageManager.NPM; | ||
case PackageManager.YARN.lockFile: | ||
return PackageManager.YARN; | ||
default: | ||
return PackageManager.NPM; | ||
} | ||
} | ||
|
||
public readonly lockFile: string; | ||
public readonly installCommand: string[]; | ||
public readonly runCommand: string[]; | ||
|
||
constructor(props: PackageManagerProps) { | ||
this.lockFile = props.lockFile; | ||
this.installCommand = props.installCommand; | ||
this.runCommand = props.runCommand; | ||
} | ||
|
||
public runBinCommand(bin: string): string { | ||
const [runCommand, ...runArgs] = this.runCommand; | ||
return [ | ||
os.platform() === 'win32' ? `${runCommand}.cmd` : runCommand, | ||
...runArgs, | ||
bin, | ||
].join(' '); | ||
} | ||
} |
Oops, something went wrong.