GithubHelp home page GithubHelp logo

xcodebuild / asar-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from toyobayashi/asar-node

0.0 1.0 0.0 755 KB

Enable require('./path/to/any-node-project.asar') & require('./path/to/any-node-project.asar/any/file'). Or just run asar-node ./path/to/any-node-project.asar

License: MIT License

JavaScript 97.79% HTML 2.10% CSS 0.11%

asar-node's Introduction

asar-node

Enable require('./path/to/any-node-project.asar') & require('./path/to/any-node-project.asar/any/file') in your nodejs app.

Usage

$ npm install -g asar-node

Exists ./path/to/any-node-project.asar

$ asar-node ./path/to/any-node-project # OK!
$ asar-node ./path/to/any-node-project.asar # OK!

$ asar-node ./path/to/any-node-project.asar/any/file # OK!
$ asar-node ./path/to/any-node-project.asar/any/file.js # OK!
$ asar-node ./path/to/any-node-project.asar/any/file.json # OK!
$ asar-node ./path/to/any-node-project.asar/any/file.node # OK!

Or

require('asar-node').register()
// Equivalent to require('asar-node/lib/register.js').register()

require('./path/to/any-node-project') // like require a nodejs directory
// or require('./path/to/any-node-project.asar')
require('./path/to/any-node-project.asar/any/file')

If require a asar file, make sure there is package.json and main field or index.js / index.json / index.node in the asar root.

You can also pack node_modules into node_modules.asar instead of packing the hole project folder into an asar file.

To let node find modules from node_modules.asar, You should

const { register, addAsarToLookupPaths } = require('asar-node')
// Equivalent to 
// const register = require('asar-node/lib/register.js').register
// const addAsarToLookupPaths = require('asar-node/lib/lookup.js').addAsarToLookupPaths

register()
addAsarToLookupPaths()

const Koa = require('koa') // koa is in node_modules.asar

In an electron project, it's unnecessary to call register() but you can also call addAsarToLookupPaths() to enable node_modules.asar support.

Migrate from v1

v1.x

require('asar-node')

v2.x

require('asar-node/lib/autorun/index')

Note

  • Only these fs api functions are available in asar file and you should use absolute path. Also child_process api is not supported in asar file.

    • fs.readFileSync()
    • fs.createReadStream()
    • fs.statSync()
    • fs.lstatSync()
    • fs.readdirSync()
    • fs.existsSync()
    • fs.realpathSync()
  • If your nodejs project use C++ native addons, please unpack it from asar file by specifying --unpack=*.node to asar CLI

  • Express or Koa serving static file in asar file is not supported, but you can unpack the static file folder.

asar-node's People

Contributors

andywer avatar toyobayashi avatar

Watchers

 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.