@valbuild/server 0.154.4 → 0.156.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 (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
  4. package/browser/dist/valbuild-server-browser.esm.js +2 -2
  5. package/dist/{ValOpsMemory-a1a58597.cjs.prod.js → ValOpsMemory-073f9526.cjs.prod.js} +1 -1
  6. package/dist/{ValOpsMemory-88633e0f.cjs.dev.js → ValOpsMemory-3ce3e9e8.cjs.dev.js} +1 -1
  7. package/dist/{ValOpsMemory-82af54c9.esm.js → ValOpsMemory-ecc15827.esm.js} +1 -1
  8. package/dist/{createPrettierFormatter-5d830bdf.cjs.dev.js → createPrettierFormatter-8e60f596.cjs.prod.js} +1 -1
  9. package/dist/{createPrettierFormatter-b31bfbe5.cjs.prod.js → createPrettierFormatter-a9109288.cjs.dev.js} +1 -1
  10. package/dist/{createPrettierFormatter-ce478de1.esm.js → createPrettierFormatter-fb68e363.esm.js} +1 -1
  11. package/dist/{createValRuntime-d34c69e8.esm.js → createValRuntime-02197b93.esm.js} +6 -4
  12. package/dist/{createValRuntime-07bf43dd.cjs.prod.js → createValRuntime-42622f8f.cjs.prod.js} +6 -4
  13. package/dist/{createValRuntime-858474b4.cjs.dev.js → createValRuntime-b55d14f0.cjs.dev.js} +6 -4
  14. package/dist/declarations/src/internal/index.d.ts +14 -0
  15. package/dist/declarations/src/proposalMerge/foldContent.d.ts +45 -0
  16. package/dist/declarations/src/proposalMerge/project.d.ts +124 -0
  17. package/dist/declarations/src/proposalMerge/threeWay.d.ts +51 -0
  18. package/dist/declarations/src/proposalMerge/validate.d.ts +16 -0
  19. package/dist/foldContent-2c218a30.cjs.dev.js +216 -0
  20. package/dist/foldContent-54f2c87c.cjs.prod.js +216 -0
  21. package/dist/foldContent-f065c19f.esm.js +214 -0
  22. package/dist/{inTabFetch-e9a48fac.cjs.prod.js → inTabFetch-46ad6b87.cjs.prod.js} +1 -1
  23. package/dist/{inTabFetch-54c1cb83.esm.js → inTabFetch-6dacc8a1.esm.js} +1 -1
  24. package/dist/{inTabFetch-fb9cf5e0.cjs.dev.js → inTabFetch-85b1aef4.cjs.dev.js} +1 -1
  25. package/dist/{proposalJsonEntries-2cd6f6fe.esm.js → jsonValuesModule-12fc4bb0.esm.js} +2 -128
  26. package/dist/{proposalJsonEntries-d21900d4.cjs.dev.js → jsonValuesModule-6cf73937.cjs.prod.js} +2 -130
  27. package/dist/{proposalJsonEntries-d4623810.cjs.prod.js → jsonValuesModule-ed68a9de.cjs.dev.js} +2 -130
  28. package/dist/merge-5a8fc685.cjs.prod.js +1596 -0
  29. package/dist/merge-a21a9c78.cjs.dev.js +1596 -0
  30. package/dist/merge-eca8ec38.esm.js +1566 -0
  31. package/dist/proposalJsonEntries-4fcfab08.cjs.prod.js +135 -0
  32. package/dist/proposalJsonEntries-878ad5b6.cjs.dev.js +135 -0
  33. package/dist/proposalJsonEntries-e1b07915.esm.js +128 -0
  34. package/dist/{publishKit-cf3858a0.cjs.prod.js → publishKit-70276aed.cjs.prod.js} +19 -22
  35. package/dist/{publishKit-4e7a1516.esm.js → publishKit-a732e3c3.esm.js} +11 -14
  36. package/dist/{publishKit-6b88a02e.cjs.dev.js → publishKit-f7a77be5.cjs.dev.js} +19 -22
  37. package/dist/{valRuntime-ca9958fc.esm.js → valRuntime-407399c1.esm.js} +11 -982
  38. package/dist/{valRuntime-5cadce34.cjs.dev.js → valRuntime-7a4bbb5d.cjs.dev.js} +21 -995
  39. package/dist/{valRuntime-ae69b225.cjs.prod.js → valRuntime-8585d3ce.cjs.prod.js} +21 -995
  40. package/dist/valbuild-server.cjs.dev.js +45 -462
  41. package/dist/valbuild-server.cjs.prod.js +45 -462
  42. package/dist/valbuild-server.esm.js +15 -431
  43. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
  44. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
  45. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
  46. package/internal/dist/valbuild-server-internal.cjs.dev.js +20 -2
  47. package/internal/dist/valbuild-server-internal.cjs.prod.js +20 -2
  48. package/internal/dist/valbuild-server-internal.esm.js +20 -3
  49. package/package.json +4 -4
@@ -1,22 +1,22 @@
1
- import { a as analyzeValModule, f as flatMapErrors, b as formatSyntaxError, c as analyzeJsonValuesEntries } from './proposalJsonEntries-2cd6f6fe.esm.js';
2
- export { a as analyzeValModule, d as formatSyntaxErrorTree, p as proposalSnapshotForReaders } from './proposalJsonEntries-2cd6f6fe.esm.js';
1
+ import { a as analyzeValModule, f as flatMapErrors, b as formatSyntaxError, c as analyzeJsonValuesEntries } from './jsonValuesModule-12fc4bb0.esm.js';
2
+ export { a as analyzeValModule, d as formatSyntaxErrorTree } from './jsonValuesModule-12fc4bb0.esm.js';
3
3
  import { applyPatch, PatchError, JSONOps, deepClone, sourceToPatchPath, isNotRoot } from '@valbuild/core/patch';
4
- import { T as TSOps, g as getPersonalAccessTokenPath, p as parsePersonalAccessTokenFile, v as valRuntime, a as verifyJwt, d as decodeJwtWithoutVerifying, e as encodeJwt, b as getExpire, r as readValLoginToken, c as resolveRemoteFileAuth, l as loadTypeScriptKit, i as initHandlerOptions, f as removeValJsonEntry, h as insertValJsonEntry, V as ValOpsFS } from './valRuntime-ca9958fc.esm.js';
5
- export { A as APP_MODE_REQUIRES_REMOTE_FILES, V as ValOpsFS, k as ValOpsHttp, j as createValOps, d as decodeJwtWithoutVerifying, n as describePatchStoreProblems, e as encodeJwt, b as getExpire, g as getPersonalAccessTokenPath, i as initHandlerOptions, l as loadTypeScriptKit, p as parsePersonalAccessTokenFile, m as readPatchStore, c as resolveRemoteFileAuth, v as valRuntime, a as verifyJwt } from './valRuntime-ca9958fc.esm.js';
4
+ import { T as TSOps, g as getCompilerOptions, l as loadValModules, r as removeValJsonEntry, i as insertValJsonEntry, c as createNodeRequire } from './merge-eca8ec38.esm.js';
5
+ export { a as createValModuleFileInspector, f as findDefaultExport, g as getCompilerOptions, l as loadValModules } from './merge-eca8ec38.esm.js';
6
6
  import { pipe, result } from '@valbuild/core/fp';
7
- import { derefPatch, Internal, extractValModules, DEFAULT_VAL_REMOTE_HOST, DEFAULT_CONTENT_HOST } from '@valbuild/core';
7
+ import { derefPatch, extractValModules, Internal, DEFAULT_VAL_REMOTE_HOST, DEFAULT_CONTENT_HOST } from '@valbuild/core';
8
8
  export { hasRemoteFileSchema } from '@valbuild/core';
9
9
  import ts from 'typescript';
10
10
  import path from 'path';
11
11
  import fs from 'fs';
12
- import vm from 'node:vm';
13
- import { Module } from 'node:module';
14
12
  import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, g as getNewJsonEntryPaths } from './jsonValuesPatch-13acc674.esm.js';
15
- import { v as validateJsonValuesEntries, i as isHlsMasterPlaylist, s as sumHlsSegmentDurations, p as parseHlsMasterVariants, l as largestHlsVariant, g as getFileExt, f as fallbackRefOf, m as mapHlsUris, a as movedRemoteHost, n as needsHostCheck, r as rewriteRefHost, b as fallbackRemoteHost, c as checkRemoteFiles, d as getFieldsForType, V as ValServer, e as formatPatchSourceError, h as VAL_CLIENT_HEADERS } from './ValOpsMemory-82af54c9.esm.js';
16
- export { o as ValOpsMemory, j as askOncePerHost, e as formatPatchSourceError, g as getFileExt, k as getSettings, u as uploadRemoteFile } from './ValOpsMemory-82af54c9.esm.js';
13
+ import { v as validateJsonValuesEntries, i as isHlsMasterPlaylist, s as sumHlsSegmentDurations, p as parseHlsMasterVariants, l as largestHlsVariant, g as getFileExt, f as fallbackRefOf, m as mapHlsUris, a as movedRemoteHost, n as needsHostCheck, r as rewriteRefHost, b as fallbackRemoteHost, c as checkRemoteFiles, d as getFieldsForType, V as ValServer, e as formatPatchSourceError, h as VAL_CLIENT_HEADERS } from './ValOpsMemory-ecc15827.esm.js';
14
+ export { o as ValOpsMemory, j as askOncePerHost, e as formatPatchSourceError, g as getFileExt, k as getSettings, u as uploadRemoteFile } from './ValOpsMemory-ecc15827.esm.js';
17
15
  import { isJsonValuesRootOp, rebaseContentOp, classifyJsonValuesOp, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, traverseSchemaSource, richTextImageSchema, forEachRichTextImage, isStudioFix } from '@valbuild/shared/internal';
18
16
  export { classifyJsonValuesOp, rebaseContentOp } from '@valbuild/shared/internal';
19
17
  import { createUIRequestHandler } from '@valbuild/ui/server';
18
+ import { g as getPersonalAccessTokenPath, p as parsePersonalAccessTokenFile, v as valRuntime, a as verifyJwt, d as decodeJwtWithoutVerifying, e as encodeJwt, b as getExpire, r as readValLoginToken, c as resolveRemoteFileAuth, l as loadTypeScriptKit, i as initHandlerOptions, V as ValOpsFS } from './valRuntime-407399c1.esm.js';
19
+ export { A as APP_MODE_REQUIRES_REMOTE_FILES, V as ValOpsFS, h as ValOpsHttp, f as createValOps, d as decodeJwtWithoutVerifying, k as describePatchStoreProblems, e as encodeJwt, b as getExpire, g as getPersonalAccessTokenPath, i as initHandlerOptions, l as loadTypeScriptKit, p as parsePersonalAccessTokenFile, j as readPatchStore, c as resolveRemoteFileAuth, v as valRuntime, a as verifyJwt } from './valRuntime-407399c1.esm.js';
20
20
  import http from 'node:http';
21
21
  import https from 'node:https';
22
22
  import net from 'node:net';
@@ -24,14 +24,17 @@ import sizeOf from 'image-size';
24
24
  import http$1 from 'http';
25
25
  import https$1 from 'https';
26
26
  import { s as setRequestGuard, p as parseAllowedHosts, c as createValRequestHandler } from './ValRouterCore-f7d6394e.esm.js';
27
- export { c as contentFromEnv, b as createPrettierFormatter, l as layeredSnapshot, p as proposalFromEnv, a as proposalSnapshot } from './createPrettierFormatter-ce478de1.esm.js';
27
+ export { c as contentFromEnv, b as createPrettierFormatter, l as layeredSnapshot, p as proposalFromEnv, a as proposalSnapshot } from './createPrettierFormatter-fb68e363.esm.js';
28
+ export { proposalSnapshotForReaders } from './proposalJsonEntries-e1b07915.esm.js';
28
29
  import { transform } from 'sucrase';
29
30
  import fs$1 from 'fs/promises';
31
+ import vm from 'node:vm';
30
32
  import z from 'zod';
31
33
  import os from 'os';
32
34
  export { I as InMemoryPatchStore } from './ValPatchStore-9ccc09e7.esm.js';
33
- import 'zod-validation-error';
34
35
  import 'crypto';
36
+ import 'node:module';
37
+ import 'zod-validation-error';
35
38
  import 'buffer';
36
39
 
37
40
  function getSyntheticContainingPath(rootDir) {
@@ -145,425 +148,6 @@ class ValSourceFileHandler {
145
148
  }
146
149
  }
147
150
 
148
- const getCompilerOptions = (rootDir, parseConfigHost) => {
149
- const tsConfigPath = path.resolve(rootDir, "tsconfig.json");
150
- const jsConfigPath = path.resolve(rootDir, "jsconfig.json");
151
- let configFilePath;
152
- if (parseConfigHost.fileExists(jsConfigPath)) {
153
- configFilePath = jsConfigPath;
154
- } else if (parseConfigHost.fileExists(tsConfigPath)) {
155
- configFilePath = tsConfigPath;
156
- } else {
157
- throw Error(`Could not read config from: "${tsConfigPath}" nor "${jsConfigPath}". Root dir: "${rootDir}"`);
158
- }
159
- const {
160
- config,
161
- error
162
- } = ts.readConfigFile(configFilePath, parseConfigHost.readFile.bind(parseConfigHost));
163
- if (error) {
164
- if (typeof error.messageText === "string") {
165
- throw Error(`Could not parse config file: ${configFilePath}. Error: ${error.messageText}`);
166
- }
167
- throw Error(`Could not parse config file: ${configFilePath}. Error: ${error.messageText.messageText}`);
168
- }
169
- const optionsOverrides = undefined;
170
- const parsedConfigFile = ts.parseJsonConfigFileContent(config, parseConfigHost, rootDir, optionsOverrides, configFilePath);
171
- if (parsedConfigFile.errors.length > 0) {
172
- throw Error(`Could not parse config file: ${configFilePath}. Errors: ${parsedConfigFile.errors.map(e => e.messageText).join("\n")}`);
173
- }
174
- return parsedConfigFile.options;
175
- };
176
-
177
- /**
178
- * Node's `require`, resolving as if from `filename`.
179
- *
180
- * Use this instead of importing `createRequire` from `node:module` directly.
181
- * webpack special-cases a `createRequire` binding imported from `module` /
182
- * `node:module`: it tries to resolve the call's argument at build time, and
183
- * when the argument is not a literal it gives up with
184
- *
185
- * module.createRequire failed parsing argument.
186
- *
187
- * Our argument is never a literal — it is a path inside the user's project,
188
- * known only at runtime — so there is nothing for that analysis to find, and
189
- * nothing the warning can tell anyone. It is emitted on every build of every
190
- * Next app that bundles `@valbuild/server` into its Val API route, which is
191
- * all of them. Reaching `createRequire` through the `Module` class is the same
192
- * function and is not what webpack tags, so the call is invisible to it.
193
- *
194
- * It has to stay a real `node:module` import: jest's module registry hands out
195
- * its own `node:module`, and a `require` obtained around it (via
196
- * `process.getBuiltinModule`, say) would resolve against the real filesystem
197
- * rather than the registry the tests run in.
198
- */
199
- function createNodeRequire(filename) {
200
- return Module.createRequire(filename);
201
- }
202
-
203
- /**
204
- * The filesystem seam `loadValModules` reads through.
205
- *
206
- * Defaults to `ts.sys`, i.e. the real filesystem. An editor integration (see
207
- * `@valbuild/language-server`) passes a host that overlays unsaved buffers, so
208
- * that evaluation sees what the user is looking at rather than what was last
209
- * saved.
210
- */
211
-
212
- /**
213
- * Loads the project's root `val.modules.ts` (or `.js`) using Node's `vm`
214
- * module and returns its default export (a `ValModules` registry).
215
- *
216
- * This is a recursive CommonJS loader: the root modules file and every
217
- * relative `*.val.ts` / `val.config.ts` it (dynamically) imports are
218
- * transpiled to CommonJS and evaluated in a `vm` sandbox. Bare specifiers
219
- * (e.g. `@valbuild/core`) are resolved with the real Node `require` so the
220
- * user modules share the exact same `@valbuild/core` instance that
221
- * `extractValModules` uses.
222
- *
223
- * Mirrors the pattern already used by the CLI's `evalValConfigFile`.
224
- *
225
- * SECURITY: The `vm` context is NOT a security sandbox. It deliberately exposes
226
- * `process` and a `require` that falls back to the real Node resolver (so user
227
- * modules share the same `@valbuild/core` instance). This loader must therefore
228
- * only ever be used to evaluate the project's own first-party, trusted files
229
- * (`val.modules` and the local `*.val.ts`/`val.config.ts` it imports) — i.e. the
230
- * same trust level as running the project's build. It must never be used to
231
- * evaluate untrusted or third-party modules.
232
- */
233
- function loadValModules(projectRoot, host = ts.sys) {
234
- const valModulesPath = findValModulesPath(projectRoot, host);
235
- if (!valModulesPath) {
236
- throw Error(`Could not find 'val.modules.ts' nor 'val.modules.js' in project root: '${projectRoot}'`);
237
- }
238
- const compilerOptions = getCompilerOptions(projectRoot, host);
239
- const cache = {};
240
- const loaded = loadModule(valModulesPath, cache, compilerOptions, host);
241
- const valModules = loaded.exports.default;
242
- if (!valModules) {
243
- throw Error(`Val modules file at path: '${valModulesPath}' must have a default export. Got: ${valModules}`);
244
- }
245
- return valModules;
246
- }
247
- function findValModulesPath(projectRoot, host) {
248
- for (const fileName of ["val.modules.ts", "val.modules.js"]) {
249
- const candidate = path.join(projectRoot, fileName);
250
- if (host.fileExists(candidate)) {
251
- return candidate;
252
- }
253
- }
254
- return null;
255
- }
256
- const RESOLVE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cjs", ".mjs", ".json"];
257
-
258
- // Specifiers that user val files must not actually use. We stub them so that
259
- // importing is fine, but using a value throws a clear error. Real @valbuild
260
- // packages are resolved via the real require, so when they (legitimately)
261
- // import react/next internally those go through Node, not this stub.
262
- function isStubbedSpecifier(spec) {
263
- return spec === "react" || spec.startsWith("react/") || spec === "next" || spec.startsWith("next/") || spec === "@valbuild/ui" || spec === "@valbuild/react" || spec.startsWith("@valbuild/react/");
264
- }
265
- function makeStub(spec) {
266
- const throwing = prop => () => {
267
- throw Error(`Cannot use '${prop}' from '${spec}' in this type of file`);
268
- };
269
- const handler = {
270
- get(_target, prop) {
271
- if (prop === "__esModule") {
272
- return true;
273
- }
274
- if (typeof prop === "symbol") {
275
- return undefined;
276
- }
277
- // React.createContext is sometimes called at module top-level; return a
278
- // proxy-returning function so evaluation does not crash on import.
279
- if (prop === "createContext") {
280
- return () => new Proxy({}, handler);
281
- }
282
- if (prop === "default") {
283
- return stub;
284
- }
285
- return throwing(prop);
286
- }
287
- };
288
- const stub = new Proxy({}, handler);
289
- return stub;
290
- }
291
- function loadModule(absPath, cache, compilerOptions, host) {
292
- const cached = cache[absPath];
293
- if (cached) {
294
- return cached;
295
- }
296
- // JSON modules (e.g. the `*.val.json` files backing `.jsonValues()` entries)
297
- // are loaded by parsing, mirroring Node's `require("./x.json")` which returns
298
- // the parsed object as `module.exports`. The importing `.val.ts` wraps this
299
- // with `__importStar` so `import("./x.val.json")` yields `{ default, ... }`.
300
- // These are only loaded when an entry thunk is invoked, never during
301
- // `extractValModules`, so this stays lazy.
302
- //
303
- // Read through `host` like every other project file: an editor integration
304
- // passes a host that overlays unsaved buffers, and an entry the user is
305
- // editing has to resolve to what they are looking at.
306
- if (absPath.endsWith(".json")) {
307
- const json = host.readFile(absPath);
308
- if (json === undefined) {
309
- throw Error(`Could not read Val module file: '${absPath}'`);
310
- }
311
- const jsonModule = {
312
- exports: JSON.parse(json)
313
- };
314
- cache[absPath] = jsonModule;
315
- return jsonModule;
316
- }
317
- const code = host.readFile(absPath);
318
- if (code === undefined) {
319
- throw Error(`Could not read Val module file: '${absPath}'`);
320
- }
321
- const transpiled = ts.transpileModule(code, {
322
- compilerOptions: {
323
- target: ts.ScriptTarget.ES2020,
324
- module: ts.ModuleKind.CommonJS,
325
- esModuleInterop: true,
326
- jsx: ts.JsxEmit.ReactJSX
327
- },
328
- fileName: absPath
329
- });
330
- const moduleObj = {
331
- exports: {}
332
- };
333
- // Insert into the cache before evaluating so cyclic imports resolve.
334
- cache[absPath] = moduleObj;
335
- const dirName = path.dirname(absPath);
336
- const realRequire = createNodeRequire(absPath);
337
- const customRequire = spec => {
338
- var _ts$resolveModuleName;
339
- if (isStubbedSpecifier(spec)) {
340
- return makeStub(spec);
341
- }
342
- if (spec.startsWith(".") || path.isAbsolute(spec)) {
343
- const resolved = resolveRelative(dirName, spec, host);
344
- if (!resolved) {
345
- throw Error(`Could not resolve module '${spec}' from '${absPath}'`);
346
- }
347
- return loadModule(resolved, cache, compilerOptions, host).exports;
348
- }
349
- // Non-relative specifier: it might be a tsconfig path alias (e.g. "_/val.config")
350
- // pointing at a local source file, or an actual node_modules package.
351
- const tsResolved = (_ts$resolveModuleName = ts.resolveModuleName(spec, absPath, compilerOptions, host).resolvedModule) === null || _ts$resolveModuleName === void 0 ? void 0 : _ts$resolveModuleName.resolvedFileName;
352
- if (tsResolved && !tsResolved.includes("/node_modules/") && !tsResolved.endsWith(".d.ts")) {
353
- return loadModule(tsResolved, cache, compilerOptions, host).exports;
354
- }
355
- // Real node_modules package – use the real require so user modules share
356
- // the same @valbuild/core instance as extractValModules.
357
- return realRequire(spec);
358
- };
359
-
360
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
361
- const sandbox = {
362
- exports: moduleObj.exports,
363
- module: moduleObj,
364
- require: customRequire,
365
- __filename: absPath,
366
- __dirname: dirName,
367
- console,
368
- process
369
- };
370
- sandbox.global = sandbox;
371
- sandbox.globalThis = sandbox;
372
- const context = vm.createContext(sandbox);
373
- const script = new vm.Script(transpiled.outputText, {
374
- filename: absPath
375
- });
376
- script.runInContext(context);
377
- return moduleObj;
378
- }
379
- function resolveRelative(dirName, spec, host) {
380
- var _host$directoryExists;
381
- const base = path.resolve(dirName, spec);
382
- // Exact file (with extension)
383
- if (host.fileExists(base)) {
384
- return base;
385
- }
386
- // Probe extensions (handles `./x.val` -> `./x.val.ts`)
387
- for (const ext of RESOLVE_EXTENSIONS) {
388
- const candidate = base + ext;
389
- if (host.fileExists(candidate)) {
390
- return candidate;
391
- }
392
- }
393
- // Directory index
394
- if (((_host$directoryExists = host.directoryExists) === null || _host$directoryExists === void 0 ? void 0 : _host$directoryExists.call(host, base)) ?? fs.existsSync(base)) {
395
- for (const ext of RESOLVE_EXTENSIONS) {
396
- const candidate = path.join(base, "index" + ext);
397
- if (host.fileExists(candidate)) {
398
- return candidate;
399
- }
400
- }
401
- }
402
- return null;
403
- }
404
-
405
- /**
406
- * What a `*.val.ts` file that is NOT registered in `val.modules` turns out to
407
- * be.
408
- *
409
- * A file matching `*.val.ts` is not necessarily a Val module: the same
410
- * convention is used for shared schemas and other content-adjacent helpers, and
411
- * those are not meant to be registered. Only a file that actually default
412
- * exports a module is worth warning about; one that default exports something
413
- * else is a mistake, because nothing will ever load it.
414
- *
415
- * See {@link createValModuleFileInspector}.
416
- */
417
-
418
- /**
419
- * Inspects individual `*.val.{ts,js}` files, sharing one module cache and one
420
- * parsed tsconfig across every call.
421
- *
422
- * The default export is checked SYNTACTICALLY first and only evaluated if it is
423
- * there. That ordering is the point: a `.val.ts` with no default export is a
424
- * helper file, and evaluating it to learn that would be both wasted work and a
425
- * way to turn an unrelated top-level throw into a reported error.
426
- *
427
- * SECURITY: evaluation goes through the same `vm` loader as
428
- * {@link loadValModules} — see the warning there. Only ever point this at the
429
- * project's own first-party files.
430
- */
431
- function createValModuleFileInspector(projectRoot, host = ts.sys) {
432
- const compilerOptions = getCompilerOptions(projectRoot, host);
433
- const cache = {};
434
- return absPath => {
435
- const code = host.readFile(absPath);
436
- if (code === undefined) {
437
- return {
438
- status: "invalid",
439
- message: `Could not read file: '${absPath}'`
440
- };
441
- }
442
- const sourceFile = ts.createSourceFile(absPath, code, ts.ScriptTarget.ES2020, true);
443
- if (!hasDefaultExport(sourceFile)) {
444
- return {
445
- status: "no-default-export"
446
- };
447
- }
448
- let exports;
449
- // `loadModule` inserts a module into the cache BEFORE evaluating it, so
450
- // that a cycle resolves. One that throws therefore leaves a half-built
451
- // entry behind - and unlike `loadValModules`, which builds a cache per
452
- // call and lets the throw escape, this cache outlives the failure. A later
453
- // inspection of the same file (or of the helper that actually threw) would
454
- // hit that entry, see empty exports, and report "default export is
455
- // undefined" instead of the real error - or, worse, quietly downgrade it to
456
- // a warning. So roll the cache back to what it was before this attempt.
457
- const before = new Set(Object.keys(cache));
458
- try {
459
- exports = loadModule(absPath, cache, compilerOptions, host).exports;
460
- } catch (e) {
461
- for (const key of Object.keys(cache)) {
462
- if (!before.has(key)) {
463
- delete cache[key];
464
- }
465
- }
466
- return {
467
- status: "invalid",
468
- message: `Could not be loaded. Error: ${errorMessage(e)}`
469
- };
470
- }
471
- if (Internal.isValModule(exports.default)) {
472
- return {
473
- status: "val-module"
474
- };
475
- }
476
- // NOTE: do NOT suggest wrapping this in `c.define`. A shared schema turned
477
- // into a module is an UNREGISTERED module, i.e. straight back to a warning.
478
- // The fix is to move it out of the default export slot, which is the one
479
- // thing about a `.val.ts` that Val reserves for itself.
480
- return {
481
- status: "invalid",
482
- message: `Default export is ${describeDefaultExport(exports.default)}, not a Val module. Only 'c.define(...)' may be the default export of a '*.val.ts' file: use a named export for a shared schema or helper`
483
- };
484
- };
485
- }
486
-
487
- /**
488
- * The statement that exports a RUNTIME value as `default`, without evaluating
489
- * it — or `undefined` when the file has no such export.
490
- *
491
- * This is the one rule that separates a Val module from a `*.val.ts` that
492
- * merely wears the naming convention: a shared schema or helper is exported by
493
- * name, a module is exported by default. Every caller that needs to tell those
494
- * apart goes through this — `val validate` to decide whether an unregistered
495
- * file is worth reporting, and the language server to decide the same thing and
496
- * to put its diagnostic on the export rather than on line 1.
497
- *
498
- * Two things deliberately do not count, because neither exists once the file is
499
- * transpiled — and treating either as a default export would send a pure helper
500
- * off to be evaluated and reported:
501
- *
502
- * - `export * from "./x"`, since a star re-export never carries the default;
503
- * - a type-only export, in any of its three spellings
504
- * (`export type { T as default }`, `export { type T as default }` and
505
- * `export default interface T {}` — the last one parses as a declaration
506
- * carrying a `default` modifier, exactly like `export default class`, and is
507
- * the one that looks like a runtime export and is not).
508
- */
509
- function findDefaultExport(sourceFile) {
510
- return sourceFile.statements.find(statement => {
511
- // `export default <expr>` — but not `export = x`, which shares this node.
512
- if (ts.isExportAssignment(statement)) {
513
- return !statement.isExportEquals;
514
- }
515
- // `export { x as default }` / `export { default } from "./x"`
516
- if (ts.isExportDeclaration(statement) && !statement.isTypeOnly && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
517
- return statement.exportClause.elements.some(element => !element.isTypeOnly && element.name.text === "default");
518
- }
519
- // `export default function f() {}` / `export default class C {}`, which are
520
- // declarations carrying a `default` modifier rather than export assignments.
521
- // `export default interface T {}` is spelled the same way and is a type, so
522
- // it is excluded here rather than by the `isTypeOnly` checks above.
523
- return !ts.isInterfaceDeclaration(statement) && ts.canHaveModifiers(statement) && (ts.getModifiers(statement) ?? []).some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword);
524
- });
525
- }
526
-
527
- /** Whether the file exports a runtime value as `default`. */
528
- function hasDefaultExport(sourceFile) {
529
- return findDefaultExport(sourceFile) !== undefined;
530
- }
531
-
532
- /** A short, human-readable "what you exported instead" for the error message. */
533
- function describeDefaultExport(value) {
534
- if (value === null) {
535
- return "null";
536
- }
537
- if (Array.isArray(value)) {
538
- return "an array";
539
- }
540
- if (typeof value === "object") {
541
- // Duck-typed rather than `instanceof Schema`, for the same cross-realm
542
- // reason `isValModule` avoids a constructor check.
543
- if ("executeSerialize" in value && typeof value["executeSerialize"] === "function") {
544
- return "a schema";
545
- }
546
- return "an object";
547
- }
548
- if (typeof value === "undefined") {
549
- return "undefined";
550
- }
551
- return `a ${typeof value}`;
552
- }
553
- function errorMessage(e) {
554
- // NOT `e instanceof Error`: an error thrown from inside the `vm` context is
555
- // built from that realm's Error constructor. Duck-type the message instead.
556
- if (typeof e === "object" && e !== null && "message" in e) {
557
- const {
558
- message
559
- } = e;
560
- if (typeof message === "string") {
561
- return message;
562
- }
563
- }
564
- return String(e);
565
- }
566
-
567
151
  /**
568
152
  * Which `*.val.json` holds a `.jsonValues()` entry's content, given the module's
569
153
  * `.val.ts`.
@@ -7518,4 +7102,4 @@ function readCapturedReport(snapshotDir) {
7518
7102
  return JSON.parse(fs.readFileSync(reportPath, "utf-8"));
7519
7103
  }
7520
7104
 
7521
- export { DEFAULT_LOGIN_EXPIRES_IN_SECONDS, DEFAULT_LOGIN_HOST, DEFAULT_LOGIN_POLL_INTERVAL_SECONDS, EXTERNAL_RESULT, Service, ValFSHost, ValLoginError, ValModuleLoader, ValSourceFileHandler, awaitValLoginConfirmation, checkRemoteRef, compareWithCapturedReport, createDefaultValFSHost, createFixPatch, createJsonEntryPathMap, createModulePathMap, createService, createValApiRouter, createValModuleFileInspector, createValServer, currentFixHandlers, defineExternal, downloadFileFromRemote, err, evalValConfigFile, extractFileMetadata, extractImageMetadata, extractJsonValuesEntry, extractVideoMetadata, extractVideoMetadataFromFile, filesOfVideo, filesOfVideosetEntry, findAndEvalValConfigFile, findDefaultExport, findJsonEntryFilePath, fixHandlers, getCachedRemoteFileDir, getCachedRemoteFilePath, getCompilerOptions, getModulePathRange, getValidationErrorFileRef, handleCheckAllFiles, handleExternalUpload, handleFileMetadata, handleJsonValuesExtractEntry, handleRemoteFileCheck, handleRemoteFileDownload, handleRemoteFileUpload, handleRemoteGalleryFileUpload, handleUniqueFolderCheck, handleVideosetCheckAllFiles, handleVideosetCheckRemote, handleVideosetMetadata, handleVideosetUploadRemote, isExternalResult, loadValModules, ok, patchSourceFile, persistPersonalAccessToken, planJsonValuesEntryExtraction, readCapturedReport, replaySnapshot, safeReadGit, startValLogin, validateMetadata, videosetEntryVideoSchema };
7105
+ export { DEFAULT_LOGIN_EXPIRES_IN_SECONDS, DEFAULT_LOGIN_HOST, DEFAULT_LOGIN_POLL_INTERVAL_SECONDS, EXTERNAL_RESULT, Service, ValFSHost, ValLoginError, ValModuleLoader, ValSourceFileHandler, awaitValLoginConfirmation, checkRemoteRef, compareWithCapturedReport, createDefaultValFSHost, createFixPatch, createJsonEntryPathMap, createModulePathMap, createService, createValApiRouter, createValServer, currentFixHandlers, defineExternal, downloadFileFromRemote, err, evalValConfigFile, extractFileMetadata, extractImageMetadata, extractJsonValuesEntry, extractVideoMetadata, extractVideoMetadataFromFile, filesOfVideo, filesOfVideosetEntry, findAndEvalValConfigFile, findJsonEntryFilePath, fixHandlers, getCachedRemoteFileDir, getCachedRemoteFilePath, getModulePathRange, getValidationErrorFileRef, handleCheckAllFiles, handleExternalUpload, handleFileMetadata, handleJsonValuesExtractEntry, handleRemoteFileCheck, handleRemoteFileDownload, handleRemoteFileUpload, handleRemoteGalleryFileUpload, handleUniqueFolderCheck, handleVideosetCheckAllFiles, handleVideosetCheckRemote, handleVideosetMetadata, handleVideosetUploadRemote, isExternalResult, ok, patchSourceFile, persistPersonalAccessToken, planJsonValuesEntryExtraction, readCapturedReport, replaySnapshot, safeReadGit, startValLogin, validateMetadata, videosetEntryVideoSchema };
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var inTabFetch = require('../../../dist/inTabFetch-fb9cf5e0.cjs.dev.js');
5
+ var inTabFetch = require('../../../dist/inTabFetch-85b1aef4.cjs.dev.js');
6
6
  var draftReads = require('../../../dist/draftReads-1f256502.cjs.dev.js');
7
7
  require('@valbuild/core');
8
- require('../../../dist/ValOpsMemory-88633e0f.cjs.dev.js');
8
+ require('../../../dist/ValOpsMemory-3ce3e9e8.cjs.dev.js');
9
9
  require('zod');
10
10
  require('@valbuild/shared/internal');
11
11
  require('../../../dist/jsonValuesPatch-88bc661d.cjs.dev.js');
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var inTabFetch = require('../../../dist/inTabFetch-e9a48fac.cjs.prod.js');
5
+ var inTabFetch = require('../../../dist/inTabFetch-46ad6b87.cjs.prod.js');
6
6
  var draftReads = require('../../../dist/draftReads-27351e97.cjs.prod.js');
7
7
  require('@valbuild/core');
8
- require('../../../dist/ValOpsMemory-a1a58597.cjs.prod.js');
8
+ require('../../../dist/ValOpsMemory-073f9526.cjs.prod.js');
9
9
  require('zod');
10
10
  require('@valbuild/shared/internal');
11
11
  require('../../../dist/jsonValuesPatch-92798812.cjs.prod.js');
@@ -1,7 +1,7 @@
1
- export { a as createInTabVal } from '../../../dist/inTabFetch-54c1cb83.esm.js';
1
+ export { a as createInTabVal } from '../../../dist/inTabFetch-6dacc8a1.esm.js';
2
2
  export { s as serverDraftSource } from '../../../dist/draftReads-7f0f0eb3.esm.js';
3
3
  import '@valbuild/core';
4
- import '../../../dist/ValOpsMemory-82af54c9.esm.js';
4
+ import '../../../dist/ValOpsMemory-ecc15827.esm.js';
5
5
  import 'zod';
6
6
  import '@valbuild/shared/internal';
7
7
  import '../../../dist/jsonValuesPatch-13acc674.esm.js';
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var draftReads = require('../../dist/draftReads-1f256502.cjs.dev.js');
6
- var createPrettierFormatter = require('../../dist/createPrettierFormatter-5d830bdf.cjs.dev.js');
6
+ var createPrettierFormatter = require('../../dist/createPrettierFormatter-a9109288.cjs.dev.js');
7
7
  var ValPatchStore = require('../../dist/ValPatchStore-b53db740.cjs.dev.js');
8
8
  require('@valbuild/core');
9
9
  require('@valbuild/shared/internal');
@@ -37,9 +37,26 @@ require('path');
37
37
  async function createValRuntime(valModules, route, opts, config) {
38
38
  const {
39
39
  createValRuntime
40
- } = await Promise.resolve().then(function () { return require('../../dist/createValRuntime-858474b4.cjs.dev.js'); });
40
+ } = await Promise.resolve().then(function () { return require('../../dist/createValRuntime-b55d14f0.cjs.dev.js'); });
41
41
  return createValRuntime(valModules, route, opts, config);
42
42
  }
43
+ /**
44
+ * Content written back into a project's files, for connecting a project Val
45
+ * Build hosts to a repository (valbuild/home,
46
+ * docs/plans/connect-with-history.md, phase 6a). See
47
+ * `proposalMerge/foldContent.ts`.
48
+ *
49
+ * Loaded when it is called, never with this entry: it brings the TypeScript
50
+ * compiler, and this entry is also what a site's page reads content through,
51
+ * which must evaluate none of it (`servingPath.test.ts` in
52
+ * `@valbuild/tanstack`).
53
+ */
54
+ async function foldContent(...args) {
55
+ const {
56
+ foldContent
57
+ } = await Promise.resolve().then(function () { return require('../../dist/foldContent-2c218a30.cjs.dev.js'); });
58
+ return foldContent(...args);
59
+ }
43
60
 
44
61
  exports.draftForRequest = draftReads.draftForRequest;
45
62
  exports.readDraftChanges = draftReads.readDraftChanges;
@@ -57,3 +74,4 @@ exports.InMemoryPatchStore = ValPatchStore.InMemoryPatchStore;
57
74
  exports.ValHead = ValPatchStore.ValHead;
58
75
  exports.headWork = ValPatchStore.headWork;
59
76
  exports.createValRuntime = createValRuntime;
77
+ exports.foldContent = foldContent;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var draftReads = require('../../dist/draftReads-27351e97.cjs.prod.js');
6
- var createPrettierFormatter = require('../../dist/createPrettierFormatter-b31bfbe5.cjs.prod.js');
6
+ var createPrettierFormatter = require('../../dist/createPrettierFormatter-8e60f596.cjs.prod.js');
7
7
  var ValPatchStore = require('../../dist/ValPatchStore-457b166f.cjs.prod.js');
8
8
  require('@valbuild/core');
9
9
  require('@valbuild/shared/internal');
@@ -37,9 +37,26 @@ require('path');
37
37
  async function createValRuntime(valModules, route, opts, config) {
38
38
  const {
39
39
  createValRuntime
40
- } = await Promise.resolve().then(function () { return require('../../dist/createValRuntime-07bf43dd.cjs.prod.js'); });
40
+ } = await Promise.resolve().then(function () { return require('../../dist/createValRuntime-42622f8f.cjs.prod.js'); });
41
41
  return createValRuntime(valModules, route, opts, config);
42
42
  }
43
+ /**
44
+ * Content written back into a project's files, for connecting a project Val
45
+ * Build hosts to a repository (valbuild/home,
46
+ * docs/plans/connect-with-history.md, phase 6a). See
47
+ * `proposalMerge/foldContent.ts`.
48
+ *
49
+ * Loaded when it is called, never with this entry: it brings the TypeScript
50
+ * compiler, and this entry is also what a site's page reads content through,
51
+ * which must evaluate none of it (`servingPath.test.ts` in
52
+ * `@valbuild/tanstack`).
53
+ */
54
+ async function foldContent(...args) {
55
+ const {
56
+ foldContent
57
+ } = await Promise.resolve().then(function () { return require('../../dist/foldContent-54f2c87c.cjs.prod.js'); });
58
+ return foldContent(...args);
59
+ }
43
60
 
44
61
  exports.draftForRequest = draftReads.draftForRequest;
45
62
  exports.readDraftChanges = draftReads.readDraftChanges;
@@ -57,3 +74,4 @@ exports.InMemoryPatchStore = ValPatchStore.InMemoryPatchStore;
57
74
  exports.ValHead = ValPatchStore.ValHead;
58
75
  exports.headWork = ValPatchStore.headWork;
59
76
  exports.createValRuntime = createValRuntime;
77
+ exports.foldContent = foldContent;
@@ -1,5 +1,5 @@
1
1
  export { d as draftForRequest, r as readDraftChanges, s as serverDraftSource } from '../../dist/draftReads-7f0f0eb3.esm.js';
2
- export { b as createPrettierFormatter, l as layeredSnapshot, g as proposalAsBuilt, r as readerSnapshot, h as serverCanStartLazily, e as servingBuildOf, s as stagedAfterBuild } from '../../dist/createPrettierFormatter-ce478de1.esm.js';
2
+ export { b as createPrettierFormatter, l as layeredSnapshot, g as proposalAsBuilt, r as readerSnapshot, h as serverCanStartLazily, e as servingBuildOf, s as stagedAfterBuild } from '../../dist/createPrettierFormatter-fb68e363.esm.js';
3
3
  export { H as HEAD_BUDGET_BYTES, a as HEAD_VERSIONS_PER_MODULE, I as InMemoryPatchStore, V as ValHead, h as headWork } from '../../dist/ValPatchStore-9ccc09e7.esm.js';
4
4
  import '@valbuild/core';
5
5
  import '@valbuild/shared/internal';
@@ -33,8 +33,25 @@ import 'path';
33
33
  async function createValRuntime(valModules, route, opts, config) {
34
34
  const {
35
35
  createValRuntime
36
- } = await import('../../dist/createValRuntime-d34c69e8.esm.js');
36
+ } = await import('../../dist/createValRuntime-02197b93.esm.js');
37
37
  return createValRuntime(valModules, route, opts, config);
38
38
  }
39
+ /**
40
+ * Content written back into a project's files, for connecting a project Val
41
+ * Build hosts to a repository (valbuild/home,
42
+ * docs/plans/connect-with-history.md, phase 6a). See
43
+ * `proposalMerge/foldContent.ts`.
44
+ *
45
+ * Loaded when it is called, never with this entry: it brings the TypeScript
46
+ * compiler, and this entry is also what a site's page reads content through,
47
+ * which must evaluate none of it (`servingPath.test.ts` in
48
+ * `@valbuild/tanstack`).
49
+ */
50
+ async function foldContent(...args) {
51
+ const {
52
+ foldContent
53
+ } = await import('../../dist/foldContent-f065c19f.esm.js');
54
+ return foldContent(...args);
55
+ }
39
56
 
40
- export { createValRuntime };
57
+ export { createValRuntime, foldContent };