Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs');
const path = require('path');

const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
const idbVersion = packageJson.dependencies.idb;

const outputDir = path.join(__dirname, 'generated');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

const content = `// AUTO-GENERATED from package.json - DO NOT EDIT\nexport const IDB_VERSION = "${idbVersion}";\n`;

fs.writeFileSync(path.join(outputDir, 'idb-version.ts'), content);
console.log(`Generated idb-version.ts with version ${idbVersion}`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// AUTO-GENERATED from package.json - DO NOT EDIT
export const IDB_VERSION = "8.0.3";
14 changes: 9 additions & 5 deletions src/CloudNimble.BlazorEssentials.IndexedDb/Scripts/idb-loader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IDB_VERSION } from './generated/idb-version';

let idbModule: any = null;
let isLoading = false;
let loadPromise: Promise<any> | null = null;
Expand Down Expand Up @@ -32,18 +34,20 @@ async function ensureIdbLoaded() {

async function loadIdbWithFallback() {
try {
// Try online CDN first for latest version
// Try online CDN first
// @ts-ignore - Dynamic import from CDN
const onlineModule = await import('https://cdn.skypack.dev/idb');
const onlineModule = await import(`https://cdn.jsdelivr.net/npm/idb@${IDB_VERSION}/+esm`);
console.log('Loaded idb from online CDN');
return onlineModule;
} catch (onlineError) {
console.warn('Failed to load idb from CDN, falling back to bundled version:', onlineError);

try {
// Fallback to bundled version (will be available as static asset)
// In Blazor, this would be loaded via JS interop or as a module
const bundledModule = await import('../wwwroot/lib/index.js');
// Use import.meta.url so the path resolves correctly at runtime regardless of
// deployment location (e.g., /_content/BlazorEssentials.IndexedDb/lib/index.js)
const libUrl = new URL('./lib/index.js', import.meta.url).href;
const bundledModule = await import(libUrl);
console.log('Loaded idb from bundled version');
return bundledModule;
} catch (localError) {
Expand Down
3 changes: 2 additions & 1 deletion src/CloudNimble.BlazorEssentials.IndexedDb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"author": "CloudNimble, Inc.",
"license": "ISC",
"scripts": {
"prebuild": "node Scripts/generate-idb-version.js",
"build": "tsc",
"watch": "tsc --watch",
"clean": "rimraf wwwroot/*.js wwwroot/*.js.map"
"clean": "rimraf wwwroot/*.js wwwroot/*.js.map Scripts/generated"
},
"devDependencies": {
"@microsoft/dotnet-js-interop": "10.0.0",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/CloudNimble.BlazorEssentials.IndexedDb/wwwroot/idb-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.