personium / personium-engine

Additional module for personium-core to enable server-side JavaScript execution.
Apache License 2.0
16 stars 7 forks source link

【contains incompatible】Using Rhino Require function. #148

Open yoh1496 opened 3 years ago

yoh1496 commented 3 years ago

This PR make you be able to use commonjs features. But it contains imcompatibility with old version. Please review carefully.

Before

You have to write module name to import your engine script. For example,

function(requrest) {
  const util = require("testCommon");
}

And the imported script must be written in "Engine Script" specific rules.

After

You can write import line like below.

function(request) {
  const util = require("./textCommon");
}

And you can write script in common rules.

yoh1496 commented 3 years ago

This feature is very useful!

image

I could import ordinal library without any editing. (for example: xpath) Of course, the intellisense work because it is same as requireJS. And maybe, it is useful to run tests.

xmldom needed to transpile with rollup, but you can import them without editing.

tochi-y commented 3 years ago

@yoh1496 Thank you for creating a Pull Request. Please let me confirm the behavior after the correction just in case. My understanding is as follows, is it correct?

Before

// The following code works
const util = require("testCommon");

// The following code does not work
const util = require("./testCommon");

After

// The following code does not work
const util = require("testCommon");

// The following code works
const util = require("./testCommon");

As you said, I think require(./testCommon) is correct in CommonJS.

yoh1496 commented 3 years ago

Yes, you are right.

But the main part of change is switching Require module which is hand-made in Personium community to Rhino module.