Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@std/esm

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@std/esm - npm Package Compare versions

Comparing version 0.19.1 to 0.19.2

52

index.js

@@ -1,51 +0,1 @@

/* eslint strict: off, node/no-unsupported-features: ["error", { version: 4 }] */
"use strict"
const fs = require("fs")
const path = require("path")
const util = require("util")
const vm = require("vm")
const zlib = require("zlib")
// Guard against mocked environments (e.g. Jest).
const useBuiltins = module.constructor.length > 1
const Module = useBuiltins ? module.constructor : require("module")
const stdMod = new Module(module.id, null)
const stdPath = path.resolve(__dirname, "esm.js.gz")
const stdReq = useBuiltins ? require : stdMod.require
stdMod.filename = __filename
stdMod.parent = module.parent
const content =
"(function(require,module,__shared__){" +
zlib.gunzipSync(fs.readFileSync(stdPath)) +
"\n})"
const scriptOptions = Object.create(null)
scriptOptions.filename = __filename
const compiled = vm.runInThisContext(content, scriptOptions)
function load() {
compiled(stdReq, stdMod, shared)
return stdMod.exports
}
function makeRequireFunction(mod, options) {
return load()(mod, options)
}
let shared
shared = load()
const descriptor = Object.create(null)
descriptor.value = () => "@std/esm enabled"
const inspectKey = util.inspect.custom || "inspect"
Object.defineProperty(makeRequireFunction, inspectKey, descriptor)
Object.freeze(makeRequireFunction)
module.exports = makeRequireFunction
"use strict";const e=require("fs"),r=require("path"),n=require("util"),t=require("vm"),u=require("zlib"),l=module.constructor.length>1,i=l?module.constructor:require("module"),o=new i(module.id,null),c=r.resolve(__dirname,"esm.js.gz"),s=l?require:e=>o.require(e);o.filename=__filename,o.parent=module.parent;const a="(function(require,module,__shared__){"+u.gunzipSync(e.readFileSync(c))+"\n})",m=Object.create(null);m.filename=__filename;const d=t.runInThisContext(a,m);function f(){return d(s,o,p),o.exports}function _(e,r){return f()(e,r)}let p;p=f(),p.global=global;const q=Object.create(null);q.value=(()=>"@std/esm enabled");const b=n.inspect.custom||"inspect";Object.defineProperty(_,b,q),Object.freeze(_),module.exports=_;

2

package.json
{
"name": "@std/esm",
"version": "0.19.1",
"version": "0.19.2",
"description": "Enable ES modules in Node today!",

@@ -5,0 +5,0 @@ "keywords": "commonjs, ecmascript, export, import, modules, node, require",

@@ -41,9 +41,5 @@ # @std/esm

@std/esm enabled
> import p from "path"
undefined
> p.join("hello", "world")
'hello/world'
```
*Note: The `"cjs"` and `"gz"` options are [unlocked](#unlockables) in the Node REPL.*
*Note: All `"cjs"` options are [unlocked](#unlockables) in the Node REPL.*

@@ -65,3 +61,3 @@ Standard Features

* [`import.meta`](https://github.com/tc39/proposal-import-meta)
* [Dynamic `import()`](https://github.com/tc39/proposal-dynamic-import)
* [Dynamic `import`](https://github.com/tc39/proposal-dynamic-import)
* [Improved errors](https://github.com/standard-things/esm/wiki/improved-errors)

@@ -76,3 +72,3 @@ * [Live bindings](https://ponyfoo.com/articles/es6-modules-in-depth#bindings-not-values)

Unlock extra features with options specified as one of the following:
Unlock features with options specified as one of the following:

@@ -89,150 +85,8 @@ * The `"@std/esm"` field in your package.json

<table>
<tr>
<td colspan="2">
<pre><code>{</code></pre>
</td>
</tr>
<tr>
<td valign="top"><code>"esm":</code></td>
<td>
<p>A string ESM mode:</p>
<ul>
<li><code>"mjs"</code> files as ESM <i>(default)</i></li>
<li><code>"all"</code> files as ESM</li>
<li><code>"js"</code> and other files with <code>import</code>, <code>export</code>, or <a href="https://github.com/tc39/proposal-modules-pragma"><code>"use module"</code></a> as ESM</li>
<li><code>"cjs"</code> shorthand for <code>"@std/esm":{"cjs":true,"esm":"js"}</code></li>
</ul>
</td>
</tr>
<tr>
<td valign="top"><code>"cjs":</code></td>
<td>
<p>A boolean to <a href="#contd">unlock</a> CJS features in ESM.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"await":</code></td>
<td>
<p>A boolean to support top-level <code>await</code> in the main module <i>(requires Node 7.6+)</i>.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"gz":</code></td>
<td>
<p>A boolean to support gzipped module <i>(i.e. <code>.js.gz</code>, <code>.mjs.gz</code>).</i></p>
<p><i>Note: Don’t forget the webpack <a href="https://github.com/webpack-contrib/gzip-loader"><code>gzip-loader</code></a>.</i></p>
</td>
</tr>
<tr>
<td colspan="2">
<pre><code>}</code></pre>
</td>
</tr>
</table>
<table><tr><td colspan=2><code>{</code><tr><td valign=top><code>"esm":</code><td><p>A string mode:<ul><li><code>"all"</code>files as ESM<li><code>"js"</code>and other files with<code>import</code>,<code>export</code>, or<a href=https://github.com/tc39/proposal-modules-pragma><code>"use module"</code></a>as ESM</ul><tr><td valign=top><code>"cjs":</code><td><p>A boolean or object to unlock CJS features in ESM.<details><summary>Unlockable Features</summary><table><tr><td colspan=2><code>{</code><tr><td valign=top><code>"cache":</code><td><p>A boolean for storing ES modules in<code>require.cache</code>.<tr><td valign=top><code>"extensions":</code><td><p>A boolean for respecting<code>require.extensions</code>in ESM.<tr><td valign=top><code>"interop":</code><td><p>A boolean for<code>__esModule</code>interoperability.<tr><td valign=top><code>"namedExports":</code><td><p>A boolean for<a href=https://ponyfoo.com/articles/es6-modules-in-depth#importing-named-exports>importing named exports</a>of CJS modules.<tr><td valign=top><code>"paths":</code><td><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.<tr><td valign=top><code>"topLevelReturn":</code><td><p>A boolean for<a href=http://stackoverflow.com/questions/28955047/why-does-a-module-level-return-statement-work-in-node-js/#28955050>top-level<code>return</code></a>.<tr><td valign=top><code>"vars":</code><td><p>A boolean for<code>__dirname</code>,<code>__filename</code>, and<code>require</code>in ESM.<tr><td colspan=2><code>}</code></table></details><tr><td valign=top><code>"await":</code><td><p>A boolean for top-level<code>await</code>in the main module.<i>(requires Node 7.6+)</i><tr><td colspan=2><code>}</code></table>
Cont’d
---
The `"cjs"` option may also be specified as an object.
<table>
<tr>
<td colspan="2">
<pre><code>{
"cjs": {</code></pre>
</td>
</tr>
<tr>
<td valign="top"><code>"cache":</code></td>
<td>
<p>A boolean for storing ES modules in <code>require.cache</code>.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"extensions":</code></td>
<td>
<p>A boolean for respecting <code>require.extensions</code> in ESM.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"interop":</code></td>
<td>
<p>A boolean for <code>__esModule</code> interoperability.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"namedExports":</code></td>
<td>
<p>A boolean to support <a href="https://ponyfoo.com/articles/es6-modules-in-depth#importing-named-exports">importing named exports</a> of CJS modules.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"paths":</code></td>
<td>
<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>
</td>
</tr>
<tr>
<td valign="top"><code>"topLevelReturn":</code></td>
<td>
<p>A boolean to support <a href="http://stackoverflow.com/questions/28955047/why-does-a-module-level-return-statement-work-in-node-js/#28955050">top-level <code>return</code></a>.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"vars":</code></td>
<td>
<p>A boolean to expose <code>__dirname</code>, <code>__filename</code>, and <code>require</code> in ESM.</p>
</td>
</tr>
<tr>
<td colspan="2">
<pre><code> }
}</code></pre>
</td>
</tr>
</table>
DevOpts
---
<table>
<tr>
<td colspan="2">
<pre><code>{</code></pre>
</td>
</tr>
<tr>
<td valign="top"><code>"cache":</code></td>
<td>
<p>A boolean for toggling <code>.cache</code> creation <i>(default: <code>true</code>).</i></p>
</td>
</tr>
<tr>
<td valign="top"><code>"debug":</code></td>
<td>
<p>A boolean for unmasking stack traces.</p>
</td>
</tr>
<tr>
<td valign="top"><code>"sourceMap":</code></td>
<td>
<p>A boolean for including inline source maps.</p>
<p><i>Note: Automatically enabled using the Node CLI
<a href="https://nodejs.org/en/docs/inspector/"><code>--inspect</code> option</a>.</i></p>
</td>
</tr>
<tr>
<td valign="top"><code>"warnings":</code></td>
<td>
<p>A boolean for logging parse and runtime warnings.</p>
<p><i>(default: <code>process.env.NODE_ENV !== "production"</code>)</i></p>
</td>
</tr>
<tr>
<td colspan="2">
<pre><code>}</code></pre>
</td>
</tr>
</table>
<table><tr><td colspan=2><code>{</code><tr><td valign=top><code>"cache":</code><td><p>A boolean for toggling<code>.cache</code>creation.<tr><td valign=top><code>"debug":</code><td><p>A boolean for unmasking stack traces.<tr><td valign=top><code>"sourceMap":</code><td><p>A boolean for including inline source maps.<tr><td valign=top><code>"warnings":</code><td><p>A boolean for logging development parse and runtime warnings.<tr><td colspan=2><code>}</code></table>

@@ -244,2 +98,3 @@ Tips

* Load `@std/esm` with the *“require”* option of
[`ava`](https://github.com/avajs/ava#options),
[`mocha`](https://mochajs.org/#-r---require-module-name),

@@ -252,2 +107,3 @@ [`nyc`](https://github.com/istanbuljs/nyc#require-additional-modules), and

[`pm2`](http://pm2.keymetrics.io/docs/usage/quick-start/#options)
* Use `@std/esm` to load [`jasmine`](https://jasmine.github.io/setup/nodejs.html#a-simple-example-using-the-library)
* Use `"@std/esm":"cjs"` with the `--watch` and `--watch-extensions` options of

@@ -254,0 +110,0 @@ [`mocha`](https://mochajs.org/#-w---watch)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc