Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

esm-ast-to-cjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esm-ast-to-cjs

Pure AST compiler for ESM to CJS

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

This library converts and the AST (Abstract Syntax Tree) of an ESM program to CommonJS.

Note: Dynamic imports are not yet supported.

import acorn from 'acorn'
import astring from 'astring'
import convert from 'esm-ast-to-cjs'

const script = `
import test from 'test'
export default test
`

const opts = { sourceType: 'module' }
const ast = acorn.parse(script, opts)
convert(ast)
const cjs = astring.generate(ast)
console.log(cjs)
// const test = require('test');\nmodule.exports = test'\n

FAQs

Package last updated on 14 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts