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.7.1 to 0.8.0

53

index.js
/* eslint strict: off, node/no-unsupported-features: ["error", { version: 4 }] */
"use strict"
const Module = module.constructor
const fs = require("fs")
const path = require("path")
const util = require("util")
const vm = require("vm")
const zlib = require("zlib")
const gunzipSync = require("zlib").gunzipSync
const join = require("path").join
const readFileSync = require("fs").readFileSync
const esmPath = path.join(__dirname, "esm.js.gz")
const inspectKey = util.inspect.custom || "inspect"
const filePath = join(__dirname, "esm.js.gz")
const content = gunzipSync(readFileSync(filePath)).toString()
const mod = new Module(filePath, module.parent)
const descriptor = Object.create(null)
descriptor.value = () => "@std/esm enabled"
mod.filename = filePath
mod._compile(content, filePath)
module.exports = mod.exports
const mod = new module.constructor(module.id)
mod.filename = __filename
mod.parent = module.parent
const scriptOptions = Object.create(null)
scriptOptions.filename = esmPath
const content =
"(function(require,module,__filename){" +
zlib.gunzipSync(fs.readFileSync(esmPath)).toString() +
"\n})"
const compiled = vm.runInThisContext(content, scriptOptions)
function makeLoaderFunction() {
compiled(require, mod, __filename)
return mod.exports
}
const loader = makeLoaderFunction()
module.exports = (mod, options) => {
const type = typeof options
if (options === true ||
type === "function" ||
(type === "object" && options !== null)) {
return makeLoaderFunction()(mod, options)
}
return loader(mod, options)
}
Object.freeze(Object.defineProperty(module.exports, inspectKey, descriptor))

2

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

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

@@ -22,2 +22,14 @@ # @std/esm

By default, `@std/esm` **only** processes files of packages that opt-in
with a `@std/esm` options object or `@std/esm` as a dependency, dev
dependency, or peer dependency in their package.json. However, you can
enable processing **all** files with specific options by passing an options
object as the second argument or passing `true` to use the options from
your package.json.
```js
const loader1 = require("@std/esm")(module, { cjs: true, esm: "js" })
const loader2 = require("@std/esm")(module, true)
```
Enable ESM in the Node CLI by loading `@std/esm` with the [`-r` option](https://nodejs.org/api/cli.html#cli_r_require_module):

@@ -24,0 +36,0 @@

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