mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 02:36:32 +00:00
patch: handle ext2fs with webpack
This commit is contained in:
parent
28726584c2
commit
b59b171e43
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as CopyPlugin from 'copy-webpack-plugin';
|
import * as CopyPlugin from 'copy-webpack-plugin';
|
||||||
import { readdirSync } from 'fs';
|
import { readdirSync, existsSync } from 'fs';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import outdent from 'outdent';
|
import outdent from 'outdent';
|
||||||
@ -77,6 +77,27 @@ function renameNodeModules(resourcePath: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findExt2fsFolder(): string {
|
||||||
|
const ext2fs = 'node_modules/ext2fs';
|
||||||
|
const biFsExt2fs = 'node_modules/balena-image-fs/node_modules/ext2fs';
|
||||||
|
|
||||||
|
if (existsSync(ext2fs)) {
|
||||||
|
return ext2fs;
|
||||||
|
} else if (existsSync(biFsExt2fs)) {
|
||||||
|
return biFsExt2fs;
|
||||||
|
} else {
|
||||||
|
throw Error('ext2fs not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeExt2FsRegex(): RegExp {
|
||||||
|
const folder = findExt2fsFolder();
|
||||||
|
const libpath = '/lib/libext2fs\\.js&';
|
||||||
|
|
||||||
|
const regex = folder.concat(libpath).split('/').join('/');
|
||||||
|
return new RegExp(regex);
|
||||||
|
}
|
||||||
|
|
||||||
function findUsbPrebuild(): string[] {
|
function findUsbPrebuild(): string[] {
|
||||||
const usbPrebuildsFolder = path.join('node_modules', 'usb', 'prebuilds');
|
const usbPrebuildsFolder = path.join('node_modules', 'usb', 'prebuilds');
|
||||||
const prebuildFolders = readdirSync(usbPrebuildsFolder);
|
const prebuildFolders = readdirSync(usbPrebuildsFolder);
|
||||||
@ -152,6 +173,7 @@ function slashOrAntislash(pattern: RegExp): RegExp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replace(test: RegExp, ...replacements: ReplacementRule[]) {
|
function replace(test: RegExp, ...replacements: ReplacementRule[]) {
|
||||||
|
console.log(test.source);
|
||||||
return {
|
return {
|
||||||
loader: 'string-replace-loader',
|
loader: 'string-replace-loader',
|
||||||
// Handle windows path separators
|
// Handle windows path separators
|
||||||
@ -322,7 +344,7 @@ const commonConfig = {
|
|||||||
// Use the libext2fs.wasm file in the generated folder
|
// Use the libext2fs.wasm file in the generated folder
|
||||||
// The way to find the app directory depends on whether we run in the renderer or in the child-writer
|
// The way to find the app directory depends on whether we run in the renderer or in the child-writer
|
||||||
// We use __dirname in the child-writer and electron.remote.app.getAppPath() in the renderer
|
// We use __dirname in the child-writer and electron.remote.app.getAppPath() in the renderer
|
||||||
replace(/node_modules\/ext2fs\/lib\/libext2fs\.js$/, {
|
replace(makeExt2FsRegex(), {
|
||||||
search: 'scriptDirectory = __dirname + "/";',
|
search: 'scriptDirectory = __dirname + "/";',
|
||||||
replace: fetchWasm('ext2fs', 'lib'),
|
replace: fetchWasm('ext2fs', 'lib'),
|
||||||
}),
|
}),
|
||||||
@ -385,7 +407,7 @@ const guiConfigCopyPatterns = [
|
|||||||
to: 'modules/node-raspberrypi-usbboot/blobs',
|
to: 'modules/node-raspberrypi-usbboot/blobs',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: 'node_modules/ext2fs/lib/libext2fs.wasm',
|
from: `${findExt2fsFolder()}/lib/libext2fs.wasm`,
|
||||||
to: 'modules/ext2fs/lib/libext2fs.wasm',
|
to: 'modules/ext2fs/lib/libext2fs.wasm',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -394,6 +416,8 @@ const guiConfigCopyPatterns = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
console.log(guiConfigCopyPatterns);
|
||||||
|
|
||||||
if (os.platform() === 'win32') {
|
if (os.platform() === 'win32') {
|
||||||
// liblzma.dll is required on Windows for lzma-native
|
// liblzma.dll is required on Windows for lzma-native
|
||||||
guiConfigCopyPatterns.push({
|
guiConfigCopyPatterns.push({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user