Skip to content

Commit 3bb2ab8

Browse files
committed
fix: from as file and to as dir
Close #1245
1 parent bbc1df6 commit 3bb2ab8

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

packages/electron-builder/src/fileMatcher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export function copyFiles(patterns: Array<FileMatcher> | null): Promise<any> {
9393
}
9494

9595
if (fromStat.isFile()) {
96+
const toStat = await statOrNull(pattern.to)
97+
// https://github.com/electron-userland/electron-builder/issues/1245
98+
if (toStat != null && toStat.isDirectory()) {
99+
return await copyFile(pattern.from, path.join(pattern.to, path.basename(pattern.from)), fromStat)
100+
}
101+
96102
await mkdirs(path.dirname(pattern.to))
97103
return await copyFile(pattern.from, pattern.to, fromStat)
98104
}

test/src/filesTest.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,28 @@ test.ifDevOrLinuxCi("map resources", app({
3535
targets: Platform.LINUX.createTarget(DIR_TARGET),
3636
config: {
3737
asar: false,
38-
extraResources: {
39-
from: "foo/old",
40-
to: "foo/new",
41-
},
38+
extraResources: [
39+
{
40+
from: "foo/old",
41+
to: "foo/new",
42+
},
43+
{
44+
from: "license.txt",
45+
to: ".",
46+
},
47+
],
4248
}
4349
}, {
4450
projectDirCreated: projectDir => BluebirdPromise.all([
4551
outputFile(path.join(projectDir, "foo", "old"), "data"),
52+
outputFile(path.join(projectDir, "license.txt"), "data"),
4653
]),
4754
packed: context => {
4855
const resources = path.join(context.getResources(Platform.LINUX))
4956
return BluebirdPromise.all([
5057
assertThat(path.join(resources, "app", "foo", "old")).doesNotExist(),
5158
assertThat(path.join(resources, "foo", "new")).isFile(),
59+
assertThat(path.join(resources, "license.txt")).isFile(),
5260
])
5361
},
5462
}))

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,8 @@ glob@~5.0.0:
12721272
path-is-absolute "^1.0.0"
12731273

12741274
globals@^9.0.0:
1275-
version "9.14.0"
1276-
resolved "https://registry.yarnpkg.com/globals/-/globals-9.14.0.tgz#8859936af0038741263053b39d0e76ca241e4034"
1275+
version "9.15.0"
1276+
resolved "https://registry.yarnpkg.com/globals/-/globals-9.15.0.tgz#7a5d8fd865e69de910b090b15a87772f9423c5de"
12771277

12781278
got@^5.0.0:
12791279
version "5.7.1"

0 commit comments

Comments
 (0)