nwutils/nw-builder

Copying of files does not work

sysrage opened this issue · 4 comments

Issue Type

  • Bug Report
  • Feature Request
  • Other

Current/Missing Behaviour

This section of code is failing to copy things recursively: https://github.com/nwutils/nw-builder/blob/main/src/bld/build.js#L40-L52

Using this configuration object:

  const nwBuildArgs = {
    srcDir: `${appBaseDir.replaceAll('\\', '/')}/*`,
    version: nwVersion,
    flavour: 'normal',
    platform: platform,
    arch: 'x64',
    outDir,
    run: false,
    zip: true
  };
  try {
    await nwbuild(nwBuildArgs);
  } catch (error) {
    console.error(`Error building package for ${osType}`);
  }

Would result in srcDir being: C:/Users/Brian/Documents/Code/nw-react-example/dist/app/*.

This then fails:

[ DEBUG ] 2023-03-21T00:20:29.023Z Copy C:/Users/Brian/Documents/Code/nw-react-example/dist/app file to C:\Users\Brian\Documents\Code\nw-react-example\dist\nw-react-example-0.1.2-windows directory
[ ERROR ] 2023-03-21T00:20:29.025Z Path is a directory: cp returned EISDIR (\\?\C:\Users\Brian\Documents\Code\nw-react-example\dist\app is a directory (not copied)) \\?\C:\Users\Brian\Documents\Code\nw-react-example\dist\app        
[ ERROR ] 2023-03-21T00:20:29.025Z Path is a directory: cp returned EISDIR (\\?\C:\Users\Brian\Documents\Code\nw-react-example\dist\app is a directory (not copied)) \\?\C:\Users\Brian\Documents\Code\nw-react-example\dist\app        

Expected/Proposed Behaviour

Get rid of the globbing stuff or fix it so it actually works. If the solution is to add each file/directory inside "app" individually, that's unacceptable.

Additional Info

  • Package version: 4.1.1

Maybe, if we add recursive option to the cp function at line 50 in /src/bld/build.js, it should work.

Like this:

42    await cp(
43        file,
44        resolve(
45           outDir,
46           platform !== "osx"
47               ? "package.nw"
48               : "nwjs.app/Contents/Resources/app.nw",
49               filePath,
50        ),{ recursive: true }
51   );

I was testing locally and it works for me on Windows

Maybe, if we add recursive option to the cp function at line 50 in /src/bld/build.js, it should work.

This still only works for relative paths and would also fail in some glob cases (e.g. somedir/ would include all of the directory instead of just the empty directory).

I believe @tharatau is adding a --no-glob parameter (or something similar), which solves my use-case but somebody will need to spend a lot of time to get globbing to actually work properly.

I'm happy to close this, now that we have glob: false. I'll never use globbing, so my needs are met.

That said, I doubt files are copied correctly in all cases with globbing enabled. Somebody should verify before closing this issue (or open a new one).

Cool, tracking file glob issue in #836