@nocobase/cli-v1 2.1.0-alpha.35 → 2.1.0-alpha.37
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-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.37",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,11 +8,9 @@
|
|
|
8
8
|
"nocobase-v1": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/cli": "2.1.0-alpha.
|
|
11
|
+
"@nocobase/cli": "2.1.0-alpha.37",
|
|
12
12
|
"@nocobase/license-kit": "^0.3.8",
|
|
13
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
14
|
-
"@types/fs-extra": "^11.0.1",
|
|
15
|
-
"@umijs/utils": "3.5.20",
|
|
13
|
+
"@nocobase/utils": "2.1.0-alpha.37",
|
|
16
14
|
"chalk": "^4.1.1",
|
|
17
15
|
"commander": "^9.2.0",
|
|
18
16
|
"deepmerge": "^4.3.1",
|
|
@@ -24,16 +22,16 @@
|
|
|
24
22
|
"pm2": "^6.0.5",
|
|
25
23
|
"portfinder": "^1.0.28",
|
|
26
24
|
"tar": "^7.4.3",
|
|
27
|
-
"tree-kill": "^1.2.2"
|
|
28
|
-
"tsx": "^4.19.0"
|
|
25
|
+
"tree-kill": "^1.2.2"
|
|
29
26
|
},
|
|
30
27
|
"devDependencies": {
|
|
31
|
-
"@nocobase/devtools": "2.1.0-alpha.
|
|
28
|
+
"@nocobase/devtools": "2.1.0-alpha.37",
|
|
29
|
+
"@types/fs-extra": "^11.0.1"
|
|
32
30
|
},
|
|
33
31
|
"repository": {
|
|
34
32
|
"type": "git",
|
|
35
33
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
36
34
|
"directory": "packages/core/cli"
|
|
37
35
|
},
|
|
38
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "8b45f4586ea5b386b376188cfc1012ec12e9bc8b"
|
|
39
37
|
}
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
const testCommandModule = require('../commands/test');
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
buildVitestNodeArgs,
|
|
14
|
+
requiresNoNodeSnapshot,
|
|
15
|
+
stripDelegatedWorkspaceArgs,
|
|
16
|
+
resolveWorkspaceTestDelegation,
|
|
17
|
+
} = testCommandModule._test;
|
|
13
18
|
|
|
14
19
|
describe('cli-v1 test command helpers', () => {
|
|
15
20
|
test('requiresNoNodeSnapshot enables the Node 20+ compatibility flag', () => {
|
|
@@ -34,4 +39,32 @@ describe('cli-v1 test command helpers', () => {
|
|
|
34
39
|
'foo.test.ts',
|
|
35
40
|
]);
|
|
36
41
|
});
|
|
42
|
+
|
|
43
|
+
test('stripDelegatedWorkspaceArgs removes workspace-only routing flags while preserving extra test args', () => {
|
|
44
|
+
expect(
|
|
45
|
+
stripDelegatedWorkspaceArgs(
|
|
46
|
+
[
|
|
47
|
+
'packages/core/cli',
|
|
48
|
+
'--server',
|
|
49
|
+
'--single-thread=true',
|
|
50
|
+
'--runInBand',
|
|
51
|
+
'src/__tests__/skills-manager.test.ts',
|
|
52
|
+
],
|
|
53
|
+
'packages/core/cli',
|
|
54
|
+
),
|
|
55
|
+
).toEqual(['--runInBand', 'src/__tests__/skills-manager.test.ts']);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('resolveWorkspaceTestDelegation forwards workspace package roots that define a test script', () => {
|
|
59
|
+
const delegation = resolveWorkspaceTestDelegation(
|
|
60
|
+
['packages/core/cli'],
|
|
61
|
+
['packages/core/cli', '--server'],
|
|
62
|
+
'/Users/chen/t300/app5/source',
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(delegation).toEqual({
|
|
66
|
+
packageDir: '/Users/chen/t300/app5/source/packages/core/cli',
|
|
67
|
+
forwardedArgv: [],
|
|
68
|
+
});
|
|
69
|
+
});
|
|
37
70
|
});
|
package/src/commands/test.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
const { Command } = require('commander');
|
|
11
11
|
const { run, checkDBDialect } = require('../util');
|
|
12
12
|
const path = require('path');
|
|
13
|
+
const fs = require('fs');
|
|
13
14
|
|
|
14
15
|
function stripSingleThreadArgs(argv) {
|
|
15
16
|
const nextArgv = [];
|
|
@@ -35,6 +36,85 @@ function stripSingleThreadArgs(argv) {
|
|
|
35
36
|
return nextArgv;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
function stripDelegatedWorkspaceArgs(argv, delegatedPath) {
|
|
40
|
+
const nextArgv = [];
|
|
41
|
+
const normalizedDelegatedPath = String(delegatedPath || '')
|
|
42
|
+
.trim()
|
|
43
|
+
.split(path.sep)
|
|
44
|
+
.join('/');
|
|
45
|
+
let skippedPath = false;
|
|
46
|
+
|
|
47
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
48
|
+
const token = argv[index];
|
|
49
|
+
const normalizedToken = String(token || '')
|
|
50
|
+
.trim()
|
|
51
|
+
.split(path.sep)
|
|
52
|
+
.join('/');
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
!skippedPath &&
|
|
56
|
+
normalizedDelegatedPath &&
|
|
57
|
+
!token.startsWith('-') &&
|
|
58
|
+
normalizedToken === normalizedDelegatedPath
|
|
59
|
+
) {
|
|
60
|
+
skippedPath = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (token === '--server' || token === '--client') {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (token === '--single-thread') {
|
|
69
|
+
const next = argv[index + 1];
|
|
70
|
+
if (next && !next.startsWith('-')) {
|
|
71
|
+
index += 1;
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (token.startsWith('--single-thread=')) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
nextArgv.push(token);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return nextArgv;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function resolveWorkspaceTestDelegation(paths = [], argv = process.argv.slice(3), cwd = process.cwd()) {
|
|
87
|
+
const firstPath = String(paths?.[0] || '').trim();
|
|
88
|
+
if (!firstPath) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const packageDir = path.resolve(cwd, firstPath);
|
|
93
|
+
if (packageDir === cwd) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const packageJsonPath = path.join(packageDir, 'package.json');
|
|
98
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
104
|
+
const testScript = String(packageJson?.scripts?.test || '').trim();
|
|
105
|
+
if (!testScript) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
packageDir,
|
|
111
|
+
forwardedArgv: stripDelegatedWorkspaceArgs(argv, firstPath),
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
38
118
|
function requiresNoNodeSnapshot(nodeVersion = process.versions.node) {
|
|
39
119
|
const major = Number.parseInt(String(nodeVersion).split('.')[0], 10);
|
|
40
120
|
return Number.isFinite(major) && major >= 20;
|
|
@@ -69,6 +149,12 @@ function addTestCommand(name, cli) {
|
|
|
69
149
|
.arguments('[paths...]')
|
|
70
150
|
.allowUnknownOption()
|
|
71
151
|
.action(async (paths, opts) => {
|
|
152
|
+
const delegation = name === 'test' ? resolveWorkspaceTestDelegation(paths, process.argv.slice(3)) : undefined;
|
|
153
|
+
if (delegation) {
|
|
154
|
+
await run('yarn', ['--cwd', delegation.packageDir, 'test', ...delegation.forwardedArgv]);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
72
158
|
checkDBDialect();
|
|
73
159
|
if (name === 'test:server') {
|
|
74
160
|
process.env.TEST_ENV = 'server-side';
|
|
@@ -144,6 +230,8 @@ module.exports = (cli) => {
|
|
|
144
230
|
|
|
145
231
|
module.exports._test = {
|
|
146
232
|
stripSingleThreadArgs,
|
|
233
|
+
stripDelegatedWorkspaceArgs,
|
|
234
|
+
resolveWorkspaceTestDelegation,
|
|
147
235
|
requiresNoNodeSnapshot,
|
|
148
236
|
buildVitestNodeArgs,
|
|
149
237
|
};
|