@friggframework/devtools 2.0.0--canary.386.cf751ae.0 → 2.0.0--canary.388.f6a3f63.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.
@@ -16,6 +16,7 @@ program
16
16
  .command('start')
17
17
  .description('Run the backend and optional frontend')
18
18
  .option('-s, --stage <stage>', 'deployment stage', 'dev')
19
+ .option('-v, --verbose', 'enable verbose output')
19
20
  .action(startCommand);
20
21
 
21
22
  program
@@ -29,6 +30,7 @@ program
29
30
  .command('deploy')
30
31
  .description('Deploy the serverless application')
31
32
  .option('-s, --stage <stage>', 'deployment stage', 'dev')
33
+ .option('-v, --verbose', 'enable verbose output')
32
34
  .action(deployCommand);
33
35
 
34
36
  program.parse(process.argv);
@@ -1,7 +1,11 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
1
+ const { spawn } = require('node:child_process');
2
+ const path = require('node:path');
3
3
 
4
4
  function startCommand(options) {
5
+ if (options.verbose) {
6
+ console.log('Verbose mode enabled');
7
+ console.log('Options:', options);
8
+ }
5
9
  console.log('Starting backend and optional frontend...');
6
10
  // Suppress AWS SDK warning message about maintenance mode
7
11
  process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = 1;
@@ -17,6 +21,16 @@ function startCommand(options) {
17
21
  options.stage
18
22
  ];
19
23
 
24
+ // Add verbose flag to serverless if verbose option is enabled
25
+ if (options.verbose) {
26
+ args.push('--verbose');
27
+ }
28
+
29
+ if (options.verbose) {
30
+ console.log(`Executing command: ${command} ${args.join(' ')}`);
31
+ console.log(`Working directory: ${backendPath}`);
32
+ }
33
+
20
34
  const childProcess = spawn(command, args, {
21
35
  cwd: backendPath,
22
36
  stdio: 'inherit',
@@ -1,6 +1,107 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
 
4
+ // Function to find the actual path to node_modules
5
+ const findNodeModulesPath = () => {
6
+ try {
7
+ // Method 1: Try to find node_modules by traversing up from current directory
8
+ let currentDir = process.cwd();
9
+ let nodeModulesPath = null;
10
+
11
+ // Traverse up to 5 levels to find node_modules
12
+ for (let i = 0; i < 5; i++) {
13
+ const potentialPath = path.join(currentDir, 'node_modules');
14
+ if (fs.existsSync(potentialPath)) {
15
+ nodeModulesPath = potentialPath;
16
+ console.log(`Found node_modules at: ${nodeModulesPath} (method 1)`);
17
+ break;
18
+ }
19
+ // Move up one directory
20
+ const parentDir = path.dirname(currentDir);
21
+ if (parentDir === currentDir) {
22
+ // We've reached the root
23
+ break;
24
+ }
25
+ currentDir = parentDir;
26
+ }
27
+
28
+ // Method 2: If method 1 fails, try using npm root command
29
+ if (!nodeModulesPath) {
30
+ try {
31
+ // This requires child_process, so let's require it here
32
+ const { execSync } = require('node:child_process');
33
+ const npmRoot = execSync('npm root', { encoding: 'utf8' }).trim();
34
+ if (fs.existsSync(npmRoot)) {
35
+ nodeModulesPath = npmRoot;
36
+ console.log(`Found node_modules at: ${nodeModulesPath} (method 2)`);
37
+ }
38
+ } catch (npmError) {
39
+ console.error('Error executing npm root:', npmError);
40
+ }
41
+ }
42
+
43
+ // Method 3: If all else fails, check for a package.json and assume node_modules is adjacent
44
+ if (!nodeModulesPath) {
45
+ currentDir = process.cwd();
46
+ for (let i = 0; i < 5; i++) {
47
+ const packageJsonPath = path.join(currentDir, 'package.json');
48
+ if (fs.existsSync(packageJsonPath)) {
49
+ const potentialNodeModules = path.join(currentDir, 'node_modules');
50
+ if (fs.existsSync(potentialNodeModules)) {
51
+ nodeModulesPath = potentialNodeModules;
52
+ console.log(`Found node_modules at: ${nodeModulesPath} (method 3)`);
53
+ break;
54
+ }
55
+ }
56
+ // Move up one directory
57
+ const parentDir = path.dirname(currentDir);
58
+ if (parentDir === currentDir) {
59
+ // We've reached the root
60
+ break;
61
+ }
62
+ currentDir = parentDir;
63
+ }
64
+ }
65
+
66
+ if (nodeModulesPath) {
67
+ return nodeModulesPath;
68
+ }
69
+
70
+ console.warn('Could not find node_modules path, falling back to default');
71
+ return path.resolve(process.cwd(), '../node_modules');
72
+ } catch (error) {
73
+ console.error('Error finding node_modules path:', error);
74
+ return path.resolve(process.cwd(), '../node_modules');
75
+ }
76
+ };
77
+
78
+ // Function to modify handler paths to point to the correct node_modules
79
+ const modifyHandlerPaths = (functions) => {
80
+ // Check if we're running in offline mode
81
+ const isOffline = process.argv.includes('offline');
82
+ console.log('isOffline', isOffline);
83
+
84
+ if (!isOffline) {
85
+ console.log('Not in offline mode, skipping handler path modification');
86
+ return functions;
87
+ }
88
+
89
+ const nodeModulesPath = findNodeModulesPath();
90
+ const modifiedFunctions = { ...functions };
91
+
92
+ for (const functionName of Object.keys(modifiedFunctions)) {
93
+ console.log('functionName', functionName);
94
+ const functionDef = modifiedFunctions[functionName];
95
+ if (functionDef?.handler?.includes('node_modules/')) {
96
+ // Replace node_modules/ with the actual path to node_modules/
97
+ functionDef.handler = functionDef.handler.replace('node_modules/', '../node_modules/');
98
+ console.log(`Updated handler for ${functionName}: ${functionDef.handler}`);
99
+ }
100
+ }
101
+
102
+ return modifiedFunctions;
103
+ };
104
+
4
105
  const composeServerlessDefinition = (AppDefinition) => {
5
106
  const definition = {
6
107
  frameworkVersion: '>=3.17.0',
@@ -273,6 +374,9 @@ const composeServerlessDefinition = (AppDefinition) => {
273
374
  definition.custom[queueReference] = queueName;
274
375
  }
275
376
 
377
+ // Modify handler paths to point to the correct node_modules location
378
+ definition.functions = modifyHandlerPaths(definition.functions);
379
+
276
380
  return definition;
277
381
  };
278
382
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.386.cf751ae.0",
4
+ "version": "2.0.0--canary.388.f6a3f63.0",
5
5
  "dependencies": {
6
6
  "@babel/eslint-parser": "^7.18.9",
7
7
  "@babel/parser": "^7.25.3",
8
8
  "@babel/traverse": "^7.25.3",
9
- "@friggframework/test": "2.0.0--canary.386.cf751ae.0",
9
+ "@friggframework/test": "2.0.0--canary.388.f6a3f63.0",
10
10
  "@hapi/boom": "^10.0.1",
11
11
  "@inquirer/prompts": "^5.3.8",
12
12
  "axios": "^1.7.2",
@@ -27,8 +27,8 @@
27
27
  "serverless-http": "^2.7.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@friggframework/eslint-config": "2.0.0--canary.386.cf751ae.0",
31
- "@friggframework/prettier-config": "2.0.0--canary.386.cf751ae.0",
30
+ "@friggframework/eslint-config": "2.0.0--canary.388.f6a3f63.0",
31
+ "@friggframework/prettier-config": "2.0.0--canary.388.f6a3f63.0",
32
32
  "prettier": "^2.7.1",
33
33
  "serverless": "3.39.0",
34
34
  "serverless-dotenv-plugin": "^6.0.0",
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "cf751ae93d1f18bf491cf9c2fa59322d76d07880"
62
+ "gitHead": "f6a3f63000269f925a6e6c1f0e64440315b9831b"
63
63
  }