Skip to content

Commit

Permalink
use patterns instead of filter
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp committed Dec 6, 2024
1 parent f4d40f9 commit 2f8401e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
15 changes: 4 additions & 11 deletions packages/app-builder-lib/src/asar/asarUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateOptions, createPackageWithOptions } from "@electron/asar"
import { AsyncTaskManager, log } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { FileCopier, Filter, Link, MAX_FILE_REQUESTS } from "builder-util/out/fs"
import { FileCopier, Link, MAX_FILE_REQUESTS } from "builder-util/out/fs"
import * as fs from "fs-extra"
import { mkdir, readlink, symlink } from "fs-extra"
import { platform } from "os"
Expand All @@ -26,7 +26,7 @@ export class AsarPackager {
defaultDestination: string
resourcePath: string
options: AsarOptions
unpackPattern: Filter | undefined
unpackPattern: Array<string>
}
) {
this.outFile = path.join(config.resourcePath, `app.asar`)
Expand All @@ -45,7 +45,8 @@ export class AsarPackager {
fileSets[0],
].map(orderFileSet)

const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets)
const { unpackedPaths: paths, copiedFiles } = await this.detectAndCopy(orderedFileSets)
const unpackedPaths = [...paths, ...this.config.unpackPattern]
const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(",")}}` : unpackedPaths.pop()

await this.executeElectronAsar(copiedFiles, unpackGlob)
Expand Down Expand Up @@ -87,13 +88,6 @@ export class AsarPackager {
const links: Array<Link> = []
const symlinkType = platform() === "win32" ? "junction" : "file"

const matchUnpacker = (file: string, dest: string, stat: fs.Stats) => {
if (this.config.unpackPattern?.(file, stat)) {
log.debug({ file }, "unpacking")
unpackedPaths.add(dest)
return
}
}
const writeFileOrProcessSymlink = async (options: {
file: string
destination: string
Expand Down Expand Up @@ -153,7 +147,6 @@ export class AsarPackager {
const relative = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))
const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative)

matchUnpacker(file, destination, stat)
taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }))

if (taskManager.tasks.length > MAX_FILE_REQUESTS) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
defaultDestination,
resourcePath,
options: asarOptions,
unpackPattern: fileMatcher?.createFilter(),
unpackPattern: fileMatcher?.patterns || [],
}).pack(fileSets)
})
)
Expand Down
5 changes: 2 additions & 3 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { checkBuildRequestOptions } from "app-builder-lib"
import { doMergeConfigs } from "app-builder-lib/out/util/config/config"
import { Arch, createTargets, DIR_TARGET, Platform } from "electron-builder"
import { promises as fs } from "fs"
import { outputJson ,outputFile} from "fs-extra"
import { outputJson, outputFile } from "fs-extra"
import * as path from "path"
import { createYargs } from "electron-builder/out/builder"
import { app, appTwo, appTwoThrows, assertPack, linuxDirTarget, modifyPackageJson, packageJson, toSystemIndependentPath } from "./helpers/packTester"
Expand Down Expand Up @@ -330,7 +330,7 @@ test.ifDevOrWinCi("smart unpack local module with dll file", () => {
targets: Platform.WINDOWS.createTarget(DIR_TARGET),
},
{
isInstallDepsBefore:true,
isInstallDepsBefore: true,
projectDirCreated: async (projectDir, tmpDir) => {
const tempDir = await tmpDir.getTempDir()
let localPath = path.join(tempDir, "foo")
Expand All @@ -351,7 +351,6 @@ test.ifDevOrWinCi("smart unpack local module with dll file", () => {
)()
})


// https://github.com/electron-userland/electron-builder/issues/1738
test.ifDevOrLinuxCi(
"posix smart unpack",
Expand Down

0 comments on commit 2f8401e

Please sign in to comment.