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

orbital.js

v0.1.4

Published

Plugin System for Webpack

Downloads

5

Readme

Orbital.js

A plugin system for webpack

Install

npm install orbital.js

Example

$ git clone [email protected]:naver/orbital.js.git
$ cd ./orbital.js/example
$ npm install
$ npm run dev

http://127.0.0.1:3030 will show a screen like below.

image

image

The example has the following directory structure.

image

And has a architecture stack like this.

image

package.json

Basic Sample

{
    "name": "your-package-name",
    "version": "0.1.0",
    ...
    "dependencies": {
        "orbital": "^0.1.0"
    },
    "orbital": {
        "activator": "./src/Activator.js",
        "contributable": {
            "services": [],
            "extensions": []
        },
        "contributes": {
            "services": [],
            "extensions": []
        }
    }
}

activator

  • Activator is optional. It is called on start and stop phases. Activator is an entry point to make your plugin do something. onStart() and onStop() method is called with / object, which enables you to access extensions, services and other plugins.

      
    class Activator {
    
        onStart(context) {
            //do some on plugin start
        }
    
        onStop(context) {
            //do some on plugin end
        }
    }
    
    export default Activator;
    
  • Real example

    import {getSettingsFragment} from './extensions/settingsContents';
    
    class Activator {
    
        constructor() {
            super();
            this.stateListener = this.handlePluginStateChange.bind(this);
        }
    
        onStart(context) {
            this.context = context;
            context.getPlugins().forEach((plugin) => {
                plugin.on('stateChange', this.stateListener);
            });
        }
    
        onStop(context) {
            context.getPlugins().forEach((plugin) => {
                plugin.off('stateChange', this.stateListener);
            });
        }
    
        handlePluginStateChange(/* who, state, oldState */) {
            this.refresh();
        }
    
        refresh() {
            const settingsPane = document.querySelector('#settingsPane');
            if (settingsPane) {
                const newSettingsPane = getSettingsFragment(this.context);
                settingsPane.parentNode.replaceChild(newSettingsPane, settingsPane);
            }
        }
    }
    
    export default Activator;
    

contributable

Receives contributions from other plugins. contributable is a kind of interface.

  • contributable extensions

    An extension point is an object where other plugins can contribute extensions to.

    contributable extensions field requires three fields id, desc, spec.

    • id (mandatory) : The extension point id which should be unique.
    • desc (optional) : The explanation for the extension point.
    • spec (mandatory) : The interface which should be implemented by contributor plugins.

    The following example shows three extension points. examples.shop.layout:contents, examples.shop.layout:aside and examples.shop.layout:header

    {
        "name": "examples.shop.layout",
        "version": "0.1.0",
        "description": "This package provides a layout for shop app",
        "orbital": {
            "activator": "./src/Activator.js",
            "contributable": {
                "services": [],
                "extensions": [
                    {
                        "id": "examples.shop.layout:contents",
                        "desc": "You can contribute ui(s) to the contents area.",
                        "spec": {
                            "path": "string",
                            "getElement": "function"
                        }
                    },
                    {
                        "id": "examples.shop.layout:aside",
                        "desc": "You can contribute ui(s) to the aside area.",
                        "spec": {
                            "getView": "function"
                        }
                    },
                    {
                        "id": "examples.shop.layout:header",
                        "desc": "You can contribute ui(s) to the header area.",
                        "spec": {
                            "getView": "function"
                        }
                    }
                ]
            },
            "contributes": {
                "services": [],
                "extensions": []
            }
        }
    }
    
  • contributable services

    A service point is an interface which should be implemented by other plugins.

    contributable services field requires three fields id, desc, spec.

    • id (mandatory) : The service point id which should be unique.
    • desc (optional) : The explanation for the service point.
    • spec (mandatory) : The interface which should be implemented by contributor plugins.

    Following example shows contributable service examples.shop.resources:api

    {
        "name": "examples.shop.resources",
        "version": "0.1.0",
        "description": "This package serves resources(Rest API, Images) for shop app",
        "dependencies": {
        },
        "orbital": {
            "contributable": {
                "services": [
                    {
                        "id": "examples.shop.resources:api",
                        "desc": "This spec provides rest api for shop",
                        "spec": {
                            "deleteFromCart": "function",
                            "getAccount": "function",
                            "getCart": "function",
                            "getProductById": "function",
                            "getProductCategories": "function",
                            "getProducts": "function",
                            "postToCart": "function",
                            "postLogin": "function",
                            "postLogout": "function"
                        }
                    }
                ],
                "extensions": []
            },
            "contributes": {
                "services": [
                    {
                        "id": "examples.shop.resources:api",
                        "realize": "./src/services/RestApi.js"
                    }
                ],
                "extensions": []
            }
        }
    }
    

contributes

Using contributes field, plugins can contribute to the contributable services and extensions.

  • contributes extensions

    Following example implements two extensions. examples.shop.layout:contents and examples.shop.layout:aside of examples.shop.layout plugin package.

    {
        "name": "examples.shop.products",
        "version": "0.1.0",
        "description": "Products package for shop app",
        "dependencies": {
            "examples.shop.layout": "file:../examples.shop.layout",
            "orbital.js": "^0.1.2"
        },
        "orbital": {
            "activator": "./src/Activator.js",
            "contributable": {
                "services": [],
                "extensions": []
            },
            "contributes": {
                "services": [],
                "extensions": [
                    {
                        "id": "examples.shop.layout:contents",
                        "realize": "./src/extensions/contents.js"
                    },
                    {
                        "id": "examples.shop.layout:aside",
                        "realize": "./src/extensions/aside.js",
                        "priority": 100
                    }
                ]
            }
        }
    }
    
  • contributes services

    Following example implements examples.shop.resources:api contributable service itself. Plugin can implement it's own contributables.

    {
        "name": "examples.shop.resources",
        "version": "0.1.0",
        "description": "This package serves resources(Rest API, Images) for shop app",
        "dependencies": {
        },
        "orbital": {
            "contributable": {
                "services": [
                    {
                        "id": "examples.shop.resources:api",
                        "desc": "This spec provides rest api for shop",
                        "spec": {
                            "deleteFromCart": "function",
                            "getAccount": "function",
                            "getCart": "function",
                            "getProductById": "function",
                            "getProductCategories": "function",
                            "getProducts": "function",
                            "postToCart": "function",
                            "postLogin": "function",
                            "postLogout": "function"
                        }
                    }
                ],
                "extensions": []
            },
            "contributes": {
                "services": [
                    {
                        "id": "examples.shop.resources:api",
                        "realize": "./src/services/RestApi.js"
                    }
                ],
                "extensions": []
            }
        }
    }
    

priority

Using priority, you can control the orders of plugin contributions. For example, the order of ui components contributions, or service priority.

Following two examples show priority 100 and 200. Extensions are sorted with higher priority value. Default priority is 0.

{
    "name": "examples.shop.products",
    "version": "0.1.0",
    "description": "Products package for shop app",
    "dependencies": {
        "examples.shop.layout": "file:../examples.shop.layout",
        "orbital.js": "^0.1.2"
    },
    "orbital": {
        "activator": "./src/Activator.js",
        "contributable": {
            "services": [],
            "extensions": []
        },
        "contributes": {
            "services": [],
            "extensions": [{
                "id": "examples.shop.layout:header",
                "realize": "./src/extensions/header.js",
                "priority": 100
            }]
        }
    }
}
{
    "name": "examples.shop.cart",
    "version": "0.1.0",
    "description": "Cart package for shop app",
    "dependencies": {
        "examples.shop.layout": "file:../examples.shop.layout",
        "orbital.js": "^0.1.2"
    },
    "orbital": {
        "contributable": {
            "services": [],
            "extensions": []
        },
        "contributes": {
            "services": [],
            "extensions": [
                {
                    "id": "examples.shop.layout:header",
                    "realize": "./src/extensions/header.js",
                    "priority": 200
                }
            ]
        }
    }
}

orbital.config.js

module.exports = {
    packages: {
        ignored: [
            /* packages to be ignored */
        ],
        stopped: [
            /* packages to be stopped on start, but later it could be started */
        ]
    }
};

webpack.config.js

module: {
    rules: [
        ...,
        {
            test: /orbital.js$/,
            loader: 'orbital-loader'
        },
        ...
    ]
}

Bug Report

If you find a bug, please report to us posting issues on GitHub.

License

orbital.js is released under the MIT license.

Copyright (c) 2019 NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.