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

@require-transpile/babel

v0.3.2

Published

For on-the-fly transpiling similar to [@babel/register](https://babeljs.io/docs/en/babel-register/), but without hooking into your global `require`;

Downloads

2

Readme

@require-transpile/babel

For on-the-fly transpiling similar to @babel/register, but without hooking into your global require;

If you want to bring your own transpiler logic, look at @require-transpile/core.

Word of warning:

This module seems to work for me, but as of writing this, I do not have a thorough understanding of nodejs internals. So, here be dragons.

License, donations

GPL-3.0. If you want to support my work, you can:

Example

see example.js in the repo:

"use strict";
const requireBabel = require("@require-transpile/babel");
const React = require('react');
const ReactDOMServer = require('react-dom/server');

const config = {
	presets: [
		"@babel/preset-react",
		[
			"@babel/preset-env",
			{
				useBuiltIns: "entry",
				corejs: "3.0.0"
			}
		]
	],
	extensions: [".jsx"]
};

const component = requireBabel("./component", config);
let rendered = ReactDOMServer.renderToStaticMarkup(React.createElement(component));
console.log(rendered); // <div>Hello World</div>

API

requireBabel(filepath, [options])

  • filepath: the path to the module you want to load.
  • options: optional object with options for require-transpile, merged with your babel configuration
    • includeNodeModules: default: false, apply transpiler to modules loaded from node_modules as well.
    • extensions: default: [], additional extensions to search for, as require.resolve defaults to just .js.
    • cache: default: {}, object used for module caching, can be reused across babelTranspile calls as long as files don't change.
    • entryFile: default: module.parent.filename, used as basepath to resolve filepath from.
    • withDependencies: default: false, if true returns {mod, dependencies} where dependencies is an array of all transpiled files
    • overrideScope: default: {}, object with variables to inject/override in module scopes
    • overrideHook: function(path) {} to short-circuit require calls, if it returns a non-null value it is returned instead of normal require logic
    • Any other keys will be passed to babel, and need to be valid babel options

requireBabel.resolve(path, [options])

Resolve similarly to require.resolve, but with custome extensions

  • path: the path to resolve
  • options: optional object with:
    • exts: non-default extensions to look for, like ".jsx", or an array of strings for more options
    • paths: paths to look in, defaults as relative from __filename where you are calling this

requireBabel.invalidate(cache, fullpath)

Invalidate a cache entry, for livereloading dependencies with surgical precision.
It will delete fullpath from the cache, and mark all it's parents as invalid, which will re-execute their code upon require returns Set of invalidated entries

  • cache: cache Map that contains an entry for the key fullpath
  • fullpath: entry to invalidate

Changelog

v0.3.2 (August 25, 2022)

  • add option to inject/override variables into module scope
  • update @require-transpile/core to 0.4.2

v0.3.1 (July 1, 2020)

  • bump @require-transpile/core, invalidate now returns Set of affected paths

v0.3.0 (🏳️‍🌈 June 29, 2020)

  • bump @require-transpile/core, exposing resolve and cache invalidate functions

v0.2.3 (🏳️‍🌈 June 16, 2020)

  • add support for @require-transpile/core overrideHook

v0.2.1 (🏳️‍🌈 June 2, 2020)

  • bump @require-transpile/core, correctly returns dependencies for cache-hits

v0.2.0 (May 31, 2020)

  • pass new entryFile and withDependency options