@bleedingdev/modern-js-renderer-octane 0.0.0-stage → 3.9.3-ultramodern.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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/bin/octane-tsc.mjs +4 -0
  3. package/dist/cjs/bootstrap.js +68 -0
  4. package/dist/cjs/client.js +371 -0
  5. package/dist/cjs/entry-application.js +83 -0
  6. package/dist/cjs/entry-client.js +92 -0
  7. package/dist/cjs/entry-server.js +127 -0
  8. package/dist/cjs/federation-context.js +72 -0
  9. package/dist/cjs/federation.js +103 -0
  10. package/dist/cjs/i18n/I18nProvider.js +67 -0
  11. package/dist/cjs/i18n/LocalizedLink.js +89 -0
  12. package/dist/cjs/i18n/context.js +41 -0
  13. package/dist/cjs/i18n/index.js +86 -0
  14. package/dist/cjs/i18n/languageSync.js +99 -0
  15. package/dist/cjs/i18n/types.js +18 -0
  16. package/dist/cjs/i18n/useI18n.js +110 -0
  17. package/dist/cjs/index.js +46 -0
  18. package/dist/cjs/manifest.js +167 -0
  19. package/dist/cjs/plugin/compiler.js +125 -0
  20. package/dist/cjs/plugin/create.js +265 -0
  21. package/dist/cjs/plugin/index.js +151 -0
  22. package/dist/cjs/plugin/profile.js +89 -0
  23. package/dist/cjs/plugin/source.js +56 -0
  24. package/dist/cjs/router-client.js +139 -0
  25. package/dist/cjs/router-handler.js +168 -0
  26. package/dist/cjs/router-injection.js +139 -0
  27. package/dist/cjs/router-server-cleanup.js +46 -0
  28. package/dist/cjs/router-server-snapshot.js +405 -0
  29. package/dist/cjs/router-server.js +108 -0
  30. package/dist/cjs/router-snapshot.js +270 -0
  31. package/dist/cjs/router.js +218 -0
  32. package/dist/cjs/routes.js +187 -0
  33. package/dist/cjs/server.js +224 -0
  34. package/dist/cjs/typecheck.js +615 -0
  35. package/dist/esm/bootstrap.mjs +24 -0
  36. package/dist/esm/client.mjs +327 -0
  37. package/dist/esm/entry-application.mjs +39 -0
  38. package/dist/esm/entry-client.mjs +54 -0
  39. package/dist/esm/entry-server.mjs +86 -0
  40. package/dist/esm/federation-context.mjs +25 -0
  41. package/dist/esm/federation.mjs +65 -0
  42. package/dist/esm/i18n/I18nProvider.mjs +29 -0
  43. package/dist/esm/i18n/LocalizedLink.mjs +48 -0
  44. package/dist/esm/i18n/context.mjs +3 -0
  45. package/dist/esm/i18n/index.mjs +8 -0
  46. package/dist/esm/i18n/languageSync.mjs +61 -0
  47. package/dist/esm/i18n/types.mjs +0 -0
  48. package/dist/esm/i18n/useI18n.mjs +72 -0
  49. package/dist/esm/index.mjs +8 -0
  50. package/dist/esm/manifest.mjs +117 -0
  51. package/dist/esm/router-client.mjs +98 -0
  52. package/dist/esm/router-handler.mjs +130 -0
  53. package/dist/esm/router-injection.mjs +101 -0
  54. package/dist/esm/router-server-cleanup.mjs +8 -0
  55. package/dist/esm/router-server-snapshot.mjs +367 -0
  56. package/dist/esm/router-server.mjs +12 -0
  57. package/dist/esm/router-snapshot.mjs +199 -0
  58. package/dist/esm/router.mjs +94 -0
  59. package/dist/esm/routes.mjs +134 -0
  60. package/dist/esm/server.mjs +183 -0
  61. package/dist/esm-node/bootstrap.mjs +24 -0
  62. package/dist/esm-node/manifest.mjs +117 -0
  63. package/dist/esm-node/plugin/compiler.mjs +70 -0
  64. package/dist/esm-node/plugin/create.mjs +227 -0
  65. package/dist/esm-node/plugin/index.mjs +103 -0
  66. package/dist/esm-node/plugin/profile.mjs +51 -0
  67. package/dist/esm-node/plugin/source.mjs +7 -0
  68. package/dist/esm-node/typecheck.mjs +560 -0
  69. package/dist/types/bootstrap.d.ts +10 -0
  70. package/dist/types/client.d.ts +36 -0
  71. package/dist/types/entry-application.d.ts +19 -0
  72. package/dist/types/entry-client.d.ts +8 -0
  73. package/dist/types/entry-server.d.ts +11 -0
  74. package/dist/types/federation-context.d.ts +28 -0
  75. package/dist/types/federation.d.ts +18 -0
  76. package/dist/types/i18n/I18nProvider.d.ts +8 -0
  77. package/dist/types/i18n/LocalizedLink.d.ts +41 -0
  78. package/dist/types/i18n/context.d.ts +9 -0
  79. package/dist/types/i18n/index.d.ts +9 -0
  80. package/dist/types/i18n/languageSync.d.ts +26 -0
  81. package/dist/types/i18n/types.d.ts +34 -0
  82. package/dist/types/i18n/useI18n.d.ts +21 -0
  83. package/dist/types/index.d.ts +9 -0
  84. package/dist/types/manifest.d.ts +34 -0
  85. package/dist/types/plugin/compiler-manifest.d.cts +10 -0
  86. package/dist/types/plugin/compiler.d.ts +5 -0
  87. package/dist/types/plugin/create.d.ts +23 -0
  88. package/dist/types/plugin/index.d.ts +3 -0
  89. package/dist/types/plugin/profile.d.ts +2 -0
  90. package/dist/types/plugin/source.d.ts +1 -0
  91. package/dist/types/plugin/svg-component-template.d.cts +6 -0
  92. package/dist/types/router-client.d.ts +12 -0
  93. package/dist/types/router-handler.d.ts +13 -0
  94. package/dist/types/router-injection.d.ts +8 -0
  95. package/dist/types/router-server-cleanup.d.ts +3 -0
  96. package/dist/types/router-server-snapshot.d.ts +15 -0
  97. package/dist/types/router-server.d.ts +13 -0
  98. package/dist/types/router-snapshot.d.ts +14 -0
  99. package/dist/types/router.d.ts +30 -0
  100. package/dist/types/routes.d.ts +18 -0
  101. package/dist/types/server.d.ts +41 -0
  102. package/dist/types/typecheck.d.ts +31 -0
  103. package/package.json +216 -4
  104. package/src/bootstrap.ts +60 -0
  105. package/src/client.ts +485 -0
  106. package/src/entry-application.ts +72 -0
  107. package/src/entry-client.ts +80 -0
  108. package/src/entry-server.ts +142 -0
  109. package/src/federation-context.ts +53 -0
  110. package/src/federation.ts +158 -0
  111. package/src/i18n/I18nProvider.ts +56 -0
  112. package/src/i18n/LocalizedLink.ts +112 -0
  113. package/src/i18n/context.ts +12 -0
  114. package/src/i18n/index.ts +35 -0
  115. package/src/i18n/languageSync.ts +132 -0
  116. package/src/i18n/types.ts +36 -0
  117. package/src/i18n/useI18n.ts +119 -0
  118. package/src/index.ts +10 -0
  119. package/src/manifest.ts +253 -0
  120. package/src/plugin/compiler-manifest.cjs +178 -0
  121. package/src/plugin/compiler.ts +112 -0
  122. package/src/plugin/create.ts +272 -0
  123. package/src/plugin/index.ts +105 -0
  124. package/src/plugin/profile.ts +46 -0
  125. package/src/plugin/source.ts +16 -0
  126. package/src/plugin/svg-component-template.cjs +17 -0
  127. package/src/router-client.ts +144 -0
  128. package/src/router-handler.ts +182 -0
  129. package/src/router-injection.ts +145 -0
  130. package/src/router-server-cleanup.ts +11 -0
  131. package/src/router-server-snapshot.ts +564 -0
  132. package/src/router-server.ts +23 -0
  133. package/src/router-snapshot.ts +251 -0
  134. package/src/router.ts +192 -0
  135. package/src/routes.ts +263 -0
  136. package/src/server.ts +300 -0
  137. package/src/typecheck.ts +723 -0
  138. package/README.md +0 -3
@@ -0,0 +1,615 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ checkOctaneProject: ()=>checkOctaneProject,
41
+ formatOctaneDiagnostic: ()=>formatOctaneDiagnostic,
42
+ runOctaneTypecheck: ()=>runOctaneTypecheck
43
+ });
44
+ const external_node_crypto_namespaceObject = require("node:crypto");
45
+ const external_node_fs_namespaceObject = require("node:fs");
46
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
47
+ const external_node_path_namespaceObject = require("node:path");
48
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
49
+ const language_core_namespaceObject = require("@volar/language-core");
50
+ const external_jsonc_parser_namespaceObject = require("jsonc-parser");
51
+ const volar_namespaceObject = require("octane/compiler/volar");
52
+ const external_typescript_namespaceObject = require("typescript");
53
+ const fs_namespaceObject = require("typescript/unstable/fs");
54
+ const sync_namespaceObject = require("typescript/unstable/sync");
55
+ const nativeExtension = /\.tsrx$/u;
56
+ const projectedExtension = /\.tsrx\.tsx$/u;
57
+ function typecheck_location(source, pos) {
58
+ const prefix = source.slice(0, pos);
59
+ const lines = prefix.split(/\r\n|\r|\n/u);
60
+ return {
61
+ line: lines.length,
62
+ column: (lines.at(-1)?.length ?? 0) + 1
63
+ };
64
+ }
65
+ function readFile(file) {
66
+ try {
67
+ return external_node_fs_default().readFileSync(file, 'utf8');
68
+ } catch (error) {
69
+ if (error instanceof Error && 'code' in error && ('ENOENT' === error.code || 'ENOTDIR' === error.code)) return;
70
+ throw error;
71
+ }
72
+ }
73
+ function projectConfig(source, fileName, discovery, roots) {
74
+ const errors = [];
75
+ const config = (0, external_jsonc_parser_namespaceObject.parseTree)(source.replace(/^\uFEFF/u, ' '), errors, {
76
+ allowTrailingComma: true
77
+ });
78
+ if (errors.length || !config || 'object' !== config.type) return;
79
+ const edits = [];
80
+ const additions = [];
81
+ for (const field of [
82
+ 'files',
83
+ 'include',
84
+ 'exclude'
85
+ ]){
86
+ const array = (0, external_jsonc_parser_namespaceObject.findNodeAtLocation)(config, [
87
+ field
88
+ ]);
89
+ if (roots) {
90
+ const content = JSON.stringify('files' === field ? roots : []);
91
+ if (array) {
92
+ if ('array' === array.type && (array.children ?? []).every((node)=>'string' === node.type)) edits.push({
93
+ offset: array.offset,
94
+ length: array.length,
95
+ content
96
+ });
97
+ } else additions.push(`${JSON.stringify(field)}:${content}`);
98
+ continue;
99
+ }
100
+ if (array?.type === 'array') for (const node of array.children ?? []){
101
+ const file = (0, external_jsonc_parser_namespaceObject.getNodeValue)(node);
102
+ if ('string' != typeof file) continue;
103
+ const projected = 'files' === field || 'complete' === discovery ? nativeExtension.test(file) ? `${file}.tsx` : file : 'native' === discovery && /[.*?]/u.test(file.replaceAll('\\', '/').split('/').at(-1) ?? '') ? `${file.endsWith('/**') ? `${file}/*` : file}.tsx` : file;
104
+ if (projected !== file) edits.push({
105
+ offset: node.offset,
106
+ length: node.length,
107
+ content: JSON.stringify(projected)
108
+ });
109
+ }
110
+ }
111
+ if (additions.length) edits.push({
112
+ offset: config.offset + 1,
113
+ length: 0,
114
+ content: `${additions.join(',')}${config.children?.length ? ',' : ''}`
115
+ });
116
+ if (!edits.length) return;
117
+ const mappings = [];
118
+ let sourceOffset = 0;
119
+ let code = '';
120
+ for (const edit of edits.sort((left, right)=>left.offset - right.offset)){
121
+ const unchanged = source.slice(sourceOffset, edit.offset);
122
+ mappings.push({
123
+ sourceOffsets: [
124
+ sourceOffset
125
+ ],
126
+ generatedOffsets: [
127
+ code.length
128
+ ],
129
+ lengths: [
130
+ unchanged.length
131
+ ],
132
+ data: {
133
+ verification: true
134
+ }
135
+ });
136
+ code += unchanged;
137
+ mappings.push({
138
+ sourceOffsets: [
139
+ edit.offset
140
+ ],
141
+ generatedOffsets: [
142
+ code.length
143
+ ],
144
+ lengths: [
145
+ edit.length
146
+ ],
147
+ generatedLengths: [
148
+ edit.content.length
149
+ ],
150
+ data: {
151
+ verification: true
152
+ }
153
+ });
154
+ code += edit.content;
155
+ sourceOffset = edit.offset + edit.length;
156
+ }
157
+ mappings.push({
158
+ sourceOffsets: [
159
+ sourceOffset
160
+ ],
161
+ generatedOffsets: [
162
+ code.length
163
+ ],
164
+ lengths: [
165
+ source.length - sourceOffset
166
+ ],
167
+ data: {
168
+ verification: true
169
+ }
170
+ });
171
+ code += source.slice(sourceOffset);
172
+ return {
173
+ source,
174
+ fileName,
175
+ code,
176
+ map: new language_core_namespaceObject.SourceMap(mappings)
177
+ };
178
+ }
179
+ function diagnosticText(diagnostic) {
180
+ return [
181
+ diagnostic.text,
182
+ ...diagnostic.messageChain?.map(diagnosticText) ?? []
183
+ ].join('\n');
184
+ }
185
+ function checkOctaneProject(options) {
186
+ if ('7.0.2' !== external_typescript_namespaceObject.version) throw new Error(`Octane typechecking requires TypeScript 7.0.2; found ${external_typescript_namespaceObject.version}`);
187
+ const cwd = external_node_path_default().resolve(options.cwd ?? process.cwd());
188
+ let project = external_node_path_default().resolve(cwd, options.project);
189
+ if (external_node_fs_default().existsSync(project) && external_node_fs_default().statSync(project).isDirectory()) project = external_node_path_default().join(project, 'tsconfig.json');
190
+ if (!external_node_fs_default().existsSync(project)) throw new Error(`Cannot find project ${project}`);
191
+ if (options.compilerOptions?.noEmit === false || options.compilerOptions?.noCheck === true || options.compilerOptions?.skipLibCheck === true || options.compilerOptions?.skipDefaultLibCheck === true) throw new Error('Octane typechecking requires noEmit, full checking, and library checking');
192
+ const effectiveConfig = external_node_path_default().join(external_node_path_default().dirname(project), `.octane-typecheck-${(0, external_node_crypto_namespaceObject.randomUUID)()}.json`);
193
+ const authoredConfig = (0, external_jsonc_parser_namespaceObject.parse)((readFile(project) ?? '').replace(/^\uFEFF/u, ' '), [], {
194
+ allowTrailingComma: true
195
+ });
196
+ const effectiveOptions = {
197
+ extends: project,
198
+ ...Array.isArray(authoredConfig?.references) ? {
199
+ references: authoredConfig.references
200
+ } : {},
201
+ compilerOptions: {
202
+ ...options.compilerOptions,
203
+ noEmit: true,
204
+ noCheck: false,
205
+ skipLibCheck: false,
206
+ skipDefaultLibCheck: false
207
+ }
208
+ };
209
+ const virtual = (0, fs_namespaceObject.createVirtualFileSystem)({
210
+ [effectiveConfig]: JSON.stringify(effectiveOptions)
211
+ });
212
+ const projections = new Map();
213
+ const configurations = new Map();
214
+ const configFiles = new Set([
215
+ project
216
+ ]);
217
+ const referencedConfigs = new Set([
218
+ project
219
+ ]);
220
+ const referenceRoots = new Map();
221
+ let discovery = 'ordinary';
222
+ function authoredName(file) {
223
+ if (!projectedExtension.test(file)) return file;
224
+ const authored = file.slice(0, -4);
225
+ if (!external_node_fs_default().existsSync(authored)) return file;
226
+ if (external_node_fs_default().existsSync(file)) throw new Error(`Octane projection collision: ${authored} conflicts with physical ${file}`);
227
+ return authored;
228
+ }
229
+ function projection(file) {
230
+ const fileName = authoredName(file);
231
+ if (fileName === file) return;
232
+ const known = projections.get(file);
233
+ if (known) return known;
234
+ const source = readFile(fileName);
235
+ if (void 0 === source) return;
236
+ let compiled;
237
+ try {
238
+ compiled = (0, volar_namespaceObject.compileToVolarMappings)(source, fileName, {
239
+ loose: true
240
+ });
241
+ } catch (error) {
242
+ if (!(error instanceof SyntaxError)) throw error;
243
+ compiled = {
244
+ code: 'export {};',
245
+ mappings: [],
246
+ diagnostics: [],
247
+ errors: [
248
+ {
249
+ name: error.name,
250
+ message: error.message,
251
+ fileName,
252
+ type: 'fatal',
253
+ ...'pos' in error && 'number' == typeof error.pos ? {
254
+ pos: error.pos
255
+ } : {},
256
+ ...'end' in error && 'number' == typeof error.end ? {
257
+ end: error.end
258
+ } : {}
259
+ }
260
+ ]
261
+ };
262
+ }
263
+ const result = {
264
+ ...compiled,
265
+ source,
266
+ fileName,
267
+ map: new language_core_namespaceObject.SourceMap(compiled.mappings)
268
+ };
269
+ projections.set(file, result);
270
+ virtual.writeFile?.(file, compiled.code);
271
+ return result;
272
+ }
273
+ const overlay = {
274
+ readFile (file) {
275
+ const content = virtual.readFile?.(file);
276
+ if (void 0 !== content) return content;
277
+ const compiled = projection(file);
278
+ if (compiled) return compiled.code;
279
+ if (file.endsWith('.json')) {
280
+ const source = readFile(file);
281
+ if (void 0 !== source) {
282
+ if (!configFiles.has(file) && ('complete' === discovery || 'package.json' === external_node_path_default().basename(file))) return source;
283
+ configFiles.add(file);
284
+ const configData = (0, external_jsonc_parser_namespaceObject.parse)(source.replace(/^\uFEFF/u, ' '), [], {
285
+ allowTrailingComma: true
286
+ });
287
+ for (const reference of referencedConfigs.has(file) && Array.isArray(configData?.references) ? configData.references : []){
288
+ if ('string' != typeof reference?.path) continue;
289
+ const target = external_node_path_default().resolve(external_node_path_default().dirname(file), reference.path);
290
+ const referenceFile = target.endsWith('.json') ? target : external_node_path_default().join(target, 'tsconfig.json');
291
+ configFiles.add(referenceFile);
292
+ referencedConfigs.add(referenceFile);
293
+ }
294
+ const roots = 'complete' === discovery ? referenceRoots.get(file) : void 0;
295
+ const config = projectConfig(source, file, discovery, roots ? [
296
+ ...roots
297
+ ] : void 0);
298
+ if (config) configurations.set(file, config);
299
+ else configurations.delete(file);
300
+ return config?.code ?? source;
301
+ }
302
+ }
303
+ },
304
+ fileExists (file) {
305
+ if (virtual.fileExists?.(file)) return true;
306
+ if (authoredName(file) !== file) return true;
307
+ },
308
+ directoryExists (directory) {
309
+ return virtual.directoryExists?.(directory) || void 0;
310
+ },
311
+ getAccessibleEntries (directory) {
312
+ const files = new Set(virtual.getAccessibleEntries?.(directory)?.files);
313
+ const directories = new Set(virtual.getAccessibleEntries?.(directory)?.directories);
314
+ try {
315
+ for (const entry of external_node_fs_default().readdirSync(directory, {
316
+ withFileTypes: true
317
+ })){
318
+ let isDirectory = entry.isDirectory();
319
+ if (entry.isSymbolicLink()) try {
320
+ isDirectory = external_node_fs_default().statSync(external_node_path_default().join(directory, entry.name)).isDirectory();
321
+ } catch (error) {
322
+ if (error instanceof Error && 'code' in error && ('ENOENT' === error.code || 'ENOTDIR' === error.code)) continue;
323
+ throw error;
324
+ }
325
+ if (isDirectory) directories.add(entry.name);
326
+ else {
327
+ files.add(entry.name);
328
+ if (nativeExtension.test(entry.name)) {
329
+ const projected = external_node_path_default().join(directory, `${entry.name}.tsx`);
330
+ authoredName(projected);
331
+ files.add(`${entry.name}.tsx`);
332
+ }
333
+ }
334
+ }
335
+ } catch (error) {
336
+ if (!(error instanceof Error && 'code' in error && ('ENOENT' === error.code || 'ENOTDIR' === error.code))) throw error;
337
+ }
338
+ return {
339
+ files: [
340
+ ...files
341
+ ].filter((file)=>'ordinary' !== discovery || authoredName(external_node_path_default().join(directory, file)) === external_node_path_default().join(directory, file)).sort(),
342
+ directories: [
343
+ ...directories
344
+ ].sort()
345
+ };
346
+ },
347
+ realpath (file) {
348
+ const authored = authoredName(file);
349
+ if (authored !== file) try {
350
+ return `${external_node_fs_default().realpathSync(authored)}.tsx`;
351
+ } catch {
352
+ return;
353
+ }
354
+ return virtual.fileExists?.(file) ? file : void 0;
355
+ }
356
+ };
357
+ const roots = new Set();
358
+ for (const mode of [
359
+ 'ordinary',
360
+ 'native'
361
+ ]){
362
+ discovery = mode;
363
+ const parser = new sync_namespaceObject.API({
364
+ cwd,
365
+ fs: overlay
366
+ });
367
+ try {
368
+ for (const file of parser.parseConfigFile(effectiveConfig).fileNames)if ('ordinary' === mode || authoredName(file) !== file) roots.add(file);
369
+ const parsedReferences = new Set([
370
+ project
371
+ ]);
372
+ for (const reference of referencedConfigs){
373
+ if (parsedReferences.has(reference)) continue;
374
+ parsedReferences.add(reference);
375
+ const selected = referenceRoots.get(reference) ?? new Set();
376
+ referenceRoots.set(reference, selected);
377
+ for (const file of parser.parseConfigFile(reference).fileNames)if ('ordinary' === mode || authoredName(file) !== file) selected.add(file);
378
+ }
379
+ } finally{
380
+ parser.close();
381
+ }
382
+ }
383
+ discovery = 'complete';
384
+ virtual.writeFile?.(effectiveConfig, JSON.stringify({
385
+ ...effectiveOptions,
386
+ files: [
387
+ ...roots
388
+ ],
389
+ include: [],
390
+ exclude: []
391
+ }));
392
+ const api = new sync_namespaceObject.API({
393
+ cwd,
394
+ fs: overlay
395
+ });
396
+ try {
397
+ const snapshot = api.updateSnapshot({
398
+ openProjects: [
399
+ effectiveConfig
400
+ ],
401
+ openFiles: [
402
+ ...roots
403
+ ]
404
+ });
405
+ const program = snapshot.getProject(effectiveConfig)?.program;
406
+ if (!program) throw new Error(`Native TypeScript did not load project ${project}`);
407
+ function remap(diagnostic) {
408
+ const relatedInformation = diagnostic.relatedInformation?.flatMap((info)=>{
409
+ const mapped = remap(info);
410
+ return mapped ? [
411
+ mapped
412
+ ] : [];
413
+ });
414
+ const text = diagnosticText(diagnostic);
415
+ const compiled = diagnostic.fileName ? projections.get(diagnostic.fileName) ?? configurations.get(diagnostic.fileName) : void 0;
416
+ let pos = diagnostic.pos;
417
+ let end = diagnostic.end;
418
+ let origin = "typescript";
419
+ let message = text;
420
+ if (compiled) {
421
+ const ranges = compiled.map.toSourceRange(pos, end, true, (info)=>(0, language_core_namespaceObject.shouldReportDiagnostics)(info, void 0, diagnostic.code));
422
+ const range = ranges.next().value;
423
+ if (range) [pos, end] = range;
424
+ else {
425
+ if (!compiled.map.toSourceRange(pos, end, true).next().done) return;
426
+ origin = 'projection';
427
+ message = `Cannot map native TS${diagnostic.code} at generated offsets ${pos}-${end}: ${text}`;
428
+ pos = 0;
429
+ end = 0;
430
+ }
431
+ }
432
+ const fileName = compiled?.fileName ?? (diagnostic.fileName === effectiveConfig ? void 0 : diagnostic.fileName);
433
+ const source = compiled?.source ?? (fileName ? readFile(fileName) : void 0);
434
+ return {
435
+ ...fileName ? {
436
+ fileName
437
+ } : {},
438
+ pos,
439
+ end,
440
+ ...void 0 !== source ? typecheck_location(source, pos) : {},
441
+ code: diagnostic.code,
442
+ category: 'projection' === origin || 1 === diagnostic.category ? 'error' : 0 === diagnostic.category ? 'warning' : 'message',
443
+ text: message,
444
+ origin,
445
+ ...relatedInformation?.length ? {
446
+ relatedInformation
447
+ } : {}
448
+ };
449
+ }
450
+ const diagnostics = [
451
+ ...program.getConfigFileParsingDiagnostics(),
452
+ ...program.getProgramDiagnostics(),
453
+ ...program.getGlobalDiagnostics(),
454
+ ...program.getSyntacticDiagnostics(),
455
+ ...program.getBindDiagnostics(),
456
+ ...program.getSemanticDiagnostics()
457
+ ].flatMap((diagnostic)=>{
458
+ const mapped = remap(diagnostic);
459
+ return mapped ? [
460
+ mapped
461
+ ] : [];
462
+ });
463
+ const nativeFiles = program.getSourceFileNames();
464
+ for (const file of nativeFiles){
465
+ const compiled = projections.get(file);
466
+ if (compiled) {
467
+ for (const diagnostic of compiled.diagnostics)diagnostics.push({
468
+ fileName: compiled.fileName,
469
+ pos: diagnostic.start.offset,
470
+ end: diagnostic.end.offset,
471
+ ...typecheck_location(compiled.source, diagnostic.start.offset),
472
+ code: diagnostic.code,
473
+ category: 'error' === diagnostic.severity ? 'error' : 'warning' === diagnostic.severity ? 'warning' : 'message',
474
+ text: diagnostic.message,
475
+ origin: 'octane'
476
+ });
477
+ for (const error of compiled.errors){
478
+ const pos = error.pos ?? 0;
479
+ diagnostics.push({
480
+ fileName: compiled.fileName,
481
+ pos,
482
+ end: error.end ?? pos,
483
+ ...typecheck_location(compiled.source, pos),
484
+ code: 'OCTANE_PARSE',
485
+ category: 'error',
486
+ text: error.message,
487
+ origin: 'octane'
488
+ });
489
+ }
490
+ }
491
+ }
492
+ const unique = new Map(diagnostics.map((diagnostic)=>[
493
+ JSON.stringify(diagnostic),
494
+ diagnostic
495
+ ]));
496
+ return {
497
+ compilerVersion: external_typescript_namespaceObject.version,
498
+ files: [
499
+ ...new Set(nativeFiles.map((file)=>projections.get(file)?.fileName ?? file))
500
+ ].sort(),
501
+ diagnostics: [
502
+ ...unique.values()
503
+ ].sort((left, right)=>(left.fileName ?? '').localeCompare(right.fileName ?? '') || left.pos - right.pos || String(left.code).localeCompare(String(right.code)))
504
+ };
505
+ } finally{
506
+ api.close();
507
+ }
508
+ }
509
+ function formatOctaneDiagnostic(diagnostic, cwd = process.cwd()) {
510
+ const file = diagnostic.fileName ? `${external_node_path_default().relative(cwd, diagnostic.fileName)}(${diagnostic.line ?? 1},${diagnostic.column ?? 1}): ` : '';
511
+ const code = 'number' == typeof diagnostic.code ? `TS${diagnostic.code}` : diagnostic.code;
512
+ const related = diagnostic.relatedInformation?.map((info)=>` ${formatOctaneDiagnostic(info, cwd)}`).join('\n');
513
+ return `${file}${diagnostic.category} ${code}: ${diagnostic.text}${related ? `\n${related}` : ''}`;
514
+ }
515
+ const booleanOptions = new Set([
516
+ 'strict',
517
+ 'isolatedModules',
518
+ 'verbatimModuleSyntax',
519
+ 'allowImportingTsExtensions',
520
+ 'allowJs',
521
+ 'esModuleInterop',
522
+ 'noUncheckedIndexedAccess',
523
+ 'exactOptionalPropertyTypes',
524
+ 'noImplicitOverride',
525
+ 'noFallthroughCasesInSwitch',
526
+ 'noPropertyAccessFromIndexSignature',
527
+ 'noImplicitReturns',
528
+ 'resolveJsonModule',
529
+ 'strictNullChecks',
530
+ 'strictFunctionTypes',
531
+ 'strictBindCallApply',
532
+ 'strictPropertyInitialization',
533
+ 'noImplicitAny',
534
+ 'noImplicitThis',
535
+ 'useUnknownInCatchVariables',
536
+ 'alwaysStrict'
537
+ ]);
538
+ const stringOptions = new Set([
539
+ 'target',
540
+ 'module',
541
+ 'moduleResolution',
542
+ 'moduleDetection',
543
+ 'jsx',
544
+ 'jsxImportSource'
545
+ ]);
546
+ function runOctaneTypecheck(argv, io = {}) {
547
+ const stdout = io.stdout ?? ((text)=>process.stdout.write(text));
548
+ const stderr = io.stderr ?? ((text)=>process.stderr.write(text));
549
+ try {
550
+ let project = 'tsconfig.json';
551
+ let listFiles = false;
552
+ const compilerOptions = {};
553
+ for(let index = 0; index < argv.length; index++){
554
+ const argument = argv[index];
555
+ if ('--version' === argument || '-v' === argument) {
556
+ stdout(`Version ${external_typescript_namespaceObject.version}\n`);
557
+ return 0;
558
+ }
559
+ if ('--help' === argument || '-h' === argument) {
560
+ stdout('octane-tsc --project <tsconfig.json> [--noEmit] [--strict]\n');
561
+ return 0;
562
+ }
563
+ if ('--project' === argument || '-p' === argument) {
564
+ const value = argv[++index];
565
+ if (!value || value.startsWith('-')) throw new Error('--project requires a configuration path');
566
+ project = value;
567
+ continue;
568
+ }
569
+ if (!argument?.startsWith('--')) throw new Error(`Unsupported Octane typecheck argument ${argument}`);
570
+ const name = argument.slice(2);
571
+ if (booleanOptions.has(name) || [
572
+ 'noEmit',
573
+ 'noCheck',
574
+ 'skipLibCheck',
575
+ 'skipDefaultLibCheck',
576
+ 'pretty',
577
+ 'listFiles',
578
+ 'explainFiles'
579
+ ].includes(name)) {
580
+ const explicit = argv[index + 1];
581
+ const value = 'true' === explicit || 'false' === explicit ? 'true' === argv[++index] : true;
582
+ if ('noEmit' === name && !value || ('noCheck' === name || 'skipLibCheck' === name || 'skipDefaultLibCheck' === name) && value) throw new Error(`--${name} ${value} is incompatible with full Octane typechecking`);
583
+ if ('listFiles' === name || 'explainFiles' === name) listFiles ||= value;
584
+ else if ('pretty' !== name) compilerOptions[name] = value;
585
+ } else if (stringOptions.has(name) || 'lib' === name || 'types' === name) {
586
+ const value = argv[++index];
587
+ if (!value || value.startsWith('-')) throw new Error(`--${name} requires a value`);
588
+ compilerOptions[name] = 'lib' === name || 'types' === name ? value.split(',') : value;
589
+ } else throw new Error(`Unsupported Octane typecheck option --${name}`);
590
+ }
591
+ const cwd = external_node_path_default().resolve(io.cwd ?? process.cwd());
592
+ const result = checkOctaneProject({
593
+ project,
594
+ cwd,
595
+ compilerOptions
596
+ });
597
+ for (const diagnostic of result.diagnostics)stdout(`${formatOctaneDiagnostic(diagnostic, cwd)}\n`);
598
+ if (listFiles) for (const file of result.files)stdout(`${file}\n`);
599
+ return result.diagnostics.some((diagnostic)=>'error' === diagnostic.category) ? 1 : 0;
600
+ } catch (error) {
601
+ stderr(`${error instanceof Error ? error.message : String(error)}\n`);
602
+ return 1;
603
+ }
604
+ }
605
+ exports.checkOctaneProject = __webpack_exports__.checkOctaneProject;
606
+ exports.formatOctaneDiagnostic = __webpack_exports__.formatOctaneDiagnostic;
607
+ exports.runOctaneTypecheck = __webpack_exports__.runOctaneTypecheck;
608
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
609
+ "checkOctaneProject",
610
+ "formatOctaneDiagnostic",
611
+ "runOctaneTypecheck"
612
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
613
+ Object.defineProperty(exports, '__esModule', {
614
+ value: true
615
+ });
@@ -0,0 +1,24 @@
1
+ import { readDocumentBootstrap } from "@modern-js/renderer-core/document";
2
+ import { readRendererIdentity } from "@modern-js/renderer-core/identity";
3
+ function assertNativeHydrationBuildId(value) {
4
+ if ('string' != typeof value || 0 === value.trim().length) throw new Error('An Octane document requires its native client compilation identity.');
5
+ }
6
+ function assertOctaneIdentity(identity) {
7
+ readRendererIdentity(identity, identity);
8
+ if ('octane' !== identity.renderer) throw new Error('An Octane application requires an Octane renderer identity.');
9
+ }
10
+ function readOctaneDocumentBootstrap(document, expectedIdentity, expectedNativeHydrationBuildId) {
11
+ assertOctaneIdentity(expectedIdentity);
12
+ const { identity, documentId, hydrating, nativeHydrationBuildId } = readDocumentBootstrap(document, expectedIdentity, [
13
+ 'nativeHydrationBuildId'
14
+ ]);
15
+ assertNativeHydrationBuildId(nativeHydrationBuildId);
16
+ if (void 0 !== expectedNativeHydrationBuildId && nativeHydrationBuildId !== expectedNativeHydrationBuildId) throw new Error('Octane hydration bytes belong to a different native client compilation.');
17
+ return Object.freeze({
18
+ identity,
19
+ documentId,
20
+ hydrating,
21
+ nativeHydrationBuildId
22
+ });
23
+ }
24
+ export { assertNativeHydrationBuildId, assertOctaneIdentity, readOctaneDocumentBootstrap };