mindoodb-app-sdk 0.0.44 → 0.0.45
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.
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +76 -54
- package/package.json +1 -1
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// src/vite/index.ts
|
|
10
10
|
import { createHash } from "crypto";
|
|
11
|
-
import { readdir, readFile, writeFile } from "fs/promises";
|
|
11
|
+
import { access, readdir, readFile, writeFile } from "fs/promises";
|
|
12
12
|
import path from "path";
|
|
13
13
|
|
|
14
14
|
// src/vite/zip.ts
|
|
@@ -155,6 +155,14 @@ var DEFAULT_EXCLUDED_ROOT_FILES = /* @__PURE__ */ new Set([
|
|
|
155
155
|
MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME
|
|
156
156
|
]);
|
|
157
157
|
var WORKBOX_RUNTIME_PATTERN = /^workbox-[a-z0-9]+\.js(\.map)?$/i;
|
|
158
|
+
async function directoryExists(dir) {
|
|
159
|
+
try {
|
|
160
|
+
await access(dir);
|
|
161
|
+
return true;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
158
166
|
function sha256(data) {
|
|
159
167
|
return `sha256-${createHash("sha256").update(data).digest("hex")}`;
|
|
160
168
|
}
|
|
@@ -223,66 +231,80 @@ async function readPackageMetadata(root) {
|
|
|
223
231
|
}
|
|
224
232
|
function havenBundle(options = {}) {
|
|
225
233
|
let resolvedConfig = null;
|
|
234
|
+
let emitted = false;
|
|
235
|
+
async function emitBundle() {
|
|
236
|
+
if (emitted) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!resolvedConfig) {
|
|
240
|
+
throw new Error("[haven-bundle] Plugin ran without a resolved Vite config.");
|
|
241
|
+
}
|
|
242
|
+
const outDir = path.resolve(resolvedConfig.root, resolvedConfig.build.outDir);
|
|
243
|
+
if (!await directoryExists(outDir)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const allPaths = await collectFiles(outDir);
|
|
247
|
+
const bundlePaths = allPaths.filter((candidate) => !isExcluded(candidate, options));
|
|
248
|
+
if (!bundlePaths.length) {
|
|
249
|
+
throw new Error(`[haven-bundle] No bundle files found in "${outDir}".`);
|
|
250
|
+
}
|
|
251
|
+
const entry = resolveEntryPath(bundlePaths, options.entry);
|
|
252
|
+
const packageMetadata = await readPackageMetadata(resolvedConfig.root);
|
|
253
|
+
const appId = options.appId ?? packageMetadata.name;
|
|
254
|
+
const version = options.version ?? packageMetadata.version;
|
|
255
|
+
if (!appId) {
|
|
256
|
+
throw new Error("[haven-bundle] Unable to determine appId \u2014 pass it explicitly.");
|
|
257
|
+
}
|
|
258
|
+
if (!version) {
|
|
259
|
+
throw new Error("[haven-bundle] Unable to determine version \u2014 pass it explicitly.");
|
|
260
|
+
}
|
|
261
|
+
const files = [];
|
|
262
|
+
const archiveEntries = [];
|
|
263
|
+
for (const relativePath of bundlePaths) {
|
|
264
|
+
const data = await readFile(path.join(outDir, relativePath));
|
|
265
|
+
files.push({ path: relativePath, hash: sha256(data), size: data.byteLength });
|
|
266
|
+
archiveEntries.push({ path: relativePath, data });
|
|
267
|
+
}
|
|
268
|
+
const archive = createZipArchive(archiveEntries);
|
|
269
|
+
const manifest = {
|
|
270
|
+
format: MINDOODB_APP_BUNDLE_MANIFEST_FORMAT,
|
|
271
|
+
formatVersion: MINDOODB_APP_BUNDLE_MANIFEST_VERSION,
|
|
272
|
+
appId,
|
|
273
|
+
version,
|
|
274
|
+
entry,
|
|
275
|
+
archive: {
|
|
276
|
+
path: MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
277
|
+
hash: sha256(archive),
|
|
278
|
+
size: archive.byteLength
|
|
279
|
+
},
|
|
280
|
+
contentHash: sha256(buildMindooDBAppBundleContentHashInput(files)),
|
|
281
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
282
|
+
files
|
|
283
|
+
};
|
|
284
|
+
await writeFile(path.join(outDir, MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME), archive);
|
|
285
|
+
await writeFile(
|
|
286
|
+
path.join(outDir, MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME),
|
|
287
|
+
`${JSON.stringify(manifest, null, 2)}
|
|
288
|
+
`,
|
|
289
|
+
"utf8"
|
|
290
|
+
);
|
|
291
|
+
const totalBytes = files.reduce((sum, file) => sum + file.size, 0);
|
|
292
|
+
console.log(
|
|
293
|
+
`[haven-bundle] ${files.length} files (${(totalBytes / 1024 / 1024).toFixed(2)} MB) \u2192 ${MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME} (${(archive.byteLength / 1024 / 1024).toFixed(2)} MB), contentHash ${manifest.contentHash.slice(7, 19)}`
|
|
294
|
+
);
|
|
295
|
+
emitted = true;
|
|
296
|
+
}
|
|
226
297
|
return {
|
|
227
298
|
name: "haven-bundle",
|
|
228
299
|
apply: "build",
|
|
229
300
|
configResolved(config) {
|
|
230
301
|
resolvedConfig = config;
|
|
231
302
|
},
|
|
303
|
+
async writeBundle() {
|
|
304
|
+
await emitBundle();
|
|
305
|
+
},
|
|
232
306
|
async closeBundle() {
|
|
233
|
-
|
|
234
|
-
throw new Error("[haven-bundle] Plugin ran without a resolved Vite config.");
|
|
235
|
-
}
|
|
236
|
-
const outDir = path.resolve(resolvedConfig.root, resolvedConfig.build.outDir);
|
|
237
|
-
const allPaths = await collectFiles(outDir);
|
|
238
|
-
const bundlePaths = allPaths.filter((candidate) => !isExcluded(candidate, options));
|
|
239
|
-
if (!bundlePaths.length) {
|
|
240
|
-
throw new Error(`[haven-bundle] No bundle files found in "${outDir}".`);
|
|
241
|
-
}
|
|
242
|
-
const entry = resolveEntryPath(bundlePaths, options.entry);
|
|
243
|
-
const packageMetadata = await readPackageMetadata(resolvedConfig.root);
|
|
244
|
-
const appId = options.appId ?? packageMetadata.name;
|
|
245
|
-
const version = options.version ?? packageMetadata.version;
|
|
246
|
-
if (!appId) {
|
|
247
|
-
throw new Error("[haven-bundle] Unable to determine appId \u2014 pass it explicitly.");
|
|
248
|
-
}
|
|
249
|
-
if (!version) {
|
|
250
|
-
throw new Error("[haven-bundle] Unable to determine version \u2014 pass it explicitly.");
|
|
251
|
-
}
|
|
252
|
-
const files = [];
|
|
253
|
-
const archiveEntries = [];
|
|
254
|
-
for (const relativePath of bundlePaths) {
|
|
255
|
-
const data = await readFile(path.join(outDir, relativePath));
|
|
256
|
-
files.push({ path: relativePath, hash: sha256(data), size: data.byteLength });
|
|
257
|
-
archiveEntries.push({ path: relativePath, data });
|
|
258
|
-
}
|
|
259
|
-
const archive = createZipArchive(archiveEntries);
|
|
260
|
-
const manifest = {
|
|
261
|
-
format: MINDOODB_APP_BUNDLE_MANIFEST_FORMAT,
|
|
262
|
-
formatVersion: MINDOODB_APP_BUNDLE_MANIFEST_VERSION,
|
|
263
|
-
appId,
|
|
264
|
-
version,
|
|
265
|
-
entry,
|
|
266
|
-
archive: {
|
|
267
|
-
path: MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME,
|
|
268
|
-
hash: sha256(archive),
|
|
269
|
-
size: archive.byteLength
|
|
270
|
-
},
|
|
271
|
-
contentHash: sha256(buildMindooDBAppBundleContentHashInput(files)),
|
|
272
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
273
|
-
files
|
|
274
|
-
};
|
|
275
|
-
await writeFile(path.join(outDir, MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME), archive);
|
|
276
|
-
await writeFile(
|
|
277
|
-
path.join(outDir, MINDOODB_APP_BUNDLE_MANIFEST_FILE_NAME),
|
|
278
|
-
`${JSON.stringify(manifest, null, 2)}
|
|
279
|
-
`,
|
|
280
|
-
"utf8"
|
|
281
|
-
);
|
|
282
|
-
const totalBytes = files.reduce((sum, file) => sum + file.size, 0);
|
|
283
|
-
console.log(
|
|
284
|
-
`[haven-bundle] ${files.length} files (${(totalBytes / 1024 / 1024).toFixed(2)} MB) \u2192 ${MINDOODB_APP_BUNDLE_ARCHIVE_FILE_NAME} (${(archive.byteLength / 1024 / 1024).toFixed(2)} MB), contentHash ${manifest.contentHash.slice(7, 19)}`
|
|
285
|
-
);
|
|
307
|
+
await emitBundle();
|
|
286
308
|
}
|
|
287
309
|
};
|
|
288
310
|
}
|