@bifravst/aws-cdk-lambda-helpers 1.3.3 → 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.
- package/dist/src/packLayer.js +20 -10
- package/package.json +1 -1
package/dist/src/packLayer.js
CHANGED
@@ -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
|
-
|
38
|
-
|
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',
|
@@ -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
|
};
|