-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from aws/develop
chore: Merge develop into master
- Loading branch information
Showing
21 changed files
with
809 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
AWS Lambda Builder Library | ||
""" | ||
__version__ = "1.11.0" | ||
__version__ = "1.12.0" | ||
RPC_PROTOCOL_VERSION = "0.3" |
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
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
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
19 changes: 19 additions & 0 deletions
19
aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild-plugin.js.template
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,19 @@ | ||
let skipBundleNodeModules = {{ | ||
name: 'make-all-packages-external', | ||
setup(build) {{ | ||
let filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ // Must not start with "/" or "./" or "../" | ||
build.onResolve({{ filter }}, args => ({{ path: args.path, external: true }})) | ||
}}, | ||
}} | ||
|
||
require('esbuild').build({{ | ||
entryPoints: {entry_points}, | ||
bundle: true, | ||
platform: 'node', | ||
format: 'cjs', | ||
target: '{target}', | ||
sourcemap: {sourcemap}, | ||
outdir: {out_dir}, | ||
minify: {minify}, | ||
plugins: [skipBundleNodeModules], | ||
}}).catch(() => process.exit(1)) |
104 changes: 104 additions & 0 deletions
104
aws_lambda_builders/workflows/nodejs_npm_esbuild/node.py
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,104 @@ | ||
""" | ||
Wrapper around calling nodejs through a subprocess. | ||
""" | ||
|
||
import logging | ||
|
||
from aws_lambda_builders.exceptions import LambdaBuilderError | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class NodejsExecutionError(LambdaBuilderError): | ||
|
||
""" | ||
Exception raised in case nodejs execution fails. | ||
It will pass on the standard error output from the Node.js console. | ||
""" | ||
|
||
MESSAGE = "Nodejs Failed: {message}" | ||
|
||
|
||
class SubprocessNodejs(object): | ||
|
||
""" | ||
Wrapper around the nodejs command line utility, making it | ||
easy to consume execution results. | ||
""" | ||
|
||
def __init__(self, osutils, executable_search_paths, which): | ||
""" | ||
:type osutils: aws_lambda_builders.workflows.nodejs_npm.utils.OSUtils | ||
:param osutils: An instance of OS Utilities for file manipulation | ||
:type executable_search_paths: list | ||
:param executable_search_paths: List of paths to the node package binary utilities. This will | ||
be used to find embedded Nodejs at runtime if present in the package | ||
:type which: aws_lambda_builders.utils.which | ||
:param which: Function to get paths which conform to the given mode on the PATH | ||
with the prepended additional search paths | ||
""" | ||
self.osutils = osutils | ||
self.executable_search_paths = executable_search_paths | ||
self.which = which | ||
|
||
def nodejs_binary(self): | ||
""" | ||
Finds the Nodejs binary at runtime. | ||
The utility may be present as a package dependency of the Lambda project, | ||
or in the global path. If there is one in the Lambda project, it should | ||
be preferred over a global utility. The check has to be executed | ||
at runtime, since nodejs dependencies will be installed by the workflow | ||
using one of the previous actions. | ||
""" | ||
|
||
LOG.debug("checking for nodejs in: %s", self.executable_search_paths) | ||
binaries = self.which("node", executable_search_paths=self.executable_search_paths) | ||
LOG.debug("potential nodejs binaries: %s", binaries) | ||
|
||
if binaries: | ||
return binaries[0] | ||
else: | ||
raise NodejsExecutionError(message="cannot find nodejs") | ||
|
||
def run(self, args, cwd=None): | ||
|
||
""" | ||
Runs the action. | ||
:type args: list | ||
:param args: Command line arguments to pass to Nodejs | ||
:type cwd: str | ||
:param cwd: Directory where to execute the command (defaults to current dir) | ||
:rtype: str | ||
:return: text of the standard output from the command | ||
:raises aws_lambda_builders.workflows.nodejs_npm.npm.NodejsExecutionError: | ||
when the command executes with a non-zero return code. The exception will | ||
contain the text of the standard error output from the command. | ||
:raises ValueError: if arguments are not provided, or not a list | ||
""" | ||
|
||
if not isinstance(args, list): | ||
raise ValueError("args must be a list") | ||
|
||
if not args: | ||
raise ValueError("requires at least one arg") | ||
|
||
invoke_nodejs = [self.nodejs_binary()] + args | ||
|
||
LOG.debug("executing Nodejs: %s", invoke_nodejs) | ||
|
||
p = self.osutils.popen(invoke_nodejs, stdout=self.osutils.pipe, stderr=self.osutils.pipe, cwd=cwd) | ||
|
||
out, err = p.communicate() | ||
|
||
if p.returncode != 0: | ||
raise NodejsExecutionError(message=err.decode("utf8").strip()) | ||
|
||
return out.decode("utf8").strip() |
Oops, something went wrong.