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

@ms-cloudpack/esm-stub-utilities

Package Overview
Dependencies
Maintainers
0
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/esm-stub-utilities

Generates ESM stubs for CommonJS entry files.

  • 0.12.14
  • npm
  • Socket score

Version published
Weekly downloads
846
increased by12.8%
Maintainers
0
Weekly downloads
 
Created
Source

@ms-cloudpack/esm-stub-utilities

This library contains utilities for generating ESM stubs for CommonJS modules. Some bundlers require this for extracting named exports needed to produce a browser-compatible ESM bundle.

Usage

Call writeESMStubs to generate stubs for CJS entries of a package:

import { writeESMStubs } from '@ms-cloudpack/esm-stub-utilities';

const esmStub = await writeESMStubs({
  inputPath: '/path/to/package',
  entries: {
    './entry1': './cjsEntry1.js',
    './entry2': './cjsEntry2.js',
  },
});

Special considerations

When evaluating named entries in the exports of the cjs file, the library is loaded in the node process. A few libraries are used to simulate the browser environment in order for the script to load. (E.g. some libraries will reference window on load, and therefore must be parsed in an environment that accommodates this.)

Libraries which export a default entry in their exports will have that value preserved as the default export in the stub. However libraries which have an object exported which don't have a default key will have the entire object exported as the default.

Libraries which export a function or literal value as the exports result will have a default export for that entry.

Some libraries don't export anything. In this case, the stub will simply import the entry.

Exported members that are keywords will be ignored. (E.g. module.exports = { 'delete': "foo" }; would be considered an empty export.)

FAQs

Package last updated on 13 Sep 2024

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

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