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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jenkins-js-core

v1.0.0-alpha-9

Published

Jenkins CI core JavaScript module

Readme

Jenkins CI core JavaScript module (CommonJS).

Install Package:

npm install --save jenkins-js-core

__ TODO__ Maybe rename to "jenkins-modules".

The "problem"

Browserify is a really nice solution for modularising CommonJS style JavaScript code for running in the browser. The problems for Jenkins are:

  1. There are many components potentially building JavaScript modules, all requiring access to common JavaScript libraries (jQuery, Bootstrap, jQuery UI etc). We don't want each module loading their own copy of jQuery etc.
  2. Jenkins is not a website built by one team of developers. There are 1000+ plugins now, all contributing to the UI and all developed in different "eras", which among other things means they will be developed to work against different versions of JavaScript libraries.
    • jQuery is the really big concern here, where the version issue is exacerbated by the jQuery extensions issue i.e. Jenkins may have a single jQuery instance with a varying version + any number of unknown jQuery extensions "glom'd" onto it, all potentially conflicting with each other. So in effect, this is basically replicating the global window namespace issues of old into the $ namespace. This is not sustainable for Jenkins and is guaranteed to lead to all sorts of strange UI errors. See "jquery-detached"
  3. It is expect that Jenkins plugins will be building shareable JavaScript components e.g. a plugin that has a REST API could expose that rest API to other plugin UI components via a JavaScript module.

Browserify can be used to build a single, self contained JavaScript bundle. The modules in that bundle can require other modules in the bundle, but cannot require modules from other bundles. That means each bundle needs to include everything it needs, including jQuery and other framework libraries. This is not sustainable for Jenkins and is the problem that this module is targeted at i.e. to allow plugins (or Jenkins core) that are building self contained CommonJS style JavaScript modules (using Browserify if they want) to "export" one or more of those modules in the browser, allowing those modules to be "required" across bundle boundaries.

Exporting JavaScript modules

A Jenkins Plugin can "export" a JavaScript module (CommonJS style module) by calling require('jenkins-js-core').exportModule, allowing other plugin bundles to require that module (see next section).

exports.add = function(lhs, rhs {
    return lhs + hrs;
}

// export the module/bundle
require('jenkins-js-core').exportModule('pluginA', 'mathUtils', exports);

We assume that the plugin bundle JavaScript is bundled using Browserify, and can be loaded from <jenkins>/plugin/<pluginName>/jsmodules/<moduleName>.js e.g. /jenkins/plugin/pluginA/jsmodules/mathUtils.js.

Requiring/importing JavaScript modules

A JavaScript module in one plugin ("pluginB") can "require" a module from another plugin ("pluginA" see above) by calling require('jenkins-js-core').requireModule.

var mathUtil; // initialise once the module is loaded and registered 

// The require is async (returning a Promise) because the 'pluginA:mathUtils' is loaded async.
require('jenkins-js-core').requireModule('pluginA', 'mathUtils')
    .then(function(module) {
        // Module loaded ok
        mathUtil = module;
    })
    .catch(function(error) {
        // Module didn't load for some reason e.g. a timeout
        alert(error.detail);
    });

exports.magicFunc = function() {
    // might want to assert mathUtil is initialised
    
    // do stuff ...
}

If require('jenkins-js-core').requireModule is called for a module that is not yet loaded, require('jenkins-js-core').requireModule will trigger the loading of that module from the plugin, hence the async/promise nature i.e. you can't synchronously get a module.