( projectDir: string, packageJsonContents: any, config: ResolvedConfig, options: DeployCommandOptions )
| 1488 | // If the package-lock.json is not found, we will run `npm install --package-lock-only` and then write the package-lock.json |
| 1489 | // to the project directory, and finally we'll write the digest to the `.trigger/cache` directory with the contents of the package-lock.json |
| 1490 | async function resolveDependencies( |
| 1491 | projectDir: string, |
| 1492 | packageJsonContents: any, |
| 1493 | config: ResolvedConfig, |
| 1494 | options: DeployCommandOptions |
| 1495 | ) { |
| 1496 | return await tracer.startActiveSpan("resolveDependencies", async (span) => { |
| 1497 | const resolvingDepsSpinner = spinner(); |
| 1498 | resolvingDepsSpinner.start("Resolving dependencies"); |
| 1499 | |
| 1500 | const hasher = createHash("sha256"); |
| 1501 | hasher.update(JSON.stringify(packageJsonContents)); |
| 1502 | const digest = hasher.digest("hex").slice(0, 16); |
| 1503 | |
| 1504 | const cacheDir = join(config.projectDir, ".trigger", "cache"); |
| 1505 | const cachePath = join(cacheDir, `${digest}.json`); |
| 1506 | |
| 1507 | span.setAttributes({ |
| 1508 | "packageJson.digest": digest, |
| 1509 | "cache.path": cachePath, |
| 1510 | ...flattenAttributes(packageJsonContents, "packageJson.contents"), |
| 1511 | }); |
| 1512 | |
| 1513 | try { |
| 1514 | const cachedPackageLock = await readFile(cachePath, "utf-8"); |
| 1515 | |
| 1516 | logger.debug(`Using cached package-lock.json for ${digest}`); |
| 1517 | |
| 1518 | await writeFile(join(projectDir, "package-lock.json"), cachedPackageLock); |
| 1519 | |
| 1520 | span.setAttributes({ |
| 1521 | "cache.hit": true, |
| 1522 | }); |
| 1523 | |
| 1524 | span.end(); |
| 1525 | |
| 1526 | resolvingDepsSpinner.stop("Dependencies resolved"); |
| 1527 | |
| 1528 | return true; |
| 1529 | } catch (e) { |
| 1530 | // If the file doesn't exist, we'll continue to the next step |
| 1531 | if (e instanceof Error && "code" in e && e.code !== "ENOENT") { |
| 1532 | span.recordException(e as Error); |
| 1533 | span.end(); |
| 1534 | |
| 1535 | resolvingDepsSpinner.stop(`Failed to resolve dependencies: ${e.message}`); |
| 1536 | |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | span.setAttributes({ |
| 1541 | "cache.hit": false, |
| 1542 | }); |
| 1543 | |
| 1544 | logger.debug(`No cached package-lock.json found for ${digest}`); |
| 1545 | |
| 1546 | try { |
| 1547 | if (logger.loggerLevel === "debug") { |
no test coverage detected
searching dependent graphs…