Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ES module compatibility #72

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

feat: ES module compatibility #72

wants to merge 12 commits into from

Conversation

ecarriou
Copy link
Member

@ecarriou ecarriou commented Oct 31, 2022

What has been done

  • System Runtime is now an ES module. You can now use the JavaScript native import API to import the library from a CDN:
<script type="module">
  import runtime from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/system-runtime.js'
  const system = runtime.system('mySystem')
  // ...
</script>
  • You can now use the JavaScript native import API to import the library in nodeJS:
  import runtime from 'system-runtime'  
  const system = runtime.system('mySystem')
  // ...
  • Breaking change: we can not use require in the code. We have this breaking change because your scripts are evaluated inside System Runtime which is now an ES module.
  • Breaking change: we change the way we access collections with $db internal component. Example:
// before
$db.Person.find()

// now
$db.collections.Person.find()
  • We can now use dynamic import for event:
Person.on('anEvent', async (val) => {
  const newValue = await import('../address.js')
  this.address(newValue.default)
})
  • Added Mocha and Cypress for server and frontend tests.
  • Added Rollup for building the frontend package / source map.
  • Improved DX: use of prettier, eslint, format/check on commit.

How to test the PR

Test in HTML

  • install the lib in your HTML:
<script type="module">
  import runtime from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/system-runtime.js'
</script>
  • play with the library:
<script type="module">
  import runtime from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/system-runtime.js'
  console.log(runtime.version())
</script>

Test with nodeJS

  • create a JavaScript project that is ES compliant (i.e. with "type":"module" in the package.json),
  • Install the lib with npm i [email protected].

You will have something like that in your package.json:

{
  "type":"module",
  "dependencies": {
    "system-runtime": "^6.0.0-beta.5"
  }
}
  • Create a JavaScript file and import system-runtime library:
import runtime from 'system-runtime'
  • play with the library:
console.log(runtime.version())

TODO

  • remove call to require API to load system.
  • clean system.
  • tests with System Designer.

@ecarriou ecarriou marked this pull request as draft October 31, 2022 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant