@@ -357,6 +357,21 @@ module.exports = EventEmitter;
|
||||
const relBack = relForward.replace(/\//g, '\\')
|
||||
if (relBack !== key && relBack !== winKey) bundle.write(relBack, content)
|
||||
}
|
||||
// The embedded runtime looks up by URL pathname (e.g. bare:/runtime.bundle/node_modules/...).
|
||||
// Add keys with the "runtime.bundle" prefix so protocol.read(url) finds content on all hosts.
|
||||
if (content && content.length > 0) {
|
||||
const keyNoLead = key.replace(/^\/+/, '')
|
||||
const prefixSlash = 'runtime.bundle/' + keyNoLead
|
||||
const prefixLead = '/runtime.bundle/' + keyNoLead
|
||||
if (prefixSlash !== key) bundle.write(prefixSlash, content)
|
||||
if (prefixLead !== key) bundle.write(prefixLead, content)
|
||||
if (hasWin32) {
|
||||
const prefixBack = 'runtime.bundle\\' + keyNoLead.replace(/\//g, '\\')
|
||||
const prefixBackLead = '\\runtime.bundle\\' + keyNoLead.replace(/\//g, '\\')
|
||||
bundle.write(prefixBack, content)
|
||||
bundle.write(prefixBackLead, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Verification pass: ensure every .json key in the bundle has valid JSON content
|
||||
// (catches keys we added or any the runtime might use with different normalization)
|
||||
@@ -382,8 +397,28 @@ module.exports = EventEmitter;
|
||||
if (missingJson.length > 0) {
|
||||
console.warn(' Warning: could not refill .json from disk (Windows exe may fail at runtime):', missingJson.slice(0, 5).join(', ') + (missingJson.length > 5 ? ' ...' : ''))
|
||||
}
|
||||
// Ensure every .json key with content also exists under runtime.bundle pathname (used by embedded runtime).
|
||||
keysToProcess = typeof bundle.keys === 'function' ? [...bundle.keys()] : Object.keys(bundle.files || {})
|
||||
for (const key of keysToProcess) {
|
||||
if (!key.endsWith('.json')) continue
|
||||
const content = bundle.read(key)
|
||||
if (!content || content.length === 0) continue
|
||||
const keyNoLead = key.replace(/^[/\\]+/, '')
|
||||
if (keyNoLead.startsWith('runtime.bundle')) continue // already prefixed
|
||||
const prefixSlash = 'runtime.bundle/' + keyNoLead.replace(/\\/g, '/')
|
||||
const prefixLead = '/runtime.bundle/' + keyNoLead.replace(/\\/g, '/')
|
||||
if (prefixSlash !== key) bundle.write(prefixSlash, content)
|
||||
if (prefixLead !== key) bundle.write(prefixLead, content)
|
||||
if (hasWin32) {
|
||||
const prefixBack = 'runtime.bundle\\' + keyNoLead.replace(/\//g, '\\')
|
||||
const prefixBackLead = '\\runtime.bundle\\' + keyNoLead.replace(/\//g, '\\')
|
||||
bundle.write(prefixBack, content)
|
||||
bundle.write(prefixBackLead, content)
|
||||
}
|
||||
}
|
||||
if (jsonFixed > 0) console.log(` Patched ${jsonFixed} empty/invalid .json entries`)
|
||||
if (hasWin32 && keysToProcess.some((k) => k.endsWith('.json'))) console.log(' Added Windows backslash path variants for .json entries')
|
||||
console.log(' Added runtime.bundle pathname variants for .json entries')
|
||||
}
|
||||
|
||||
async function build(hosts, doPackage) {
|
||||
|
||||
Reference in New Issue
Block a user