tschaub / gh-pages

General purpose task for publishing files to a gh-pages branch on GitHub
https://www.npmjs.com/package/gh-pages
MIT License
3.26k stars 191 forks source link

Error: spawn ENAMETOOLONG #585

Open Krinopotam opened 2 weeks ago

Krinopotam commented 2 weeks ago

After updating to version 6.2.0, when I call the gh-pages --nojekyll -d deploy command, I get the following error:

Error: spawn ENAMETOOLONG
    at ChildProcess.spawn (node:internal/child_process:421:11)
    at Object.spawn (node:child_process:761:9)
    at d:\projects\@krinopotam\ui-kit\node_modules\gh-pages\lib\git.js:30:22
    at new Promise (<anonymous>)
    at spawn (d:\projects\@krinopotam\ui-kit\node_modules\gh-pages\lib\git.js:29:10)
    at Git.exec (d:\projects\@krinopotam\ui-kit\node_modules\gh-pages\lib\git.js:69:10)
    at Git.rm (d:\projects\@krinopotam\ui-kit\node_modules\gh-pages\lib\git.js:146:15)
    at d:\projects\@krinopotam\ui-kit\node_modules\gh-pages\lib\index.js:180:22
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
darainfo commented 1 week ago

It seems to be an error occurring on Windows. I have temporarily resolved it by modifying the file as follows:

By replacing the Git.prototype.rm section in the node_modules\gh-pages\lib\git.js file with the code below, the issue is resolved.

const os = require('os');
/**
 * Remove all unversioned files.
 * @param {string | Array<string>} files Files argument.
 * @return {Promise} A promise.
 */
Git.prototype.rm = function (files) {
  if (!Array.isArray(files)) {
    files = [files];
  }

  if(os.platform() ==='win32'){
    return separateRm(this, files);
  } else{
    return this.exec('rm', '--ignore-unmatch', '-r', '-f', ...files);
  }
};

/**
 * files separate deletion
 * 
 * @param {Git} thisObj git
 * @param {Array} files files Files argument
 * @returns 
 */
async function separateRm (thisObj , files ) {

  const limitFileCount = 100;
  const fileLength = files.length;
  let loopCount = Math.ceil(fileLength /limitFileCount);

  let startIdx = 0;
  const allExecResult =[];
  let endIdx =limitFileCount; 
  for(let i =0;i <loopCount; i++){

    if(endIdx > fileLength){
      endIdx = fileLength-1;
    }

    let rmFiles = files.slice(startIdx, endIdx);
    allExecResult.push(await thisObj.exec('rm', '--ignore-unmatch', '-r', '-f', ...rmFiles));
    startIdx  = endIdx;
    endIdx = endIdx+ limitFileCount;
  }

  return allExecResult[allExecResult.length-1];
}

586