@nocobase/cli-v1 2.1.0-alpha.34 → 2.1.0-alpha.36

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/nocobase.conf.tpl CHANGED
@@ -33,9 +33,19 @@ server {
33
33
  gzip on;
34
34
  gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
35
35
 
36
+ location ~* ^{{publicPath}}storage/uploads/(.*\.(?:htm|html|svg|svgz|xhtml))$ {
37
+ alias {{cwd}}/storage/uploads/$1;
38
+ add_header Cache-Control "public";
39
+ add_header Content-Disposition "attachment" always;
40
+ add_header X-Content-Type-Options "nosniff" always;
41
+ access_log off;
42
+ autoindex off;
43
+ }
44
+
36
45
  location {{publicPath}}storage/uploads/ {
37
46
  alias {{cwd}}/storage/uploads/;
38
47
  add_header Cache-Control "public";
48
+ add_header X-Content-Type-Options "nosniff" always;
39
49
  access_log off;
40
50
  autoindex off;
41
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli-v1",
3
- "version": "2.1.0-alpha.34",
3
+ "version": "2.1.0-alpha.36",
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.34",
11
+ "@nocobase/cli": "2.1.0-alpha.36",
12
12
  "@nocobase/license-kit": "^0.3.8",
13
- "@nocobase/utils": "2.1.0-alpha.34",
14
- "@types/fs-extra": "^11.0.1",
15
- "@umijs/utils": "3.5.20",
13
+ "@nocobase/utils": "2.1.0-alpha.36",
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.34"
28
+ "@nocobase/devtools": "2.1.0-alpha.36",
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": "59970f73bdbea2656e20cd24357bacf78a3f759f"
36
+ "gitHead": "54cf3ac93b02ea9a409def6ebe4bdfdad07d0691"
39
37
  }
@@ -9,7 +9,12 @@
9
9
 
10
10
  const testCommandModule = require('../commands/test');
11
11
 
12
- const { buildVitestNodeArgs, requiresNoNodeSnapshot } = testCommandModule._test;
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
  });
@@ -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
  };
package/src/util.js CHANGED
@@ -227,6 +227,38 @@ exports.getVersion = async () => {
227
227
  return versions[versions.length - 1];
228
228
  };
229
229
 
230
+ function normalizeAppDevClientRsbuildConfig(appDevDir) {
231
+ const configPath = resolve(appDevDir, 'client/rsbuild.config.ts');
232
+ if (!existsSync(configPath)) {
233
+ return;
234
+ }
235
+ const content = fs.readFileSync(configPath, 'utf-8');
236
+ const normalized = content.replace(
237
+ "require('../../devtools/package.json')",
238
+ "require('@nocobase/devtools/package.json')",
239
+ );
240
+ if (normalized !== content) {
241
+ fs.writeFileSync(configPath, normalized, 'utf-8');
242
+ }
243
+ }
244
+
245
+ function normalizeAppDevClientV2Tsconfig(appDevDir) {
246
+ const tsconfigPath = resolve(appDevDir, 'client-v2/tsconfig.json');
247
+ if (!existsSync(tsconfigPath)) {
248
+ return;
249
+ }
250
+ const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
251
+ tsconfig.extends = '../../../tsconfig.json';
252
+ tsconfig.compilerOptions = tsconfig.compilerOptions || {};
253
+ tsconfig.compilerOptions.baseUrl = '../../../';
254
+ fs.writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\n`, 'utf-8');
255
+ }
256
+
257
+ function normalizeAppDevFiles(appDevDir) {
258
+ normalizeAppDevClientRsbuildConfig(appDevDir);
259
+ normalizeAppDevClientV2Tsconfig(appDevDir);
260
+ }
261
+
230
262
  exports.generateAppDir = function generateAppDir() {
231
263
  const appPkgPath = dirname(dirname(require.resolve('@nocobase/app/src/index.ts')));
232
264
  const appDevDir = resolve(process.cwd(), './storage/.app-dev');
@@ -238,6 +270,7 @@ exports.generateAppDir = function generateAppDir() {
238
270
  force: true,
239
271
  });
240
272
  }
273
+ normalizeAppDevFiles(appDevDir);
241
274
  process.env.APP_PACKAGE_ROOT = appDevDir;
242
275
  } else {
243
276
  process.env.APP_PACKAGE_ROOT = appPkgPath;