Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntaxhighlighter - Building: loadReposFromCache(...).error is not a function

I am trying to use the plugin SyntaxHighlighter v4, but I cannot get the build process to work!

Following the instructions here, I get the following error:

$ ./node_modules/gulp/bin/gulp.js setup-project
[10:12:20] Requiring external module babel-register
[10:12:20] Using gulpfile C:\git\syntaxhighlighter\gulpfile.babel.js
[10:12:20] Starting 'setup-project:clone-repos'...
[10:12:20] 'setup-project:clone-repos' errored after 1.96 ms
[10:12:20] TypeError: loadReposFromCache(...).error is not a function
    at loadRepos (C:/git/syntaxhighlighter/build/setup-project.js:39:48)
    at Gulp.<anonymous> (C:/git/syntaxhighlighter/build/setup-project.js:48:5)
    at module.exports (C:\git\syntaxhighlighter\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:134:8)
    at C:\git\syntaxhighlighter\node_modules\gulp\bin\gulp.js:129:20
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:606:11)
(node:2532) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, open 'C:\git\syntaxhighlighter\.projects-cache.json'

It seems not to be importing the github repository files to the /repos/ directory. Can I do this manually somehow? Is there another way to get this to build so I can use it? Or even find the built files like in v3?

Here is the function that's failing in build/setup-project.js

gulp.task('setup-project:clone-repos', 'Clones all repositories from 
  SyntaxHighlighter GitHub organization', () =>
    loadRepos()
      .then(R.filter(repo => !fs.existsSync(pathToRepo(repo))))
      .then(R.filter(repo => repo.name !== 'syntaxhighlighter'))
      .then(R.map(R.curry(cloneRepo)))
      .then(Promise.all)
);

Tracing backward we see:

const loadReposFromCache = () => fs.readFile.promise(REPOS_CACHE, 'utf8').then(JSON.parse);
const loadRepos = () => loadReposFromCache().error(loadReposFromGitHub).then(R.map(R.pick(['clone_url', 'name'])));

function loadReposFromGitHub() {
  const request = require('request');

  const opts = {
    url: 'https://api.github.com/orgs/syntaxhighlighter/repos?per_page=300',
    json: true,
    headers: { 'User-Agent': 'node.js' },
  };

  return new Promise((resolve, reject) =>
    request(opts, (err, response) => {
      if (err) return reject(err);
      const json = response.body;
      fs.writeFile(REPOS_CACHE, JSON.stringify(json, null, 2));
      resolve(json);
    })
  );
}
like image 520
mhatch Avatar asked Nov 22 '17 15:11

mhatch


2 Answers

There are a couple of issues in the build code for that project.

For the specific issue here, the Songbird wrapper on Bluebird promises doesn't seem to match up any more - hence the ".error is not a function" (on songbird, but ok on bluebird).

So replace .error with .catch or replace require('songbird') with require('bluebird')

In either case, that's just the start of your build woes...

I've added this to the project's issue tracking anyway, but here's what I did to get it to buiid: https://github.com/karljacuncha/syntaxhighlighter/commit/dc015fa299d4d249e8518664e205a838c55372cf

like image 80
karljacuncha Avatar answered Oct 18 '22 21:10

karljacuncha


The build broke again (April 2021). I forked the project from karljacuncha's answer and changed the call for fs.writeFile to fs.writeFileSync

https://github.com/BartJolling/syntaxhighlighter/commit/7dbd08203cba8ef3be72cbe1abbfb3475be19ef4

I also included other fixes I found in the larger community and I fixed the usage of the -output parameter as well.

like image 45
Bart Jolling Avatar answered Oct 18 '22 21:10

Bart Jolling