Slbox
Slbox

Reputation: 13108

How can I read or copy assets out of an .exe packaged with vercel/pkg?

I have a pkg-packaged .exe I need to copy files out of - which I'm aware may not be possible - but surely there's some way to get the asset files out, right?

I'm quite confident that the assets are included in the pkg after I added this to my package.json:

  "pkg": {
    "assets": [
      "assets/**/*"
    ]
  },

and --config package.json to my pkg command.

But still, there doesn't seem to be any way to get files out of the executable besides, I guess, to store the files as strings and then write them to the disk (which seems, to me, madness.)

Is there some better way I'm overlooking? I guess Node's fs command can't read into the .exe in any way, but hopefully the .exe should be able to write the files out somewhere, somehow?

Does anyone know how?

TLDR: I'm looking to read, or ideally copy, assets out of the .exe

By the way: Vercel/pkg used to be known as Zeit/pkg

Upvotes: 1

Views: 998

Answers (1)

Slbox
Slbox

Reputation: 13108

I was able to get this working with code like this:

const isPackaged = process.pkg !== undefined; // process.pkg is only defined when packaged
const root = isPackaged ? 'C:\\snapshot\\your-package-name' : process.cwd();

export const ASSETS_PATH = path.join(root, 'assets');

At first I was hesitant to try this because I thought C:\snapshot may not be a reliable path if the user already had such a directory - and that some other path may be used - but that's not the case. C:\snapshot is virtual so there will never be a conflict with the real filesystem.


To clarify, the root of my project has these folders at the same level as my package.json enter image description here

Upvotes: 1

Related Questions