esm-sync 3.3.3-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/LICENSE +23 -0
- package/README.md +261 -0
- package/esm/loader.js +1 -0
- package/esm.js +223 -0
- package/index.js +4 -0
- package/package.json +124 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright esm contributors
|
|
4
|
+
|
|
5
|
+
Based on reify, copyright Ben Newman <https://github.com/benjamn/reify>
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# @nktnet1/esm
|
|
2
|
+
|
|
3
|
+
> _Part of [HTTP Toolkit](https://nktnet1.com): powerful tools for building, testing & debugging HTTP(S)_
|
|
4
|
+
|
|
5
|
+
**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
|
+
|
|
7
|
+
* Assorted updates from the [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 v21), and supporting `node:*` imports.
|
|
8
|
+
* 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 unresolveable (reporting "Cannot find module", even though `import()` works correctly).
|
|
10
|
+
|
|
11
|
+
Install
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Run `npm i @nktnet1/esm` or `yarn add @nktnet1/esm`.
|
|
15
|
+
|
|
16
|
+
Getting started
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
There are two ways to enable `@nktnet1/esm`.
|
|
20
|
+
|
|
21
|
+
1. Enable `@nktnet1/esm` for packages:
|
|
22
|
+
|
|
23
|
+
Use `@nktnet1/esm` to load the main ES module and export it as CommonJS.
|
|
24
|
+
|
|
25
|
+
__index.js__
|
|
26
|
+
```js
|
|
27
|
+
// Set options as a parameter, environment variable, or rc file.
|
|
28
|
+
require = require("@nktnet1/esm")(module/*, options*/)
|
|
29
|
+
module.exports = require("./main.js")
|
|
30
|
+
```
|
|
31
|
+
__main.js__
|
|
32
|
+
```js
|
|
33
|
+
// ESM syntax is supported.
|
|
34
|
+
export {}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Enable `@nktnet1/esm` for local runs:
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
node -r @nktnet1/esm main.js
|
|
41
|
+
```
|
|
42
|
+
:bulb: Omit the filename to enable `@nktnet1/esm` in the REPL.
|
|
43
|
+
|
|
44
|
+
Features
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
: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 `@nktnet1/esm` options.
|
|
49
|
+
|
|
50
|
+
Out of the box `@nktnet1/esm` just works, no configuration necessary, and supports:
|
|
51
|
+
|
|
52
|
+
* Passing all applicable [test262](https://github.com/tc39/test262) compliance tests
|
|
53
|
+
* [`import`](https://ponyfoo.com/articles/es6-modules-in-depth#import)/[`export`](https://ponyfoo.com/articles/es6-modules-in-depth#export)
|
|
54
|
+
* [`import.meta`](https://github.com/tc39/proposal-import-meta)
|
|
55
|
+
* [Dynamic `import`](https://github.com/tc39/proposal-dynamic-import)
|
|
56
|
+
* [Live bindings](https://ponyfoo.com/articles/es6-modules-in-depth#bindings-not-values)
|
|
57
|
+
* [File URI scheme](https://en.wikipedia.org/wiki/File_URI_scheme)
|
|
58
|
+
* Node `stdin`, [`--eval`](https://nodejs.org/api/cli.html#cli_e_eval_script), [`--print`](https://nodejs.org/api/cli.html#cli_p_print_script) flags
|
|
59
|
+
* Node [`--check`](https://nodejs.org/api/cli.html#cli_c_check) flag _(Node 10+)_
|
|
60
|
+
|
|
61
|
+
Options
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
Specify options with one of the following:
|
|
65
|
+
|
|
66
|
+
* `"esm"` field in `package.json`
|
|
67
|
+
* CJS/ESM in an `.esmrc.js`, `.esmrc.cjs`, or `.esmrc.mjs` file
|
|
68
|
+
* [JSON6](https://github.com/d3x0r/json6) in an `.esmrc` or `.esmrc.json` file
|
|
69
|
+
* JSON6 or file path in the `ESM_OPTIONS` environment variable
|
|
70
|
+
* `ESM_DISABLE_CACHE` environment variable
|
|
71
|
+
|
|
72
|
+
<table>
|
|
73
|
+
<tr>
|
|
74
|
+
<td colspan="2"><code>{</code></td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr>
|
|
77
|
+
<td valign="top"><code>"cjs":true</code></td>
|
|
78
|
+
<td>
|
|
79
|
+
<p>A boolean or object for toggling CJS features in ESM.</p>
|
|
80
|
+
<details>
|
|
81
|
+
<summary>Features</summary>
|
|
82
|
+
<table>
|
|
83
|
+
<tr>
|
|
84
|
+
<td colspan="2"><code>{</code></td>
|
|
85
|
+
</tr>
|
|
86
|
+
<tr>
|
|
87
|
+
<td valign="top"><code>"cache":true</code></td>
|
|
88
|
+
<td>
|
|
89
|
+
<p>A boolean for storing ES modules in <code>require.cache</code>.</p>
|
|
90
|
+
</td>
|
|
91
|
+
</tr>
|
|
92
|
+
<tr>
|
|
93
|
+
<td valign="top"><code>"esModule":true</code></td>
|
|
94
|
+
<td>
|
|
95
|
+
<p>A boolean for <code>__esModule</code> interoperability.</p>
|
|
96
|
+
</td>
|
|
97
|
+
</tr>
|
|
98
|
+
<tr>
|
|
99
|
+
<td valign="top"><code>"extensions":true</code></td>
|
|
100
|
+
<td>
|
|
101
|
+
<p>A boolean for respecting <code>require.extensions</code> in ESM.</p>
|
|
102
|
+
</td>
|
|
103
|
+
</tr>
|
|
104
|
+
<tr>
|
|
105
|
+
<td valign="top"><code>"mutableNamespace":true</code></td>
|
|
106
|
+
<td>
|
|
107
|
+
<p>A boolean for mutable <a href="https://ponyfoo.com/articles/es6-modules-in-depth#import-all-the-things">namespace objects</a>.</p>
|
|
108
|
+
</td>
|
|
109
|
+
</tr>
|
|
110
|
+
<tr>
|
|
111
|
+
<td valign="top"><code>"namedExports":true</code></td>
|
|
112
|
+
<td>
|
|
113
|
+
<p>A boolean for <a href="https://ponyfoo.com/articles/es6-modules-in-depth#importing-named-exports">importing named exports</a> of CJS modules.</p>
|
|
114
|
+
</td>
|
|
115
|
+
</tr>
|
|
116
|
+
<tr>
|
|
117
|
+
<td valign="top"><code>"paths":true</code></td>
|
|
118
|
+
<td>
|
|
119
|
+
<p>A boolean for following CJS <a href="https://github.com/nodejs/node-eps/blob/master/002-es-modules.md#432-removal-of-non-local-dependencies">path rules</a> in ESM.</p>
|
|
120
|
+
</td>
|
|
121
|
+
</tr>
|
|
122
|
+
<tr>
|
|
123
|
+
<td valign="top"><code>"vars":true</code></td>
|
|
124
|
+
<td>
|
|
125
|
+
<p>A boolean for <code>__dirname</code>, <code>__filename</code>, and <code>require</code> in ESM.</p>
|
|
126
|
+
</td>
|
|
127
|
+
</tr>
|
|
128
|
+
<tr>
|
|
129
|
+
<td valign="top"><code>"dedefault":false</code></td>
|
|
130
|
+
<td>
|
|
131
|
+
<p>A boolean for requiring ES modules without the dangling <code>require().default</code>.</p>
|
|
132
|
+
</td>
|
|
133
|
+
</tr>
|
|
134
|
+
<tr>
|
|
135
|
+
<td valign="top"><code>"topLevelReturn":false</code></td>
|
|
136
|
+
<td>
|
|
137
|
+
<p>A boolean for top-level <code>return</code> support.</p>
|
|
138
|
+
</td>
|
|
139
|
+
</tr>
|
|
140
|
+
<tr>
|
|
141
|
+
<td colspan="2"><code>}</code></td>
|
|
142
|
+
</tr>
|
|
143
|
+
</table>
|
|
144
|
+
</details>
|
|
145
|
+
</td>
|
|
146
|
+
</tr>
|
|
147
|
+
<tr>
|
|
148
|
+
<td valign="top"><code>"mainFields":["main"]</code></td>
|
|
149
|
+
<td>
|
|
150
|
+
<p>An array of fields checked when importing a package.</p>
|
|
151
|
+
</td>
|
|
152
|
+
</tr>
|
|
153
|
+
<tr>
|
|
154
|
+
<td valign="top"><code>"mode":"auto"</code></td>
|
|
155
|
+
<td>
|
|
156
|
+
<p>A string mode:</p>
|
|
157
|
+
<ul>
|
|
158
|
+
<li><code>"auto"</code> detect files with <code>import</code>, <code>import.meta</code>, <code>export</code>,<br><a href="https://github.com/tc39/proposal-modules-pragma"><code>"use module"</code></a>, or <code>.mjs</code> as ESM.</li>
|
|
159
|
+
<li><code>"all"</code> files besides those with <code>"use script"</code> or <code>.cjs</code> are treated as ESM.</li>
|
|
160
|
+
<li><code>"strict"</code> to treat <strong>only</strong> <code>.mjs</code> files as ESM.</li>
|
|
161
|
+
</ul>
|
|
162
|
+
</td>
|
|
163
|
+
</tr>
|
|
164
|
+
<tr>
|
|
165
|
+
<td valign="top"><code>"await":false</code></td>
|
|
166
|
+
<td>
|
|
167
|
+
<p>A boolean for <a href="https://github.com/tc39/proposal-top-level-await">top-level <code>await</code></a> in modules without ESM exports. <em>(Node 10+)</em></p>
|
|
168
|
+
</td>
|
|
169
|
+
</tr>
|
|
170
|
+
<tr>
|
|
171
|
+
<td valign="top"><code>"force":false</code></td>
|
|
172
|
+
<td>
|
|
173
|
+
<p>A boolean to apply these options to all module loads.</p>
|
|
174
|
+
</td>
|
|
175
|
+
</tr>
|
|
176
|
+
<tr>
|
|
177
|
+
<td valign="top"><code>"wasm":false</code></td>
|
|
178
|
+
<td>
|
|
179
|
+
<p>A boolean for <a href="https://nodejs.org/api/globals.html#globals_webassembly">WebAssembly</a> module support. <em>(Node 8+)</em></p>
|
|
180
|
+
</td>
|
|
181
|
+
</tr>
|
|
182
|
+
<tr>
|
|
183
|
+
<td colspan="2"><code>}</code></td>
|
|
184
|
+
</tr>
|
|
185
|
+
</table>
|
|
186
|
+
|
|
187
|
+
DevOpts
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
<table>
|
|
191
|
+
<tr>
|
|
192
|
+
<td colspan="2"><code>{</code></td>
|
|
193
|
+
</tr>
|
|
194
|
+
<tr>
|
|
195
|
+
<td valign="top"><code>"cache":true</code></td>
|
|
196
|
+
<td>
|
|
197
|
+
<p>A boolean for toggling cache creation or a cache directory path.</p>
|
|
198
|
+
</td>
|
|
199
|
+
</tr>
|
|
200
|
+
<tr>
|
|
201
|
+
<td valign="top"><code>"sourceMap":false</code></td>
|
|
202
|
+
<td>
|
|
203
|
+
<p>A boolean for including inline source maps.</p>
|
|
204
|
+
</td>
|
|
205
|
+
</tr>
|
|
206
|
+
<tr>
|
|
207
|
+
<td colspan="2"><code>}</code></td>
|
|
208
|
+
</tr>
|
|
209
|
+
</table>
|
|
210
|
+
|
|
211
|
+
Tips
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Bundling
|
|
215
|
+
|
|
216
|
+
* For bundlers like [`browserify`](http://browserify.org/)+[`esmify`](https://github.com/mattdesl/esmify),
|
|
217
|
+
[`parcel-bundler`](https://parceljs.org/), and [`webpack`](https://webpack.js.org/)
|
|
218
|
+
add a `"module"` field to `package.json` pointing to the main ES module.
|
|
219
|
+
```json
|
|
220
|
+
"main": "index.js",
|
|
221
|
+
"module": "main.js"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
:bulb: This is automagically done with `npm init esm` or `yarn create esm`.
|
|
225
|
+
|
|
226
|
+
### Extensions
|
|
227
|
+
|
|
228
|
+
* Enable `@nktnet1/esm` for [`wallaby.js`](https://wallabyjs.com/) following their
|
|
229
|
+
[integration example](https://wallabyjs.com/docs/integration/node.html#es-modules).
|
|
230
|
+
|
|
231
|
+
### Loading
|
|
232
|
+
|
|
233
|
+
* Load `@nktnet1/esm` before loaders/monitors like
|
|
234
|
+
[`@babel/register`](https://babeljs.io/docs/en/next/babel-register.html),
|
|
235
|
+
[`newrelic`](https://github.com/newrelic/node-newrelic),
|
|
236
|
+
[`sqreen`](https://docs.sqreen.io/sqreen-for-nodejs/getting-started-2/), and
|
|
237
|
+
[`ts-node`](https://github.com/TypeStrong/ts-node#programmatic).
|
|
238
|
+
|
|
239
|
+
* Load `@nktnet1/esm` for [`jasmine`](https://jasmine.github.io/) using the
|
|
240
|
+
[`"helpers"`](https://jasmine.github.io/setup/nodejs.html#configuration)
|
|
241
|
+
field in `jasmine.json`:
|
|
242
|
+
```json
|
|
243
|
+
"helpers": [
|
|
244
|
+
"node_modules/@nktnet1/esm"
|
|
245
|
+
]
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
* Load `@nktnet1/esm` with “node-args" options of:<br>
|
|
249
|
+
- [`pm2`](https://pm2.io/doc/en/runtime/reference/pm2-cli/#pm2-flags): `--node-args="-r @nktnet1/esm"`
|
|
250
|
+
|
|
251
|
+
* Load `@nktnet1/esm` with “require” options of
|
|
252
|
+
[`ava`](https://github.com/avajs/ava/blob/master/docs/recipes/es-modules.md),
|
|
253
|
+
[`mocha`](https://mochajs.org/#-require-module-r-module),
|
|
254
|
+
[`nodemon`](https://nodemon.io/),
|
|
255
|
+
[`nyc`](https://github.com/istanbuljs/nyc#require-additional-modules),
|
|
256
|
+
[`qunit`](https://github.com/qunitjs/qunit/releases/tag/2.6.0),
|
|
257
|
+
[`tape`](https://github.com/substack/tape#preloading-modules), and
|
|
258
|
+
[`webpack`](https://webpack.js.org/api/cli/#config-options).
|
|
259
|
+
|
|
260
|
+
:bulb: Builtin `require` cannot sideload `.mjs` files. However, `.js` files
|
|
261
|
+
can be sideloaded or `.mjs` files may be loaded with dynamic `import`.
|