Skip to content

Commit b59b171

Browse files
committed
patch: handle ext2fs with webpack
1 parent 2872658 commit b59b171

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

webpack.config.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as CopyPlugin from 'copy-webpack-plugin';
18-
import { readdirSync } from 'fs';
18+
import { readdirSync, existsSync } from 'fs';
1919
import * as _ from 'lodash';
2020
import * as os from 'os';
2121
import outdent from 'outdent';
@@ -77,6 +77,27 @@ function renameNodeModules(resourcePath: string) {
7777
);
7878
}
7979

80+
function findExt2fsFolder(): string {
81+
const ext2fs = 'node_modules/ext2fs';
82+
const biFsExt2fs = 'node_modules/balena-image-fs/node_modules/ext2fs';
83+
84+
if (existsSync(ext2fs)) {
85+
return ext2fs;
86+
} else if (existsSync(biFsExt2fs)) {
87+
return biFsExt2fs;
88+
} else {
89+
throw Error('ext2fs not found');
90+
}
91+
}
92+
93+
function makeExt2FsRegex(): RegExp {
94+
const folder = findExt2fsFolder();
95+
const libpath = '/lib/libext2fs\\.js&';
96+
97+
const regex = folder.concat(libpath).split('/').join('/');
98+
return new RegExp(regex);
99+
}
100+
80101
function findUsbPrebuild(): string[] {
81102
const usbPrebuildsFolder = path.join('node_modules', 'usb', 'prebuilds');
82103
const prebuildFolders = readdirSync(usbPrebuildsFolder);
@@ -152,6 +173,7 @@ function slashOrAntislash(pattern: RegExp): RegExp {
152173
}
153174

154175
function replace(test: RegExp, ...replacements: ReplacementRule[]) {
176+
console.log(test.source);
155177
return {
156178
loader: 'string-replace-loader',
157179
// Handle windows path separators
@@ -322,7 +344,7 @@ const commonConfig = {
322344
// Use the libext2fs.wasm file in the generated folder
323345
// The way to find the app directory depends on whether we run in the renderer or in the child-writer
324346
// We use __dirname in the child-writer and electron.remote.app.getAppPath() in the renderer
325-
replace(/node_modules\/ext2fs\/lib\/libext2fs\.js$/, {
347+
replace(makeExt2FsRegex(), {
326348
search: 'scriptDirectory = __dirname + "/";',
327349
replace: fetchWasm('ext2fs', 'lib'),
328350
}),
@@ -385,7 +407,7 @@ const guiConfigCopyPatterns = [
385407
to: 'modules/node-raspberrypi-usbboot/blobs',
386408
},
387409
{
388-
from: 'node_modules/ext2fs/lib/libext2fs.wasm',
410+
from: `${findExt2fsFolder()}/lib/libext2fs.wasm`,
389411
to: 'modules/ext2fs/lib/libext2fs.wasm',
390412
},
391413
{
@@ -394,6 +416,8 @@ const guiConfigCopyPatterns = [
394416
},
395417
];
396418

419+
console.log(guiConfigCopyPatterns);
420+
397421
if (os.platform() === 'win32') {
398422
// liblzma.dll is required on Windows for lzma-native
399423
guiConfigCopyPatterns.push({

0 commit comments

Comments
 (0)