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

@warren-bank/electron-portable-paths

v3.0.8

Published

Cross-platform helper functions to perform Electron boilerplate to configure 'special' directory paths relative to the executable

Downloads

18

Readme

electron-portable-paths

Cross-platform helper functions to perform Electron boilerplate to configure "special" directory paths relative to the executable

Resulting Directory Structure:

> tree . /F /A
C:\PortableApps\${productName}Portable
|   ${productName}.exe
|
\---${productName}
    +---data
    |   |   Cookies
    |   |   Cookies-journal
    |   |
    |   +---blob_storage
    |   |   \---aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
    |   +---Cache
    |   |       data_0
    |   |       data_1
    |   |       data_2
    |   |       data_3
    |   |       f_000001
    |   |       index
    |   |
    |   +---GPUCache
    |   |       data_0
    |   |       data_1
    |   |       data_2
    |   |       data_3
    |   |       index
    |   |
    |   +---temp
    |   \---webrtc_event_logs
    +---home
    |   +---desktop
    |   +---documents
    |   +---downloads
    |   +---music
    |   +---pictures
    |   \---videos
    \---logs

Installation:

npm install --save "@warren-bank/electron-portable-paths"

API:

  • success = makePortable(app)

    • input parameters:
    • output value:
      • boolean
        • indicates whether a non-portable build has been configured in such a way that its paths can now be remapped by setPortablePaths
    • notes:
      • works across all platforms
      • has no effect when the Electron executable is a Windows portable target
  • success = setPortablePaths(app, make_dirs, rootPath, blacklist, allow_remapping_into_blacklisted_parent_directory)

    • input parameters:
      • required:
      • optional:
        • make_dirs: boolean
          • allow the creation of all remapped "special" directories that do not already exist
            • Electron will often choose to ignore a directory path when it cannot be found
          • default value: true
        • rootPath: string
          • path to custom root directory
          • default value: ./${app.getName()}
        • blacklist: Array of string
        • allow_remapping_into_blacklisted_parent_directory: boolean
    • output value:
      • boolean
        • indicates whether paths have been successfully remapped
    • notes:
      • only has effect when any of the following conditions are true:
        • the Electron executable is a Windows portable target
        • makePortable was previously called

Usage Example (basic):

  • file: ./src/main.js
      const {app} = require('electron')
      const {makePortable, setPortablePaths} = require('@warren-bank/electron-portable-paths')
    
      makePortable(app)
      setPortablePaths(app)

Usage Example (advanced):

  • file: ./src/main.js
      const {app} = require('electron')
      const {makePortable, setPortablePaths} = require('@warren-bank/electron-portable-paths')
    
      const parseArgv = require('yargs').parse
      const argv = parseArgv(process.argv.slice(1))
    
      if (argv['portable'])
        makePortable(app)
    
      if (!setPortablePaths(app, true, argv['data-dir'], ["documents","downloads"]) && argv['data-dir'])
        app.setPath('userData', path.resolve(argv['data-dir']))

Build Targets (tested and working):

  • linux
    • [x] tar.gz
    • [x] appimage
    • [x] deb
    • [ ] rpm
  • win
    • [x] zip
    • [x] portable
    • [x] squirrel
  • mac
    • [x] zip
    • [x] dmg

notes:

  • linux
    • deb
      • installation:
          app_name='myapp-desktop'
          app_productName='MyApp'
        
          sudo apt-get install ./${app_name}.deb
      • observations:
          which ${app_name}
          # /usr/local/bin/${app_name}
        
          ls -la `which ${app_name}`
          # /usr/local/bin/${app_name} -> /opt/${app_productName}/${app_name}
        
          ${app_name} --portable
        
          ls -d /opt/${app_productName}/${app_productName}
          # No such file or directory
        
          sudo ${app_name} --portable
        
          ls -d /opt/${app_productName}/${app_productName}
          # /opt/${app_productName}/${app_productName}
      • take-aways:
        • when the .deb package is installed by root
          • when the app is run by a regular user
            • need to make sure that rootPath:
              • exists, or can be created
              • is writable
      • workaround:
        • electron-builder.json:
            {
              "linux": {
                "target": ["deb"]
              },
              "deb": {
                "afterInstall": "build_resources/scripts/linux-package.after-install.sh",
                "afterRemove":  "build_resources/scripts/linux-package.after-remove.sh"
              }
            }
        • build_resources/scripts/linux-package.after-install.sh
            #!/bin/bash
          
            # Link to the binary
            ln -sf '/opt/${productFilename}/${executable}' '/usr/local/bin/${executable}'
          
            # Create default --portable directory
            mkdir --mode=777 '/opt/${productFilename}/${productFilename}'
        • build_resources/scripts/linux-package.after-remove.sh
            #!/bin/bash
          
            # Delete the link to the binary
            rm -f '/usr/local/bin/${executable}'
          
            # Delete default --portable directory
            rm -rf '/opt/${productFilename}/${productFilename}'
          
            # Cleanup
            rm -rf '/opt/${productFilename}'
      • scope of workaround:

Legal: