@bifravst/aws-cdk-lambda-helpers 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { createWriteStream } from 'fs';
3
- import { copyFile, mkdir, readFile, rm, writeFile } from 'fs/promises';
3
+ import { copyFile, mkdir, readFile, rm, stat, writeFile } from 'fs/promises';
4
4
  import { glob } from 'glob';
5
5
  import path from 'path';
6
6
  import { ZipFile } from 'yazl';
@@ -30,16 +30,31 @@ export const packLayer = async ({ id, dependencies, baseDir, distDir, }) => {
30
30
  [dep]: resolvedDependency,
31
31
  };
32
32
  }, {});
33
+ const checkSumFiles = [
34
+ // Include this script, so artefact is updated if the way it's built is changed
35
+ fileURLToPath(import.meta.url),
36
+ ];
33
37
  const packageJSON = path.join(nodejsDir, 'package.json');
34
38
  await writeFile(packageJSON, JSON.stringify({
35
39
  dependencies: depsToBeInstalled,
36
40
  }), 'utf-8');
37
- const packageLock = path.join(nodejsDir, 'package-lock.json');
38
- await copyFile(packageLockJsonFile, packageLock);
41
+ checkSumFiles.push(packageJSON);
42
+ let hasLockFile = true;
43
+ try {
44
+ // package-lock.json may not exist
45
+ await stat(packageLockJsonFile);
46
+ const packageLock = path.join(nodejsDir, 'package-lock.json');
47
+ await copyFile(packageLockJsonFile, packageLock);
48
+ checkSumFiles.push(packageLock);
49
+ }
50
+ catch {
51
+ hasLockFile = false;
52
+ // pass
53
+ }
39
54
  await new Promise((resolve, reject) => {
40
55
  const [cmd, ...args] = [
41
56
  'npm',
42
- 'ci',
57
+ hasLockFile ? 'ci' : 'i',
43
58
  '--ignore-scripts',
44
59
  '--only=prod',
45
60
  '--no-audit',
@@ -64,7 +79,7 @@ export const packLayer = async ({ id, dependencies, baseDir, distDir, }) => {
64
79
  zipfile.addFile(path.join(layerDir, f), f);
65
80
  });
66
81
  const zipFileName = await new Promise((resolve) => {
67
- const zipFileName = path.join(base, 'dist', 'layers', `${id}.zip`);
82
+ const zipFileName = path.join(dist, `${id}.zip`);
68
83
  zipfile.outputStream
69
84
  .pipe(createWriteStream(zipFileName))
70
85
  .on('close', () => {
@@ -76,12 +91,7 @@ export const packLayer = async ({ id, dependencies, baseDir, distDir, }) => {
76
91
  layerZipFile: zipFileName,
77
92
  hash: checkSumOfStrings([
78
93
  JSON.stringify(dependencies),
79
- await checkSumOfFiles([
80
- packageJSON,
81
- packageLock,
82
- // Include this script, so artefact is updated if the way it's built is changed
83
- fileURLToPath(import.meta.url),
84
- ]),
94
+ await checkSumOfFiles(checkSumFiles),
85
95
  ]),
86
96
  };
87
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/aws-cdk-lambda-helpers",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
5
5
  "exports": {
6
6
  ".": {