Skip to content

Commit

Permalink
feat: Remove scripts, devDependencies and build from package.json
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `scripts`, `devDependencies` and `build` automatically removed from package.json

Close electron-userland#1212
  • Loading branch information
develar committed Feb 4, 2017
1 parent 9c62be9 commit 32b8ae4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions packages/electron-builder/src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,22 @@ class AsarPackager {
const fileParent = path.dirname(file)
const dirNode = this.fs.searchNodeFromPath(fileParent)
const packageDataPromise = fileIndexToModulePackageData.get(i)
let newData: any | null = null
let newData: string | null = null
if (packageDataPromise == null) {
if (this.options.extraMetadata != null && file === mainPackageJson) {
newData = JSON.stringify(deepAssign(await readJson(file), this.options.extraMetadata), null, 2)
if (file === mainPackageJson) {
const mainPackageData = await readJson(file)
if (this.options.extraMetadata != null) {
deepAssign(mainPackageData, this.options.extraMetadata)
}

// https://github.com/electron-userland/electron-builder/issues/1212
const serializedDataIfChanged = cleanupPackageJson(mainPackageData)
if (serializedDataIfChanged != null) {
newData = serializedDataIfChanged
}
else if (this.options.extraMetadata != null) {
newData = JSON.stringify(mainPackageData, null, 2)
}
}
}
else {
Expand Down Expand Up @@ -352,7 +364,7 @@ function cleanupPackageJson(data: any): any {
try {
let changed = false
for (const prop of Object.getOwnPropertyNames(data)) {
if (prop[0] === "_" || prop === "dist" || prop === "gitHead" || prop === "keywords") {
if (prop[0] === "_" || prop === "dist" || prop === "gitHead" || prop === "keywords" || prop === "build" || prop === "devDependencies" || prop === "scripts") {
delete data[prop]
changed = true
}
Expand Down
6 changes: 5 additions & 1 deletion packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
log(`Packaging for ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`)

const appDir = this.info.appDir
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir), path.resolve(this.info.projectDir, this.buildResourcesDir)])
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir),
path.resolve(this.info.projectDir, this.buildResourcesDir),
path.resolve(this.info.projectDir, "electron-builder.yml"),
path.resolve(this.info.projectDir, "electron-builder.json"),
path.resolve(this.info.projectDir, "electron-builder.json5")])
if (this.info.isPrepackedAppAsar) {
await unpackElectron(this, appOutDir, platformName, Arch[arch], this.info.electronVersion)
}
Expand Down
14 changes: 0 additions & 14 deletions test/out/__snapshots__/extraMetadataTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
exports[`test extra metadata 1`] = `
Object {
"author": "Foo Bar <[email protected]>",
"build": Object {
"appId": "org.electron-builder.testApp",
"compression": "store",
"electronVersion": "1.4.12",
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
"linux": Object {
"category": "Development",
"packageCategory": "devel",
},
"mac": Object {
"category": "your.app.category.type",
},
"npmRebuild": false,
},
"description": "Test Application (test quite \" #378)",
"foo": Object {
"bar": 12,
Expand Down
2 changes: 1 addition & 1 deletion test/out/__snapshots__/globTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object {

exports[`test outside link 1`] = `
Object {
"offset": "5290",
"offset": "4877",
"size": 4,
}
`;
2 changes: 2 additions & 0 deletions test/src/extraMetadataTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ test.ifDevOrLinuxCi("extra metadata", app({
},
}, {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.scripts = {}
data.devDependencies = {"foo": "boo"}
data.foo = {
bar: 42,
existingProp: 22,
Expand Down
5 changes: 5 additions & 0 deletions test/src/linux/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { remove, readFile, rename } from "fs-extra-p"
import * as path from "path"
import { Platform, build } from "electron-builder"
import { assertThat } from "../helpers/fileAssert"
import { ELECTRON_VERSION } from "../helpers/config"

test.ifDevOrLinuxCi("AppImage", app({targets: Platform.LINUX.createTarget()}))

Expand Down Expand Up @@ -38,6 +39,10 @@ test.ifNotWindows("icons from ICNS", app({targets: Platform.LINUX.createTarget()
await build({
targets: Platform.LINUX.createTarget(),
projectDir: projectDir,
config: {
electronVersion: ELECTRON_VERSION,
compression: "store",
}
})

await assertThat(path.join(projectDir, "dist")).isDirectory()
Expand Down

0 comments on commit 32b8ae4

Please sign in to comment.