@snap/valdi 1.0.1 → 1.0.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.
- package/.bootstrap/apps/cli_application/AGENTS.md.template +76 -0
- package/.bootstrap/apps/ui_application/AGENTS.md.template +79 -3
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +3 -3
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +18 -19
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +3 -0
- package/.github/README.md +164 -0
- package/.metadata/.cursorrules.template +53 -0
- package/.metadata/.editorconfig.template +37 -0
- package/LINUX_COMPATIBILITY.md +248 -0
- package/README.md +99 -15
- package/dist/commands/bootstrap.js +79 -19
- package/dist/commands/doctor.js +361 -54
- package/dist/commands/newModule.js +15 -12
- package/dist/core/constants.js +2 -0
- package/dist/setup/DevSetupHelper.js +81 -6
- package/dist/setup/linuxSetup.js +149 -11
- package/dist/setup/macOSSetup.js +96 -8
- package/dist/utils/githubUtils.js +74 -2
- package/dist/utils/linuxDistro.js +255 -0
- package/dist/utils/linuxDistro.spec.js +170 -0
- package/dist/utils/stringUtils.js +60 -0
- package/dist/utils/stringUtils.spec.js +63 -0
- package/package.json +11 -3
- package/scripts/sync-agents-md.sh +44 -0
- package/scripts/update-agents-templates.ts +170 -0
- package/src/commands/bootstrap.ts +117 -25
- package/src/commands/doctor.ts +469 -59
- package/src/commands/newModule.ts +18 -19
- package/src/core/constants.ts +2 -0
- package/src/setup/DevSetupHelper.ts +108 -6
- package/src/setup/linuxSetup.ts +235 -12
- package/src/setup/macOSSetup.ts +122 -8
- package/src/utils/githubUtils.ts +98 -2
- package/src/utils/linuxDistro.spec.ts +219 -0
- package/src/utils/linuxDistro.ts +326 -0
- package/src/utils/stringUtils.spec.ts +77 -1
- package/src/utils/stringUtils.ts +88 -0
- package/test/ValdiSmokeTest.ts +5 -4
- package/test/helpers/TypeScriptClient.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'jasmine';
|
|
2
|
-
import { toPascalCase, toSnakeCase } from './stringUtils';
|
|
2
|
+
import { sanitizeProjectName, toPascalCase, toSnakeCase, validateProjectName } from './stringUtils';
|
|
3
3
|
|
|
4
4
|
describe('stringUtils', () => {
|
|
5
5
|
it('converts strings to pascal case', () => {
|
|
@@ -15,5 +15,81 @@ describe('stringUtils', () => {
|
|
|
15
15
|
expect(toSnakeCase(input)).toBe(expected);
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
|
+
|
|
19
|
+
describe('sanitizeProjectName', () => {
|
|
20
|
+
it('replaces dashes with underscores', () => {
|
|
21
|
+
expect(sanitizeProjectName('my-project')).toBe('my_project');
|
|
22
|
+
expect(sanitizeProjectName('my-cool-app')).toBe('my_cool_app');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('preserves original case', () => {
|
|
26
|
+
expect(sanitizeProjectName('MyProject')).toBe('MyProject');
|
|
27
|
+
expect(sanitizeProjectName('MY_PROJECT')).toBe('MY_PROJECT');
|
|
28
|
+
expect(sanitizeProjectName('testNewModule')).toBe('testNewModule');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('removes invalid characters', () => {
|
|
32
|
+
expect(sanitizeProjectName('my project!')).toBe('myproject');
|
|
33
|
+
expect(sanitizeProjectName('my@project#')).toBe('myproject');
|
|
34
|
+
expect(sanitizeProjectName('my.project')).toBe('myproject');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('prefixes with underscore if starts with number', () => {
|
|
38
|
+
expect(sanitizeProjectName('123project')).toBe('_123project');
|
|
39
|
+
expect(sanitizeProjectName('7-eleven')).toBe('_7_eleven');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('handles mixed cases', () => {
|
|
43
|
+
expect(sanitizeProjectName('My-Cool_Project123')).toBe('My_Cool_Project123');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('handles already valid names', () => {
|
|
47
|
+
expect(sanitizeProjectName('my_project')).toBe('my_project');
|
|
48
|
+
expect(sanitizeProjectName('myproject')).toBe('myproject');
|
|
49
|
+
expect(sanitizeProjectName('my_project_123')).toBe('my_project_123');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('validateProjectName', () => {
|
|
54
|
+
it('rejects empty names', () => {
|
|
55
|
+
expect(validateProjectName('')).toBeTruthy();
|
|
56
|
+
expect(validateProjectName(' ')).toBeTruthy();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('rejects reserved words (case-insensitive)', () => {
|
|
60
|
+
expect(validateProjectName('test')).toContain('reserved word');
|
|
61
|
+
expect(validateProjectName('Test')).toContain('reserved word');
|
|
62
|
+
expect(validateProjectName('TEST')).toContain('reserved word');
|
|
63
|
+
expect(validateProjectName('build')).toContain('reserved word');
|
|
64
|
+
expect(validateProjectName('workspace')).toContain('reserved word');
|
|
65
|
+
expect(validateProjectName('native')).toContain('reserved word');
|
|
66
|
+
expect(validateProjectName('package')).toContain('reserved word');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('accepts valid names with mixed case', () => {
|
|
70
|
+
expect(validateProjectName('my_project')).toBeNull();
|
|
71
|
+
expect(validateProjectName('myproject')).toBeNull();
|
|
72
|
+
expect(validateProjectName('my_cool_app')).toBeNull();
|
|
73
|
+
expect(validateProjectName('project123')).toBeNull();
|
|
74
|
+
expect(validateProjectName('MyProject')).toBeNull();
|
|
75
|
+
expect(validateProjectName('testNewModule')).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('accepts names with dashes (they will be sanitized)', () => {
|
|
79
|
+
expect(validateProjectName('my-project')).toBeNull();
|
|
80
|
+
expect(validateProjectName('my-cool-app')).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('rejects names with only invalid characters', () => {
|
|
84
|
+
expect(validateProjectName('!!!')).toBeTruthy();
|
|
85
|
+
expect(validateProjectName('...')).toBeTruthy();
|
|
86
|
+
expect(validateProjectName('@#$')).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('handles names that start with numbers', () => {
|
|
90
|
+
// These are valid because sanitization will prefix with underscore
|
|
91
|
+
expect(validateProjectName('123project')).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
18
94
|
});
|
|
19
95
|
|
package/src/utils/stringUtils.ts
CHANGED
|
@@ -1,5 +1,93 @@
|
|
|
1
1
|
const wordSplitRegex = /[\W_]/;
|
|
2
2
|
|
|
3
|
+
// Bazel and common programming language reserved words that should not be used as project names
|
|
4
|
+
const RESERVED_PROJECT_NAMES = new Set([
|
|
5
|
+
// Bazel reserved words
|
|
6
|
+
'test',
|
|
7
|
+
'tests',
|
|
8
|
+
'build',
|
|
9
|
+
'workspace',
|
|
10
|
+
'native',
|
|
11
|
+
'rule',
|
|
12
|
+
'package',
|
|
13
|
+
'glob',
|
|
14
|
+
'select',
|
|
15
|
+
'repository',
|
|
16
|
+
'external',
|
|
17
|
+
'bazel',
|
|
18
|
+
// Common programming language keywords that might cause issues
|
|
19
|
+
'class',
|
|
20
|
+
'function',
|
|
21
|
+
'var',
|
|
22
|
+
'let',
|
|
23
|
+
'const',
|
|
24
|
+
'if',
|
|
25
|
+
'else',
|
|
26
|
+
'for',
|
|
27
|
+
'while',
|
|
28
|
+
'return',
|
|
29
|
+
'import',
|
|
30
|
+
'export',
|
|
31
|
+
'module',
|
|
32
|
+
'require',
|
|
33
|
+
// Other problematic names
|
|
34
|
+
'main',
|
|
35
|
+
'lib',
|
|
36
|
+
'src',
|
|
37
|
+
'bin',
|
|
38
|
+
'data',
|
|
39
|
+
'config',
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Sanitizes a project name to be safe for use in Bazel rules and generated code.
|
|
44
|
+
* - Replaces dashes with underscores
|
|
45
|
+
* - Removes any characters that are not alphanumeric or underscore
|
|
46
|
+
* - Ensures the name starts with a letter or underscore
|
|
47
|
+
* - Preserves original case (Bazel target names are case-sensitive)
|
|
48
|
+
*/
|
|
49
|
+
export function sanitizeProjectName(name: string): string {
|
|
50
|
+
// Replace dashes with underscores
|
|
51
|
+
let sanitized = name.replace(/-/g, '_');
|
|
52
|
+
|
|
53
|
+
// Remove any characters that are not alphanumeric or underscore
|
|
54
|
+
sanitized = sanitized.replace(/[^a-zA-Z0-9_]/g, '');
|
|
55
|
+
|
|
56
|
+
// Ensure it starts with a letter or underscore
|
|
57
|
+
if (sanitized.length > 0 && /^[0-9]/.test(sanitized)) {
|
|
58
|
+
sanitized = '_' + sanitized;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return sanitized;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validates a project name and returns an error message if invalid, or null if valid.
|
|
66
|
+
*/
|
|
67
|
+
export function validateProjectName(name: string): string | null {
|
|
68
|
+
if (!name || name.trim().length === 0) {
|
|
69
|
+
return 'Project name cannot be empty.';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const sanitized = sanitizeProjectName(name);
|
|
73
|
+
|
|
74
|
+
if (sanitized.length === 0) {
|
|
75
|
+
return 'Project name must contain at least one alphanumeric character.';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Check if the sanitized name (case-insensitive) is a reserved word
|
|
79
|
+
if (RESERVED_PROJECT_NAMES.has(sanitized.toLowerCase())) {
|
|
80
|
+
return `Project name "${name}" (sanitized to "${sanitized}") is a reserved word and cannot be used. Please choose a different name.`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Warn if the name was significantly changed during sanitization
|
|
84
|
+
if (sanitized !== name.replace(/-/g, '_')) {
|
|
85
|
+
return `Project name "${name}" contains invalid characters. It will be sanitized to "${sanitized}". Please use only letters, numbers, underscores, and dashes.`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
3
91
|
export function toPascalCase(str: string): string {
|
|
4
92
|
const words = str.trim().toLowerCase().split(wordSplitRegex);
|
|
5
93
|
return words.reduce((acc, curr) => {
|
package/test/ValdiSmokeTest.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import assert from 'node:assert';
|
|
3
|
-
import { mkdir,
|
|
3
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
4
4
|
import { basename, join } from 'node:path';
|
|
5
5
|
import { afterEach, beforeEach, describe, it } from 'node:test';
|
|
6
6
|
import { lookForOutput } from './helpers/AsyncHelpers';
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from './helpers/ProjectHelpers';
|
|
16
16
|
import { type ProjectConfig } from './helpers/ProjectHelpers';
|
|
17
17
|
import { type TSServerClient, createClient, lineAndOffset } from './helpers/TypeScriptClient';
|
|
18
|
+
import { error } from 'node:console';
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
const PROJECT_ROOT = process.env['PROJECT_ROOT']!;
|
|
@@ -257,9 +258,9 @@ async function bootstrap(
|
|
|
257
258
|
applicationType: 'ui_application' | 'cli_application',
|
|
258
259
|
) {
|
|
259
260
|
// Delete and recreate the bootstrapped project
|
|
260
|
-
await
|
|
261
|
-
// Logging the failure
|
|
262
|
-
console.
|
|
261
|
+
await rm(projectRootPath, { recursive: true, force: true }).catch((error) => {
|
|
262
|
+
// Logging the failure; if it doesn't exist the force flag will handle it
|
|
263
|
+
console.error('Failed to remove', projectRootPath, ':', error);
|
|
263
264
|
});
|
|
264
265
|
await mkdir(projectRootPath, { recursive: true });
|
|
265
266
|
|
|
@@ -34,7 +34,7 @@ export function createClient(workingDir: string): TSServerClient {
|
|
|
34
34
|
|
|
35
35
|
const send = (
|
|
36
36
|
request: Record<string, unknown>,
|
|
37
|
-
{ timeout =
|
|
37
|
+
{ timeout = 300000 }: { timeout?: number } = {},
|
|
38
38
|
): Promise<Record<string, unknown>> => {
|
|
39
39
|
const seq = reserveSequence();
|
|
40
40
|
const body = JSON.stringify({
|
|
@@ -113,7 +113,7 @@ export async function lineAndOffset(searchToken: string, file: string): Promise<
|
|
|
113
113
|
return { line, offset: Math.max(0, offset), position };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
function withTimeout<T>(promise: Promise<T>, ms: number | false =
|
|
116
|
+
function withTimeout<T>(promise: Promise<T>, ms: number | false = 300000): Promise<T> {
|
|
117
117
|
if (ms === false) {
|
|
118
118
|
return promise;
|
|
119
119
|
}
|