Code Monkey home page Code Monkey logo

pkgify's Introduction

pkgify Build Status

Pkgify is a browserify transform that allows you to rewrite module/package-style require calls to local files. It is built using the browserify-transform-tools.

  • Clean up your require calls!
  • Supports individual files and entire directories
  • Supports nested packages (priorities deepest match)
  • Simple configuration
  • File-type indifferent
  • Efficient

But we already have aliasify and remapify?

Aliasify is designed for mapping individual files to new names. Remapify actually uses aliasify internally for it's mapping process which means it has to generate a list of all possible files that might be mapped from the source directory, and then compare them when processing files. This gives remapify less control since it isn't doing the transform itself.

Purpose

Say, for example, your project has the following tree structure:

myproject
  - /app
    - /views
      - /home
        - index.js
      - /about
        - index.js
    - /models
      - cars.js
    - log.js

Normally, if you wanted to access log.js and models/cars.js from either of the two view files, you would have to do it like so:

var log = require("../../log");
var Cars = require("../../models/cars");

With pkgify, however, you can save yourself time and clean up your code so it looks like this:

var log = require("log");
var Cars = require("models/cars");

Installation

npm install --save-dev pkgify

Usage

Usage is identical to any other browserify-transform-tools transforms:

package.json

Directly in package.json:

{
  "pkgify": {
    "packages": {
      "views": "./app/views",
      "log": "./app/log.js"
    }
  }
}

or using referencing a separate JS file in package.json:

{
  "pkgify": "./pkgifyConfig.js"
}

Browserify API

var pkgify = require("pkgify");

b.transform(pkgify, {
  packages: {
    views: "./app/views",
    log: "./app/log.js"
  },
  relativeTo: __dirname
});

Configuration options

packages

  • Type: object
  • Required: yes
  • Description: A mapping of package names to their source. The source is resolved in relation to the relativeTo option and can reference either a file or directory. If a file is specified it's extension must be included.

relativeTo

  • Type: string
  • Required: no
  • Description: Path to resolve package sources against. If using package.json for configuration, this value will default to the location of the package.json file. If you are using the API, it will default to the location you are configuring from. It is advisable to always explicitly set this option when using the API using __dirname.

appliesTo

  • Type: object
  • Required: no
  • Description: Control what files are processed by the transform. This is an option provided by browserify-transform-tools.

Contributing

Setup

make bootstrap

Running tests

make test

Commit messages

  • Use the present tense ("Add feature" not "Added feature")
  • Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
  • Limit the first line to 72 characters or less
  • Reference issues and pull requests liberally
  • Consider starting the commit message with an applicable emoji:
    • 💄 :lipstick: when improving the format/structure of the code
    • 🐎 :racehorse: when improving performance
    • 🚱 :non-potable_water: when plugging memory leaks
    • 📝 :memo: when writing docs
    • 🐧 :penguin: when fixing something on Linux
    • 🍎 :apple: when fixing something on Mac OS
    • 🏁 :checkered_flag: when fixing something on Windows
    • 🐛 :bug: when fixing a bug
    • 🔥 :fire: when removing code or files
    • 💚 :green_heart: when fixing the CI build
    • :white_check_mark: when adding tests
    • 🔒 :lock: when dealing with security
    • ⬆️ :arrow_up: when upgrading dependencies
    • ⬇️ :arrow_down: when downgrading dependencies

(From atom)

pkgify's People

Contributors

oliverwoodings avatar kingease avatar olizilla avatar

Watchers

James Cloos avatar Rubén López Gómez avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.