forked from aws/aws-lambda-builders
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkflow.py
81 lines (66 loc) · 2.88 KB
/
workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
NodeJS NPM Workflow
"""
from aws_lambda_builders.path_resolver import PathResolver
from aws_lambda_builders.workflow import BaseWorkflow, Capability
from aws_lambda_builders.actions import CopySourceAction
from .actions import NodejsNpmPackAction, NodejsNpmInstallAction, NodejsNpmrcCopyAction, \
NodejsNpmrcCleanUpAction, NodejsNpmRewriteLocalDependenciesAction
from .utils import OSUtils
from .npm import SubprocessNpm, NpmModulesUtils
class NodejsNpmWorkflow(BaseWorkflow):
"""
A Lambda builder workflow that knows how to pack
NodeJS projects using NPM.
"""
NAME = "NodejsNpmBuilder"
CAPABILITY = Capability(language="nodejs",
dependency_manager="npm",
application_framework=None)
EXCLUDED_FILES = (".aws-sam")
def __init__(self,
source_dir,
artifacts_dir,
scratch_dir,
manifest_path,
runtime=None,
osutils=None,
**kwargs):
super(NodejsNpmWorkflow, self).__init__(source_dir,
artifacts_dir,
scratch_dir,
manifest_path,
runtime=runtime,
**kwargs)
if osutils is None:
osutils = OSUtils()
subprocess_npm = SubprocessNpm(osutils)
tar_dest_dir = osutils.joinpath(scratch_dir, 'unpacked')
tar_package_dir = osutils.joinpath(tar_dest_dir, 'package')
npm_pack = NodejsNpmPackAction(tar_dest_dir,
scratch_dir,
manifest_path,
osutils=osutils,
subprocess_npm=subprocess_npm)
npm_install = NodejsNpmInstallAction(artifacts_dir,
subprocess_npm=subprocess_npm)
npm_copy_npmrc = NodejsNpmrcCopyAction(tar_package_dir, source_dir, osutils=osutils)
self.actions = [
npm_pack,
npm_copy_npmrc,
CopySourceAction(tar_package_dir, artifacts_dir, excludes=self.EXCLUDED_FILES),
NodejsNpmRewriteLocalDependenciesAction(
artifacts_dir,
source_dir,
tar_dest_dir,
npm_modules_utils=NpmModulesUtils(osutils, subprocess_npm, scratch_dir),
osutils=osutils
),
npm_install,
NodejsNpmrcCleanUpAction(artifacts_dir, osutils=osutils)
]
def get_resolvers(self):
"""
specialized path resolver that just returns the list of executable for the runtime on the path.
"""
return [PathResolver(runtime=self.runtime, binary="npm")]