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

my-runner

v3.1.3

Published

Run CommonJS script in sandbox with customized style

Downloads

110

Readme

my-runner

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

Run CommonJS script in sandbox with customized style

How it works?

my-runner uses vm module for mocking an CommonJS's script environment. So we can make the environment as your wish.

For example, jest uses customized environment for running test files. And we could use it running browser's script.

Installation

npm install my-runner
# or use yarn
yarn add my-runner

Usage

Package

const myRunner = require('my-runner')

myRunner.runFile('/path/to/file.js').module.exports

Cli

npm i my-runner -g
my-runner --help

API

run

index.js:53-69

Run code script

Parameters

  • code {string}
  • opts {{}} (optional, default {})
    • opts.rootDir string? The run environment's root directory path.
    • opts.myrunnerrc boolean? Whether or not to look up .my-runnerrc or my-runner.config.js file.
    • opts.preset ({} | Function | {name: string, options: any})? A preset that is used as a base for configuration.
    • opts.moduleNameMapper Object<string, string>? A map from regular expressions to module names that allow to stub out resources, like images or styles with a single module.
    • opts.modulePathIgnorePatterns Array<string>? An array of regexp pattern strings that are matched against all module paths before those paths are to be considered 'visible' to the module loader.
    • opts.modulePaths Array<string>? An array of absolute paths to additional locations to search when resolving modules. Use NODE_PATH env variable by default.
    • opts.moduleFileExtensions Array<string> An array of file extensions your modules use. (optional, default ['.js','.json','.jsx','.ts','.tsx','.node'])
    • opts.moduleDirectories Array<string> An array of directory names to be searched recursively up from the requiring module's location. (optional, default ['node_modules'])
    • opts.preserveSymlinks boolean? preserveSymlinks
    • opts.resolver Function? This option allows the use of a custom resolver. More information see jest.
    • opts.browser boolean Respect Browserify's "browser" field in package.json when resolving modules. (optional, default false)
    • opts.transformIgnorePatterns Array<string> An array of regexp pattern strings that are matched against all source file paths before transformation. If the test path matches any of the patterns, it will not be transformed. (optional, default ['/node_modules/'])
    • opts.transform Object<string, (string | Function | {name: string, options: any})> A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. (optional, default {})
    • opts.globalSetup string? This option allows the use of a custom global setup module which exports an async function that is triggered once.
    • opts.globals Object? A set of global variables that need to be available in environments.
    • opts.transformContext Function? A sync function for transforming context.
    • opts.global any The reference on global environment. (optional, default {...global})
    • opts.moduleCache {}? The reference of require.cache
    • opts.moduleMain {}? The reference of require.main
    • opts.fs Object The fs module. (optional, default require('fs'))
    • opts.vm Object The vm module. (optional, default require('vm'))

Returns RunResult

runFile

index.js:78-84

Run file script

Parameters

  • filename string
  • opts Object Same as run options parameter. (optional, default {})

Returns RunResult

RunResult

index.js:97-106

Type: {module: {exports}, exports, require, global}

defaultAdvancedOptions

index.js:105-105

The default options

How to mock module?

my-runner had injected myRunner in global.

for example, Mocking prop-types and setting moduleNameMapper to be {"^prop-types$": "/path/to/mock-prop-types.js"}

myRunner

requireActual

Requires the actual module rather than the mock module.

  • Type: Function

Contributing

  • Fork it!
  • Create your new branch:
    git checkout -b feature-new or git checkout -b fix-which-bug
  • Start your magic work now
  • Make sure npm test passes
  • Commit your changes:
    git commit -am 'feat: some description (close #123)' or git commit -am 'fix: some description (fix #123)'
  • Push to the branch: git push
  • Submit a pull request :)

Authors

This library is written and maintained by imcuttle, [email protected].

License

MIT - imcuttle 🐟