@friggframework/devtools 2.0.0--canary.482.caa9000.0 → 2.0.0--canary.482.f16726b.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.
@@ -3,32 +3,65 @@ const fs = require('fs-extra');
3
3
  const { composeServerlessDefinition } = require('./infrastructure-composer');
4
4
  const { findNearestBackendPackageJson } = require('@friggframework/core');
5
5
 
6
+ // Memoization cache to prevent duplicate infrastructure composition
7
+ // when serverless framework loads configuration multiple times
8
+ let cachedInfrastructure = null;
9
+ let isComposing = false;
10
+
6
11
  async function createFriggInfrastructure() {
7
- const backendPath = findNearestBackendPackageJson();
8
- if (!backendPath) {
9
- throw new Error('Could not find backend package.json');
12
+ // Return cached infrastructure if already composed
13
+ if (cachedInfrastructure) {
14
+ console.log(' Using cached infrastructure definition (already composed)');
15
+ return cachedInfrastructure;
10
16
  }
11
17
 
12
- const backendDir = path.dirname(backendPath);
13
- const backendFilePath = path.join(backendDir, 'index.js');
14
- if (!fs.existsSync(backendFilePath)) {
15
- throw new Error('Could not find index.js');
18
+ // Wait if another call is currently composing
19
+ if (isComposing) {
20
+ console.log('⏳ Infrastructure composition in progress - waiting...');
21
+ // Poll every 100ms until composition completes
22
+ while (isComposing) {
23
+ await new Promise(resolve => setTimeout(resolve, 100));
24
+ }
25
+ // Return the newly cached infrastructure
26
+ return cachedInfrastructure;
16
27
  }
17
28
 
18
- const backend = require(backendFilePath);
19
- const appDefinition = backend.Definition;
29
+ // Mark as composing to prevent concurrent composition
30
+ isComposing = true;
31
+
32
+ try {
33
+ const backendPath = findNearestBackendPackageJson();
34
+ if (!backendPath) {
35
+ throw new Error('Could not find backend package.json');
36
+ }
37
+
38
+ const backendDir = path.dirname(backendPath);
39
+ const backendFilePath = path.join(backendDir, 'index.js');
40
+ if (!fs.existsSync(backendFilePath)) {
41
+ throw new Error('Could not find index.js');
42
+ }
20
43
 
21
- // const serverlessTemplate = require(path.resolve(
22
- // __dirname,
23
- // './serverless-template.js'
24
- // ));
25
- const definition = await composeServerlessDefinition(
26
- appDefinition,
27
- );
44
+ const backend = require(backendFilePath);
45
+ const appDefinition = backend.Definition;
28
46
 
29
- return {
30
- ...definition,
31
- };
47
+ // const serverlessTemplate = require(path.resolve(
48
+ // __dirname,
49
+ // './serverless-template.js'
50
+ // ));
51
+ const definition = await composeServerlessDefinition(
52
+ appDefinition,
53
+ );
54
+
55
+ // Cache the composed infrastructure
56
+ cachedInfrastructure = {
57
+ ...definition,
58
+ };
59
+
60
+ return cachedInfrastructure;
61
+ } finally {
62
+ // Always clear composing flag
63
+ isComposing = false;
64
+ }
32
65
  }
33
66
 
34
67
  module.exports = { createFriggInfrastructure };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.482.caa9000.0",
4
+ "version": "2.0.0--canary.482.f16726b.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-ec2": "^3.835.0",
7
7
  "@aws-sdk/client-kms": "^3.835.0",
@@ -12,8 +12,8 @@
12
12
  "@babel/eslint-parser": "^7.18.9",
13
13
  "@babel/parser": "^7.25.3",
14
14
  "@babel/traverse": "^7.25.3",
15
- "@friggframework/schemas": "2.0.0--canary.482.caa9000.0",
16
- "@friggframework/test": "2.0.0--canary.482.caa9000.0",
15
+ "@friggframework/schemas": "2.0.0--canary.482.f16726b.0",
16
+ "@friggframework/test": "2.0.0--canary.482.f16726b.0",
17
17
  "@hapi/boom": "^10.0.1",
18
18
  "@inquirer/prompts": "^5.3.8",
19
19
  "axios": "^1.7.2",
@@ -35,8 +35,8 @@
35
35
  "serverless-http": "^2.7.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@friggframework/eslint-config": "2.0.0--canary.482.caa9000.0",
39
- "@friggframework/prettier-config": "2.0.0--canary.482.caa9000.0",
38
+ "@friggframework/eslint-config": "2.0.0--canary.482.f16726b.0",
39
+ "@friggframework/prettier-config": "2.0.0--canary.482.f16726b.0",
40
40
  "aws-sdk-client-mock": "^4.1.0",
41
41
  "aws-sdk-client-mock-jest": "^4.1.0",
42
42
  "jest": "^30.1.3",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "caa90009460831fdb4685c012c2cdf11b1df78de"
71
+ "gitHead": "f16726b784edfdeb427abdc037842fbbb763fb60"
72
72
  }