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

@talend/module-to-cdn

v9.12.0

Published

Get cdn config from npm module name

Downloads

2,676

Readme

@talend/module-to-cdn

Get cdn config from npm module name

Fork

This module is fork of module-to-cdn from Thomas Sileghem.

Because unpkg is great for free usage but not for production usage we decided to made some changes to going forward.

After big PR on the repository and an email to the author we have got no news as all other PRs. So we decided to fork.

Install

$ npm install --save @talend/module-to-cdn

Usage

const moduleToCdn = require('@talend/module-to-cdn');

moduleToCdn('react', '15.3.0');
/* => {
    name: 'react',
    var: 'React',
    url: 'https://unpkg.com/[email protected]/dist/react.min.js',
    version: '15.3.0',
    path: '/dist/react.min.js',
    local: '/Users/me/module-to-cdn/node_modules/react/dist/react.min.js'
}
*/

Note if the package comes with css you will have them under styleUrl and stylePath properties

API

moduleToCdn(moduleName, version, options)

return the result Object or null (if module couldn't be find)

moduleName

Type: string

The name of the module

version

Type: string

The version of the module

options

options.env

Type: string Values: development, production Default: development

Result

  • name: name of the module
  • var: name of the global variable exposing the module
  • url: url where the module is available
  • version: the version asked for
  • path: relative path of the umd file in the distributed package
  • local: absolute path on the current system to the file

Configuration of the resolver

By default the URL resolver just resolve to unpkg. You can change that using the following API.

import moduleToCdn from '@talend/module-to-cdn';

function myResolver(...args) {
    const info = moduleToCdn(...args);
    if (process.env.NODE_ENV !== 'development') {
        return {
            ...info,
            url: `https://cdn.talend.com/${info.name}/${info.version}${info.path}`
        };
    }
    return info;
}
moduleToCdn.configure(myResolver);

Support private CDN

The module.json file is an open effort on existing opensource libs. If you want to support custom internal library you can add entries in this file using the following API:

import moduleToCdn from '@talend/module-to-cdn';

moduleToCdn.add({
    '@talend/my-private-module': {
        var: 'TalendMyPrivateModule',
        versions: {
            '>= 0.0.0': {
                development: '/dist/build.js',
                production: '/dist/build.min.js'
            }
        }
    }
});

This will affect all future call to moduleToCdn;

Tests

This module do integration tests so it requests npm / unpkg for every packages on the limit of each version and also it tries to fetch the @next version to be as future proof as possible

So if you want to focus on a given module you can use the LIMIT env variable

LIMIT=";ag-grid;ag-grid-community;ag-grid-enterprise;" ava -v

Excluded modules

  • hoist-non-react-statics: the umd build contains JS errors (process.env.NODE and require) on every versions.

style-versions

For the sake of simplicity, range must match between js and styles. Here is the line in the code that read it:

const styleConfig = moduleConf['style-versions'] && moduleConf['style-versions'][range];

So take it as a constraint, for example:

  "@talend/design-tokens": {
    "var": "TalendDesignTokens",
    "versions": {
      "> 2.6.0": {
        "development": "/dist/TalendDesignTokens.js",
        "production": "/dist/TalendDesignTokens.min.js"
      }
    },
    "style-versions": {
      "> 2.6.0": {
        "development": "/dist/TalendDesignTokens.css",
        "production": "/dist/TalendDesignTokens.min.css"
      }
    }
  }

Contribute

To add your modules you have to

  • checkout this package on github
  • install and run the tests (it will load the cache for the tests)
  • add your module in the module.json file
  • ensure everytime the provided umd path exists and is valid.

Example of not valid umd: https://unpkg.com/browse/[email protected]/dist/index.umd.js createContext,deepEqual dependencies are always null.

License

MIT © Thomas Sileghem