Ncc: Doesn't work with modules depending on highlights e.g marky-markdown

Created on 2 Jan 2019  路  2Comments  路  Source: vercel/ncc

When including marky-markdown it compiles but it doesn't include the required gen/grammar.json from highlights and then fails on runtime.

It gets loaded here and here

    Highlights.prototype.loadGrammarsSync = function() {
      var filePath, grammar, grammarPath, grammarsPath, k, len, ref, ref1;
      if (this.registry.grammars.length > 1) {
        return;
      }
      if (typeof this.includePath === 'string') {
        if (fs.isFileSync(this.includePath)) {
          this.registry.loadGrammarSync(this.includePath);
        } else if (fs.isDirectorySync(this.includePath)) {
          ref = fs.listSync(this.includePath, ['cson', 'json']);
          for (k = 0, len = ref.length; k < len; k++) {
            filePath = ref[k];
            this.registry.loadGrammarSync(filePath);
          }
        }
      }
      grammarsPath = path.join(__dirname, '..', 'gen', 'grammars.json');
      ref1 = JSON.parse(fs.readFileSync(grammarsPath));
      for (grammarPath in ref1) {
        grammar = ref1[grammarPath];
        if (this.registry.grammarForScopeName(grammar.scopeName) != null) {
          continue;
        }
        grammar = this.registry.createGrammar(grammarPath, grammar);
        this.registry.addGrammar(grammar);
      }
    };

Highlights.prototype._loadGrammarsJSON = function(cb) {
      var grammarsPath;
      grammarsPath = path.join(__dirname, '..', 'gen', 'grammars.json');
      return fs.readFile(grammarsPath, function(err, contents) {
        var error;
        try {
          return cb(false, JSON.parse(contents));
        } catch (error) {
          err = error;
          return cb(err);
        }
      });
    };
package issue

Most helpful comment

Thanks for posting, I had a look and the problem here is that the path binding is being populated with the following wrapper:

(function () {
  var ..., path, ...;
  path = require('path');


});

Currently we only support detections of var path = require('path') in the top scope.

This is just a matter of extending the detection of the path require to this wrapper case, which should be straightforward it just has to be done carefully to properly take into account shadowing (eg what happens when path means something else in the outer wrapper).

All 2 comments

Thanks for posting, I had a look and the problem here is that the path binding is being populated with the following wrapper:

(function () {
  var ..., path, ...;
  path = require('path');


});

Currently we only support detections of var path = require('path') in the top scope.

This is just a matter of extending the detection of the path require to this wrapper case, which should be straightforward it just has to be done carefully to properly take into account shadowing (eg what happens when path means something else in the outer wrapper).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drewolson picture drewolson  路  3Comments

hrueger picture hrueger  路  4Comments

benseitz picture benseitz  路  5Comments

omar2205 picture omar2205  路  5Comments

tmtron picture tmtron  路  5Comments