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-multi-env

v0.6.1

Published

`babel` CLI replacement with multiple node version support by `babel-preset-env` and `babel-plugin-transform-runtime`. Useful for node.js libraries/modules

Downloads

29

Readme

babel-multi-env

babel CLI replacement with multiple node version support by babel-preset-env and babel-plugin-transform-runtime. Useful for node.js libraries/modules

Version Travis CI Quality Coverage Dependencies Gitter

Usage

Transforms:

example/src/index.js

import fs from "fs";
import promisify from "util.promisify";

export async function demoBumpVersion(nextVersion = "1.0.0") {
  const content = await promisify(fs.readFile)("package.json", "utf8");
  const json = JSON.parse(content);
  json.version = nextVersion;
  await promisify(fs.writeFile)(
    "package.json",
    JSON.stringify(json, null, 4),
    "utf8"
  );
  return () => console.log(`Successfully bumped version to: ${nextVersion}`);
}

with the command:

cd example
yarn babel-multi-env --multi-versions 8.0.0 6.0.0 4.0.0 0.12.0 0.10.0 --given src/index.js --out-dir lib

and output these files:

example/lib/index.js
example/lib/index__0.10.0__.js
example/lib/index__0.12.0__.js
example/lib/index__4.0.0__.js
example/lib/index__6.0.0__.js
example/lib/index__8.0.0__.js

where

example/lib/index.js

var gte = require("semver").gte;

var version = process.version;

if (gte(version, "8.0.0")) {
  module.exports = require("./index__8.0.0__.js");
} else if (gte(version, "6.0.0")) {
  module.exports = require("./index__6.0.0__.js");
} else if (gte(version, "4.0.0")) {
  module.exports = require("./index__4.0.0__.js");
} else if (gte(version, "0.12.0")) {
  module.exports = require("./index__0.12.0__.js");
} else {
  module.exports = require("./index__0.10.0__.js");
}

example/lib/index__8.0.0__.js

"use strict";
var _interopRequireDefault = require("babel-runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.demoBumpVersion = demoBumpVersion;
var _stringify = _interopRequireDefault(
  require("babel-runtime/core-js/json/stringify")
);
var _fs = _interopRequireDefault(require("fs"));
var _util = _interopRequireDefault(require("util.promisify"));
async function demoBumpVersion(nextVersion = "1.0.0") {
  const content = await (0, _util.default)(_fs.default.readFile)(
    "package.json",
    "utf8"
  );
  const json = JSON.parse(content);
  json.version = nextVersion;
  await (0, _util.default)(_fs.default.writeFile)(
    "package.json",
    (0, _stringify.default)(json, null, 4),
    "utf8"
  );
  return () => console.log(`Successfully bumped version to: ${nextVersion}`);
}

example/lib/index__6.0.0__.js

"use strict";
var _interopRequireDefault = require("babel-runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.demoBumpVersion = void 0;
var _stringify = _interopRequireDefault(
  require("babel-runtime/core-js/json/stringify")
);
var _asyncToGenerator2 = _interopRequireDefault(
  require("babel-runtime/helpers/asyncToGenerator")
);
var _fs = _interopRequireDefault(require("fs"));
var _util = _interopRequireDefault(require("util.promisify"));
let demoBumpVersion = (() => {
  var _ref = (0, _asyncToGenerator2.default)(function*(nextVersion = "1.0.0") {
    const content = yield (0, _util.default)(_fs.default.readFile)(
      "package.json",
      "utf8"
    );
    const json = JSON.parse(content);
    json.version = nextVersion;
    yield (0,
    _util.default)(_fs.default.writeFile)("package.json", (0, _stringify.default)(json, null, 4), "utf8");
    return () => console.log(`Successfully bumped version to: ${nextVersion}`);
  });
  return function demoBumpVersion() {
    return _ref.apply(this, arguments);
  };
})();
exports.demoBumpVersion = demoBumpVersion;

……and you get the idea.

/* lib/index__4.0.0__.js */
"use strict";
var _interopRequireDefault = require("babel-runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.demoBumpVersion = void 0;
var _regenerator = _interopRequireDefault(require("babel-runtime/regenerator"));
var _stringify = _interopRequireDefault(require("babel-runtime/core-js/json/stringify"));
var _asyncToGenerator2 = _interopRequireDefault(require("babel-runtime/helpers/asyncToGenerator"));
var _fs = _interopRequireDefault(require("fs"));
var _util = _interopRequireDefault(require("util.promisify"));

var demoBumpVersion = function () {
  var _ref = (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee() {
    var nextVersion,
        content,
        json,
        _args = arguments;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            nextVersion = _args.length > 0 && _args[0] !== undefined ? _args[0] : "1.0.0";
            _context.next = 3;
            return (0, _util.default)(_fs.default.readFile)("package.json", "utf8");

          case 3:
            content = _context.sent;
            json = JSON.parse(content);
            json.version = nextVersion;
            _context.next = 8;
            return (0, _util.default)(_fs.default.writeFile)("package.json", (0, _stringify.default)(json, null, 4), "utf8");

          case 8:
            return _context.abrupt("return", function () {
              return console.log(`Successfully bumped version to: ${nextVersion}`);
            });

          case 9:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function demoBumpVersion() {
    return _ref.apply(this, arguments);
  };
}();
exports.demoBumpVersion = demoBumpVersion;
/* lib/index__0.12.0__.js */
"use strict";
var _interopRequireDefault = require("babel-runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.demoBumpVersion = void 0;
var _regenerator = _interopRequireDefault(require("babel-runtime/regenerator"));
var _stringify = _interopRequireDefault(require("babel-runtime/core-js/json/stringify"));
var _asyncToGenerator2 = _interopRequireDefault(require("babel-runtime/helpers/asyncToGenerator"));
var _fs = _interopRequireDefault(require("fs"));
var _util = _interopRequireDefault(require("util.promisify"));
var demoBumpVersion = function () {
  var _ref = (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee() {
    var nextVersion,
        content,
        json,
        _args = arguments;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            nextVersion = _args.length > 0 && _args[0] !== undefined ? _args[0] : "1.0.0";
            _context.next = 3;
            return (0, _util.default)(_fs.default.readFile)("package.json", "utf8");

          case 3:
            content = _context.sent;
            json = JSON.parse(content);
            json.version = nextVersion;
            _context.next = 8;
            return (0, _util.default)(_fs.default.writeFile)("package.json", (0, _stringify.default)(json, null, 4), "utf8");

          case 8:
            return _context.abrupt("return", function () {
              return console.log("Successfully bumped version to: ".concat(nextVersion));
            });

          case 9:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function demoBumpVersion() {
    return _ref.apply(this, arguments);
  };
}();
exports.demoBumpVersion = demoBumpVersion;
/* lib/index__0.10.0__.js */
"use strict";
var _interopRequireDefault = require("babel-runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.demoBumpVersion = void 0;
var _regenerator = _interopRequireDefault(require("babel-runtime/regenerator"));
var _stringify = _interopRequireDefault(require("babel-runtime/core-js/json/stringify"));
var _asyncToGenerator2 = _interopRequireDefault(require("babel-runtime/helpers/asyncToGenerator"));
var _fs = _interopRequireDefault(require("fs"));
var _util = _interopRequireDefault(require("util.promisify"));
var demoBumpVersion = function () {
  var _ref = (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee() {
    var nextVersion,
        content,
        json,
        _args = arguments;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            nextVersion = _args.length > 0 && _args[0] !== undefined ? _args[0] : "1.0.0";
            _context.next = 3;
            return (0, _util.default)(_fs.default.readFile)("package.json", "utf8");

          case 3:
            content = _context.sent;
            json = JSON.parse(content);
            json.version = nextVersion;
            _context.next = 8;
            return (0, _util.default)(_fs.default.writeFile)("package.json", (0, _stringify.default)(json, null, 4), "utf8");

          case 8:
            return _context.abrupt("return", function () {
              return console.log("Successfully bumped version to: ".concat(nextVersion));
            });

          case 9:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function demoBumpVersion() {
    return _ref.apply(this, arguments);
  };
}();
exports.demoBumpVersion = demoBumpVersion;

Installation

npm i --save-dev babel-multi-env
# or
yarn add --dev babel-multi-env

Note on the peerDependencies

There are currently five peerDependencies listed under the package.json for babel-multi-env. Be sure not to screw up their versions sicne babel@^7 are currently in beta and can be found under the next dist-tags on npm.

dependencies

Your should add these to your dependencies:

  • "babel-runtime": "^7.0.0-beta.3"
  • "semver": "^5.4.1"

since they'll be used in the runtime.

devDependencies

And, these three for the code generation only:

  • "babel-core": "^7.0.0-beta.3",
  • "babel-plugin-transform-runtime": "^7.0.0-beta.3",
  • "babel-preset-env": "^7.0.0-beta.3",

Options

[babel-multi-env]
  --multi-versions  list of supported semver versions. Example: 8.0.0 6.0.0
                    4.0.0                                     [array] [required]
  --given           source glob patterns                      [array] [required]
  --out-dir         compile into an output directory         [string] [required]

[babel-preset-env]
  --use-built-ins  apply babel-preset-env for polyfills with "useBuiltIns":
                   "usage" (via babel-polyfill)      [string] [choices: "usage"]

[babel-plugin-transform-runtime]
  --helpers      Enables inlined Babel helpers (classCallCheck, extends, etc.)
                 are replaced with calls to moduleName [boolean] [default: true]
  --polyfill     Enables new built-ins (Promise, Set, Map, etc.) are transformed
                 to use a non-global polluting polyfill[boolean] [default: true]
  --regenerator  Enables generator functions are transformed to use a
                 regenerator runtime that does not pollute the global scope
                                                       [boolean] [default: true]
  --module-name  sets the name/path of the module used when importing helpers
                                               [string] [default: babel-runtime]

[babel-core]
  --presets  list of preset names                                        [array]
  --plugins  list of plugins names                                       [array]

Options:
  --help, -h     Show help                                             [boolean]
  --version, -v  Show version number                                   [boolean]

Examples