From 26c8360627ad313966649f15010d124e7a7306be Mon Sep 17 00:00:00 2001 From: develar Date: Mon, 22 Aug 2016 21:29:35 +0200 Subject: [PATCH] fix: auto-unpack doesn't create file parent dirs Closes #689 --- src/asarUtil.ts | 21 ++++++++++++++------- test/src/helpers/runTests.ts | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/asarUtil.ts b/src/asarUtil.ts index f24c0dd807a..c970bcbcbd3 100644 --- a/src/asarUtil.ts +++ b/src/asarUtil.ts @@ -165,12 +165,11 @@ async function detectUnpackedDirs(src: string, files: Array, metadata: M const fileParent = path.dirname(file) if (fileParent !== nodeModuleDir && !autoUnpackDirs.has(fileParent)) { autoUnpackDirs.add(fileParent) - + createDirPromises.push(ensureDir(path.join(unpackedDest, path.relative(src, fileParent)))) if (createDirPromises.length > MAX_FILE_REQUESTS) { await BluebirdPromise.all(createDirPromises) createDirPromises.length = 0 } - createDirPromises.push(ensureDir(path.join(unpackedDest, path.relative(src, fileParent)))) } continue } @@ -189,13 +188,21 @@ async function detectUnpackedDirs(src: string, files: Array, metadata: M } log(`${path.relative(src, nodeModuleDir)} is not packed into asar archive - contains executable code`) - autoUnpackDirs.add(nodeModuleDir) - const fileParent = path.dirname(file) - if (fileParent !== nodeModuleDir) { + + let fileParent = path.dirname(file) + + // create parent dir to be able to copy file later without directory existence check + createDirPromises.push(ensureDir(path.join(unpackedDest, path.relative(src, fileParent)))) + if (createDirPromises.length > MAX_FILE_REQUESTS) { + await BluebirdPromise.all(createDirPromises) + createDirPromises.length = 0 + } + + while (fileParent !== nodeModuleDir) { autoUnpackDirs.add(fileParent) - // create parent dir to be able to copy file later without directory existence check - createDirPromises.push(ensureDir(path.join(unpackedDest, path.relative(src, fileParent)))) + fileParent = path.dirname(fileParent) } + autoUnpackDirs.add(nodeModuleDir) } if (readPackageJsonPromises.length > 0) { diff --git a/test/src/helpers/runTests.ts b/test/src/helpers/runTests.ts index 3586053721f..e84c69073b9 100755 --- a/test/src/helpers/runTests.ts +++ b/test/src/helpers/runTests.ts @@ -161,6 +161,9 @@ function runTests(): BluebirdPromise { else if (process.platform === "win32") { args.push("test/out/*.js", "!test/out/macPackagerTest.js", "!test/out/linuxPackagerTest.js", "!test/out/CodeSignTest.js", "!test/out/ArtifactPublisherTest.js", "!test/out/httpRequestTest.js") } + else if (!util.isCi()) { + args.push("test/out/*.js", "!test/out/ArtifactPublisherTest.js", "!test/out/httpRequestTest.js") + } return utilSpawn(path.join(rootDir, "node_modules", ".bin", "ava"), args, { cwd: rootDir,