forked from trent_larson/crowd-funder-for-time-pwa
refactor: improve type safety and browser compatibility - Replace any types with SqlValue[] in migration system - Add browser-compatible implementations of Node.js modules (crypto, fs, path) - Update Vite config to handle Node.js module polyfills - Remove outdated migration documentation files
This commit is contained in:
1159
package-lock.json
generated
1159
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -146,7 +146,9 @@
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"browserify-fs": "^1.0.0",
|
||||
"concurrently": "^8.2.2",
|
||||
"crypto-browserify": "^3.12.1",
|
||||
"electron": "^33.2.1",
|
||||
"electron-builder": "^25.1.8",
|
||||
"eslint": "^8.57.0",
|
||||
@@ -157,6 +159,7 @@
|
||||
"markdownlint": "^0.37.4",
|
||||
"markdownlint-cli": "^0.44.0",
|
||||
"npm-check-updates": "^17.1.13",
|
||||
"path-browserify": "^1.0.1",
|
||||
"postcss": "^8.4.38",
|
||||
"prettier": "^3.2.5",
|
||||
"rimraf": "^6.0.1",
|
||||
|
||||
2
src/utils/empty-module.js
Normal file
2
src/utils/empty-module.js
Normal file
@@ -0,0 +1,2 @@
|
||||
// Empty module to satisfy Node.js built-in module imports
|
||||
export default {};
|
||||
17
src/utils/node-modules/crypto.js
Normal file
17
src/utils/node-modules/crypto.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Minimal crypto module implementation for browser using Web Crypto API
|
||||
const crypto = {
|
||||
...window.crypto,
|
||||
// Add any Node.js crypto methods that might be needed
|
||||
randomBytes: (size) => {
|
||||
const buffer = new Uint8Array(size);
|
||||
window.crypto.getRandomValues(buffer);
|
||||
return buffer;
|
||||
},
|
||||
createHash: () => ({
|
||||
update: () => ({
|
||||
digest: () => new Uint8Array(32) // Return empty hash
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
export default crypto;
|
||||
18
src/utils/node-modules/fs.js
Normal file
18
src/utils/node-modules/fs.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// Minimal fs module implementation for browser
|
||||
const fs = {
|
||||
readFileSync: () => {
|
||||
throw new Error('fs.readFileSync is not supported in browser');
|
||||
},
|
||||
writeFileSync: () => {
|
||||
throw new Error('fs.writeFileSync is not supported in browser');
|
||||
},
|
||||
existsSync: () => false,
|
||||
mkdirSync: () => {},
|
||||
readdirSync: () => [],
|
||||
statSync: () => ({
|
||||
isDirectory: () => false,
|
||||
isFile: () => false
|
||||
})
|
||||
};
|
||||
|
||||
export default fs;
|
||||
13
src/utils/node-modules/path.js
Normal file
13
src/utils/node-modules/path.js
Normal file
@@ -0,0 +1,13 @@
|
||||
// Minimal path module implementation for browser
|
||||
const path = {
|
||||
resolve: (...parts) => parts.join('/'),
|
||||
join: (...parts) => parts.join('/'),
|
||||
dirname: (p) => p.split('/').slice(0, -1).join('/'),
|
||||
basename: (p) => p.split('/').pop(),
|
||||
extname: (p) => {
|
||||
const parts = p.split('.');
|
||||
return parts.length > 1 ? '.' + parts.pop() : '';
|
||||
}
|
||||
};
|
||||
|
||||
export default path;
|
||||
@@ -36,7 +36,15 @@ export async function createBuildConfig(mode: string) {
|
||||
assetsDir: 'assets',
|
||||
chunkSizeWarningLimit: 1000,
|
||||
rollupOptions: {
|
||||
external: isCapacitor ? ['@capacitor/app'] : []
|
||||
external: isCapacitor
|
||||
? ['@capacitor/app']
|
||||
: [],
|
||||
output: {
|
||||
format: 'es',
|
||||
generatedCode: {
|
||||
preset: 'es2015'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
@@ -46,11 +54,22 @@ export async function createBuildConfig(mode: string) {
|
||||
__dirname: isElectron ? JSON.stringify(process.cwd()) : '""',
|
||||
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
||||
__USE_QR_READER__: JSON.stringify(!isCapacitor),
|
||||
'process.platform': JSON.stringify('browser'),
|
||||
'process.version': JSON.stringify('v16.0.0'),
|
||||
'process.env.NODE_DEBUG': JSON.stringify(false),
|
||||
'global.process': JSON.stringify({
|
||||
platform: 'browser',
|
||||
version: 'v16.0.0',
|
||||
env: { NODE_DEBUG: false }
|
||||
})
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
...appConfig.aliasConfig,
|
||||
'path': path.resolve(__dirname, './src/utils/node-modules/path.js'),
|
||||
'fs': path.resolve(__dirname, './src/utils/node-modules/fs.js'),
|
||||
'crypto': path.resolve(__dirname, './src/utils/node-modules/crypto.js'),
|
||||
'nostr-tools/nip06': mode === 'development'
|
||||
? 'nostr-tools/nip06'
|
||||
: path.resolve(__dirname, 'node_modules/nostr-tools/nip06'),
|
||||
@@ -62,7 +81,13 @@ export async function createBuildConfig(mode: string) {
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: ['nostr-tools', 'nostr-tools/nip06', 'nostr-tools/core', 'dexie-export-import'],
|
||||
include: [
|
||||
'nostr-tools',
|
||||
'nostr-tools/nip06',
|
||||
'nostr-tools/core',
|
||||
'dexie-export-import',
|
||||
'@jlongster/sql.js'
|
||||
],
|
||||
exclude: isElectron ? [
|
||||
'register-service-worker',
|
||||
'workbox-window',
|
||||
|
||||
Reference in New Issue
Block a user