-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lambda-nodejs): esbuild detection with Yarn 2 in PnP mode #13257
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c95f393
fix(lambda-nodejs): esbuild detection with Yarn 2 in PnP mode
jogold af8e73c
isLocal
jogold 5f713ce
isLocal in test
jogold 4bc3964
Merge branch 'master' into lambda-nodejs-detect-esbuild
jogold ce588e1
Merge branch 'master' into lambda-nodejs-detect-esbuild
jogold 1cd295a
tryGetModuleVersion
jogold 6b99302
Merge branch 'lambda-nodejs-detect-esbuild' of github.com:jogold/aws-…
jogold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { getModuleVersion } from './util'; | ||
|
||
/** | ||
* An esbuild installation | ||
*/ | ||
export abstract class EsbuildInstallation { | ||
public static detect(): EsbuildInstallation | undefined { | ||
try { | ||
try { | ||
// Check local version first | ||
const version = getModuleVersion('esbuild'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this have to throw if the module doesn't exist? Can this be |
||
return { | ||
isLocal: true, | ||
version, | ||
}; | ||
} catch (err) { | ||
// 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(' '); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
esbuildInstallation?.isLocal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many locals... this
runsLocally
here means local bundling (vs Docker bundling). TheisLocal
of theesbuildInstallation
means is locally installed (vs globally installed).