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

promisify-loader-runner

v1.0.1

Published

a promisify wrapper of `loader-runner`

Downloads

16

Readme

promisify-loader-runner

This is a promisify method of loader-runner https://github.com/webpack/loader-runner

and you can use both promisify or callback calling style

Usage

Promise

import { runLoaders } from "promisify-loader-runner";

try {
  const result = await runLoaders({
    resource: "/abs/path/to/file.txt?query",
    loaders: ["/abs/path/to/loader.js?query"],
    context: { minimize: true },
    processResource: (loaderContext, resourcePath, callback) => { ... },
    readResource: fs.readFile.bind(fs)
  })
} catch (err){
  // err: Error?
}

Callback (original way)

import { runLoaders } from "promisify-loader-runner";

runLoaders({
 resource: "/abs/path/to/file.txt?query",
 // String: Absolute path to the resource (optionally including query string)

 loaders: ["/abs/path/to/loader.js?query"],
 // String[]: Absolute paths to the loaders (optionally including query string)
 // {loader, options}[]: Absolute paths to the loaders with options object

 context: { minimize: true },
 // Additional loader context which is used as base context

 processResource: (loaderContext, resourcePath, callback) => { ... },
 // Optional: A function to process the resource
 // Must have signature function(context, path, function(err, buffer))
 // By default readResource is used and the resource is added a fileDependency

 readResource: fs.readFile.bind(fs)
 // Optional: A function to read the resource
 // Only used when 'processResource' is not provided
 // Must have signature function(path, function(err, buffer))
 // By default fs.readFile is used
}, function(err, result) {
 // err: Error?

 // result.result: Buffer | String
 // The result
 // only available when no error occurred

 // result.resourceBuffer: Buffer
 // The raw resource as Buffer (useful for SourceMaps)
 // only available when no error occurred

 // result.cacheable: Bool
 // Is the result cacheable or do it require reexecution?

 // result.fileDependencies: String[]
 // An array of paths (existing files) on which the result depends on

 // result.missingDependencies: String[]
 // An array of paths (not existing files) on which the result depends on

 // result.contextDependencies: String[]
 // An array of paths (directories) on which the result depends on
})