@snap/valdi 1.0.1

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.
Files changed (143) hide show
  1. package/.bazelignore +2 -0
  2. package/.bootstrap/apps/cli_application/AGENTS.md.template +215 -0
  3. package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
  4. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
  5. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
  6. package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
  7. package/.bootstrap/apps/ui_application/AGENTS.md.template +202 -0
  8. package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
  9. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
  10. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  11. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
  12. package/.bootstrap/apps/ui_application/package.json +24 -0
  13. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +21 -0
  14. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +29 -0
  15. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +1 -0
  16. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +39 -0
  17. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
  18. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
  19. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +4 -0
  20. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +41 -0
  21. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +42 -0
  22. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +60 -0
  23. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +6 -0
  24. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +82 -0
  25. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +15 -0
  26. package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
  27. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
  28. package/.config/copyconfig.json +10 -0
  29. package/.editorconfig +21 -0
  30. package/.eslintignore +1 -0
  31. package/.eslintrc.js +72 -0
  32. package/.metadata/.bazelrc.template +91 -0
  33. package/.metadata/.bazelversion.template +1 -0
  34. package/.metadata/.eslintrc.js.template +27 -0
  35. package/.metadata/.gitignore.template +4 -0
  36. package/.metadata/.prettierrc.json.template +7 -0
  37. package/.metadata/.watchmanconfig.template +8 -0
  38. package/.metadata/README.md.template +31 -0
  39. package/.metadata/WORKSPACE.template +57 -0
  40. package/.metadata/config.yaml.template +1 -0
  41. package/.metadata/package.json.template +23 -0
  42. package/.prettierignore +2 -0
  43. package/.prettierrc.json +7 -0
  44. package/README.md +123 -0
  45. package/dist/commands/bootstrap.js +233 -0
  46. package/dist/commands/build.js +67 -0
  47. package/dist/commands/devSetup.js +18 -0
  48. package/dist/commands/doctor.js +892 -0
  49. package/dist/commands/export.js +84 -0
  50. package/dist/commands/hotreload.js +89 -0
  51. package/dist/commands/install.js +71 -0
  52. package/dist/commands/lint.js +18 -0
  53. package/dist/commands/lint_commands/lintCheck.js +31 -0
  54. package/dist/commands/lint_commands/lintFormat.js +31 -0
  55. package/dist/commands/log.js +84 -0
  56. package/dist/commands/newModule.js +208 -0
  57. package/dist/commands/package.js +66 -0
  58. package/dist/commands/projectsync.js +316 -0
  59. package/dist/commands/test.js +54 -0
  60. package/dist/core/constants.js +76 -0
  61. package/dist/core/errors.js +12 -0
  62. package/dist/index.js +22 -0
  63. package/dist/setup/DevSetupHelper.js +146 -0
  64. package/dist/setup/linuxSetup.js +31 -0
  65. package/dist/setup/macOSSetup.js +35 -0
  66. package/dist/setup/setupEntryPoint.js +56 -0
  67. package/dist/setup/versions.js +8 -0
  68. package/dist/utils/ArgumentsResolver.js +23 -0
  69. package/dist/utils/BazelClient.js +219 -0
  70. package/dist/utils/Digraph.js +71 -0
  71. package/dist/utils/LoadingIndicator.js +38 -0
  72. package/dist/utils/applicationUtils.js +201 -0
  73. package/dist/utils/buildInfo.js +60 -0
  74. package/dist/utils/byString.js +6 -0
  75. package/dist/utils/cliUtils.js +93 -0
  76. package/dist/utils/copyBootstrapFiles.js +26 -0
  77. package/dist/utils/deviceUtils.js +72 -0
  78. package/dist/utils/errorUtils.js +55 -0
  79. package/dist/utils/fileUtils.js +204 -0
  80. package/dist/utils/githubUtils.js +8 -0
  81. package/dist/utils/jsonUtils.js +28 -0
  82. package/dist/utils/lintUtils.js +149 -0
  83. package/dist/utils/logUtils.js +8 -0
  84. package/dist/utils/pathUtils.js +12 -0
  85. package/dist/utils/stringUtils.js +17 -0
  86. package/dist/utils/stringUtils.spec.js +18 -0
  87. package/dist/utils/tempDir.js +26 -0
  88. package/dist/utils/zipUtils.js +16 -0
  89. package/package.json +51 -0
  90. package/prettier.config.js +4 -0
  91. package/spec/support/jasmine.json +6 -0
  92. package/src/commands/bootstrap.ts +317 -0
  93. package/src/commands/build.ts +89 -0
  94. package/src/commands/devSetup.ts +17 -0
  95. package/src/commands/doctor.ts +1422 -0
  96. package/src/commands/export.ts +131 -0
  97. package/src/commands/hotreload.ts +108 -0
  98. package/src/commands/install.ts +93 -0
  99. package/src/commands/lint.ts +15 -0
  100. package/src/commands/lint_commands/lintCheck.ts +53 -0
  101. package/src/commands/lint_commands/lintFormat.ts +49 -0
  102. package/src/commands/log.ts +108 -0
  103. package/src/commands/newModule.ts +287 -0
  104. package/src/commands/package.ts +102 -0
  105. package/src/commands/projectsync.ts +488 -0
  106. package/src/commands/test.ts +68 -0
  107. package/src/core/constants.ts +95 -0
  108. package/src/core/errors.ts +10 -0
  109. package/src/index.ts +22 -0
  110. package/src/setup/DevSetupHelper.ts +188 -0
  111. package/src/setup/linuxSetup.ts +38 -0
  112. package/src/setup/macOSSetup.ts +42 -0
  113. package/src/setup/setupEntryPoint.ts +64 -0
  114. package/src/setup/versions.ts +8 -0
  115. package/src/utils/ArgumentsResolver.ts +23 -0
  116. package/src/utils/BazelClient.ts +285 -0
  117. package/src/utils/Digraph.ts +81 -0
  118. package/src/utils/LoadingIndicator.ts +43 -0
  119. package/src/utils/applicationUtils.ts +276 -0
  120. package/src/utils/buildInfo.ts +99 -0
  121. package/src/utils/byString.ts +3 -0
  122. package/src/utils/cliUtils.ts +112 -0
  123. package/src/utils/copyBootstrapFiles.ts +30 -0
  124. package/src/utils/deviceUtils.ts +76 -0
  125. package/src/utils/errorUtils.ts +63 -0
  126. package/src/utils/fileUtils.ts +257 -0
  127. package/src/utils/githubUtils.ts +6 -0
  128. package/src/utils/jsonUtils.ts +30 -0
  129. package/src/utils/lintUtils.ts +190 -0
  130. package/src/utils/logUtils.ts +9 -0
  131. package/src/utils/pathUtils.ts +12 -0
  132. package/src/utils/stringUtils.spec.ts +19 -0
  133. package/src/utils/stringUtils.ts +15 -0
  134. package/src/utils/tempDir.ts +24 -0
  135. package/src/utils/zipUtils.ts +14 -0
  136. package/test/ValdiSmokeTest.ts +278 -0
  137. package/test/helpers/AsyncHelpers.ts +113 -0
  138. package/test/helpers/CommandHelpers.ts +37 -0
  139. package/test/helpers/ProjectHelpers.ts +153 -0
  140. package/test/helpers/StreamHelpers.ts +37 -0
  141. package/test/helpers/TypeScriptClient.ts +217 -0
  142. package/tsconfig.dist.json +8 -0
  143. package/tsconfig.json +42 -0
@@ -0,0 +1,217 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { run } from './CommandHelpers';
4
+
5
+ const HEADER_END = '\r\n\r\n';
6
+
7
+ export interface TSServerClient {
8
+ command: (command: string, args?: Record<string, unknown>) => Promise<Record<string, unknown>>;
9
+ disconnect: () => Promise<number>;
10
+ }
11
+
12
+ export function createClient(workingDir: string): TSServerClient {
13
+ const reserveSequence = createNonceService();
14
+ const read = createMessageBuffer();
15
+
16
+ // eslint-disable-next-line unicorn/prefer-event-target
17
+ const queue = new EventEmitter<{
18
+ response: [Record<string, unknown>];
19
+ message: [Record<string, unknown>];
20
+ }>();
21
+
22
+ const service = run('npx', ['tsserver'], {cwd: workingDir});
23
+
24
+ service.process.stdout?.on('data', (chunk: Buffer) => {
25
+ for (const [message] of read(chunk)) {
26
+ if ('type' in message && message['type'] === 'response') {
27
+ queue.emit('response', message);
28
+ }
29
+ queue.emit('message', message);
30
+ }
31
+ });
32
+
33
+ service.process.stderr?.pipe(process.stderr)
34
+
35
+ const send = (
36
+ request: Record<string, unknown>,
37
+ { timeout = 1000 }: { timeout?: number } = {},
38
+ ): Promise<Record<string, unknown>> => {
39
+ const seq = reserveSequence();
40
+ const body = JSON.stringify({
41
+ seq,
42
+ ...request,
43
+ });
44
+ const payload = body + '\r\n';
45
+ service.process.stdin.write(payload);
46
+
47
+ return withTimeout(
48
+ new Promise(resolve => {
49
+ const listener = (message: Record<string, unknown>) => {
50
+ if ('request_seq' in message && message['request_seq'] !== seq) {
51
+ return;
52
+ }
53
+ queue.removeListener('response', listener);
54
+ resolve(message);
55
+ };
56
+ queue.addListener('response', listener);
57
+ }),
58
+ timeout,
59
+ );
60
+ };
61
+
62
+ return {
63
+ command: (command: string, args?: Record<string, unknown>) =>
64
+ send({
65
+ command,
66
+ ...(args ? { arguments: args } : null),
67
+ }),
68
+ disconnect: () => {
69
+ service.process.stdin.end();
70
+ service.process.kill('SIGINT');
71
+ return service.wait();
72
+ },
73
+ };
74
+ }
75
+
76
+ export interface FilePosition {
77
+ /**
78
+ * 1 indexed line number (first line is line 1)
79
+ */
80
+ line: number;
81
+ /**
82
+ * 1 indexed column number (first column is column 1)
83
+ */
84
+ offset: number;
85
+ /**
86
+ * 0-index within the file content, the nth character
87
+ */
88
+ position: number;
89
+ }
90
+
91
+ export async function lineAndOffset(searchToken: string, file: string): Promise<FilePosition> {
92
+ const buffer = await readFile(file);
93
+ const position = buffer.indexOf(searchToken);
94
+
95
+ if (position === -1) {
96
+ throw new Error('searchToken not found in file');
97
+ }
98
+
99
+ let line = 1;
100
+ let index = 0;
101
+ let offset = -1;
102
+ while (index <= position) {
103
+ const nextLine = buffer.indexOf('\n', index);
104
+ if (nextLine < position) {
105
+ line += 1;
106
+ index = nextLine + 1;
107
+ continue;
108
+ } else {
109
+ offset = position - index;
110
+ break;
111
+ }
112
+ }
113
+ return { line, offset: Math.max(0, offset), position };
114
+ }
115
+
116
+ function withTimeout<T>(promise: Promise<T>, ms: number | false = 400): Promise<T> {
117
+ if (ms === false) {
118
+ return promise;
119
+ }
120
+ let timer: NodeJS.Timeout;
121
+ return Promise.race([
122
+ new Promise<never>((_resolve, reject) => {
123
+ timer = setTimeout(() => reject(new Error('timeout')), ms);
124
+ }),
125
+ promise.then(value => {
126
+ clearTimeout(timer);
127
+ return value;
128
+ }),
129
+ ]);
130
+ }
131
+
132
+ function* eachLine(buffer: Buffer) {
133
+ let index = 0;
134
+ while (index > -1 && index < buffer.length) {
135
+ const endIndex = buffer.indexOf('\n', index);
136
+ if (endIndex === -1) {
137
+ yield buffer.subarray(index);
138
+ break;
139
+ }
140
+ yield buffer.subarray(index, endIndex);
141
+ index = endIndex;
142
+ }
143
+ }
144
+
145
+ function* parseHeaders(chunk: Buffer): Generator<[name: string, value: string]> {
146
+ for (const line of eachLine(chunk)) {
147
+ const sep = line.indexOf(':');
148
+ const name = line.subarray(0, sep);
149
+ const value = line.subarray(sep + 1);
150
+ yield [name.toString('utf8'), value.toString('utf8').trim()];
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Create a statefull message buffer that parses TSServer messages.
156
+ *
157
+ * @returns {(chunk: Buffer) => Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]>}
158
+ */
159
+ function createMessageBuffer(): (
160
+ chunk: Buffer,
161
+ ) => Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]> {
162
+ let buffer = Buffer.from([]);
163
+ /**
164
+ *
165
+ * @param {Buffer} chunk
166
+ * @return {Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]>}
167
+ */
168
+ return function* read(chunk) {
169
+ buffer = Buffer.concat([buffer, chunk]);
170
+
171
+ let position = 0;
172
+
173
+ while (position < buffer.length) {
174
+ const headerSuffix = buffer.indexOf(HEADER_END, position);
175
+
176
+ if (headerSuffix === -1) {
177
+ throw new Error('no headers ' + buffer.toString('utf8'));
178
+ }
179
+
180
+ const headers: [string, string][] = Array.from(parseHeaders(buffer.subarray(position, headerSuffix)));
181
+
182
+ // Content length
183
+ const contentLength = Number.parseInt(
184
+ headers.find(([name]) => name === 'Content-Length')?.[1] ?? Number.NaN.toString(),
185
+ );
186
+ if (Number.isNaN(contentLength)) {
187
+ throw new TypeError('invalid message, no Content-Length');
188
+ }
189
+
190
+ const bodyStart = headerSuffix + HEADER_END.length;
191
+ const bodyEnd = bodyStart + contentLength;
192
+
193
+ if (bodyEnd > buffer.length) {
194
+ buffer = buffer.subarray(position);
195
+ return;
196
+ }
197
+
198
+ yield [JSON.parse(buffer.subarray(bodyStart, bodyEnd).toString('utf8')), headers];
199
+
200
+ position = bodyEnd;
201
+ }
202
+ };
203
+ }
204
+
205
+ /**
206
+ * Every time the returned function is called it will return a new sequenc.
207
+ *
208
+ * @returns {() => number}
209
+ */
210
+ function createNonceService() {
211
+ let sequence = 1;
212
+ return () => {
213
+ const seq = sequence;
214
+ sequence += 1;
215
+ return seq;
216
+ };
217
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDirs": [],
5
+ "rootDir": "./src",
6
+ },
7
+ "include": ["./src/**/*.ts"]
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Main settings
4
+ "rootDirs": ["./src", "./test"],
5
+ "outDir": "./dist",
6
+
7
+ // Modules
8
+ "module": "CommonJS",
9
+ "moduleResolution": "node",
10
+ "esModuleInterop": true,
11
+ "resolveJsonModule": true,
12
+
13
+ // Type Checking
14
+ "exactOptionalPropertyTypes": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "noImplicitOverride": true,
17
+ "noImplicitReturns": true,
18
+ "noPropertyAccessFromIndexSignature": true,
19
+ "noUncheckedIndexedAccess": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": true,
22
+ "strict": true,
23
+
24
+ // Emit
25
+ "importHelpers": true,
26
+ "noEmitHelpers": true,
27
+ "noEmitOnError": true,
28
+ "removeComments": true,
29
+
30
+ // Interop Constraints
31
+ "allowSyntheticDefaultImports": true,
32
+ "forceConsistentCasingInFileNames": true,
33
+ "isolatedModules": true,
34
+
35
+ // Language and Environment
36
+ "experimentalDecorators": true,
37
+ "lib": ["ESNext"],
38
+ "target": "ESNext",
39
+ "useDefineForClassFields": true
40
+ },
41
+ "include": ["./src/**/*.ts", "./test/**/*.ts"]
42
+ }