Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

resolve-unpkg

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resolve-unpkg

  • 2.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status semantic-release

The Resolve-Unpkg library helps you to keep your unpkg links up to date by patching the unpkg URLs with the package version installed in your environment. The Resolve-Unpkg may be used in command line and as a webloader.

TL;DR;

In CLI:

   npm i --save-dev resolve-unpkg
   resolve-unpkg path-to-optional-config.json

Webloader:

   import scripts from '!resolve-unpkg?unpkgPrefix=unpkg.com&versionPlaceholder=a.b.c&onlyByVersionPlaceholder=true!scripts.json';

Import

To add Resolve-Unpkg to the project, cd to the project root folder and run:

npm i --save-dev resolve-unpkg

This will add Resolve-Unpkg as a dependency to package.json enabling you to run the resolve-unpkg command manually and use resolve-unpkg as a webpack loader to resolve versions in unpkg URLs when they are imported from the JSON file.

Configuration

By default, Resolve-Unpkg processes URLs with unpkg.com prefix in the index.html file and replaces the x.x.x version placeholders with the actual version of the packages that are installed in your local environment.

To customize the default configuration, use the following options:

PropertyTypeRequiredDescriptionCLILoader
unpkgPrefixstringNoThe prefix of the unpkg URLs. Default: 'unpkg.com'YesYes
versionPlaceholderstringNoA version number placeholder to be replaced when occurs in the position of package version. Default: 'x.x.x'YesYes
onlyByVersionPlaceholderbooleanNoA flag that may limit the update to those URLs that contain the versionPlaceholder (e.g. x.x.x); when set to true, the exact package version numbers, like 1.9.1, are ignored. Default: trueYesYes
filesstring[]NoPath to file(s) to update/resolve URLs in. Default: ['index.html']YesNo
diststringNoFolder where the updated file(s) should be saved. Default: overwrite originalYesNo

Usage in CLI

With Resolve-Unpkg, you can automatically update the package versions that are mentioned in the unpkg URLs in some of your project files.

The package versions used are those installed in your local environment.

Before you begin, prepare the resolve-unpkg configuration file to override the default options if necessary. For example:

Sample Resolve-Unpkg configuration file

{
  "unpkgPrefix": "unpkg",
  "files": ["index.vm, index.ejs"],
  "dist": "dist/"
}

To update the unpkg links, run:

resolve-unpkg [optional-config.json]

As a result, the unpkg URLs in the provided files will be updated.

As an illustration to this process, let's consider the following file (index.html) :

<html>
    <head>
        <link rel="stylesheet" href="https://unpkg.com/spectrum-colorpicker@1.6.0/spectrum.css">
    </head>
    <body>
        <script src="https://unpkg.com/jquery@x.x.x/dist/jquery.min.js"></script>
    </body>
</html>

If the version of the jquery installed in the local environment is '2.21', and spectrum-colorpicker is '1.6.1', and we run the resolve-unpkg with default configuration parameters, the original index.html file will be overwritten with this one:

<html>
    <head>
        <link rel="stylesheet" href="https://unpkg.com/spectrum-colorpicker@1.6.0/spectrum.css">
    </head>
    <body>
        <script src="https://unpkg.com/jquery@2.2.1/dist/jquery.min.js"></script>
    </body>
</html>

Note that as the onlyByVersionPlaceholder is true by default, the older version for spectrum-colorpicker was not modified.

Usage in JS

For the unpkg links that are imported into your JS code from the JSON file, use resolve-unpkg loader to inject the updated versions into the URLs. To do so, update the import and provide the necessary values as parameters:

...
import scripts from '!resolve-unpkg?unpkgPrefix=unpkg.com&versionPlaceholder=a.b.c&onlyByVersionPlaceholder=true!scripts.json';
...

Testing

Make sure to test the new version since every time your links are updated you are getting code that has not yet run through your tests. So if for example you use resolve-unpkg in your build phase, you should have your code tested afterwards (e.g. in E2E tests).

FAQs

Package last updated on 11 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc