Skip to content

Make js-interpreter ready for node and NPM #267

Open
@mercmobily

Description

@mercmobily

I am currently maintaining https://github.com/mobily-enterprises/js-interpreter. It's available on npm as js-interpreter-npm. All it does, it repackage acorn.js and js-interpreter.js, but adding this at the BEGINNING of js-interpreter.js:

var globalThis
if (typeof exports === 'undefined') {
  globalThis = window
} else {
  globalThis = exports
  globalThis.acorn = require('./acorn.js')

  // This is important as JS-Interpreter assumes that the "global" scope
  // includes primitive variable types
  globalThis.String = String
  globalThis.Date = Date
  globalThis.Boolean = Boolean
  globalThis.Number = Number
  globalThis.RegExp = RegExp
}

This essentially makes sure that the module works 100% both when loaded in the browser, and when it's "required" by node.
Please note that I had to add those primitive data types to the "global scope" for node.

It is a bit of a hack, but it works. Please note that I carefully avoided complex "building" steps with webpack, etc.

I would love some input on this. Really, I just have a question:

  1. are you guys willing to include some changes so that js-interpreter is ready for node, rather than people using my silly wrapper that becomes outdated as you go further with development?

  2. are you guys willing and happy to publish to NPM, if you do go with (1)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions