@nocobase/cli-v1 2.1.0-beta.16 → 2.1.0-beta.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli-v1",
3
- "version": "2.1.0-beta.16",
3
+ "version": "2.1.0-beta.19",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
@@ -8,9 +8,9 @@
8
8
  "nocobase-v1": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/cli": "2.1.0-beta.16",
11
+ "@nocobase/cli": "2.1.0-beta.19",
12
12
  "@nocobase/license-kit": "^0.3.8",
13
- "@nocobase/utils": "2.1.0-beta.16",
13
+ "@nocobase/utils": "2.1.0-beta.19",
14
14
  "@types/fs-extra": "^11.0.1",
15
15
  "@umijs/utils": "3.5.20",
16
16
  "chalk": "^4.1.1",
@@ -28,12 +28,12 @@
28
28
  "tsx": "^4.19.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@nocobase/devtools": "2.1.0-beta.16"
31
+ "@nocobase/devtools": "2.1.0-beta.19"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",
35
35
  "url": "git+https://github.com/nocobase/nocobase.git",
36
36
  "directory": "packages/core/cli"
37
37
  },
38
- "gitHead": "b9a191705a440a336c85d82fd877fdf152bec70f"
38
+ "gitHead": "d89ab08dbcb25877de69827d5bad6823c27b2cbb"
39
39
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ const testCommandModule = require('../commands/test');
11
+
12
+ const { buildVitestNodeArgs, requiresNoNodeSnapshot } = testCommandModule._test;
13
+
14
+ describe('cli-v1 test command helpers', () => {
15
+ test('requiresNoNodeSnapshot enables the Node 20+ compatibility flag', () => {
16
+ expect(requiresNoNodeSnapshot('18.20.8')).toBe(false);
17
+ expect(requiresNoNodeSnapshot('20.19.5')).toBe(true);
18
+ expect(requiresNoNodeSnapshot('22.22.2')).toBe(true);
19
+ });
20
+
21
+ test('buildVitestNodeArgs prefixes no-node-snapshot on Node 20+', () => {
22
+ expect(buildVitestNodeArgs(['foo.test.ts', '--single-thread=true'], '20.19.5')).toEqual([
23
+ '--no-node-snapshot',
24
+ '--max_old_space_size=14096',
25
+ './node_modules/vitest/vitest.mjs',
26
+ 'foo.test.ts',
27
+ ]);
28
+ });
29
+
30
+ test('buildVitestNodeArgs leaves older Node versions unchanged', () => {
31
+ expect(buildVitestNodeArgs(['foo.test.ts'], '18.20.8')).toEqual([
32
+ '--max_old_space_size=14096',
33
+ './node_modules/vitest/vitest.mjs',
34
+ 'foo.test.ts',
35
+ ]);
36
+ });
37
+ });
@@ -11,6 +11,46 @@ const { Command } = require('commander');
11
11
  const { run, checkDBDialect } = require('../util');
12
12
  const path = require('path');
13
13
 
14
+ function stripSingleThreadArgs(argv) {
15
+ const nextArgv = [];
16
+
17
+ for (let index = 0; index < argv.length; index += 1) {
18
+ const token = argv[index];
19
+
20
+ if (token === '--single-thread') {
21
+ const next = argv[index + 1];
22
+ if (next && !next.startsWith('-')) {
23
+ index += 1;
24
+ }
25
+ continue;
26
+ }
27
+
28
+ if (token.startsWith('--single-thread=')) {
29
+ continue;
30
+ }
31
+
32
+ nextArgv.push(token);
33
+ }
34
+
35
+ return nextArgv;
36
+ }
37
+
38
+ function requiresNoNodeSnapshot(nodeVersion = process.versions.node) {
39
+ const major = Number.parseInt(String(nodeVersion).split('.')[0], 10);
40
+ return Number.isFinite(major) && major >= 20;
41
+ }
42
+
43
+ function buildVitestNodeArgs(argv, nodeVersion = process.versions.node) {
44
+ const cliArgs = ['--max_old_space_size=14096', './node_modules/vitest/vitest.mjs', ...stripSingleThreadArgs(argv)];
45
+
46
+ // `isolated-vm` requires `--no-node-snapshot` on Node 20+.
47
+ if (requiresNoNodeSnapshot(nodeVersion)) {
48
+ cliArgs.unshift('--no-node-snapshot');
49
+ }
50
+
51
+ return cliArgs;
52
+ }
53
+
14
54
  /**
15
55
  *
16
56
  * @param {String} name
@@ -65,28 +105,24 @@ function addTestCommand(name, cli) {
65
105
  process.argv.push('--poolOptions.threads.singleThread=true');
66
106
  }
67
107
 
68
- if (opts.singleThread === 'false') {
69
- process.argv.splice(process.argv.indexOf('--single-thread=false'), 1);
70
- }
71
-
72
- const cliArgs = ['--max_old_space_size=14096', './node_modules/vitest/vitest.mjs', ...process.argv.slice(3)];
108
+ const cliArgs = buildVitestNodeArgs(process.argv.slice(3));
73
109
 
74
110
  if (process.argv.includes('-h') || process.argv.includes('--help')) {
75
- await run('node', cliArgs);
111
+ await run(process.execPath, cliArgs);
76
112
  return;
77
113
  }
78
114
 
79
115
  if (process.env.TEST_ENV) {
80
116
  console.log('process.env.TEST_ENV', process.env.TEST_ENV, cliArgs);
81
- await run('node', cliArgs);
117
+ await run(process.execPath, cliArgs);
82
118
  } else {
83
119
  await Promise.all([
84
- run('node', cliArgs, {
120
+ run(process.execPath, cliArgs, {
85
121
  env: {
86
122
  TEST_ENV: 'client-side',
87
123
  },
88
124
  }),
89
- run('node', cliArgs, {
125
+ run(process.execPath, cliArgs, {
90
126
  env: {
91
127
  TEST_ENV: 'server-side',
92
128
  },
@@ -105,3 +141,9 @@ module.exports = (cli) => {
105
141
  addTestCommand('test:client', cli);
106
142
  addTestCommand('test', cli).option('--client').option('--server');
107
143
  };
144
+
145
+ module.exports._test = {
146
+ stripSingleThreadArgs,
147
+ requiresNoNodeSnapshot,
148
+ buildVitestNodeArgs,
149
+ };