@universalcms/connect 0.0.0-stage → 0.13.0

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 (132) hide show
  1. package/README.md +779 -2
  2. package/dist/angular-runtime.d.mts +4 -0
  3. package/dist/angular-runtime.mjs +7 -0
  4. package/dist/angular-setup.mjs +124 -0
  5. package/dist/astro-runtime.d.mts +6 -0
  6. package/dist/astro-runtime.mjs +255 -0
  7. package/dist/astro-setup.mjs +215 -0
  8. package/dist/astro-source.mjs +451 -0
  9. package/dist/astro-website.d.mts +5 -0
  10. package/dist/astro-website.mjs +42 -0
  11. package/dist/cli.mjs +552 -0
  12. package/dist/connector-runtime.mjs +130 -0
  13. package/dist/content-next-setup.mjs +200 -0
  14. package/dist/content-registry-validation.mjs +40 -0
  15. package/dist/content-registry.mjs +44 -0
  16. package/dist/content-setup.mjs +13 -0
  17. package/dist/content-storefront-setup.mjs +155 -0
  18. package/dist/content-vite-setup.mjs +107 -0
  19. package/dist/core.mjs +205 -0
  20. package/dist/framework-ownership.mjs +68 -0
  21. package/dist/framework.mjs +54 -0
  22. package/dist/guided.mjs +335 -0
  23. package/dist/native-adapters.mjs +31 -0
  24. package/dist/native-chrome-model.d.mts +3 -0
  25. package/dist/native-chrome-model.mjs +14 -0
  26. package/dist/native-chrome-review.mjs +49 -0
  27. package/dist/native-chrome-source.mjs +69 -0
  28. package/dist/native-route-review.mjs +152 -0
  29. package/dist/native-routes.mjs +27 -0
  30. package/dist/native-website-model.d.mts +18 -0
  31. package/dist/native-website-model.mjs +67 -0
  32. package/dist/native-website-server.d.mts +1 -0
  33. package/dist/native-website-server.mjs +35222 -0
  34. package/dist/native-website-server.mjs.LEGAL.txt +56 -0
  35. package/dist/native-website.d.mts +3 -0
  36. package/dist/native-website.mjs +120 -0
  37. package/dist/native-website.mjs.LEGAL.txt +56 -0
  38. package/dist/next-publication.d.mts +12 -0
  39. package/dist/next-publication.mjs +107 -0
  40. package/dist/next-settings-layout.mjs +233 -0
  41. package/dist/next-source.d.mts +8 -0
  42. package/dist/next-source.mjs +93 -0
  43. package/dist/page-discovery.mjs +236 -0
  44. package/dist/page-mapping-review.mjs +160 -0
  45. package/dist/preflight-recovery.mjs +122 -0
  46. package/dist/preflight.mjs +138 -0
  47. package/dist/project-files.mjs +56 -0
  48. package/dist/public-bindings.d.mts +3 -0
  49. package/dist/public-bindings.mjs +28 -0
  50. package/dist/publication-browser.d.mts +5 -0
  51. package/dist/publication-browser.mjs +258 -0
  52. package/dist/publication-check.mjs +141 -0
  53. package/dist/publication-document.d.mts +2 -0
  54. package/dist/publication-document.mjs +59 -0
  55. package/dist/publication-next-setup.mjs +134 -0
  56. package/dist/publication-setup.mjs +138 -0
  57. package/dist/publication-verification.mjs +85 -0
  58. package/dist/publication.css +6 -0
  59. package/dist/publication.d.mts +31 -0
  60. package/dist/publication.mjs +320 -0
  61. package/dist/react-publication.d.mts +22 -0
  62. package/dist/react-publication.mjs +301 -0
  63. package/dist/react-website.d.mts +15 -0
  64. package/dist/react-website.mjs +735 -0
  65. package/dist/reviewed-commerce-ownership.mjs +26 -0
  66. package/dist/reviewed-commerce-settings-setup.mjs +243 -0
  67. package/dist/reviewed-native-ownership.mjs +118 -0
  68. package/dist/reviewed-storefront-source.mjs +227 -0
  69. package/dist/runtime-dependencies.mjs +59 -0
  70. package/dist/setup-environment.mjs +307 -0
  71. package/dist/source-bindings.mjs +77 -0
  72. package/dist/source-check.mjs +149 -0
  73. package/dist/source-collect.mjs +80 -0
  74. package/dist/source-config.mjs +20 -0
  75. package/dist/source-extract.mjs +514 -0
  76. package/dist/source-finalize.mjs +52 -0
  77. package/dist/source-routes.mjs +65 -0
  78. package/dist/source-setup.mjs +490 -0
  79. package/dist/staged-setup.mjs +287 -0
  80. package/dist/static-runtime.mjs +67 -0
  81. package/dist/static-setup.mjs +136 -0
  82. package/dist/svelte-runtime.d.mts +27 -0
  83. package/dist/svelte-runtime.mjs +40 -0
  84. package/dist/svelte-setup.mjs +135 -0
  85. package/dist/svelte-template.mjs +48 -0
  86. package/dist/templates.mjs +248 -0
  87. package/dist/vendor/analyze-project.mjs +82 -0
  88. package/dist/vendor/astro-compiler/LICENSE +53 -0
  89. package/dist/vendor/astro-compiler/astro.wasm +0 -0
  90. package/dist/vendor/astro-compiler/chunk-W5DTLHV4.js +1 -0
  91. package/dist/vendor/astro-compiler/node/index.js +1 -0
  92. package/dist/vendor/check-delivery.mjs +158 -0
  93. package/dist/vendor/dependency-diagnostics.mjs +72 -0
  94. package/dist/vendor/inspect-installed-dependencies.mjs +125 -0
  95. package/dist/vendor/project-analysis.mjs +498 -0
  96. package/dist/vendor/react-LICENSE.txt +21 -0
  97. package/dist/vendor/react-document.mjs +124 -0
  98. package/dist/vendor/react-dom-LICENSE.txt +21 -0
  99. package/dist/vendor/react-form.mjs +63 -0
  100. package/dist/vendor/react-safety.mjs +47 -0
  101. package/dist/vendor/source-manifest-provider.mjs +104 -0
  102. package/dist/vendor/typescript-LICENSE.txt +55 -0
  103. package/dist/vendor/typescript.cjs +200276 -0
  104. package/dist/vite-handler.mjs +54 -0
  105. package/dist/vite-publication-server.d.mts +3 -0
  106. package/dist/vite-publication-server.mjs +82 -0
  107. package/dist/vite-publication.d.mts +15 -0
  108. package/dist/vite-publication.mjs +241 -0
  109. package/dist/vite-source-discovery.mjs +315 -0
  110. package/dist/vite-source.d.mts +30 -0
  111. package/dist/vite-source.mjs +141 -0
  112. package/dist/vue-runtime.d.mts +10 -0
  113. package/dist/vue-runtime.mjs +50 -0
  114. package/dist/vue-server.d.mts +2 -0
  115. package/dist/vue-server.mjs +58 -0
  116. package/dist/vue-setup.mjs +127 -0
  117. package/dist/vue-source.mjs +168 -0
  118. package/dist/website-check.mjs +41 -0
  119. package/dist/website-http.mjs +149 -0
  120. package/dist/website-model.d.mts +20 -0
  121. package/dist/website-model.mjs +155 -0
  122. package/dist/website-next.d.mts +2 -0
  123. package/dist/website-next.mjs +29 -0
  124. package/dist/website-node.d.mts +3 -0
  125. package/dist/website-node.mjs +50 -0
  126. package/dist/website-runtime.d.mts +13 -0
  127. package/dist/website-runtime.mjs +396 -0
  128. package/dist/website-schema.mjs +22175 -0
  129. package/dist/website-setup.mjs +256 -0
  130. package/dist/website.css +49 -0
  131. package/dist/wizard.mjs +298 -0
  132. package/package.json +60 -4
@@ -0,0 +1,498 @@
1
+ import { validateDependencyDiagnostics } from './dependency-diagnostics.mjs';
2
+
3
+ /**
4
+ * Local project evidence only. This module runs in browsers and Node without
5
+ * executing a project's scripts, importing its modules, or contacting a URL.
6
+ * Reports are integration advice, never authorization or connection proof.
7
+ */
8
+ export const MAX_ANALYSIS_FILE_BYTES = 128 * 1024;
9
+ export const MAX_ANALYSIS_TOTAL_BYTES = 1024 * 1024;
10
+ const configNames = (name) => ['js', 'mjs', 'cjs', 'ts'].map(extension => `${name}.config.${extension}`);
11
+ const nodeEntries = ['server.js', 'server.mjs', 'server.cjs', 'server.ts', 'app.js', 'app.mjs', 'index.js', 'index.mjs', 'server/index.js', 'server/index.mjs', 'server/index.cjs', 'server/index.ts', 'src/server.js', 'src/server.mjs', 'src/server.ts'];
12
+ export const PROJECT_ANALYSIS_FILES = Object.freeze([
13
+ 'package.json', 'composer.json', 'pnpm-workspace.yaml', 'angular.json',
14
+ 'requirements.txt', 'pyproject.toml', 'Gemfile', 'pom.xml', 'build.gradle', 'build.gradle.kts',
15
+ ...configNames('next'), ...configNames('nuxt'), ...configNames('astro'), ...configNames('svelte'), ...configNames('vite'),
16
+ ...nodeEntries,
17
+ ]);
18
+ export const PROJECT_ANALYSIS_SIGNALS = Object.freeze({
19
+ react: 'React dependency', vue: 'Vue dependency', angular: 'Angular dependency',
20
+ next: 'Next.js dependency and framework command', nuxt: 'Nuxt dependency and framework command',
21
+ astro: 'Astro dependency and framework command', svelte: 'SvelteKit dependency and framework command',
22
+ laravel: 'Laravel production Composer dependency', wordpress: 'WordPress production Composer dependency',
23
+ php: 'PHP runtime Composer requirement', python: 'Python web framework dependency',
24
+ ruby: 'Ruby on Rails dependency', java: 'Java Spring Boot dependency',
25
+ node: 'Node server entry, server imports and startup command',
26
+ nextStatic: 'Literal Next.js static export configuration', astroStatic: 'Literal Astro static output configuration',
27
+ astroServer: 'Literal Astro server output with Node adapter',
28
+ nuxtStatic: 'Nuxt generate command without a server startup command',
29
+ svelteStatic: 'SvelteKit static adapter configuration', svelteNode: 'SvelteKit Node adapter configuration',
30
+ monorepo: 'Multiple project workspace declaration', dynamic: 'Configuration needs developer inspection',
31
+ });
32
+ export const PROJECT_ANALYSIS_WARNINGS = Object.freeze({
33
+ unknown: 'A backend or build-time content integration could not be established. Ask the website developer to complete setup.',
34
+ monorepo: 'This folder contains a workspace. Analyze the individual website project folder instead.',
35
+ conflict: 'Conflicting framework or backend evidence needs developer review.',
36
+ invalid: 'A selected project file is invalid or exceeds the analysis limits. Ask the developer to check the project files.',
37
+ dynamic: 'A configuration uses values that cannot be resolved safely without running code. Ask the developer to confirm the deployment runtime.',
38
+ frontend: 'A frontend dependency does not identify its backend. Node.js build tools alone are not a Node.js website server.',
39
+ unverified: 'This identifies project configuration only. Credentials, deployment and CMS connectivity still need verification.',
40
+ });
41
+ const S = PROJECT_ANALYSIS_SIGNALS, W = PROJECT_ANALYSIS_WARNINGS;
42
+ const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
43
+ const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
44
+ const byteLength = value => new TextEncoder().encode(value).byteLength;
45
+ const exactKeys = (value, keys) => object(value) && Object.keys(value).length === keys.length && Object.keys(value).every(key => keys.includes(key));
46
+ const signalNames = new Set(Object.values(S));
47
+ const warningNames = new Set(Object.values(W));
48
+ const allowedFiles = new Set(PROJECT_ANALYSIS_FILES);
49
+
50
+ function skipQuoted(source, begin, quote) {
51
+ let index = begin + 1;
52
+ while (index < source.length) {
53
+ if (source[index] === '\\') { index += 2; continue; }
54
+ if (source[index++] === quote) break;
55
+ }
56
+ return index;
57
+ }
58
+
59
+ function skipTemplate(source, begin, nesting = 0) {
60
+ if (nesting > 24) return source.length;
61
+ let index = begin + 1;
62
+ while (index < source.length) {
63
+ if (source[index] === '\\') { index += 2; continue; }
64
+ if (source[index] === '`') return index + 1;
65
+ if (source[index] !== '$' || source[index + 1] !== '{') { index++; continue; }
66
+ index += 2;
67
+ let depth = 1;
68
+ while (index < source.length && depth) {
69
+ const char = source[index];
70
+ if (char === '"' || char === "'") { index = skipQuoted(source, index, char); continue; }
71
+ if (char === '`') { index = skipTemplate(source, index, nesting + 1); continue; }
72
+ if (char === '/' && source[index + 1] === '/') { while (index < source.length && source[index] !== '\n') index++; continue; }
73
+ if (char === '/' && source[index + 1] === '*') { const end = source.indexOf('*/', index + 2); index = end < 0 ? source.length : end + 2; continue; }
74
+ if (char === '\\') { index += 2; continue; }
75
+ if (char === '{') depth++;
76
+ if (char === '}') depth--;
77
+ index++;
78
+ }
79
+ }
80
+ return index;
81
+ }
82
+
83
+ // Small bounded lexical reader: comments and template bodies never count as
84
+ // configuration evidence. No code, regular-expression body or escape is run.
85
+ function tokens(source) {
86
+ const result = [];
87
+ for (let i = 0; i < source.length;) {
88
+ const c = source[i], next = source[i + 1];
89
+ if (/\s/.test(c)) { i++; continue; }
90
+ if (c === '/' && next === '/') { while (i < source.length && source[i] !== '\n') i++; continue; }
91
+ if (c === '/' && next === '*') { const end = source.indexOf('*/', i + 2); i = end < 0 ? source.length : end + 2; continue; }
92
+ if (c === '/' && (!result.length || ['=', '(', ':', ',', '[', '{', '!', '?', ';', '>', 'return', 'case', 'yield'].includes(result.at(-1)?.value))) {
93
+ // A regexp may contain quotes, comment-like text and fake source tokens.
94
+ let inClass = false, closed = false;
95
+ for (i++; i < source.length; i++) {
96
+ if (source[i] === '\\') { i++; continue; }
97
+ if (source[i] === '[') inClass = true;
98
+ if (source[i] === ']') inClass = false;
99
+ if (source[i] === '/' && !inClass) { closed = true; i++; while (/[a-z]/i.test(source[i] ?? '') && i < source.length) i++; break; }
100
+ if (source[i] === '\n' || source[i] === '\r') break;
101
+ }
102
+ result.push({ type: closed ? 'regexp' : 'dynamic', value: '' }); continue;
103
+ }
104
+ if (c === '`') {
105
+ i = skipTemplate(source, i);
106
+ result.push({ type: 'dynamic', value: '' }); continue;
107
+ }
108
+ if (c === '"' || c === "'") {
109
+ let value = '', escaped = false, closed = false;
110
+ for (i++; i < source.length; i++) {
111
+ if (source[i] === '\\') { escaped = true; i++; continue; }
112
+ if (source[i] === c) { i++; closed = true; break; }
113
+ value += source[i];
114
+ }
115
+ result.push({ type: escaped || !closed ? 'dynamic' : 'string', value: escaped || !closed ? '' : value }); continue;
116
+ }
117
+ if (/[A-Za-z_$]/.test(c)) {
118
+ const start = i++;
119
+ while (i < source.length && /[A-Za-z0-9_$]/.test(source[i])) i++;
120
+ result.push({ type: 'name', value: source.slice(start, i) }); continue;
121
+ }
122
+ if (/\d/.test(c)) {
123
+ const value = source.slice(i).match(/^\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/)[0];
124
+ result.push({ type: 'number', value }); i += value.length; continue;
125
+ }
126
+ result.push({ type: 'punctuation', value: c }); i++;
127
+ }
128
+ return result;
129
+ }
130
+
131
+ function imported(tokenList, moduleName) {
132
+ return tokenList.some((token, index) => token.type === 'string' && token.value === moduleName && (
133
+ tokenList[index - 1]?.value === 'from' ||
134
+ (tokenList[index - 1]?.value === '(' && ['require', 'import'].includes(tokenList[index - 2]?.value))
135
+ ));
136
+ }
137
+
138
+ function defaultImport(tokenList, moduleName) {
139
+ const matches = [];
140
+ for (let index = 0; index < tokenList.length; index++) {
141
+ if (tokenList[index]?.value === 'import' && tokenList[index + 1]?.type === 'name' && tokenList[index + 2]?.value === 'from' && tokenList[index + 3]?.type === 'string' && tokenList[index + 3]?.value === moduleName) matches.push(tokenList[index + 1].value);
142
+ }
143
+ return matches.length === 1 ? matches[0] : null;
144
+ }
145
+
146
+ function readObject(list, begin, depth = 0) {
147
+ const properties = Object.create(null);
148
+ if (depth > 24) return { properties, opaque: true, end: begin };
149
+ let index = begin + 1, opaque = false;
150
+ while (index < list.length && list[index]?.value !== '}') {
151
+ const key = list[index];
152
+ if (!['string', 'name'].includes(key?.type) || list[index + 1]?.value !== ':' || key.value === '__proto__' || own(properties, key.value)) return { properties, opaque: true, end: index };
153
+ index += 2;
154
+ const start = index;
155
+ const stack = [];
156
+ while (index < list.length) {
157
+ const value = list[index].value;
158
+ if (!stack.length && [',', '}'].includes(value)) break;
159
+ if (['{', '[', '('].includes(value)) stack.push(value);
160
+ if (['}', ']', ')'].includes(value)) {
161
+ const expected = { '}': '{', ']': '[', ')': '(' }[value];
162
+ if (stack.pop() !== expected) return { properties, opaque: true, end: index };
163
+ }
164
+ index++;
165
+ }
166
+ const expression = list.slice(start, index);
167
+ if (!expression.length) opaque = true;
168
+ let nested = null;
169
+ if (expression[0]?.value === '{') {
170
+ nested = readObject(expression, 0, depth + 1);
171
+ if (nested.opaque || nested.end !== expression.length - 1) opaque = true;
172
+ }
173
+ properties[key.value] = { expression, nested };
174
+ if (list[index]?.value === ',') index++;
175
+ else if (list[index]?.value !== '}') opaque = true;
176
+ }
177
+ if (list[index]?.value !== '}') opaque = true;
178
+ return { properties, opaque, end: index };
179
+ }
180
+
181
+ function adapterCall(config, moduleName, nestedKey) {
182
+ const binding = defaultImport(config.list, moduleName);
183
+ const properties = nestedKey ? config.properties[nestedKey]?.nested?.properties : config.properties;
184
+ const expression = properties?.adapter?.expression;
185
+ // Resolve the actual configured adapter. Merely importing it is insufficient.
186
+ return !!binding && !!expression && expression[0]?.type === 'name' && expression[0]?.value === binding && expression[1]?.value === '(' && expression.at(-1)?.value === ')' && !expression.some(token => ['?', '=', '&', '|'].includes(token.value));
187
+ }
188
+
189
+ /** Only literal exported objects are understood. Computed config stays pending. */
190
+ function literalConfig(source, wrapper) {
191
+ const list = tokens(source);
192
+ let begin = -1;
193
+ for (let i = 0; i < list.length; i++) {
194
+ if (list[i]?.value === 'export' && list[i + 1]?.value === 'default') begin = i + 2;
195
+ if (list[i]?.value === 'module' && list[i + 1]?.value === '.' && list[i + 2]?.value === 'exports' && list[i + 3]?.value === '=') begin = i + 4;
196
+ }
197
+ if (begin < 0) return { literals: {}, properties: {}, opaque: true, list };
198
+ if (wrapper && list[begin]?.value === wrapper && list[begin + 1]?.value === '(') begin += 2;
199
+ let aliasEnd = null;
200
+ // create-next-app emits a typed const followed by `export default config`.
201
+ // Resolve that one inert alias, never a function call, mutable assignment,
202
+ // imported runtime value, second declaration or conditional configuration.
203
+ if (!wrapper && list[begin]?.type === 'name' && list[begin - 1]?.value === 'default') {
204
+ const name = list[begin].value, declaration = list.findIndex(token => token.value === 'const');
205
+ const prefix = list.slice(0, declaration);
206
+ const typeImport = prefix.length === 0 || prefix[0]?.value === 'import' && prefix[1]?.value === 'type' && prefix.filter(token => token.value === 'import').length === 1 && prefix.filter(token => token.value === 'from').length === 1 && prefix.at(-1)?.value === ';' && prefix.at(-2)?.type === 'string' && prefix.at(-2)?.value === 'next' && prefix.at(-3)?.value === 'from' && prefix.slice(2,-3).every(token => token.type === 'name' || ['{','}',','].includes(token.value));
207
+ let initial = declaration + 2;
208
+ if (list[initial]?.value === ':') {
209
+ initial++;
210
+ // Ordinary type names only. Types are erased, not executed.
211
+ if (list[initial]?.type !== 'name') initial = -1;
212
+ else { initial++; while (list[initial]?.value === '.' && list[initial + 1]?.type === 'name') initial += 2; }
213
+ }
214
+ const tail = list.slice(begin + 1);
215
+ if (declaration < 0 || !typeImport || list[declaration + 1]?.value !== name || list[initial]?.value !== '=' || list[initial + 1]?.value !== '{' || tail.some(token => token.value !== ';')) return { literals: {}, properties: {}, opaque: true, list };
216
+ aliasEnd = begin - 2;
217
+ begin = initial + 1;
218
+ }
219
+ if (list[begin]?.value !== '{') return { literals: {}, properties: {}, opaque: true, list };
220
+ const parsed = readObject(list, begin), literals = {};
221
+ let opaque = parsed.opaque;
222
+ if (aliasEnd !== null) {
223
+ const literal = (expression, key, depth = 0) => {
224
+ if (depth > 24 || !expression.length) return false;
225
+ if (expression.length === 1) return ['string','number'].includes(expression[0].type) || ['true','false','null'].includes(expression[0].value) || key === 'htmlLimitedBots' && expression[0].type === 'regexp';
226
+ if (expression.length === 2 && ['-','+'].includes(expression[0].value) && expression[1].type === 'number') return true;
227
+ if (expression[0]?.value === '{') {
228
+ const object = readObject(expression,0,depth + 1);
229
+ return !object.opaque && object.end === expression.length - 1 && Object.entries(object.properties).every(([name, property]) => literal(property.expression,name,depth + 1));
230
+ }
231
+ if (expression[0]?.value === '[' && expression.at(-1)?.value === ']') {
232
+ let start = 1, nesting = 0;
233
+ for (let index = 1; index < expression.length; index++) {
234
+ const value = expression[index].value;
235
+ if (index === expression.length - 1 || value === ',' && nesting === 0) {
236
+ if (start !== index && !literal(expression.slice(start,index),key,depth + 1)) return false;
237
+ if (start === index && index !== expression.length - 1) return false;
238
+ start = index + 1;
239
+ } else if (['{','['].includes(value)) nesting++;
240
+ else if (['}',']'].includes(value)) nesting--;
241
+ else if (['(',')'].includes(value)) return false;
242
+ if (nesting < 0) return false;
243
+ }
244
+ return nesting === 0;
245
+ }
246
+ return false;
247
+ };
248
+ if (list.slice(parsed.end + 1,aliasEnd).some(token => token.value !== ';') || !Object.entries(parsed.properties).every(([name, property]) => literal(property.expression,name))) opaque = true;
249
+ }
250
+ for (const key of ['output', 'ssr', 'preset']) {
251
+ const expression = parsed.properties[key]?.expression;
252
+ if (!expression) continue;
253
+ if (expression.length === 1 && (expression[0].type === 'string' || ['true', 'false'].includes(expression[0].value))) literals[key] = expression[0].value;
254
+ else opaque = true;
255
+ }
256
+ // Assignment, a second export or condition after the object can override it.
257
+ if (aliasEnd === null && list.slice(parsed.end + 1).some(token => ![')', ';'].includes(token.value))) opaque = true;
258
+ return { literals, properties: parsed.properties, opaque, list };
259
+ }
260
+
261
+ function dependency(manifest, name, productionOnly = false) {
262
+ return (productionOnly ? ['dependencies'] : ['dependencies', 'devDependencies']).some(section =>
263
+ object(manifest?.[section]) && own(manifest[section], name) && typeof manifest[section][name] === 'string');
264
+ }
265
+ function commands(manifest) {
266
+ if (!object(manifest?.scripts)) return [];
267
+ return ['dev', 'start', 'serve', 'build', 'generate', 'preview'].flatMap(key => typeof manifest.scripts[key] === 'string' && manifest.scripts[key].length <= 8192 ? simpleCommands(manifest.scripts[key]) : []);
268
+ }
269
+
270
+ // Understand ordinary command boundaries and quoted words, never shell
271
+ // expansion/substitution. Text printed by `echo "next build"` is not a command.
272
+ function simpleCommands(source) {
273
+ const result = [];
274
+ let command = [], word = '', quote = null, dynamic = false;
275
+ const endWord = () => { if (word) command.push(word); word = ''; };
276
+ const endCommand = () => { endWord(); if (command.length && !dynamic) result.push(command); command = []; dynamic = false; };
277
+ for (let index = 0; index < source.length; index++) {
278
+ const value = source[index];
279
+ if (value === '\\' || value === '$' || value === '`' || value === '(' || value === ')') dynamic = true;
280
+ if (quote) { if (value === quote) quote = null; else word += value; continue; }
281
+ if (value === '"' || value === "'") { quote = value; continue; }
282
+ if ([';', '&', '|', '\n', '\r'].includes(value)) { endCommand(); continue; }
283
+ if (/\s/.test(value)) { endWord(); continue; }
284
+ if (value === '#') { endCommand(); break; }
285
+ word += value;
286
+ }
287
+ if (quote) dynamic = true;
288
+ endCommand();
289
+ return result;
290
+ }
291
+ function commandUsed(scripts, command, operation = '[a-z-]+') {
292
+ return scripts.some(words => new RegExp(`^(?:${command})$`).test(words[0]) && new RegExp(`^(?:${operation})$`).test(words[1] ?? ''));
293
+ }
294
+
295
+ // Only known execution-preserving Node options may precede a server entry.
296
+ // Unknown flags and eval, print, check, preload or loader modes stay pending;
297
+ // skipping arbitrary option values could mistake code or another file for it.
298
+ const nodeEntryFlags = new Set([
299
+ '--enable-source-maps', '--watch', '--watch-preserve-output',
300
+ '--no-warnings', '--trace-warnings', '--trace-uncaught',
301
+ ]);
302
+ const nodeCondition = /^[A-Za-z0-9][A-Za-z0-9_.:-]*$/;
303
+ function invokesServerEntry(words, entry) {
304
+ const matches = value => value === entry || value === `./${entry}`;
305
+ if (['tsx', 'ts-node'].includes(words[0])) return matches(words[1]);
306
+ if (words[0] !== 'node') return false;
307
+ for (let index = 1; index < words.length; index++) {
308
+ const option = words[index];
309
+ if (option === '--') return matches(words[index + 1]);
310
+ if (!option.startsWith('-')) return matches(option);
311
+ if (nodeEntryFlags.has(option)) continue;
312
+ if (option.startsWith('--conditions=')) {
313
+ if (!nodeCondition.test(option.slice('--conditions='.length))) return false;
314
+ continue;
315
+ }
316
+ if (option === '--conditions' || option === '-C') {
317
+ if (!nodeCondition.test(words[index + 1] ?? '')) return false;
318
+ index++;
319
+ continue;
320
+ }
321
+ return false;
322
+ }
323
+ return false;
324
+ }
325
+
326
+ function composerRequires(manifest, name) {
327
+ return object(manifest?.require) && own(manifest.require, name) && typeof manifest.require[name] === 'string';
328
+ }
329
+ function evidenceAllowed(file, signal) {
330
+ if (!allowedFiles.has(file) || !signalNames.has(signal)) return false;
331
+ if ([S.react, S.vue, S.angular, S.next, S.nuxt, S.astro, S.svelte, S.nuxtStatic].includes(signal)) return file === 'package.json';
332
+ if ([S.laravel, S.wordpress, S.php].includes(signal)) return file === 'composer.json';
333
+ if (signal === S.python) return ['requirements.txt', 'pyproject.toml'].includes(file);
334
+ if (signal === S.ruby) return file === 'Gemfile';
335
+ if (signal === S.java) return ['pom.xml', 'build.gradle', 'build.gradle.kts'].includes(file);
336
+ if (signal === S.node) return nodeEntries.includes(file);
337
+ if (signal === S.monorepo) return ['package.json', 'pnpm-workspace.yaml'].includes(file);
338
+ if (signal === S.nextStatic) return configNames('next').includes(file);
339
+ if ([S.astroStatic, S.astroServer].includes(signal)) return configNames('astro').includes(file);
340
+ if ([S.svelteStatic, S.svelteNode].includes(signal)) return configNames('svelte').includes(file);
341
+ return signal === S.dynamic && ['next', 'nuxt', 'astro', 'svelte'].some(name => configNames(name).includes(file));
342
+ }
343
+
344
+ function classify(evidence, invalid = false) {
345
+ const has = signal => evidence.some(item => item.signal === signal);
346
+ const frontends = [[S.react, 'React'], [S.vue, 'Vue'], [S.angular, 'Angular']].filter(([signal]) => has(signal)).map(([, name]) => name);
347
+ let frontend = frontends.length === 1 ? frontends[0] : frontends.length ? 'Unknown' : 'None';
348
+ const frameworks = [[S.next, 'Next.js'], [S.nuxt, 'Nuxt'], [S.astro, 'Astro'], [S.svelte, 'SvelteKit'], [S.laravel, 'Laravel'], [S.wordpress, 'WordPress']].filter(([signal]) => has(signal)).map(([, name]) => name);
349
+ // Laravel's React/Vue asset packages do not make its PHP backend into Node.
350
+ let framework = frameworks.length === 1 ? frameworks[0] : frameworks.length ? 'Custom' : frontends.length === 1 ? frontend : 'Custom';
351
+ if (framework === 'Next.js' && frontend === 'None') frontend = 'React';
352
+ if (framework === 'Nuxt' && frontend === 'None') frontend = 'Vue';
353
+ if (framework === 'SvelteKit' && frontend === 'None') frontend = 'Unknown';
354
+ const warnings = [];
355
+ const backends = new Set();
356
+ if ([S.laravel, S.wordpress, S.php].some(has)) backends.add('php');
357
+ if (has(S.python)) backends.add('python');
358
+ if (has(S.ruby)) backends.add('ruby');
359
+ if (has(S.java)) backends.add('java');
360
+ if (has(S.node)) backends.add('node');
361
+ let backend = backends.size === 1 ? [...backends][0] : 'unknown';
362
+ let runtime = null, rendering = 'unknown';
363
+ const staticMode = has(S.nextStatic) || has(S.astroStatic) || has(S.svelteStatic) || has(S.nuxtStatic);
364
+ const serverMode = has(S.node) || has(S.astroServer) || has(S.svelteNode);
365
+ const inferredNode = (framework === 'Next.js' || framework === 'Nuxt') && !staticMode;
366
+ if ((serverMode || inferredNode) && backends.size && !backends.has('node')) backends.add('node');
367
+ const configKinds = new Set(evidence.filter(item => [S.nextStatic, S.astroStatic, S.astroServer, S.svelteStatic, S.svelteNode].includes(item.signal)).map(item => item.signal));
368
+ const conflict = frameworks.length > 1 || backends.size > 1 || (staticMode && (serverMode || backends.size > 0)) || configKinds.size > 1;
369
+ if (invalid) warnings.push(W.invalid);
370
+ if (has(S.monorepo)) warnings.push(W.monorepo);
371
+ if (conflict) warnings.push(W.conflict);
372
+ if (has(S.dynamic)) warnings.push(W.dynamic);
373
+ if (!warnings.length) {
374
+ if (staticMode) { backend = 'none'; runtime = 'static'; rendering = 'static'; }
375
+ else if (serverMode || inferredNode) { backend = 'node'; runtime = 'node'; rendering = 'server'; }
376
+ else if (['php', 'python', 'ruby', 'java'].includes(backend)) { runtime = 'rest'; rendering = 'server'; }
377
+ }
378
+ if (conflict) { backend = 'unknown'; if (frameworks.length > 1) framework = 'Custom'; }
379
+ if (!runtime) {
380
+ if (frontends.length && !backends.size && !frameworks.length) warnings.push(W.frontend);
381
+ warnings.push(W.unknown);
382
+ } else warnings.push(W.unverified);
383
+ return { version: 1, status: runtime ? 'detected' : 'needs-developer', frontend, framework, backend, runtime, rendering, evidence, warnings };
384
+ }
385
+
386
+ /** @param {Record<string, string>} files Exact allowlisted project-relative names. */
387
+ export function analyzeProjectFiles(files) {
388
+ const evidence = [], selected = Object.create(null);
389
+ let total = 0, invalid = !object(files);
390
+ const add = (file, signal) => { if (!evidence.some(item => item.file === file && item.signal === signal)) evidence.push({ file, signal }); };
391
+ for (const name of PROJECT_ANALYSIS_FILES) {
392
+ if (!object(files) || !own(files, name)) continue;
393
+ const descriptor = Object.getOwnPropertyDescriptor(files, name);
394
+ const value = descriptor?.value;
395
+ if (typeof value !== 'string' || value.length > MAX_ANALYSIS_FILE_BYTES || byteLength(value) > MAX_ANALYSIS_FILE_BYTES) { invalid = true; continue; }
396
+ total += byteLength(value);
397
+ if (total > MAX_ANALYSIS_TOTAL_BYTES) { invalid = true; continue; }
398
+ selected[name] = value;
399
+ }
400
+ const json = name => {
401
+ if (!own(selected, name)) return null;
402
+ try { const value = JSON.parse(selected[name]); if (!object(value)) throw Error(); return value; }
403
+ catch { invalid = true; return null; }
404
+ };
405
+ const pkg = json('package.json'), composer = json('composer.json'), scripts = commands(pkg);
406
+ if (pkg && own(pkg, 'workspaces') && ((Array.isArray(pkg.workspaces) && pkg.workspaces.length) || (object(pkg.workspaces) && Object.keys(pkg.workspaces).length))) add('package.json', S.monorepo);
407
+ if (selected['pnpm-workspace.yaml'] && /^\s*packages\s*:/m.test(selected['pnpm-workspace.yaml'])) add('pnpm-workspace.yaml', S.monorepo);
408
+ if (dependency(pkg, 'react')) add('package.json', S.react);
409
+ if (dependency(pkg, 'vue')) add('package.json', S.vue);
410
+ if (dependency(pkg, '@angular/core')) add('package.json', S.angular);
411
+ if (dependency(pkg, 'next') && commandUsed(scripts, 'next', '(?:dev|build|start)')) add('package.json', S.next);
412
+ if (dependency(pkg, 'nuxt') && commandUsed(scripts, '(?:nuxt|nuxi)', '(?:dev|build|start|generate|preview)')) add('package.json', S.nuxt);
413
+ if (dependency(pkg, 'astro') && commandUsed(scripts, 'astro', '(?:dev|build|preview)')) add('package.json', S.astro);
414
+ if (dependency(pkg, '@sveltejs/kit') && commandUsed(scripts, '(?:vite|svelte-kit)', '(?:dev|build|preview)')) add('package.json', S.svelte);
415
+ if (composerRequires(composer, 'laravel/framework')) add('composer.json', S.laravel);
416
+ else if (['johnpbloch/wordpress', 'roots/wordpress', 'roots/wordpress-core'].some(name => composerRequires(composer, name))) add('composer.json', S.wordpress);
417
+ if (composerRequires(composer, 'php')) add('composer.json', S.php);
418
+ for (const name of ['requirements.txt', 'pyproject.toml']) {
419
+ const value = selected[name];
420
+ if (value && (name === 'requirements.txt' ? /^\s*(?:django|flask|fastapi)(?:\[[a-z, -]+\])?\s*(?:[=<>!~;]|$)/im.test(value.replace(/^\s*#.*$/gm, '')) : /(?:^\s*(?:django|flask|fastapi)\s*=|["'](?:django|flask|fastapi)(?:[=<>!~]|["']))/im.test(value.replace(/^\s*#.*$/gm, '')))) add(name, S.python);
421
+ }
422
+ if (selected.Gemfile && /^\s*gem\s+["']rails["'](?:\s|,|$)/m.test(selected.Gemfile)) add('Gemfile', S.ruby);
423
+ if (selected['pom.xml'] && /<artifactId>\s*spring-boot-starter(?:-[a-z-]+)?\s*<\/artifactId>/.test(selected['pom.xml'].replace(/<!--[\s\S]*?-->/g, ''))) add('pom.xml', S.java);
424
+ for (const name of ['build.gradle', 'build.gradle.kts']) if (selected[name] && tokens(selected[name]).some(token => token.type === 'string' && token.value.startsWith('org.springframework.boot:spring-boot-starter'))) add(name, S.java);
425
+
426
+ for (const name of nodeEntries) {
427
+ if (!own(selected, name)) continue;
428
+ if (!scripts.some(words => invokesServerEntry(words, name))) continue;
429
+ const list = tokens(selected[name]);
430
+ const serverImports = ['express', 'fastify', 'koa', 'h3'].some(name => dependency(pkg, name, true) && imported(list, name));
431
+ const httpImports = ['node:http', 'http', 'node:https', 'https'].some(name => imported(list, name));
432
+ const createsServer = list.some((token, index) => token.value === 'createServer' && list[index + 1]?.value === '(');
433
+ const listens = list.some((token, index) => token.value === 'listen' && list[index + 1]?.value === '(');
434
+ if (listens && (serverImports || (httpImports && createsServer))) add(name, S.node);
435
+ }
436
+
437
+ const has = signal => evidence.some(item => item.signal === signal);
438
+ for (const [name, wrapper, frameworkSignal] of [['next', null, S.next], ['nuxt', 'defineNuxtConfig', S.nuxt], ['astro', 'defineConfig', S.astro], ['svelte', null, S.svelte]]) {
439
+ if (!has(frameworkSignal)) continue;
440
+ const found = configNames(name).filter(file => own(selected, file));
441
+ for (const file of found) {
442
+ const config = literalConfig(selected[file], wrapper);
443
+ const { literals, opaque, list } = config;
444
+ if (opaque || found.length > 1) { add(file, S.dynamic); continue; }
445
+ if (name === 'next' && literals.output === 'export') add(file, S.nextStatic);
446
+ if (name === 'next' && literals.output && !['export', 'standalone'].includes(literals.output)) add(file, S.dynamic);
447
+ if (name === 'nuxt' && (literals.ssr === 'false' || list.some(token => token.value === 'preset'))) add(file, S.dynamic);
448
+ if (name === 'astro') {
449
+ if (literals.output === 'static') add(file, S.astroStatic);
450
+ else if (literals.output === 'server' && dependency(pkg, '@astrojs/node') && adapterCall(config, '@astrojs/node')) add(file, S.astroServer);
451
+ else add(file, S.dynamic);
452
+ }
453
+ if (name === 'svelte') {
454
+ const staticAdapter = dependency(pkg, '@sveltejs/adapter-static') && adapterCall(config, '@sveltejs/adapter-static', 'kit');
455
+ const nodeAdapter = dependency(pkg, '@sveltejs/adapter-node') && adapterCall(config, '@sveltejs/adapter-node', 'kit');
456
+ if (staticAdapter) add(file, S.svelteStatic);
457
+ if (nodeAdapter) add(file, S.svelteNode);
458
+ if (!staticAdapter && !nodeAdapter) add(file, S.dynamic);
459
+ }
460
+ }
461
+ }
462
+ if (has(S.nuxt) && commandUsed(scripts, '(?:nuxt|nuxi)', 'generate') && !commandUsed(scripts, '(?:nuxt|nuxi)', '(?:start|preview)') && !scripts.some(words => words[0] === 'node')) add('package.json', S.nuxtStatic);
463
+ return classify(evidence, invalid);
464
+ }
465
+
466
+ /** Strict imported-report validation: arbitrary text and inconsistent advice fail closed. */
467
+ export function validateProjectAnalysis(value) {
468
+ const keys = ['version', 'status', 'frontend', 'framework', 'backend', 'runtime', 'rendering', 'evidence', 'warnings'];
469
+ if (!object(value) || ![1, 2].includes(value.version) || !exactKeys(value, value.version === 2 ? [...keys, 'diagnostics'] : keys)) return null;
470
+ const diagnostics = value.version === 2 ? validateDependencyDiagnostics(value.diagnostics) : null;
471
+ if (value.version === 2 && !diagnostics) return null;
472
+ if (!Array.isArray(value.evidence) || value.evidence.length > 64 || !Array.isArray(value.warnings) || value.warnings.length > 8) return null;
473
+ const evidence = [], seen = new Set();
474
+ for (const item of value.evidence) {
475
+ if (!exactKeys(item, ['file', 'signal']) || typeof item.file !== 'string' || typeof item.signal !== 'string' || !evidenceAllowed(item.file, item.signal)) return null;
476
+ const identity = `${item.file}:${item.signal}`;
477
+ if (seen.has(identity)) return null;
478
+ seen.add(identity); evidence.push({ file: item.file, signal: item.signal });
479
+ }
480
+ if (value.warnings.some(warning => typeof warning !== 'string' || !warningNames.has(warning)) || new Set(value.warnings).size !== value.warnings.length) return null;
481
+ const has = signal => evidence.some(item => item.signal === signal);
482
+ if ((has(S.nextStatic) && !has(S.next)) || ((has(S.astroStatic) || has(S.astroServer)) && !has(S.astro)) || ((has(S.svelteStatic) || has(S.svelteNode)) && !has(S.svelte)) || (has(S.nuxtStatic) && !has(S.nuxt))) return null;
483
+ for (const item of evidence) if (item.signal === S.dynamic) {
484
+ const needed = [['next', S.next], ['nuxt', S.nuxt], ['astro', S.astro], ['svelte', S.svelte]].find(([name]) => configNames(name).includes(item.file))?.[1];
485
+ if (!needed || !has(needed)) return null;
486
+ }
487
+ const expected = classify(evidence, value.warnings.includes(W.invalid));
488
+ for (const key of ['status', 'frontend', 'framework', 'backend', 'runtime', 'rendering']) if (value[key] !== expected[key]) return null;
489
+ if (JSON.stringify(value.warnings) !== JSON.stringify(expected.warnings)) return null;
490
+ return diagnostics ? { ...expected, version: 2, diagnostics } : expected;
491
+ }
492
+
493
+ /** Framework identity may be clear even when a frontend's backend is still unknown. */
494
+ export function detectedProjectFramework(value) {
495
+ const report = validateProjectAnalysis(value);
496
+ if (!report || report.framework === 'Custom' || report.warnings.some(warning => [W.invalid, W.monorepo, W.conflict, W.dynamic].includes(warning))) return null;
497
+ return report.framework;
498
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.