esm-sync 3.3.3-beta.2 → 3.3.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -22
- package/esm/loader.js +29123 -1
- package/package.json +23 -24
package/README.md
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
> _Part of [HTTP Toolkit](https://nktnet1.com): powerful tools for building, testing & debugging HTTP(S)_
|
|
1
|
+
# esm-sync
|
|
4
2
|
|
|
5
3
|
**This is a forked version of the [esm package](https://www.npmjs.com/package/esm)**: the brilliantly simple, babel-less, bundle-less ECMAScript module loader (which is now unmaintained). This fork includes:
|
|
6
4
|
|
|
7
|
-
* Assorted updates from
|
|
5
|
+
* Assorted updates from [@httptoolkit/esm](https://github.com/httptoolkit/esm) and [esm-wallaby fork](https://www.npmjs.com/package/esm-wallaby), adding support for ES modules containing new ES syntax, supporting modern Node versions (at least up to v22), and supporting `node:*` imports.
|
|
8
6
|
* Support for modules that use the `const require = createRequire(...)` pattern (or declare any other global `require` variable) which are otherwise unusable with `esm`.
|
|
9
|
-
* Support for modules that use only an `exports` map in their package.json, without a `main` field, which are otherwise
|
|
7
|
+
* Support for modules that use only an `exports` map in their package.json, without a `main` field, which are otherwise unresolvable (reporting "Cannot find module", even though `import()` works correctly).
|
|
8
|
+
* Built-in types for use in TypeScript projects
|
|
10
9
|
|
|
11
10
|
Install
|
|
12
11
|
---
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
```sh
|
|
14
|
+
npm install esm-sync
|
|
15
|
+
```
|
|
15
16
|
|
|
16
17
|
Getting started
|
|
17
18
|
---
|
|
18
19
|
|
|
19
|
-
There are two ways to enable
|
|
20
|
+
There are two ways to enable `esm-sync`.
|
|
20
21
|
|
|
21
|
-
1. Enable
|
|
22
|
+
1. Enable `esm-sync` for packages:
|
|
22
23
|
|
|
23
|
-
Use
|
|
24
|
+
Use `esm-sync` to load the main ES module and export it as CommonJS.
|
|
24
25
|
|
|
25
26
|
__index.js__
|
|
26
27
|
```js
|
|
27
28
|
// Set options as a parameter, environment variable, or rc file.
|
|
28
|
-
require = require("
|
|
29
|
+
require = require("esm-sync")(module/*, options*/)
|
|
29
30
|
module.exports = require("./main.js")
|
|
30
31
|
```
|
|
31
32
|
__main.js__
|
|
@@ -34,20 +35,20 @@ There are two ways to enable `@nktnet1/esm`.
|
|
|
34
35
|
export {}
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
2. Enable
|
|
38
|
+
2. Enable `esm-sync` for local runs:
|
|
38
39
|
|
|
39
40
|
```shell
|
|
40
|
-
node -r
|
|
41
|
+
node -r esm-sync main.js
|
|
41
42
|
```
|
|
42
|
-
:bulb: Omit the filename to enable
|
|
43
|
+
:bulb: Omit the filename to enable `esm-sync` in the REPL.
|
|
43
44
|
|
|
44
45
|
Features
|
|
45
46
|
---
|
|
46
47
|
|
|
47
48
|
:clap: By default, :100: percent CJS interoperability is enabled so you can get stuff done.<br>
|
|
48
|
-
:lock: `.mjs` files are limited to basic functionality without support for
|
|
49
|
+
:lock: `.mjs` files are limited to basic functionality without support for `esm-sync` options.
|
|
49
50
|
|
|
50
|
-
Out of the box
|
|
51
|
+
Out of the box `esm-sync` just works, no configuration necessary, and supports:
|
|
51
52
|
|
|
52
53
|
* Passing all applicable [test262](https://github.com/tc39/test262) compliance tests
|
|
53
54
|
* [`import`](https://ponyfoo.com/articles/es6-modules-in-depth#import)/[`export`](https://ponyfoo.com/articles/es6-modules-in-depth#export)
|
|
@@ -225,30 +226,30 @@ Tips
|
|
|
225
226
|
|
|
226
227
|
### Extensions
|
|
227
228
|
|
|
228
|
-
* Enable
|
|
229
|
+
* Enable `esm-sync` for [`wallaby.js`](https://wallabyjs.com/) following their
|
|
229
230
|
[integration example](https://wallabyjs.com/docs/integration/node.html#es-modules).
|
|
230
231
|
|
|
231
232
|
### Loading
|
|
232
233
|
|
|
233
|
-
* Load
|
|
234
|
+
* Load `esm-sync` before loaders/monitors like
|
|
234
235
|
[`@babel/register`](https://babeljs.io/docs/en/next/babel-register.html),
|
|
235
236
|
[`newrelic`](https://github.com/newrelic/node-newrelic),
|
|
236
237
|
[`sqreen`](https://docs.sqreen.io/sqreen-for-nodejs/getting-started-2/), and
|
|
237
238
|
[`ts-node`](https://github.com/TypeStrong/ts-node#programmatic).
|
|
238
239
|
|
|
239
|
-
* Load
|
|
240
|
+
* Load `esm-sync` for [`jasmine`](https://jasmine.github.io/) using the
|
|
240
241
|
[`"helpers"`](https://jasmine.github.io/setup/nodejs.html#configuration)
|
|
241
242
|
field in `jasmine.json`:
|
|
242
243
|
```json
|
|
243
244
|
"helpers": [
|
|
244
|
-
"node_modules
|
|
245
|
+
"node_modules/esm-sync"
|
|
245
246
|
]
|
|
246
247
|
```
|
|
247
248
|
|
|
248
|
-
* Load
|
|
249
|
-
- [`pm2`](https://pm2.io/doc/en/runtime/reference/pm2-cli/#pm2-flags): `--node-args="-r
|
|
249
|
+
* Load `esm-sync` with “node-args" options of:<br>
|
|
250
|
+
- [`pm2`](https://pm2.io/doc/en/runtime/reference/pm2-cli/#pm2-flags): `--node-args="-r esm-sync"`
|
|
250
251
|
|
|
251
|
-
* Load
|
|
252
|
+
* Load `esm-sync` with “require” options of
|
|
252
253
|
[`ava`](https://github.com/avajs/ava/blob/master/docs/recipes/es-modules.md),
|
|
253
254
|
[`mocha`](https://mochajs.org/#-require-module-r-module),
|
|
254
255
|
[`nodemon`](https://nodemon.io/),
|