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

@consensus.enterprises/pnp-vendorize

v1.0.0

Published

Copy front-end assets from a [Plug'n'Play](https://yarnpkg.com/features/pnp)-compliant package manager such as [Yarn](https://yarnpkg.com/) or [pnpm](https://pnpm.io/) into a publicly accessible vendor directory.

Downloads

104

Readme

Copy front-end assets from a Plug'n'Play-compliant package manager such as Yarn or pnpm into a publicly accessible vendor directory.

Why?

By design, package managers like Yarn when using the Plug'n'Play installation strategy optimize for speed and portability of packages, but in order to actually make select vendor libraries web-accessible you have to either use something like Webpack to extract and bundle them, or figure out the API yourself and hack together a solution.

If you're coming from the PHP world where the Composer package manager is the de facto standard in managing dependencies, and you're working with a content management system (CMS) like Drupal that has its own framework for defining libraries, handling dependency trees, and bundling them as needed for a given route, then this package is for you. It's intended as a drop-in solution to make your front-end package manager behave a bit more like Composer for certain packages.

What?

Let's say you have dependency1 and dependency2 in your package.json:

{
  "name": "my-package",
  // ...
  "dependencies": {
    // ...
    "dependency1": "^1.0.0",
    "dependency2": "^1.0.0",
    // ...
  }
}

Then you do a yarn install or pnpm install and your package manager does its magic to pull in the packages. Now they're in .yarn/cache or node_modules but that's (hopefully) outside of your public web root. How do you make those specific dependencies web accessible without writing custom code or bundling via something like Webpack?

How?

yarn add '@consensus.enterprises/pnp-vendorize' --dev

or

pnpm add '@consensus.enterprises/pnp-vendorize' --dev

Next, you need to define the subset of dependencies you want vendorized by adding a "vendorize" entry to your package.json:

{
  "name": "my-package",
  // ...
  "dependencies": {
    // ...
    "dependency1": "^1.0.0",
    "dependency2": "^1.0.0",
    // ...
  },
  "vendorize": [
    "dependency1",
    "dependency2"
  ]
}

Note that you must explicitly declare a package as a dependency. If you don't, Vendorize will throw an error - even if the package has been installed by Yarn from another workspace in the same project.

Now you can run yarn run vendorize or pnpm run vendorize and once it's completed, you'll find a vendor directory inside your package like so:

my-package
↳ vendor
  ↳ dependency1
    ↳ ...
  ↳ dependency2
    ↳ ...

You can also automate this so you don't need to run the command yourself by adding it as a postinstall script:

{
  "name": "my-package",
  // ...
  "scripts": {
    // ...
    "postinstall": "yarn run vendorize",
    // ...
  },
  // ...
}

If using pnpm, replace yarn run vendorize with pnpm run vendorize above.

Now you only need to install your package and it'll automagically run Vendorize.

Advanced

Vendorize can be configured by converting the vendorize key in your package.json into an object with the array of packages to vendorize under a packages key like so:

{
  "name": "my-package",
  // ...
  "dependencies": {
    // ...
    "dependency1": "^1.0.0",
    "dependency2": "^1.0.0",
    // ...
  },
  "vendorize": {
    "packages": [
      "dependency1",
      "dependency2"
    ]
  }
}

Then you can specify one or more of the following:

{
  // ...
  "vendorize": {
    "packages": [
      "dependency1",
      "dependency2"
    ],
    // If true (the default), will delete the contents of the vendor directory
    // before copying files into it.
    "cleanBefore": true,
    // Don't like the name "vendor"? Weird, but you can change it, sure.
    "dirName": "vendor",
    // If true (the default), a .gitignore file will be placed in the vendor
    // directory to ignore its contents.
    "gitIgnore": true
  }
}

Miscellaneous

Not to be confused with the vendorize package, which only copies npm packages from a node_modules directory.