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

gulp-pathway

v2.1.1

Published

Gulp plugin to compile javascript source directories into Pathway modules

Downloads

2

Readme

Gulp Pathway is a gulp.js plugin which is designed to automatically wrap JavaScript source code with Pathway Module declarations based upon directory structure. This is useful for large code bases where refactoring is frequent.

var gulp = require('gulp');
var pathway = require('gulp-pathway');

gulp.task('compile', function () {
  return gulp.src('./src')
    .pipe(pathway.script('myLib', './src', {indentation: "  ", strict: true}))
    .pipe(pathway.manifest('myLib', './src', {}))
    .pipe(gulp.dest('./build'));
});

Script

pathway.script('name', 'base/path', {'opions': true})

The following Pathway features are made available to the script:

  • $import
  • $package
  • $export

The script..

var Math2 = $import('@Math2');
function divide(a, b) {
  return Math2.pretty(a/b);
}
$export(divide);

...will compile to

window["@myLib"]('utils', function ($import, $package) { 'use stict';
  var Math2 = $import('@Math2');
  function divide(a, b) {
    return Math2.pretty(a/b);
  }
  return {
    divide: divide
  };
});

$import and $package are normal JavaScript identifiers at runtime, read the Pathway Module System page for information on how they work.

$export is special to gulp-pathway, it is a function-like compiler macro which is replaced, in situ, by a return statement. It will only be matched if it is the final statement in the script.

A shorthand has also been incorporated into this which allows you to export local named variables directly, without the mapping. For example

$export(a, b, {c: x}, d);

compiles to:

return {a: a, b: b, c: x, d: d};

NB. Conflicting names will be ignored

Directory Structure

Scripts are organized into modules based upon the position of their enclosing directory on the file system. For example,

If the base directory is ./src and the library name is 'myLib'; the following files will have the these properties within Pathway:

./src/pkg/a/script.js
{library: 'myLib', package: 'pkg/a'}

./src/hello.js
{library: 'myLib', package: '/'}

Output

Script contents will be outputted as plain JavaScript in the same file structure as the source files passed in. Use other Gulp based tools in your gulpfile.js to determine what to do next, as shown in the gulp file example.

The two files referenced above will each have the following paths after passing through pathway.source

./src/myLib/pkg/a/script.js
./src/myLib/hello.js

Manifest

pathway.manifest('name', 'base/path', {'opions': true})

Library Main (myLib.js)

The 'main file' contains the module initialization code, along with a __manifest__ module which lists all files and packages in this library (for debugging). In the case of the directory structure example, this plugin would add the following file to the stream:

[BASE]/myLib.js

With the following contents

;(...pathway source here...)('myLib')('__manifest__', function () {
  return {
    files: ["main.js", "pkg/a/script.js"],
    packages: ["/", "pkg/a"]
  };
});

At runtime the main file must be loaded before all other code in the library. This is a separate step because it may be desirable for you to bootstrap the Pathway library your own way.