esa-cli 1.0.3-beta.3 → 1.0.3

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.
@@ -1,10 +1,8 @@
1
- import worker from '$userPath';
2
1
  import Cache from './mock/cache.js';
3
2
  import mockKV from './mock/kv.js';
3
+ import worker from '$userPath';
4
4
 
5
- var mock_cache = new Cache($userPort);
6
- globalThis.mockCache = mock_cache;
5
+ Cache.port = $userPort;
7
6
  mockKV.port = $userPort;
8
- globalThis.mockKV = mockKV;
9
7
 
10
8
  export default worker;
@@ -1,7 +1,7 @@
1
1
  class MockCache {
2
- constructor(port) {
3
- this.port = port;
4
- }
2
+ static port = 0;
3
+
4
+ constructor() {}
5
5
 
6
6
  async put(reqOrUrl, response) {
7
7
  if (arguments.length < 2) {
@@ -30,7 +30,7 @@ class MockCache {
30
30
 
31
31
  const key = this.normalizeKey(reqOrUrl);
32
32
  const fetchRes = await fetch(
33
- `http://localhost:${this.port}/mock_cache/put`,
33
+ `http://localhost:${MockCache.port}/mock_cache/put`,
34
34
  {
35
35
  method: 'POST',
36
36
  headers: { 'Content-Type': 'application/json' },
@@ -58,7 +58,7 @@ class MockCache {
58
58
  async get(reqOrUrl) {
59
59
  const key = this.normalizeKey(reqOrUrl);
60
60
  const fetchRes = await fetch(
61
- `http://localhost:${this.port}/mock_cache/get`,
61
+ `http://localhost:${MockCache.port}/mock_cache/get`,
62
62
  {
63
63
  method: 'POST',
64
64
  headers: { 'Content-Type': 'application/json' },
@@ -85,7 +85,7 @@ class MockCache {
85
85
  async delete(reqOrUrl) {
86
86
  const key = this.normalizeKey(reqOrUrl);
87
87
  const fetchRes = await fetch(
88
- `http://localhost:${this.port}/mock_cache/delete`,
88
+ `http://localhost:${MockCache.port}/mock_cache/delete`,
89
89
  {
90
90
  method: 'POST',
91
91
  headers: { 'Content-Type': 'application/json' },
@@ -113,4 +113,7 @@ class MockCache {
113
113
  }
114
114
  }
115
115
 
116
+ var mock_cache = new MockCache();
117
+ globalThis.mockCache = mock_cache;
118
+
116
119
  export default MockCache;
@@ -163,4 +163,6 @@ class EdgeKV {
163
163
  }
164
164
  }
165
165
 
166
+ globalThis.mockKV = EdgeKV;
167
+
166
168
  export default EdgeKV;
@@ -17,7 +17,7 @@ import Haikunator from 'haikunator';
17
17
  import t from '../../i18n/index.js';
18
18
  import logger from '../../libs/logger.js';
19
19
  import Template from '../../libs/templates/index.js';
20
- import { execCommand } from '../../utils/command.js';
20
+ import { execCommand, execWithLoginShell } from '../../utils/command.js';
21
21
  import { getDirName } from '../../utils/fileUtils/base.js';
22
22
  import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
23
23
  import promptParameter from '../../utils/prompt.js';
@@ -382,7 +382,7 @@ export const createProject = (initParams) => __awaiter(void 0, void 0, void 0, f
382
382
  const templateFlag = ((_a = frameworkConfig.language) === null || _a === void 0 ? void 0 : _a[initParams.language || 'typescript']) || '';
383
383
  const extraParams = frameworkConfig.params || '';
384
384
  const full = `${command} ${initParams.name} ${templateFlag} ${extraParams}`.trim();
385
- const res = yield execCommand(['sh', '-lc', full], {
385
+ const res = yield execWithLoginShell(full, {
386
386
  interactive: true,
387
387
  startText: `Starting to execute framework command ${chalk.gray(full)}`,
388
388
  doneText: `Framework command executed ${chalk.gray(full)}`
package/dist/index.js CHANGED
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import chalk from 'chalk';
11
11
  import yargs from 'yargs';
12
12
  import { hideBin } from 'yargs/helpers';
13
- import logger from './libs/logger.js';
14
13
  import commit from './commands/commit/index.js';
15
14
  import config from './commands/config.js';
16
15
  import deploy from './commands/deploy/index.js';
@@ -25,6 +24,7 @@ import routeCommand from './commands/route/index.js';
25
24
  import routine from './commands/routine/index.js';
26
25
  import site from './commands/site/index.js';
27
26
  import t from './i18n/index.js';
27
+ import logger from './libs/logger.js';
28
28
  import { handleCheckVersion, checkCLIVersion } from './utils/checkVersion.js';
29
29
  import { getCliConfig } from './utils/fileUtils/index.js';
30
30
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
package/dist/libs/api.js CHANGED
@@ -12,6 +12,7 @@ import * as $OpenApi from '@alicloud/openapi-client';
12
12
  import * as $Util from '@alicloud/tea-util';
13
13
  import { getApiConfig } from '../utils/fileUtils/index.js';
14
14
  import logger from './logger.js';
15
+ import { CLI_USER_AGENT } from './constants.js';
15
16
  class Client {
16
17
  constructor() {
17
18
  this.callApi = (action, request) => __awaiter(this, void 0, void 0, function* () {
@@ -77,7 +78,8 @@ class Client {
77
78
  const apiConfig = new $OpenApi.Config({
78
79
  accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
79
80
  accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
80
- endpoint: config.endpoint
81
+ endpoint: config.endpoint,
82
+ userAgent: CLI_USER_AGENT
81
83
  });
82
84
  return new ESA.default(apiConfig);
83
85
  }
@@ -13,13 +13,15 @@ import fetch from 'node-fetch';
13
13
  import t from '../i18n/index.js';
14
14
  import { getApiConfig } from '../utils/fileUtils/index.js';
15
15
  import { Environment } from './interface.js';
16
+ import { CLI_USER_AGENT } from './constants.js';
16
17
  export class ApiService {
17
18
  constructor(cliConfig) {
18
19
  var _a, _b;
19
20
  let apiConfig = new $OpenApi.Config({
20
21
  accessKeyId: (_a = cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
21
22
  accessKeySecret: (_b = cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
22
- endpoint: cliConfig.endpoint
23
+ endpoint: cliConfig.endpoint,
24
+ userAgent: CLI_USER_AGENT
23
25
  });
24
26
  this.client = new $OpenApi.default.default(apiConfig);
25
27
  }
@@ -37,7 +39,8 @@ export class ApiService {
37
39
  let apiConfig = new $OpenApi.Config({
38
40
  accessKeyId: (_a = newConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
39
41
  accessKeySecret: (_b = newConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
40
- endpoint: newConfig.endpoint
42
+ endpoint: newConfig.endpoint,
43
+ userAgent: CLI_USER_AGENT
41
44
  });
42
45
  this.client = new $OpenApi.default.default(apiConfig);
43
46
  }
@@ -0,0 +1,13 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ const packageJson = require('../../package.json');
4
+ /**
5
+ * CLI User-Agent string for API requests
6
+ * Format: esa-cli/{version}
7
+ * This helps identify requests originating from the CLI
8
+ */
9
+ export const CLI_USER_AGENT = `esa-cli/${packageJson.version}`;
10
+ /**
11
+ * CLI version from package.json
12
+ */
13
+ export const CLI_VERSION = packageJson.version;
@@ -63,9 +63,6 @@ class Logger {
63
63
  get ora() {
64
64
  return this.spinner;
65
65
  }
66
- get isDebug() {
67
- return this.logger.level === 'debug';
68
- }
69
66
  setLogLevel(level) {
70
67
  this.logger.level = level;
71
68
  }
@@ -8,14 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { spawn } from 'child_process';
11
+ import { platform } from 'os';
11
12
  import { cancel, spinner } from '@clack/prompts';
12
13
  import chalk from 'chalk';
13
- import logger from '../libs/logger.js';
14
+ export const isWindows = platform() === 'win32';
14
15
  /**
15
16
  * Execute a shell command with rich options (spinner, capture, env, cwd).
16
17
  */
17
18
  export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_1, ...args_1], void 0, function* (command, options = {}) {
18
- const { startText, doneText, silent = false, captureOutput = false, useSpinner = true, realtimeOutput = false, interactive = false, env, cwd, transformOutput, fallbackOutput, errorMessage, debug = logger.isDebug } = options;
19
+ const { startText, doneText, silent = false, captureOutput = false, useSpinner = true, realtimeOutput = false, interactive = false, env, cwd, transformOutput, fallbackOutput, errorMessage, shell = false } = options;
19
20
  // Determine stdio mode based on options
20
21
  // If realtimeOutput is true, we need to pipe to capture and display output in real-time
21
22
  // If spinner is used without realtimeOutput, pipe to avoid TTY contention
@@ -56,7 +57,7 @@ export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_
56
57
  stdio,
57
58
  cwd,
58
59
  env: Object.assign(Object.assign({}, process.env), env),
59
- shell: false
60
+ shell
60
61
  });
61
62
  if (stdio === 'pipe') {
62
63
  (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
@@ -141,27 +142,27 @@ export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_
141
142
  if (stderr)
142
143
  process.stderr.write(stderr);
143
144
  }
144
- if (debug) {
145
- console.error(chalk.red('\n--- DEBUG INFO ---'));
146
- console.error(chalk.red(`Command: ${command.join(' ')}`));
147
- if (cwd)
148
- console.error(chalk.red(`CWD: ${cwd}`));
149
- if (stdout)
150
- console.error(chalk.red(`Stdout:\n${stdout}`));
151
- if (stderr)
152
- console.error(chalk.red(`Stderr:\n${stderr}`));
153
- if (e instanceof Error && e.stack) {
154
- console.error(chalk.red(`Stack:\n${e.stack}`));
155
- }
156
- else if (e && typeof e === 'object') {
157
- console.error(chalk.red(`Error Object:\n${JSON.stringify(e, null, 2)}`));
158
- }
159
- console.error(chalk.red('------------------\n'));
160
- }
161
145
  if (errorMessage) {
162
146
  cancel(errorMessage);
163
147
  }
164
148
  return { success: false, stdout, stderr };
165
149
  }
166
150
  });
151
+ /**
152
+ * Execute a command with login shell on Unix (to load ~/.profile, ~/.zshrc etc.)
153
+ * On Windows, directly execute the command since login shell is not typically needed.
154
+ *
155
+ * @param commandStr - The full command string to execute
156
+ * @param options - ExecCommandOptions
157
+ */
158
+ export const execWithLoginShell = (commandStr_1, ...args_1) => __awaiter(void 0, [commandStr_1, ...args_1], void 0, function* (commandStr, options = {}) {
159
+ if (isWindows) {
160
+ // Windows: use cmd /c to execute the command
161
+ return execCommand(['cmd', '/c', commandStr], options);
162
+ }
163
+ else {
164
+ // Unix: use login shell to ensure PATH is properly set (nvm, fnm, etc.)
165
+ return execCommand(['sh', '-lc', commandStr], options);
166
+ }
167
+ });
167
168
  export default execCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.3-beta.3",
3
+ "version": "1.0.3",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",