@faable/faable 1.4.4 → 1.4.6

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.
@@ -10,7 +10,7 @@ const deploy_command = async (args) => {
10
10
  const workdir = args.workdir || process.cwd();
11
11
  const { api } = await context();
12
12
  // Resolve runtime
13
- const { app_name, runtime, runtime_version } = await runtime_detection(workdir);
13
+ const { app_name, runtime } = await runtime_detection(workdir);
14
14
  const name = args.app_slug || app_name;
15
15
  if (!name) {
16
16
  throw new Error("Missing <app_name>");
@@ -19,20 +19,23 @@ const deploy_command = async (args) => {
19
19
  const app = await api.getBySlug(name);
20
20
  // Check if we can build docker images
21
21
  await check_environment();
22
- log.info(`🚀 Deploying [${app.name}] runtime=${runtime}-${runtime_version} app_id=${app.id}`);
22
+ log.info(`🚀 Deploying ${app.name} (${app.id}) runtime=${runtime.name}-${runtime.version} `);
23
23
  let type;
24
- if (runtime == "node") {
25
- const node_result = await build_node(app, workdir);
24
+ if (runtime.name == "node") {
25
+ const node_result = await build_node(app, {
26
+ workdir,
27
+ runtime,
28
+ });
26
29
  type = node_result.type;
27
30
  }
28
- else if (runtime == "docker") {
31
+ else if (runtime.name == "docker") {
29
32
  type = "node";
30
33
  await cmd(`docker build -t ${app.id} .`, {
31
34
  enableOutput: true,
32
35
  });
33
36
  }
34
37
  else {
35
- throw new Error(`No build pipeline for runtime=${runtime}`);
38
+ throw new Error(`No build pipeline for runtime=${runtime.name}`);
36
39
  }
37
40
  // Upload to Faable registry
38
41
  const { upload_tagname } = await upload_tag({ app, api });
@@ -2,8 +2,12 @@ import { bundle_docker } from './bundle_docker.js';
2
2
  import { analyze_package } from './analyze_package.js';
3
3
  import { build_project } from './build_project.js';
4
4
 
5
- const build_node = async (app, workdir) => {
5
+ const build_node = async (app, options) => {
6
6
  // log.info(`🚀 Build Toolchain ${app.name} [${app.id}]`);
7
+ const { workdir, runtime } = options;
8
+ if (!runtime.version) {
9
+ throw new Error("Runtime version not specified for node");
10
+ }
7
11
  // Analyze package.json to check if build is needed
8
12
  const { build_script, type } = await analyze_package({ workdir });
9
13
  await build_project({ app, build_script });
@@ -12,7 +16,7 @@ const build_node = async (app, workdir) => {
12
16
  app,
13
17
  workdir,
14
18
  template_context: {
15
- from: "node:18.19.0-slim",
19
+ from: `node:${runtime.version}`,
16
20
  },
17
21
  });
18
22
  return { type };
@@ -1,7 +1,8 @@
1
1
  const strategy_docker = async (workdir) => {
2
2
  return {
3
- runtime: "docker",
4
- runtime_version: "docker",
3
+ runtime: {
4
+ name: "docker",
5
+ },
5
6
  };
6
7
  };
7
8
 
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path__default from 'path';
3
+ import { cmd } from '../../../../lib/cmd.js';
3
4
 
4
5
  /**
5
6
  * Strategy to detect app name from package.json
@@ -10,14 +11,22 @@ import path__default from 'path';
10
11
  const strategy_nodejs = async (workdir) => {
11
12
  const packageJSONFile = path__default.join(workdir, "package.json");
12
13
  // Check we have a valid name
13
- const { name } = fs.readJSONSync(packageJSONFile);
14
+ const { name, engines } = fs.readJSONSync(packageJSONFile);
14
15
  if (!name) {
15
16
  throw new Error("Missing name in package.json");
16
17
  }
18
+ // Use engines.node if found
19
+ let runtime_version = "18.19.0";
20
+ if (engines?.node) {
21
+ const out = await cmd(`npm view node@20.8 version | tail -n 1 | cut -d "'" -f2`);
22
+ runtime_version = out.stdout.toString();
23
+ }
17
24
  return {
18
25
  app_name: name,
19
- runtime: "node",
20
- runtime_version: "18",
26
+ runtime: {
27
+ name: "node",
28
+ version: runtime_version,
29
+ },
21
30
  };
22
31
  };
23
32
 
@@ -14,8 +14,10 @@ const strategy_python = async (workdir) => {
14
14
  runtime_version = runtime_data.split("-")[1];
15
15
  }
16
16
  return {
17
- runtime: "python",
18
- runtime_version,
17
+ runtime: {
18
+ name: "python",
19
+ version: runtime_version,
20
+ },
19
21
  };
20
22
  };
21
23
 
@@ -18,7 +18,7 @@ class ConfigurationHelper {
18
18
  }
19
19
  async demandConfig(force = false) {
20
20
  const creds = await this.store.loadCredentials();
21
- if (creds.apikey) {
21
+ if (creds?.apikey) {
22
22
  return;
23
23
  }
24
24
  const { apikey } = await prompts([
@@ -29,7 +29,7 @@ class CredentialsStore {
29
29
  }
30
30
  // Return credentials
31
31
  const config = await fs.readJSON(this.credentials_path);
32
- return config;
32
+ return config || {};
33
33
  }
34
34
  }
35
35
 
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "yaml": "^2.2.2",
15
15
  "yargs": "^17.6.2"
16
16
  },
17
- "version": "1.4.4",
17
+ "version": "1.4.6",
18
18
  "bin": {
19
19
  "faable": "bin/faable.js"
20
20
  },