15
15
*/
16
16
17
17
import * as CopyPlugin from 'copy-webpack-plugin' ;
18
- import { readdirSync } from 'fs' ;
18
+ import { readdirSync , existsSync } from 'fs' ;
19
19
import * as _ from 'lodash' ;
20
20
import * as os from 'os' ;
21
21
import outdent from 'outdent' ;
@@ -77,6 +77,27 @@ function renameNodeModules(resourcePath: string) {
77
77
) ;
78
78
}
79
79
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
+
80
101
function findUsbPrebuild ( ) : string [ ] {
81
102
const usbPrebuildsFolder = path . join ( 'node_modules' , 'usb' , 'prebuilds' ) ;
82
103
const prebuildFolders = readdirSync ( usbPrebuildsFolder ) ;
@@ -152,6 +173,7 @@ function slashOrAntislash(pattern: RegExp): RegExp {
152
173
}
153
174
154
175
function replace ( test : RegExp , ...replacements : ReplacementRule [ ] ) {
176
+ console . log ( test . source ) ;
155
177
return {
156
178
loader : 'string-replace-loader' ,
157
179
// Handle windows path separators
@@ -322,7 +344,7 @@ const commonConfig = {
322
344
// Use the libext2fs.wasm file in the generated folder
323
345
// The way to find the app directory depends on whether we run in the renderer or in the child-writer
324
346
// We use __dirname in the child-writer and electron.remote.app.getAppPath() in the renderer
325
- replace ( / n o d e _ m o d u l e s \/ e x t 2 f s \/ l i b \/ l i b e x t 2 f s \. j s $ / , {
347
+ replace ( makeExt2FsRegex ( ) , {
326
348
search : 'scriptDirectory = __dirname + "/";' ,
327
349
replace : fetchWasm ( 'ext2fs' , 'lib' ) ,
328
350
} ) ,
@@ -385,7 +407,7 @@ const guiConfigCopyPatterns = [
385
407
to : 'modules/node-raspberrypi-usbboot/blobs' ,
386
408
} ,
387
409
{
388
- from : 'node_modules/ext2fs/ lib/libext2fs.wasm' ,
410
+ from : ` ${ findExt2fsFolder ( ) } / lib/libext2fs.wasm` ,
389
411
to : 'modules/ext2fs/lib/libext2fs.wasm' ,
390
412
} ,
391
413
{
@@ -394,6 +416,8 @@ const guiConfigCopyPatterns = [
394
416
} ,
395
417
] ;
396
418
419
+ console . log ( guiConfigCopyPatterns ) ;
420
+
397
421
if ( os . platform ( ) === 'win32' ) {
398
422
// liblzma.dll is required on Windows for lzma-native
399
423
guiConfigCopyPatterns . push ( {
0 commit comments