Skip to content

Commit

Permalink
Add private option to use npm 7
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteAutumn committed Dec 6, 2021
1 parent 4549a5b commit 09d9bba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-lambda.js",
"version": "0.0.1",
"version": "0.0.2",
"main": "dist/lambda.js",
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const makeBuildDirectory = () => {
return dir;
};

const makeDockerFile = (runtime: lambda.Runtime) => (`
const makeDockerFile = (runtime: lambda.Runtime, useNpm7: boolean = false) => (`
FROM ${runtime.bundlingImage.image}:latest
COPY writeDependencies.js /lambda.js/writeDependencies.js
${useNpm7 ? "RUN npm i -g npm@^7" : ""}
RUN npm i -g typescript
`);

Expand Down Expand Up @@ -70,6 +71,7 @@ export interface BuildPreparationOptions {
entry: string;
directory: string;
inplace: boolean;
_bundleUsingNpm7?: boolean;
}

export interface BuildPreparationResult {
Expand All @@ -91,7 +93,7 @@ export interface BuildPreparationResult {
export function prepareBuild(options: BuildPreparationOptions): BuildPreparationResult {

const temporaryDirectory = makeBuildDirectory();
const dockerfile = makeDockerFile(options.runtime);
const dockerfile = makeDockerFile(options.runtime, options._bundleUsingNpm7);

let cache;
if (runtimeCache[options.directory] != null) {
Expand Down
4 changes: 3 additions & 1 deletion src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export interface FunctionProps extends lambda.FunctionOptions {
*
*/
runtime?: lambda.Runtime;

_bundleUsingNpm7?: boolean;
}

export class Function extends lambda.Function {
Expand All @@ -90,7 +92,7 @@ export class Function extends lambda.Function {
...functionProps
} = props;

const preparation = prepareBuild({ runtime, entry, directory, inplace });
const preparation = prepareBuild({ runtime, entry, directory, inplace, _bundleUsingNpm7: props._bundleUsingNpm7 });

let codeOptions: s3_assets.AssetOptions = {
exclude: makeLambdaExcludes(directory, preparation.info.sources, preparation.cache.paths)
Expand Down

0 comments on commit 09d9bba

Please sign in to comment.