npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-jsm-to-esmodules

v0.6.0

Published

Transforms imports and exports in Firefox .jsm to ES module syntax

Downloads

34

Readme

JSM to ES Module Babel Plugin

Build Status

This module converts import and export statements in .jsm modules to ES modules. For example:

Source:

const {utils: Cu} = Components;
const {Bar, Baz} = Cu.import("resource://activity-stream/addon/barbaz.jsm", {});

function Stuff() {
  return 123;
}

this.Whatever = {};
this.Stuff = Stuff;
var EXPORTED_SYMBOLS = ["Stuff", "Whatever"];

Compiles to:

import {Bar, Baz} from "addon/barbaz.js";

export function Stuff() {
  return 123;
}

export var Whatever = {};

Caveats / Limitations

Use top-level imports and exports only

Because import and export statements in ES modules must be statically analyzable, this plugin will only transform top level Cu.import / EXPORTED_SYMBOLS. Example:

Good:

const {utils: Cu} = Components;
const {Bar} = Cu.import("resource://foo/Bar.jsm", {});

this.Baz = 123;
this.EXPORTED_SYMBOLS = ["Baz"];

Bad:

const {utils: Cu} = Components;
const root = this;
function innerFunction() {
  // This won't get converted because it's inside innerFunction
  const {Bar} = Cu.import("resource://foo/Bar.jsm", {});

  // Don't do this either
  root.Baz = 123;
}

var EXPORTED_SYMBOLS = ["Baz"];

Don't alias this or dynamically add items to var EXPORTED_SYMBOLS when exporting

You should only declare this.EXPORTED_SYMBOLS once in the top-level scope, and it should not be modified.

Good:

function Foo() {...}
this.Foo = Foo;
this.Bar = 123;
this.EXPORTED_SYMBOLS = ["Foo", "Bar"];

Bad:

const root = this;
const Foo = 123;
root.EXPORTED_SYMBOLS = ["Foo"]; // Don't alias this when exporting
root.Bar = 456;
root.EXPORTED_SYMBOLS.push("Bar"); // Don't do this

Don't reassign Components.utils.import

Assigning variables to Components or Components.utils is OK, but don't assign the .import;

const C = Components; // OK
const {utils: Cu} = Components; // OK
const u = Components.utils // OK

const {import} = Cu; // Don't do this
const i = Components.utils.import // Don't do this

Options

basePath

Defaults to /^resource:\/\/. A RegEx or String that tests for which import paths to rewrite.

replace

Defaults to false. Remove the basePath component of the import string?

e.g. If the basePath is /^resource:\/\/, resource://activity-stream/foo.js will be rewritten to activity-stream/foo.js.

"plugins": ["transform-react-jsx", {basePath: "resource://activity-stream/"}],

removeOtherImports

Defaults to false. Should we remove non-matching imports?