@valbuild/server 0.43.1 → 0.45.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.
@@ -7,12 +7,12 @@ var ts = require('typescript');
7
7
  var fp = require('@valbuild/core/fp');
8
8
  var core = require('@valbuild/core');
9
9
  var patch = require('@valbuild/core/patch');
10
- var crypto = require('crypto');
11
10
  var path = require('path');
12
11
  var fs = require('fs');
13
12
  var sucrase = require('sucrase');
14
13
  var z = require('zod');
15
14
  var internal = require('@valbuild/shared/internal');
15
+ var crypto = require('crypto');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var sizeOf = require('image-size');
18
18
 
@@ -37,10 +37,10 @@ function _interopNamespace(e) {
37
37
  }
38
38
 
39
39
  var ts__default = /*#__PURE__*/_interopDefault(ts);
40
- var crypto__default = /*#__PURE__*/_interopDefault(crypto);
41
40
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
42
41
  var fs__default = /*#__PURE__*/_interopDefault(fs);
43
42
  var z__default = /*#__PURE__*/_interopDefault(z);
43
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
44
44
  var sizeOf__default = /*#__PURE__*/_interopDefault(sizeOf);
45
45
 
46
46
  class ValSyntaxError {
@@ -624,8 +624,8 @@ const ops = new TSOps(document => {
624
624
 
625
625
  // TODO: rename to patchValFiles since we may write multiple files
626
626
  const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runtime) => {
627
- const timeId = crypto.randomUUID();
628
- console.time("patchValFile" + timeId);
627
+ // const timeId = randomUUID();
628
+ // console.time("patchValFile" + timeId);
629
629
  const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
630
630
  const sourceFile = sourceFileHandler.getSourceFile(filePath);
631
631
  if (!sourceFile) {
@@ -661,8 +661,9 @@ const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runti
661
661
  }
662
662
  }
663
663
  sourceFileHandler.writeSourceFile(newSourceFile.value);
664
- console.timeEnd("patchValFile" + timeId);
664
+ // console.timeEnd("patchValFile" + timeId);
665
665
  };
666
+
666
667
  function convertDataUrlToBase64(dataUrl) {
667
668
  const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
668
669
  return Buffer.from(base64, "base64");
@@ -975,7 +976,7 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
975
976
  }
976
977
  if (modulePath === "@valbuild/react/stega") {
977
978
  return {
978
- value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; "
979
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; export const stegaDecodeString = () => { throw Error(`Cannot use 'stegaDecodeString' in this type of file`) }; "
979
980
  };
980
981
  }
981
982
  if (modulePath.startsWith("next/navigation")) {
@@ -1003,6 +1004,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
1003
1004
  value: "export const ValNextProvider = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValNextProvider' in this file`) } } } )"
1004
1005
  };
1005
1006
  }
1007
+ if (modulePath.includes("/ValImage")) {
1008
+ return {
1009
+ value: "export const ValImage = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValImage' in this file`) } } } )"
1010
+ };
1011
+ }
1006
1012
  return {
1007
1013
  value: moduleLoader.getModule(modulePath)
1008
1014
  };
@@ -1053,6 +1059,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
1053
1059
  value: requestedName
1054
1060
  };
1055
1061
  }
1062
+ if (requestedName.includes("/ValImage")) {
1063
+ return {
1064
+ value: requestedName
1065
+ };
1066
+ }
1056
1067
  const modulePath = moduleLoader.resolveModulePath(baseModuleName, requestedName);
1057
1068
  return {
1058
1069
  value: modulePath
@@ -1261,7 +1272,7 @@ class LocalValServer {
1261
1272
  return {
1262
1273
  cookies: {
1263
1274
  [internal.VAL_ENABLE_COOKIE_NAME]: {
1264
- value: null
1275
+ value: "false"
1265
1276
  }
1266
1277
  },
1267
1278
  status: 302,
@@ -1280,8 +1291,9 @@ class LocalValServer {
1280
1291
  }
1281
1292
  };
1282
1293
  }
1283
- const id = crypto.randomUUID();
1284
- console.time("patching:" + id);
1294
+
1295
+ // const id = randomUUID();
1296
+ // console.time("patching:" + id);
1285
1297
  for (const moduleId in patchJSON.data) {
1286
1298
  // Then parse/validate
1287
1299
  // TODO: validate all and then fail instead:
@@ -1292,7 +1304,8 @@ class LocalValServer {
1292
1304
  }
1293
1305
  await this.options.service.patch(moduleId, patch$1.value);
1294
1306
  }
1295
- console.timeEnd("patching:" + id);
1307
+ // console.timeEnd("patching:" + id);
1308
+
1296
1309
  return {
1297
1310
  status: 200,
1298
1311
  json: {} // no patch ids created
@@ -2252,6 +2265,7 @@ class ValFSHost {
2252
2265
  }
2253
2266
 
2254
2267
  // TODO: find a better name? transformFixesToPatch?
2268
+ const textEncoder = new TextEncoder();
2255
2269
  async function createFixPatch(config, apply, sourcePath, validationError) {
2256
2270
  async function getImageMetadata() {
2257
2271
  const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
@@ -2259,13 +2273,28 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2259
2273
  // TODO:
2260
2274
  throw Error("Cannot fix image without a file reference");
2261
2275
  }
2262
- const localFile = path__namespace["default"].join(config.projectRoot, maybeRef);
2263
- const buffer = fs__default["default"].readFileSync(localFile);
2264
- const sha256 = await core.Internal.getSHA256Hash(buffer);
2276
+ const filename = path__namespace["default"].join(config.projectRoot, maybeRef);
2277
+ const buffer = fs__default["default"].readFileSync(filename);
2265
2278
  const imageSize = sizeOf__default["default"](buffer);
2279
+ const mimeType = imageSize.type ? internal.imageTypeToMimeType(imageSize.type) : internal.filenameToMimeType(filename);
2280
+ if (!mimeType) {
2281
+ throw Error("Cannot determine mimetype of image");
2282
+ }
2283
+ const {
2284
+ width,
2285
+ height
2286
+ } = imageSize;
2287
+ if (!width || !height) {
2288
+ throw Error("Cannot determine image size");
2289
+ }
2290
+ const sha256 = core.Internal.getSHA256Hash(textEncoder.encode(
2291
+ // TODO: we should probably store the mimetype in the metadata and reuse it here
2292
+ `data:${mimeType};base64,${buffer.toString("base64")}`));
2266
2293
  return {
2267
- ...imageSize,
2268
- sha256
2294
+ width,
2295
+ height,
2296
+ sha256,
2297
+ mimeType
2269
2298
  };
2270
2299
  }
2271
2300
  const remainingErrors = [];
@@ -2300,7 +2329,8 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2300
2329
  value: {
2301
2330
  width: imageMetadata.width,
2302
2331
  height: imageMetadata.height,
2303
- sha256: imageMetadata.sha256
2332
+ sha256: imageMetadata.sha256,
2333
+ mimeType: imageMetadata.mimeType
2304
2334
  }
2305
2335
  });
2306
2336
  } else {
@@ -7,12 +7,12 @@ var ts = require('typescript');
7
7
  var fp = require('@valbuild/core/fp');
8
8
  var core = require('@valbuild/core');
9
9
  var patch = require('@valbuild/core/patch');
10
- var crypto = require('crypto');
11
10
  var path = require('path');
12
11
  var fs = require('fs');
13
12
  var sucrase = require('sucrase');
14
13
  var z = require('zod');
15
14
  var internal = require('@valbuild/shared/internal');
15
+ var crypto = require('crypto');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var sizeOf = require('image-size');
18
18
 
@@ -37,10 +37,10 @@ function _interopNamespace(e) {
37
37
  }
38
38
 
39
39
  var ts__default = /*#__PURE__*/_interopDefault(ts);
40
- var crypto__default = /*#__PURE__*/_interopDefault(crypto);
41
40
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
42
41
  var fs__default = /*#__PURE__*/_interopDefault(fs);
43
42
  var z__default = /*#__PURE__*/_interopDefault(z);
43
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
44
44
  var sizeOf__default = /*#__PURE__*/_interopDefault(sizeOf);
45
45
 
46
46
  class ValSyntaxError {
@@ -624,8 +624,8 @@ const ops = new TSOps(document => {
624
624
 
625
625
  // TODO: rename to patchValFiles since we may write multiple files
626
626
  const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runtime) => {
627
- const timeId = crypto.randomUUID();
628
- console.time("patchValFile" + timeId);
627
+ // const timeId = randomUUID();
628
+ // console.time("patchValFile" + timeId);
629
629
  const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
630
630
  const sourceFile = sourceFileHandler.getSourceFile(filePath);
631
631
  if (!sourceFile) {
@@ -661,8 +661,9 @@ const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runti
661
661
  }
662
662
  }
663
663
  sourceFileHandler.writeSourceFile(newSourceFile.value);
664
- console.timeEnd("patchValFile" + timeId);
664
+ // console.timeEnd("patchValFile" + timeId);
665
665
  };
666
+
666
667
  function convertDataUrlToBase64(dataUrl) {
667
668
  const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
668
669
  return Buffer.from(base64, "base64");
@@ -975,7 +976,7 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
975
976
  }
976
977
  if (modulePath === "@valbuild/react/stega") {
977
978
  return {
978
- value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; "
979
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; export const stegaDecodeString = () => { throw Error(`Cannot use 'stegaDecodeString' in this type of file`) }; "
979
980
  };
980
981
  }
981
982
  if (modulePath.startsWith("next/navigation")) {
@@ -1003,6 +1004,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
1003
1004
  value: "export const ValNextProvider = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValNextProvider' in this file`) } } } )"
1004
1005
  };
1005
1006
  }
1007
+ if (modulePath.includes("/ValImage")) {
1008
+ return {
1009
+ value: "export const ValImage = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValImage' in this file`) } } } )"
1010
+ };
1011
+ }
1006
1012
  return {
1007
1013
  value: moduleLoader.getModule(modulePath)
1008
1014
  };
@@ -1053,6 +1059,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
1053
1059
  value: requestedName
1054
1060
  };
1055
1061
  }
1062
+ if (requestedName.includes("/ValImage")) {
1063
+ return {
1064
+ value: requestedName
1065
+ };
1066
+ }
1056
1067
  const modulePath = moduleLoader.resolveModulePath(baseModuleName, requestedName);
1057
1068
  return {
1058
1069
  value: modulePath
@@ -1261,7 +1272,7 @@ class LocalValServer {
1261
1272
  return {
1262
1273
  cookies: {
1263
1274
  [internal.VAL_ENABLE_COOKIE_NAME]: {
1264
- value: null
1275
+ value: "false"
1265
1276
  }
1266
1277
  },
1267
1278
  status: 302,
@@ -1280,8 +1291,9 @@ class LocalValServer {
1280
1291
  }
1281
1292
  };
1282
1293
  }
1283
- const id = crypto.randomUUID();
1284
- console.time("patching:" + id);
1294
+
1295
+ // const id = randomUUID();
1296
+ // console.time("patching:" + id);
1285
1297
  for (const moduleId in patchJSON.data) {
1286
1298
  // Then parse/validate
1287
1299
  // TODO: validate all and then fail instead:
@@ -1292,7 +1304,8 @@ class LocalValServer {
1292
1304
  }
1293
1305
  await this.options.service.patch(moduleId, patch$1.value);
1294
1306
  }
1295
- console.timeEnd("patching:" + id);
1307
+ // console.timeEnd("patching:" + id);
1308
+
1296
1309
  return {
1297
1310
  status: 200,
1298
1311
  json: {} // no patch ids created
@@ -2252,6 +2265,7 @@ class ValFSHost {
2252
2265
  }
2253
2266
 
2254
2267
  // TODO: find a better name? transformFixesToPatch?
2268
+ const textEncoder = new TextEncoder();
2255
2269
  async function createFixPatch(config, apply, sourcePath, validationError) {
2256
2270
  async function getImageMetadata() {
2257
2271
  const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
@@ -2259,13 +2273,28 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2259
2273
  // TODO:
2260
2274
  throw Error("Cannot fix image without a file reference");
2261
2275
  }
2262
- const localFile = path__namespace["default"].join(config.projectRoot, maybeRef);
2263
- const buffer = fs__default["default"].readFileSync(localFile);
2264
- const sha256 = await core.Internal.getSHA256Hash(buffer);
2276
+ const filename = path__namespace["default"].join(config.projectRoot, maybeRef);
2277
+ const buffer = fs__default["default"].readFileSync(filename);
2265
2278
  const imageSize = sizeOf__default["default"](buffer);
2279
+ const mimeType = imageSize.type ? internal.imageTypeToMimeType(imageSize.type) : internal.filenameToMimeType(filename);
2280
+ if (!mimeType) {
2281
+ throw Error("Cannot determine mimetype of image");
2282
+ }
2283
+ const {
2284
+ width,
2285
+ height
2286
+ } = imageSize;
2287
+ if (!width || !height) {
2288
+ throw Error("Cannot determine image size");
2289
+ }
2290
+ const sha256 = core.Internal.getSHA256Hash(textEncoder.encode(
2291
+ // TODO: we should probably store the mimetype in the metadata and reuse it here
2292
+ `data:${mimeType};base64,${buffer.toString("base64")}`));
2266
2293
  return {
2267
- ...imageSize,
2268
- sha256
2294
+ width,
2295
+ height,
2296
+ sha256,
2297
+ mimeType
2269
2298
  };
2270
2299
  }
2271
2300
  const remainingErrors = [];
@@ -2300,7 +2329,8 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2300
2329
  value: {
2301
2330
  width: imageMetadata.width,
2302
2331
  height: imageMetadata.height,
2303
- sha256: imageMetadata.sha256
2332
+ sha256: imageMetadata.sha256,
2333
+ mimeType: imageMetadata.mimeType
2304
2334
  }
2305
2335
  });
2306
2336
  } else {
@@ -3,13 +3,13 @@ import ts from 'typescript';
3
3
  import { result, pipe } from '@valbuild/core/fp';
4
4
  import { FILE_REF_PROP, VAL_EXTENSION, derefPatch, Internal, Schema } from '@valbuild/core';
5
5
  import { deepEqual, isNotRoot, PatchError, parseAndValidateArrayIndex, applyPatch, parsePatch, sourceToPatchPath } from '@valbuild/core/patch';
6
- import crypto, { randomUUID } from 'crypto';
7
6
  import * as path from 'path';
8
7
  import path__default from 'path';
9
8
  import fs, { promises } from 'fs';
10
9
  import { transform } from 'sucrase';
11
10
  import z, { z as z$1 } from 'zod';
12
- import { VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE as VAL_STATE_COOKIE$1, VAL_SESSION_COOKIE as VAL_SESSION_COOKIE$1 } from '@valbuild/shared/internal';
11
+ import { VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE as VAL_STATE_COOKIE$1, VAL_SESSION_COOKIE as VAL_SESSION_COOKIE$1, imageTypeToMimeType, filenameToMimeType } from '@valbuild/shared/internal';
12
+ import crypto from 'crypto';
13
13
  import { createUIRequestHandler } from '@valbuild/ui/server';
14
14
  import sizeOf from 'image-size';
15
15
 
@@ -594,8 +594,8 @@ const ops = new TSOps(document => {
594
594
 
595
595
  // TODO: rename to patchValFiles since we may write multiple files
596
596
  const patchValFile = async (id, valConfigPath, patch, sourceFileHandler, runtime) => {
597
- const timeId = randomUUID();
598
- console.time("patchValFile" + timeId);
597
+ // const timeId = randomUUID();
598
+ // console.time("patchValFile" + timeId);
599
599
  const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
600
600
  const sourceFile = sourceFileHandler.getSourceFile(filePath);
601
601
  if (!sourceFile) {
@@ -631,8 +631,9 @@ const patchValFile = async (id, valConfigPath, patch, sourceFileHandler, runtime
631
631
  }
632
632
  }
633
633
  sourceFileHandler.writeSourceFile(newSourceFile.value);
634
- console.timeEnd("patchValFile" + timeId);
634
+ // console.timeEnd("patchValFile" + timeId);
635
635
  };
636
+
636
637
  function convertDataUrlToBase64(dataUrl) {
637
638
  const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
638
639
  return Buffer.from(base64, "base64");
@@ -945,7 +946,7 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
945
946
  }
946
947
  if (modulePath === "@valbuild/react/stega") {
947
948
  return {
948
- value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; "
949
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ }; export const stegaClean = () => { throw Error(`Cannot use 'stegaClean' in this type of file`) }; export const stegaDecodeString = () => { throw Error(`Cannot use 'stegaDecodeString' in this type of file`) }; "
949
950
  };
950
951
  }
951
952
  if (modulePath.startsWith("next/navigation")) {
@@ -973,6 +974,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
973
974
  value: "export const ValNextProvider = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValNextProvider' in this file`) } } } )"
974
975
  };
975
976
  }
977
+ if (modulePath.includes("/ValImage")) {
978
+ return {
979
+ value: "export const ValImage = new Proxy({}, { get() { return () => { throw new Error(`Cannot import 'ValImage' in this file`) } } } )"
980
+ };
981
+ }
976
982
  return {
977
983
  value: moduleLoader.getModule(modulePath)
978
984
  };
@@ -1023,6 +1029,11 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
1023
1029
  value: requestedName
1024
1030
  };
1025
1031
  }
1032
+ if (requestedName.includes("/ValImage")) {
1033
+ return {
1034
+ value: requestedName
1035
+ };
1036
+ }
1026
1037
  const modulePath = moduleLoader.resolveModulePath(baseModuleName, requestedName);
1027
1038
  return {
1028
1039
  value: modulePath
@@ -1231,7 +1242,7 @@ class LocalValServer {
1231
1242
  return {
1232
1243
  cookies: {
1233
1244
  [VAL_ENABLE_COOKIE_NAME]: {
1234
- value: null
1245
+ value: "false"
1235
1246
  }
1236
1247
  },
1237
1248
  status: 302,
@@ -1250,8 +1261,9 @@ class LocalValServer {
1250
1261
  }
1251
1262
  };
1252
1263
  }
1253
- const id = randomUUID();
1254
- console.time("patching:" + id);
1264
+
1265
+ // const id = randomUUID();
1266
+ // console.time("patching:" + id);
1255
1267
  for (const moduleId in patchJSON.data) {
1256
1268
  // Then parse/validate
1257
1269
  // TODO: validate all and then fail instead:
@@ -1262,7 +1274,8 @@ class LocalValServer {
1262
1274
  }
1263
1275
  await this.options.service.patch(moduleId, patch.value);
1264
1276
  }
1265
- console.timeEnd("patching:" + id);
1277
+ // console.timeEnd("patching:" + id);
1278
+
1266
1279
  return {
1267
1280
  status: 200,
1268
1281
  json: {} // no patch ids created
@@ -2222,6 +2235,7 @@ class ValFSHost {
2222
2235
  }
2223
2236
 
2224
2237
  // TODO: find a better name? transformFixesToPatch?
2238
+ const textEncoder = new TextEncoder();
2225
2239
  async function createFixPatch(config, apply, sourcePath, validationError) {
2226
2240
  async function getImageMetadata() {
2227
2241
  const maybeRef = validationError.value && typeof validationError.value === "object" && FILE_REF_PROP in validationError.value && typeof validationError.value[FILE_REF_PROP] === "string" ? validationError.value[FILE_REF_PROP] : undefined;
@@ -2229,13 +2243,28 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2229
2243
  // TODO:
2230
2244
  throw Error("Cannot fix image without a file reference");
2231
2245
  }
2232
- const localFile = path__default.join(config.projectRoot, maybeRef);
2233
- const buffer = fs.readFileSync(localFile);
2234
- const sha256 = await Internal.getSHA256Hash(buffer);
2246
+ const filename = path__default.join(config.projectRoot, maybeRef);
2247
+ const buffer = fs.readFileSync(filename);
2235
2248
  const imageSize = sizeOf(buffer);
2249
+ const mimeType = imageSize.type ? imageTypeToMimeType(imageSize.type) : filenameToMimeType(filename);
2250
+ if (!mimeType) {
2251
+ throw Error("Cannot determine mimetype of image");
2252
+ }
2253
+ const {
2254
+ width,
2255
+ height
2256
+ } = imageSize;
2257
+ if (!width || !height) {
2258
+ throw Error("Cannot determine image size");
2259
+ }
2260
+ const sha256 = Internal.getSHA256Hash(textEncoder.encode(
2261
+ // TODO: we should probably store the mimetype in the metadata and reuse it here
2262
+ `data:${mimeType};base64,${buffer.toString("base64")}`));
2236
2263
  return {
2237
- ...imageSize,
2238
- sha256
2264
+ width,
2265
+ height,
2266
+ sha256,
2267
+ mimeType
2239
2268
  };
2240
2269
  }
2241
2270
  const remainingErrors = [];
@@ -2270,7 +2299,8 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
2270
2299
  value: {
2271
2300
  width: imageMetadata.width,
2272
2301
  height: imageMetadata.height,
2273
- sha256: imageMetadata.sha256
2302
+ sha256: imageMetadata.sha256,
2303
+ mimeType: imageMetadata.mimeType
2274
2304
  }
2275
2305
  });
2276
2306
  } else {
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "./package.json": "./package.json"
13
13
  },
14
14
  "types": "dist/valbuild-server.cjs.d.ts",
15
- "version": "0.43.1",
15
+ "version": "0.45.0",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
@@ -24,9 +24,9 @@
24
24
  "concurrently": "^7.6.0"
25
25
  },
26
26
  "dependencies": {
27
- "@valbuild/core": "~0.43.1",
28
- "@valbuild/shared": "~0.43.1",
29
- "@valbuild/ui": "~0.43.1",
27
+ "@valbuild/core": "~0.45.0",
28
+ "@valbuild/shared": "~0.45.0",
29
+ "@valbuild/ui": "~0.45.0",
30
30
  "express": "^4.18.2",
31
31
  "image-size": "^1.0.2",
32
32
  "queue": "^6.0.2",