jitsi / js-utils

Utilities for Jitsi JS projects
Apache License 2.0
32 stars 60 forks source link

Mark the package as module (instead of commonjs) #43

Closed ghost closed 3 years ago

ghost commented 3 years ago

Origin

While working on a project for Mattermost Hackathon 2020, I encountered this issue. I used a bundler to solve this issue, but I think this will help future dependants of this package.

Purpose:

Node.js now has an experimental support for marking package type as es module. If we mark this package es module, other node.js es module projects that depend upon this package, can start using es imports directly, like this:

import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random/roomNameGenerator'

Reference:

See https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_package_json_type_field

ghost commented 3 years ago

We have a couple of complications. Need input @saghul

  1. transport/postis.js is in commonjs format
    1. We can rename it to transport/postis.cjs
    2. We can use export default function Postis(options) { instead of module.exports = Postis;
  2. npm run lint -> eslint . -> .eslintrc.js is in commonjs format (and eslint as well)
    1. We can rename .eslintrc.js to .eslintrc.cjs

Note:

official docs suggest this:

JavaScript (ESM) - use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json. Note that ESLint does not support ESM configuration at this time.

ghost commented 3 years ago

Also, we need to update eslint to support .eslintrc.cjs.

saghul commented 3 years ago

https://github.com/jitsi/js-utils/pull/51