-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable extra measure for removing "prebuilds"
- Loading branch information
Showing
6 changed files
with
75 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type {AfterPackContext, Configuration, Target} from "app-builder-lib"; | ||
import fastGlob from "fast-glob"; | ||
import path from "path"; | ||
|
||
import {CONSOLE_LOG, execShell} from "scripts/lib"; | ||
|
||
const hookName = "afterPack"; | ||
|
||
const printPrefix = `[hook: ${hookName}]`; | ||
|
||
async function applyChmodThing({appOutDir}: AfterPackContext, {name: targetName}: Target): Promise<void> { | ||
if (!["appimage", "snap"].includes(targetName.toLocaleLowerCase())) { | ||
await execShell(["chmod", ["4755", path.join(appOutDir, "chrome-sandbox")]]); | ||
} | ||
} | ||
|
||
const resolveDistPrebuildsDirs = async (): Promise<string[]> => { | ||
return fastGlob("./dist/**/app.asar.unpacked/node_modules/**/prebuilds", {onlyDirectories: true}); | ||
}; | ||
|
||
const hook: Required<Configuration>[typeof hookName] = async (ctx) => { | ||
if (ctx.targets.length !== 1) throw new Error(`${printPrefix} only one target is allowed at a time`); | ||
const [target] = ctx.targets; | ||
if (!target) throw new Error("Target resolving failed"); | ||
|
||
CONSOLE_LOG(`${printPrefix} processing "${target.name}" target`); | ||
|
||
if (ctx.electronPlatformName.toLowerCase().startsWith("lin")) { | ||
await applyChmodThing(ctx, target); | ||
} | ||
|
||
{ | ||
let prebuildDirs = await resolveDistPrebuildsDirs(); | ||
|
||
for (const prebuildDir of await resolveDistPrebuildsDirs()) { | ||
CONSOLE_LOG(`${printPrefix} removing "${prebuildDir}" directory`); | ||
await execShell(["npx", ["rimraf", prebuildDir]]); | ||
} | ||
|
||
if ((prebuildDirs = await resolveDistPrebuildsDirs()).length) { | ||
throw new Error(`Failed to remove the following dirs: ${JSON.stringify(prebuildDirs, null, 2)}`); | ||
} | ||
} | ||
}; | ||
|
||
export default hook; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
import {Configuration} from "webpack"; | ||
import fastGlob from "fast-glob"; | ||
import nodeExternals from "webpack-node-externals"; | ||
import path from "path"; | ||
|
||
import {buildBaseConfig, rootRelativePath, typescriptLoaderRule} from "./lib"; | ||
import {CONSOLE_LOG} from "scripts/lib"; | ||
import {sanitizeFastGlobPattern} from "src/shared/util/sanitize"; | ||
|
||
const hooksDir = (...value: string[]): string => { | ||
return path.join(rootRelativePath("./scripts/electron-builder/hooks"), ...value); | ||
}; | ||
|
||
// TODO scan folder automatically | ||
const hooksToBuild = ["afterPack"] as const; | ||
const hooksDir = rootRelativePath("./scripts/electron-builder"); | ||
const tsConfigFile = path.join(hooksDir, "tsconfig.json"); | ||
|
||
const configurations: Configuration[] = hooksToBuild.map((hookDirName) => { | ||
const hookDir = path.join(hooksDir(hookDirName)); | ||
const tsConfigFile = path.join(hookDir, "tsconfig.json"); | ||
export default async (): Promise<Configuration[]> => { | ||
const hookSrcFiles = await fastGlob( | ||
sanitizeFastGlobPattern(`${hooksDir}/hook-*.ts`), | ||
{deep: 1, onlyFiles: true, stats: false}, | ||
); | ||
|
||
return buildBaseConfig({ | ||
mode: "none", | ||
devtool: false, | ||
target: "node", | ||
entry: {index: hookDir}, | ||
output: {path: hookDir, libraryTarget: "commonjs2", libraryExport: "default", filename: "[name].cjs"}, | ||
module: {rules: [typescriptLoaderRule({tsConfigFile})]}, | ||
externals: [nodeExternals()], | ||
resolve: {alias: {scripts: rootRelativePath("scripts")}}, | ||
}, {tsConfigFile}); | ||
}); | ||
CONSOLE_LOG(`Delected hook src files: ${JSON.stringify(hookSrcFiles, null, 2)}`); | ||
|
||
export default configurations; | ||
return hookSrcFiles.map((hookSrcFile) => { | ||
return buildBaseConfig({ | ||
mode: "none", | ||
devtool: false, | ||
target: "node", | ||
entry: {[path.basename(hookSrcFile, ".ts")]: hookSrcFile}, | ||
output: {path: hooksDir, libraryTarget: "commonjs2", libraryExport: "default", filename: "[name].cjs"}, | ||
module: {rules: [typescriptLoaderRule({tsConfigFile})]}, | ||
externals: [nodeExternals()], | ||
resolve: {alias: {scripts: rootRelativePath("scripts")}}, | ||
}, {tsConfigFile}); | ||
}); | ||
}; |