Unable to correctly get filepaths with statSync in nexe built file

45 Views Asked by At

I have the bellow function:

...
function getAllFiles(dirPath, echo = true) {
  const arrayOfFiles = [];

  if (echo) {
    console.log("Diretório mapeado: " + dirPath);
  }

  const walk = function(currentDirPath) {
    const files = fs.readdirSync(currentDirPath);

    for (const name of files) {
      const filePath = path.join(currentDirPath, name);
      const stat = fs.statSync(filePath);

      if (stat.isFile()) {
        arrayOfFiles.push(filePath);
      } else if (stat.isDirectory()) {
        walk(filePath);
      }
    }
  };

  walk(dirPath);
  return arrayOfFiles;
}

...

When I use it directly from my workspace with node . it works perfectly, but after nexe build it get to me a list of non existent files in the folder like bellow:

[
  'C:\\myproject\\updater\\index.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\index.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\abort.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\async.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\defer.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\iterate.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\state.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\lib\\terminator.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\package.json',
  'C:\\myproject\\updater\\node_modules\\asynckit\\parallel.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\serial.js',
  'C:\\myproject\\updater\\node_modules\\asynckit\\serialOrdered.js',
  'C:\\myproject\\updater\\node_modules\\axios\\dist\\node\\axios.cjs',
  'C:\\myproject\\updater\\node_modules\\axios\\package.json',
  'C:\\myproject\\updater\\node_modules\\balanced-match\\index.js',
  'C:\\myproject\\updater\\node_modules\\balanced-match\\package.json',
  'C:\\myproject\\updater\\node_modules\\brace-expansion\\index.js',
  'C:\\myproject\\updater\\node_modules\\brace-expansion\\package.json',
  'C:\\myproject\\updater\\node_modules\\combined-stream\\lib\\combined_stream.js',
  'C:\\myproject\\updater\\node_modules\\combined-stream\\package.json',
  'C:\\myproject\\updater\\node_modules\\concat-map\\index.js',
  'C:\\myproject\\updater\\node_modules\\concat-map\\package.json',
  'C:\\myproject\\updater\\node_modules\\delayed-stream\\lib\\delayed_stream.js',
  'C:\\myproject\\updater\\node_modules\\delayed-stream\\package.json',
  'C:\\myproject\\updater\\node_modules\\follow-redirects\\debug.js',
  'C:\\myproject\\updater\\node_modules\\follow-redirects\\index.js',
  'C:\\myproject\\updater\\node_modules\\follow-redirects\\package.json',
  'C:\\myproject\\updater\\node_modules\\form-data\\lib\\form_data.js',
  'C:\\myproject\\updater\\node_modules\\form-data\\lib\\populate.js',
  'C:\\myproject\\updater\\node_modules\\form-data\\package.json',
  'C:\\myproject\\updater\\node_modules\\fs.realpath\\index.js',
  'C:\\myproject\\updater\\node_modules\\fs.realpath\\old.js',
  'C:\\myproject\\updater\\node_modules\\fs.realpath\\package.json',
  'C:\\myproject\\updater\\node_modules\\glob\\common.js',
  'C:\\myproject\\updater\\node_modules\\glob\\glob.js',
  'C:\\myproject\\updater\\node_modules\\glob\\package.json',
  ...
]

It looks like the function are being able to map the files inside the exe or the function is mapping an incorrect place when executed by the .exe

Can anyone help me with this?

this is my builder

const path = require('path');
const { compile } = require('nexe')

compile({
  input: './index.js',
  name:"./routine.exe",
  ico:path.join(__dirname, 'routine.ico'),
  output:"..\\Builded\\routine.exe",
  build: true,
  loglevel:'verbose'
}).then(() => {
  console.log('success')
})
.catch(e=>{
    console.log(e)
})

I'm copying manualy the file routine.exe to the folder I want.

In the code, the function is used as bellow:

let installationPath = "C:\myproject"
const fileListPaths = getAllFiles(installationPath);

Thnks you all!

I've try to change permissions, use fs.promises.readdir, use another folder, clear nexe and rebuild. I expect to get the list of all the folders in the especified file so I can map if there are any intruder file on the folder.

0

There are 0 best solutions below