nwutils/nw-builder

srcDir files are copied to incorrectly nested folder inside outDir

williamwang96 opened this issue · 6 comments

Issue Type

  • Bug Report
  • Feature Request
  • Other

Current/Missing Behaviour

log.debug(`Copy ${nwDir} files to ${outDir} directory`);
for (let file of files) {
log.debug(`Copy ${file} file to ${outDir} directory`);
await cp(
file,
resolve(
outDir,
platform !== "osx"
? "package.nw"
: "nwjs.app/Contents/Resources/app.nw",
file.split("/").splice(2).join("/"),
),
{
recursive: true,
},
);
}

line 37: probably typo in log.debug, since we're copying srcDir files below
line 44 - 46: I actually don't understand the importance of using the .nw folder, since for my use case, I only need every file in srcDir to be copied into outDir and not any folder within.
line 47: I assume we're trying to get the basename of the file here, but this is actually getting almost the entire absolute path

Expected/Proposed Behaviour

image

This is working for my use case of building a Windows installer. But happy to implement a cross-platform fix if I can get more info about the usage of the .nw folder.

Additional Info

  • Package version: 4.1.0-beta.3
  • Operating System: Windows 10
  • Node version: v18.14.2
  • NW.js version: v0.72.0

I only need every file in srcDir to be copied into outDir and not any folder within

Sample source dir:

/dir/file1
/dir/dir/file2
/file3

Sample out dir:

/file1
/file2
/file3

Without knowing too much about your application, I'm assuming you want this^ type of file structure. The thing is that other people might have different use cases where they do need nested folders.

I actually don't understand the importance of using the .nw folder

https://nwjs.readthedocs.io/en/latest/For%20Users/Package%20and%20Distribute/#package-your-app

You are correct in what I need. Understood, but I think the production code still has an issue in line 47, since splice(2) is assuming that srcDir lives in the home directory, which is usually two levels down from root dir. If I understand correctly, the expected behavior here is to preserve the folder structure in srcDir and copy recursively to package.nw in outDir. I should be able to find a way to do that.

Thanks for the pointer regarding the .nw folder! The only file that I need to copy into the NW.js binaries folder is package.json so I never paid much attention to that section of the doc.

Understood, but I think the production code still has an issue in line 47, since splice(2) is assuming that srcDir lives in the home directory, which is usually two levels down from root dir.

I think you are right. I made a small change (available in v4.1.1) but I think that is also incorrect.

@williamwang96 the linked PR should fix the issue. The changelog would be the best place to see what has changed.

Thanks for the work. However, I think the issue still exists.

log.debug(`Copy files in srcDir to ${outDir} directory`);
for (let file of files) {
log.debug(`Copy ${file} file to ${outDir} directory`);
await cp(
file,
resolve(
outDir,
platform !== "osx"
? "package.nw"
: "nwjs.app/Contents/Resources/app.nw",
file,
),
);
}

This works for srcDir that's located in root dir, but not other cases. Since files in line 40 are from srcDir, it would copy each file with its absolute path to outDir.

For example, if

  • srcDir is /home/users/williamwang96/project/desktop/installer
  • ourDir is /home/users/williamwang96/project/desktop/installer/build-output

Then the package.json in srcDir will be copied to /home/users/williamwang96/project/desktop/installer/build-output/home/users/williamwang96/project/desktop/installer/package.json.

I believe what we need in line 49 is the relative path of file to srcDir.

I believe what we need in line 49 is the relative path of file to srcDir.

Open to PR