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

hazardous

v0.3.0

Published

Overload Electron path module for asar.unpacked support

Downloads

850

Readme

Hazardous

This module overloads some functions of the path module of Electron in order to workaround a painful behaviour with the asar files.

The problem concerns the cases where a .asar.unpacked/* file must be passed to an executable somewhere on the filesystem. This executable can not access to the files packed in the .asar archive. In this case, when the .asar archive is created, it's possible to specify directories to keep unpacked, but it's not sufficient.

Example

An example will be, Perl scripts. You cannot run .pl scripts from Electron, but you can spawn perl and pass the .pl script as argument. Imagine that the .pl script is in a node_modules and this one is in the .asar archive. When you spawn perl, you catch an error because perl cannot access to app.asar/node_modules/perl-module/script.pl.

Then you try to package by this way:

asar pack app app.asar --unpack-dir "**/node_modules/perl-module/**"

The result looks good. You can see the app.asar file and the app.asar.unpacked directory with the perl-module and the perl scripts.

But when you try to use your app, you continue to receive an error because perl cannot find script.pl.

What is the real purpose of .asar.unpacked?

It seems that it's only useful with executables. If you have an executable in a node_modules, it makes sense to use the unpack way because the spawn and exec functions of child_process are aware of .asar.unpacked. Then your executable can be used transparently.

Hazardous workaround

The idea is to overload three functions of path (join (), normalize () and resolve ()).

These functions are wrapped by hazardous in order to detect if the location is in .asar.unpacked or not. If it's impossible to guess, it just returns the original responses of the real path functions.

Note that only absolute locations are considered by hazardous. With relative locations it's impossible to know if the user wants the __dirname of the caller function or the current working dir (cwd ()).

How to use

npm i --save hazardous

Just insert (at the beginning of your main script):

'use strict';

require ('hazardous');
const path = require ('path');

const script = path.join (__dirname, 'script.pl');
/* script = /home/foo/bar/app.asar.unpacked/node_modules/perl-module/script.pl */
/* -----------------------------------^                                        */

The path functions must be used only after that hazardous has been loaded.

If you use the previous code without require ('hazardous'), then the script value will be:

/* script = /home/foo/bar/app.asar/node_modules/perl-module/script.pl */
/* ------------------------------^                                    */