Socket
Socket
Sign inDemoInstall

@putout/bundler

Package Overview
Dependencies
16
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @putout/bundler

Lint Filesystem with 🐊Putout


Version published
Weekly downloads
108
increased by16.13%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Bundler License NPM version Build Status Coverage Status

Install

npm i @putout/bundle

API

import {bundle} from '@putout/bundler';

console.log(bundle(CWD, entry, filesystem));

Internals

Convert ESM to CommonJS

To Simplify things up all files converted to CommonJS first. Let's suppose none of them use top-level await to get things simpler.

Parse filenames

Traverse all files starting from entry and get all filenames.

Bundle all files to object

Traverse filesystem and create object that contains filename and file content:

const __filesystem = {
    '/entry.js': () => {
        const client = require('/client.js');
        console.log(client);
    },
    '/client.js': (exports, require, module) => {
        module.exports = 'hello';
    },
};

IIFE

Most likely we need IIFE so couple bundles can be loaded on page simultaneously.

Result Example

const __modules = {};
const __filesystem = {
    '/entry.js': () => {
        const client = require('/client.js');
        console.log(client);
    },
    '/client.js': (exports, require, module) => {
        module.exports = 'hello';
    },
};

const require = (name) => {
    const exports = {};
    const module = {
        exports,
    };
    
    if (__modules[name])
        return __modules[name];
    
    __filesystem[name](exports, require, module);
    __modules[name] = module.exports;
    
    return module.exports;
};

require('/entry.js');

License

MIT

Keywords

FAQs

Last updated on 09 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc