Skip to content

Commit ab41fcf

Browse files
committed
feat: Remove scripts, devDependencies and build from package.json
BREAKING CHANGE: `scripts`, `devDependencies` and `build` automatically removed from package.json Close #1212
1 parent 9c62be9 commit ab41fcf

File tree

8 files changed

+37
-25
lines changed

8 files changed

+37
-25
lines changed

.idea/dictionaries/develar.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/electron-builder/src/asarUtil.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,22 @@ class AsarPackager {
190190
const fileParent = path.dirname(file)
191191
const dirNode = this.fs.searchNodeFromPath(fileParent)
192192
const packageDataPromise = fileIndexToModulePackageData.get(i)
193-
let newData: any | null = null
193+
let newData: string | null = null
194194
if (packageDataPromise == null) {
195-
if (this.options.extraMetadata != null && file === mainPackageJson) {
196-
newData = JSON.stringify(deepAssign(await readJson(file), this.options.extraMetadata), null, 2)
195+
if (file === mainPackageJson) {
196+
const mainPackageData = await readJson(file)
197+
if (this.options.extraMetadata != null) {
198+
deepAssign(mainPackageData, this.options.extraMetadata)
199+
}
200+
201+
// https://github.com/electron-userland/electron-builder/issues/1212
202+
const serializedDataIfChanged = cleanupPackageJson(mainPackageData)
203+
if (serializedDataIfChanged != null) {
204+
newData = serializedDataIfChanged
205+
}
206+
else if (this.options.extraMetadata != null) {
207+
newData = JSON.stringify(mainPackageData, null, 2)
208+
}
197209
}
198210
}
199211
else {
@@ -352,7 +364,7 @@ function cleanupPackageJson(data: any): any {
352364
try {
353365
let changed = false
354366
for (const prop of Object.getOwnPropertyNames(data)) {
355-
if (prop[0] === "_" || prop === "dist" || prop === "gitHead" || prop === "keywords") {
367+
if (prop[0] === "_" || prop === "dist" || prop === "gitHead" || prop === "keywords" || prop === "build" || prop === "devDependencies" || prop === "scripts") {
356368
delete data[prop]
357369
changed = true
358370
}

packages/electron-builder/src/platformPackager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
128128
log(`Packaging for ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`)
129129

130130
const appDir = this.info.appDir
131-
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir), path.resolve(this.info.projectDir, this.buildResourcesDir)])
131+
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir),
132+
path.resolve(this.info.projectDir, this.buildResourcesDir),
133+
path.resolve(this.info.projectDir, "electron-builder.yml"),
134+
path.resolve(this.info.projectDir, "electron-builder.json"),
135+
path.resolve(this.info.projectDir, "electron-builder.json5")])
132136
if (this.info.isPrepackedAppAsar) {
133137
await unpackElectron(this, appOutDir, platformName, Arch[arch], this.info.electronVersion)
134138
}

test/out/__snapshots__/extraMetadataTest.js.snap

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
exports[`test extra metadata 1`] = `
22
Object {
33
"author": "Foo Bar <foo@example.com>",
4-
"build": Object {
5-
"appId": "org.electron-builder.testApp",
6-
"compression": "store",
7-
"electronVersion": "1.4.12",
8-
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico",
9-
"linux": Object {
10-
"category": "Development",
11-
"packageCategory": "devel",
12-
},
13-
"mac": Object {
14-
"category": "your.app.category.type",
15-
},
16-
"npmRebuild": false,
17-
},
184
"description": "Test Application (test quite \" #378)",
195
"foo": Object {
206
"bar": 12,

test/out/__snapshots__/globTest.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Object {
66

77
exports[`test outside link 1`] = `
88
Object {
9-
"offset": "5290",
9+
"offset": "4877",
1010
"size": 4,
1111
}
1212
`;

test/src/extraMetadataTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ test.ifDevOrLinuxCi("extra metadata", app({
1818
},
1919
}, {
2020
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
21+
data.scripts = {}
22+
data.devDependencies = {"foo": "boo"}
2123
data.foo = {
2224
bar: 42,
2325
existingProp: 22,

test/src/helpers/runTests.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ async function runTests() {
8383
}
8484
else if (!isEmptyOrSpaces(process.env.CIRCLE_NODE_INDEX)) {
8585
const circleNodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX, 10)
86-
if (circleNodeIndex === 0 || circleNodeIndex === 2) {
86+
if (circleNodeIndex === 0) {
8787
skipWin = true
88-
args.push("linux.*", "BuildTest.js", "extraMetadataTest.js", "mainEntryTest.js", "globTest.js", "filesTest.js", "ignoreTest.js")
89-
if (circleNodeIndex === 0) {
90-
args.push("nsisUpdaterTest")
91-
}
88+
args.push("debTest", "fpmTest", "linuxArchiveTest", "BuildTest.js", "extraMetadataTest.js", "mainEntryTest.js", "globTest.js", "filesTest.js", "ignoreTest.js")
89+
args.push("nsisUpdaterTest")
90+
}
91+
else if (circleNodeIndex === 2) {
92+
skipWin = true
93+
args.push("linuxPackagerTest", "snapTest", "BuildTest.js", "extraMetadataTest.js", "mainEntryTest.js", "globTest.js", "filesTest.js", "ignoreTest.js")
9294
}
9395
else {
9496
args.push("windows.*", "mac.*")

test/src/linux/linuxPackagerTest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { remove, readFile, rename } from "fs-extra-p"
33
import * as path from "path"
44
import { Platform, build } from "electron-builder"
55
import { assertThat } from "../helpers/fileAssert"
6+
import { ELECTRON_VERSION } from "../helpers/config"
67

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

@@ -38,6 +39,10 @@ test.ifNotWindows("icons from ICNS", app({targets: Platform.LINUX.createTarget()
3839
await build({
3940
targets: Platform.LINUX.createTarget(),
4041
projectDir: projectDir,
42+
config: {
43+
electronVersion: ELECTRON_VERSION,
44+
compression: "store",
45+
}
4146
})
4247

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

0 commit comments

Comments
 (0)