Skip to content

Commit

Permalink
fix: compiler error and test updates (#5449)
Browse files Browse the repository at this point in the history
* Fixed compiler errors with
```
/Users/travis/build/electron-userland/electron-builder/packages/dmg-builder/src/dmgLicense.ts
  12:98  error  Don't use `Object` as a type. The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.
- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.
- If you want a type meaning "any value", you probably want `unknown` instead  @typescript-eslint/ban-types
  37:9   error  'label' is never reassigned. Use 'const' instead     prefer-const
```

* Fixed compiler errors within dmgLicense.ts
- 12:98 error Don't use `Object` as a type. The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.
- 37:9 error 'label' is never reassigned. Use 'const' instead prefer-const
Fixing buildResources directory "default" to be a fully defined path as a fallback resource
Updating snapTest snapshots to include new title entry introduced in PR #5350
Switching to japanese for dmg-license tests since russian does not have a default label

* Bug fix: directories.buildResources must be used instead of buildResourcesDir (output dir)
Bug fix: fallbackSources require a path to exist first
Optimized logic using shorthand filters for undefined/null elements.

* Updating license test files to conform to dmg license spec: https://github.com/argv-minus-one/dmg-license/blob/master/docs/License%20Specifications.md#license-specifications
Bug fix: directories.buildResources (input dir) must be used instead of buildResourcesDir (output dir)
Bug fix: fallbackSources require a path to exist, filter first
Optimized logic using shorthand filters for undefined/null elements.

* Test fix: license file paths are dynamic and must be scrubbed for test snapshots

Co-authored-by: Mike Maietta <michaelmaietta@upwork.com>
  • Loading branch information
mmaietta and Mike Maietta authored Dec 9, 2020
1 parent 9fd950b commit 0dec1b8
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 2,095 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"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",
"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
29 changes: 14 additions & 15 deletions packages/app-builder-lib/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { asArray, isEmptyOrSpaces, log } from "builder-util"
import { asArray, isEmptyOrSpaces, log, exists } from "builder-util"
import { outputFile } from "fs-extra"
import { Lazy } from "lazy-val"
import { LinuxTargetSpecificOptions } from ".."
Expand Down Expand Up @@ -52,22 +52,21 @@ export class LinuxTargetHelper {
// must be name without spaces and other special characters, but not product name used
private async computeDesktopIcons(): Promise<Array<IconInfo>> {
const packager = this.packager
const iconDir = packager.platformSpecificBuildOptions.icon
const sources = iconDir == null ? [] : [iconDir]

const commonConfiguration = packager.config
const icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon
if (icnsPath != null) {
sources.push(icnsPath)
}

// if no explicit sources are defined, default to buildResources directory
if (sources.length < 1) {
sources.push('./')
}
const { platformSpecificBuildOptions, config } = packager

const sources = [
platformSpecificBuildOptions.icon,
config.mac?.icon ?? config.icon
].filter(str => !!str) as string[]

// If no explicit sources are defined, fallback to buildResources directory, then default framework icon
const fallbackSources = [
config.directories?.buildResources,
...asArray(packager.getDefaultFrameworkIcon())
].filter(async filepath => filepath && await exists(filepath)) as string[]

// need to put here and not as default because need to resolve image size
const result = await packager.resolveIcon(sources, asArray(packager.getDefaultFrameworkIcon()), "set")
const result = await packager.resolveIcon(sources, fallbackSources, "set")
this.maxIconPath = result[result.length - 1].file
return result
}
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export { Arch, getArchCliNames, toLinuxArchString, getArchSuffix, ArchType, arch
export { AsyncTaskManager } from "./asyncTaskManager"
export { DebugLogger } from "./DebugLogger"

export { copyFile } from "./fs"
export { copyFile, exists } from "./fs"
export { asArray } from "builder-util-runtime"

export { deepAssign } from "./deepAssign"
Expand Down
22 changes: 16 additions & 6 deletions packages/dmg-builder/src/dmgLicense.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { exec, log } from "builder-util"
import { safeLoad } from 'js-yaml'
import { PlatformPackager } from "app-builder-lib"
import { getLicenseFiles } from "app-builder-lib/out/util/license"
import { outputFile, readFile, readJson } from "fs-extra"
Expand All @@ -9,7 +10,15 @@ import { dmgLicenseFromJSON } from 'dmg-license'
// DropDMG/dmgbuild a in any case (even if no english, but only ru/de) set to 0 (en_US), well, without docs, just believe that's correct
const DEFAULT_REGION_CODE = 0

export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string): Promise<Object | null> {
// License Specifications
// https://github.com/argv-minus-one/dmg-license/blob/HEAD/docs/License%20Specifications.md
type LicenseConfig = {
'$schema': string
body: any[]
labels: any[]
}

export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string): Promise<LicenseConfig | null> {
const licenseFiles = await getLicenseFiles(packager)
if (licenseFiles.length === 0) {
return null
Expand All @@ -19,11 +28,11 @@ export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath:
packager.debugLogger.add("dmg.licenseFiles", licenseFiles)
packager.debugLogger.add("dmg.licenseButtons", licenseButtonFiles)

const jsonFile = {
'$schema': 'https://github.com/argv-minus-one/dmg-license/raw/master/schema.json',
const jsonFile: LicenseConfig = {
"$schema": "https://github.com/argv-minus-one/dmg-license/raw/master/schema.json",
// defaultLang: '',
body: [] as any,
labels: [] as any
body: [],
labels: []
}

for (const file of licenseFiles) {
Expand All @@ -34,7 +43,8 @@ export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath:
}

for (const button of licenseButtonFiles) {
let label = await readJson(button.file)
const filepath = button.file
const label = filepath.endsWith(".yml") ? safeLoad(await readFile(filepath, "utf-8")) : await readJson(filepath)
if (label.description) {
// to support original button file format
label.message = label.description
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/licensebuttons_en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lang: English
lang: en-US
languageName: English
agree: Agree
disagree: Disagree
print: Print
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/licensebuttons_fr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lang": "Français",
"lang": "fr-FR",
"languageName": "Français",
"agree": "J'accepte",
"disagree": "Je refuse",
"print": "Imprimer",
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/licensebuttons_ja.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lang": "日本語",
"lang": "ja-JP",
"languageName": "日本語",
"agree": "同意する",
"disagree": "同意しない",
"print": "印刷する",
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/licensebuttons_ko.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lang": "한국어",
"lang": "ko-KR",
"languageName": "한국어",
"agree": "한국어",
"disagree": "동의하지 않는다",
"print": "인쇄",
Expand Down
13 changes: 13 additions & 0 deletions test/snapshots/linux/snapTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -283,6 +284,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -363,6 +365,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -433,6 +436,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -597,6 +601,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -762,6 +767,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -927,6 +933,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1093,6 +1100,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1152,6 +1160,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1353,6 +1362,7 @@ Object {
},
},
"summary": "Test App ßW",
"title": "Test App ßW",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1554,6 +1564,7 @@ Object {
},
},
"summary": "Test App ßW",
"title": "Test App ßW",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1627,6 +1638,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down Expand Up @@ -1706,6 +1718,7 @@ Object {
},
},
"summary": "Sep",
"title": "Sep",
"version": "1.1.0",
}
`;
Expand Down
Loading

0 comments on commit 0dec1b8

Please sign in to comment.