Skip to content

Commit

Permalink
electron-userland#5465: Switching from isBinary to istextorbinary
Browse files Browse the repository at this point in the history
…. Exposing `getFilePathIfBinarySync` to app-builder-lib to consolidate binary detection logic
  • Loading branch information
Mike Maietta committed Dec 20, 2020
1 parent 2b116d1 commit adfe4c9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"///": "Please see https://github.com/electron-userland/electron-builder/blob/master/CONTRIBUTING.md#run-test-using-cli how to run particular test instead full (and very slow) run",
"test": "node ./test/out/helpers/runTests.js skipArtifactPublisher ALL_TESTS=isCi",
"test-all": "yarn pretest && node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/Library/Caches/electron:/root/.cache/electron -v ~/Library/Caches/electron-builder:/root/.cache/electron-builder electronuserland/builder:wine /bin/bash -c \"yarn && TEST_FILES=HoistedNodeModuleTest node ./test/out/helpers/runTests.js\"",
"test-update": "UPDATE_SNAPSHOT=true npm run test",
"test-linux": "docker run --rm -ti -e UPDATE_SNAPSHOT=${UPDATE_SNAPSHOT:-false} -e TEST_FILES=\"${TEST_FILES:-HoistedNodeModuleTest}\" -v $(pwd):/project -v $(pwd)-node-modules:/project/node_modules -v $HOME/Library/Caches/electron:/root/.cache/electron -v $HOME/Library/Caches/electron-builder:/root/.cache/electron-builder electronuserland/builder:wine /bin/bash -c \"yarn && yarn test-all\"",
"test-update": "UPDATE_SNAPSHOT=true yarn test",
"docker-images": "docker/build.sh",
"release": "BABEL_ENV=production yarn compile && ./scripts/publish-packages.sh && conventional-changelog-cli conventional-changelog -p angular -i CHANGELOG.md -s",
"schema": "typescript-json-schema packages/app-builder-lib/tsconfig.json Configuration --out packages/app-builder-lib/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --required && node ./scripts/fix-schema.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder-lib/electron-osx-sign/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ interface FlatOptions extends BaseSignOptions {
export function flat(opts: FlatOptions, callback: (error: Error) => void): void;

export function flatAsync(opts: FlatOptions): Promise<any>;

export function getFilePathIfBinarySync(filePath: string): string | undefined
11 changes: 10 additions & 1 deletion packages/app-builder-lib/electron-osx-sign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const sign = require('./sign')
const flat = require('./flat')
const util = require('./util')

/**
* This function is a normal callback implementation.
Expand Down Expand Up @@ -42,6 +43,14 @@ module.exports.flat = flat.flat
* This function is exported and returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
* @returns {Promise} - Promise.
*/
module.exports.flatAsync = flat.flatAsync

/**
* This function is exported and returns a filepath if detected to be a binary (sync).
* @function
* @param {string} filepath - Filepath
* @returns {string | undefined} - Filepath if binary, otherwise undefined
*/
module.exports.getFilePathIfBinarySync = util.getFilePathIfBinarySync
11 changes: 4 additions & 7 deletions packages/app-builder-lib/electron-osx-sign/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,16 @@ var detectElectronPlatformAsync = module.exports.detectElectronPlatformAsync = f
})
}

const isBinaryFile = require("isbinaryfile").isBinaryFile;
const isBinaryFile = require("istextorbinary").isBinary;

/**
* This function returns a promise resolving the file path if file binary.
* @function
* @param {string} filePath - Path to file.
* @returns {Promise} Promise resolving file path or undefined.
*/
const getFilePathIfBinaryAsync = module.exports.getFilePathIfBinaryAsync = function (filePath) {
return isBinaryFile(filePath)
.then(function (isBinary) {
return isBinary ? filePath : undefined
})
const getFilePathIfBinarySync = module.exports.getFilePathIfBinarySync = function (filePath) {
return isBinaryFile(filePath, fs.readFileSync(filePath)) ? filePath : undefined
}

/**
Expand Down Expand Up @@ -207,7 +204,7 @@ module.exports.walkAsync = async function (dirPath) {
await fs.unlink(filePath)
return
default:
return getFilePathIfBinaryAsync(filePath)
return getFilePathIfBinarySync(filePath)
}
} else if (stat.isDirectory() && !stat.isSymbolicLink()) {
const result = await _walkAsync(filePath)
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"fs-extra": "^9.0.1",
"hosted-git-info": "^3.0.7",
"is-ci": "^2.0.0",
"isbinaryfile": "^4.0.6",
"istextorbinary": "^5.12.0",
"js-yaml": "^3.14.1",
"lazy-val": "^1.0.4",
"minimatch": "^3.0.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/asar/unpackDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import BluebirdPromise from "bluebird-lst"
import { log } from "builder-util"
import { CONCURRENCY } from "builder-util/out/fs"
import { ensureDir } from "fs-extra"
import { isBinaryFile } from "isbinaryfile"
import * as path from "path"
import { NODE_MODULES_PATTERN } from "../fileTransformer"
import { getDestinationPath, ResolvedFileSet } from "../util/appFileCopier"
import { getFilePathIfBinarySync } from "../../electron-osx-sign";

function addValue(map: Map<string, Array<string>>, key: string, value: string) {
let list = map.get(key)
Expand Down Expand Up @@ -85,8 +85,8 @@ export async function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDir
if (moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
shouldUnpack = true
}
else if (!file.includes(".", nextSlashIndex) && path.extname(file) === "") {
shouldUnpack = await isBinaryFile(file)
else if (!file.includes(".", nextSlashIndex)) {
shouldUnpack = !!getFilePathIfBinarySync(file)
}

if (!shouldUnpack) {
Expand Down
70 changes: 62 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ __metadata:
fs-extra: ^9.0.1
hosted-git-info: ^3.0.7
is-ci: ^2.0.0
isbinaryfile: ^4.0.6
istextorbinary: ^5.12.0
js-yaml: ^3.14.1
lazy-val: ^1.0.4
minimatch: ^3.0.4
Expand Down Expand Up @@ -3249,6 +3249,13 @@ __metadata:
languageName: node
linkType: hard

"binaryextensions@npm:^4.15.0":
version: 4.15.0
resolution: "binaryextensions@npm:4.15.0"
checksum: c594a31c1699460a9786cd3fa57cef73eab9635dc6eba586738ea7f012dcc92d10d00f4ce60c42d2de21b0931b4fdb6b560d8095e515f69e3ebe757f8dd60be1
languageName: node
linkType: hard

"bl@npm:^4.0.3":
version: 4.0.3
resolution: "bl@npm:4.0.3"
Expand Down Expand Up @@ -4311,6 +4318,9 @@ __metadata:
js-yaml: ^3.14.1
sanitize-filename: ^1.6.3
temp-file: ^3.3.7
dependenciesMeta:
dmg-license:
optional: true
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -4391,6 +4401,16 @@ __metadata:
languageName: node
linkType: hard

"editions@npm:^6.1.0":
version: 6.1.0
resolution: "editions@npm:6.1.0"
dependencies:
errlop: ^4.0.0
version-range: ^1.0.0
checksum: 9d9b9520da8e3fc7ea1aae75642504cf26cb5634e9c74a85d0ee03fc9f29cb7987824903c18d1cbec958507cbbe079077b2e72c3037342d7a598536b39a8292a
languageName: node
linkType: hard

"ejs@npm:^3.1.5":
version: 3.1.5
resolution: "ejs@npm:3.1.5"
Expand Down Expand Up @@ -4578,6 +4598,13 @@ __metadata:
languageName: node
linkType: hard

"errlop@npm:^4.0.0":
version: 4.1.0
resolution: "errlop@npm:4.1.0"
checksum: 358fa5d7502b3e2337aec03a0fd81c9fb07d6e8b762872b766abc768d8961794efb1f4ab396974ead2a09ce8538cb972c3326c8ed307b5bc99ae5d0af0da1c1c
languageName: node
linkType: hard

"error-ex@npm:^1.3.1":
version: 1.3.2
resolution: "error-ex@npm:1.3.2"
Expand Down Expand Up @@ -6083,13 +6110,6 @@ __metadata:
languageName: node
linkType: hard

"isbinaryfile@npm:^4.0.6":
version: 4.0.6
resolution: "isbinaryfile@npm:4.0.6"
checksum: 23d94f36fbf9898c7095d29aa1e4f4b1afad77fac6e1e987f32e89036fa45d7365f3a55990de7d99b76ca591b683640efa594f1fa19b03e3d712c4f2a690efa0
languageName: node
linkType: hard

"isexe@npm:^2.0.0":
version: 2.0.0
resolution: "isexe@npm:2.0.0"
Expand Down Expand Up @@ -6171,6 +6191,17 @@ __metadata:
languageName: node
linkType: hard

"istextorbinary@npm:^5.12.0":
version: 5.12.0
resolution: "istextorbinary@npm:5.12.0"
dependencies:
binaryextensions: ^4.15.0
editions: ^6.1.0
textextensions: ^5.11.0
checksum: c30ebde873fe5f9496b4f6bbf871bf864ee848448fa4d2dc41b03408b5aa89c276f6431945f080e4a02fb7b4b53b3f3aa26d8e9d83b171f94e237071e2f4f1eb
languageName: node
linkType: hard

"jake@npm:^10.6.1":
version: 10.8.2
resolution: "jake@npm:10.8.2"
Expand Down Expand Up @@ -9524,6 +9555,13 @@ __metadata:
languageName: node
linkType: hard

"textextensions@npm:^5.11.0":
version: 5.12.0
resolution: "textextensions@npm:5.12.0"
checksum: fca9fed6c8a0d338f6300e368070883ef73004c013bbb056d56f7f00f19133016d6ccfe094b1126b66fc942c32c81f53531a4122f7a6abeab870079b8c1e857f
languageName: node
linkType: hard

"throat@npm:^5.0.0":
version: 5.0.0
resolution: "throat@npm:5.0.0"
Expand Down Expand Up @@ -10083,6 +10121,22 @@ typescript@~4.1.3:
languageName: node
linkType: hard

"version-compare@npm:^1.0.0":
version: 1.1.0
resolution: "version-compare@npm:1.1.0"
checksum: ef8802dbbf9c3ff1ce201189018aa26fc53d6615d68d3976959e5236a09057f4d6bb0f792ad76e98eb96099ee1dc21a6cca3e109f20ff1a84465be5a77826ac6
languageName: node
linkType: hard

"version-range@npm:^1.0.0":
version: 1.1.0
resolution: "version-range@npm:1.1.0"
dependencies:
version-compare: ^1.0.0
checksum: 7a18b8eeaf9c4984c7d8938ebcf02973e840e4c07b8d3ce9f3ab993bff53466612c321a6fe8330484988b852ad469a0722252a91fbedb445cd15c40e74eaba5a
languageName: node
linkType: hard

"vue-template-compiler@npm:^2.6.11":
version: 2.6.12
resolution: "vue-template-compiler@npm:2.6.12"
Expand Down

0 comments on commit adfe4c9

Please sign in to comment.