Skip to content

Advice required for working with npm packages that break Hem conventions #73

@louismrose

Description

@louismrose

Hi,

Firstly, thank-you for Hem: a fantastic tool that significantly simplifies my workflow!

I'm having a little bit of trouble understanding how I can use Hem with npm packages that don't have an index.js file. For example, I'm trying to use Hem to allow my application to require files from the codemirror npm package. I see that codemirror has the following package.json:

{
  "name": "codemirror",
  "version": "3.14.1",
  "main": "lib/codemirror.js",
  "directories": {
    "lib": "./lib"
  }
  ...
}

I have a number of questions related to this:

  1. When I try to require('codemirror'), Hem can't find the module and I receive module 'codemirror' not found. This makes sense as there is no index.js file (and I see that Hem's stitch.eco looks for the path of an index file). Instead, I see that a require('codemirror/lib/codemirror') does work. Is there any workaround for this so that I can use require('codemirror')?
  2. lib/codemirror.js exports a global variable onto window, rather than onto module.exports, like this: window.CodeMirror = (function() { ... I see that Hem expects the CommonJS style, and so won't pick up this variable. I can change lib/codemirror.js to store the variable on module.exports, but I'd prefer not to change code that I don't own. Is there any workaround for this?
  3. The codemirror npm package includes a number of additional JS files that I'd like to include, but they rely on the presence of the CodeMirror variable. I can issue a separate require statement for each: require('codemirror/lib/codemirror') then a require('codemirror/modes/javascript/javascript'). However, this fails because codemirror/modes/javascript/javascript assumes that it will be able to access the CodeMirror global variable, and I believe that Hem might be requiring files into a "sandboxed" environment where there is no access to other variables. The following doesn't work either: CodeMirror = require('codemirror/lib/codemirror') followed by a require('codemirror/modes/javascript/javascript'). Any ideas?
  4. The codemirror npm package includes a number of CSS files that I'd like to include in my application. Is there any support for this in Hem?

I'm using Spine as my application framework, and would prefer to use the npm dependencies rather than plain-old javascript files (i.e. Hem libs) if possible.

If needed and of interest to the Hem developers, I would be happy to work on a patch to support any of the features above (though I would require a little help in designing solutions).

Thank-you in advance for answers or hints towards solving any of these questions.

Best,
Louis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions