Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asar target and prepackaged option support for it #1102

Closed
pauliusuza opened this issue Jan 11, 2017 · 27 comments · May be fixed by qcif/data-curator#563
Closed

asar target and prepackaged option support for it #1102

pauliusuza opened this issue Jan 11, 2017 · 27 comments · May be fixed by qcif/data-curator#563
Labels

Comments

@pauliusuza
Copy link
Contributor

@pauliusuza pauliusuza commented Jan 11, 2017

  • electron-builder 11.2.3:
  • OSX:

Builder crashes when trying to package app with --prepackaged command with the following error:

Error: ENOENT: no such file or directory, 
open '/Users/pro/repository/desktop_app/dist/mac/Desktop.app/Contents/Resources/app-update.yml'
at /Users/pro/repository/desktop_app/node_modules/electron-builder/src/macPackager.ts:101:13

In my package.json:
{"dist": "npm run compile && build --prepackaged ./asar"}
where ./asar is the folder containing app.asar, core.asar and node_modules.asar files

What I want is to be able to point electron-builder into a folder containing app.asar and it would package the apps for distribution.

develar added a commit to develar/electron-builder that referenced this issue Jan 11, 2017
@develar
Copy link
Member

@develar develar commented Jan 11, 2017

@pauliusuza Crash fixed. But prepackaged is not for your use case. @wojtkowiak Could you please share your experience — how do you use already packed asar files?

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

So I found a temporary workaround by packing app.asar through the electron-builder, and including the remaining .asar files through extraResources key:

"build": {
    "asar": true,
    "files": [
      "!**",
      "index.js",
      "package.json"
    ],
    "extraResources": [
      {
        "from": "asar",
        "to": ""
      }
    ]
}

However, it would be really great if electron builder would have a feature which would simply pack the whole folder and it's contents if it has app.asar file without running additional checks.

build --fromAsar ./path/to/folder/containing/app.asar_file/

Would you consider adding this feature?

@develar
Copy link
Member

@develar develar commented Jan 11, 2017

@pauliusuza It is already supported (#759)

without running additional checks

What error do you get?

@wojtkowiak
Copy link
Contributor

@wojtkowiak wojtkowiak commented Jan 11, 2017

I am not sure what this problem is actually about.
@pauliusuza if you are packing your app to asars yourself you just need to turn off asar packing in electron-builder, the rest should work. I am using electron-builder programmatically so I am just setting asar to false in build options. @develar is there a cli switch for that?

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

@develar it's checking for package.json and index.js files, so if I simply point it to a folder with asar files the build step fails.

@develar
Copy link
Member

@develar develar commented Jan 11, 2017

@pauliusuza So — you have some folder where asar files are located (app.asar is required, no other electron files) and just want to pack it into .app or .dmg or any other electron-buidler target?

Just curious — why electron-builder is not suitable to produce required asar files?

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

@develar yes. Mostly for flexibility - we want to separate the build process and packaging process. Asar files would be built in one CI process (which is complex and takes more time) and stored on a cdn, and packaging would run in another process on demand.

We have a use case where we need to be able to build 20-30 different apps on demand on CI re-using same .asar files, but only changing app name and branding.

@develar
Copy link
Member

@develar develar commented Jan 11, 2017

Asar files would be built in one CI process

Using electron-builder? Or using asar tool programmatically? I just want to understand to be sure that implemented solution will be the best solution (not workaround).

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

Sure, thanks.

  1. The first step of the process would be running asar tool programmatically (through gulp or npm script) and pack the required files into .asar archives, it would then store those .asar files into a CDN. This would run on CI on each commit.

  2. Second step would be executed on demand. It would fetch the latest .asar files from CDN, store them into a folder, apply required customization / branding, and run electron builder to pack all of this into a distributable format.

@develar
Copy link
Member

@develar develar commented Jan 11, 2017

Got it. So:

  1. New target asar will be added. electron-builder will just pack your app into app.asar.
  2. --prepackaged will detect — is it fully prepackaged directory (has electron files) or not.
@develar develar changed the title Crash: app-update.yml not found when using --prepackaged asar target and prepackaged option support for it Jan 11, 2017
@develar develar added the feature label Jan 11, 2017
@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

@develar thanks, that sounds good

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 11, 2017

So just a note for --prepackaged /dir
If app.asar already exists in the /dir, then it should check for existence of the package.json and index.js files inside the app.asar file, and not in the /dir folder itself.

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Jan 17, 2017

@develar I posted a 50$ bounty for this.

@develar
Copy link
Member

@develar develar commented Feb 2, 2017

Solution: just use electron-builder in a standard way. But your project directory must contain:

  • app.asar and other files.

If electron-builder cannot find package.json in the project directory, app.asar will be used a source of project metadata.

Caveats:

  • files, extraResources and extraFiles are not taken in account. All content in the project directory copied as is. Default exclusion rules are still applied (so, you don't need to worry.
  • two-package.json structure is not supported. Because no dev package.json in the asar.app.
  • if you build deb, you must specify homepage in the package.json Default discovery doesn't work because no git repository
  • repository also cannot be detected automatically — required for publishing (if publish config doesn't contain all required information).
  • electron-builder.yml is taken in account and can define some extra config here. If you use electron-builder.yml to package your app.asar — you must copy it to the project directory (alongside side your packaged app.asar).

Easy possible solution to provide additional data: using --em (to set standard package.json fields) or --em.build (to set config) e.g.

--em.repository="develar/repo

This comment in progress — I will update as soon functionality is pushed/updated.

@develar develar closed this in 60e1406 Feb 2, 2017
@develar
Copy link
Member

@develar develar commented Feb 2, 2017

Issue closed — please try 12.3.0.

I posted a 50$ bounty for this.

If you want, you can donate. https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W6V79R2RGCCHL

@develar
Copy link
Member

@develar develar commented Feb 2, 2017

Asar target — if need, please open separate issue.

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

Sorry, this does not work.

How can i specify project directory through options and point it to a subfolder containing asar files?
Project folder contains files which should not be packaged, and there is no way to exclude them.

@develar
Copy link
Member

@develar develar commented Feb 2, 2017

How can i specify project directory through options

current working directory or set explicitly using --project CLI.

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

We are using electron-builder programmatically, not through CLI - is it possible to add a config parameter for the project directory?

@develar
Copy link
Member

@develar develar commented Feb 2, 2017

Set projectDir

to custom.

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

Can't get this to work.

builder.build({
    appId: 'com.test.asar',
    projectDir: '/Users/pro/repository/test-project/temp/asar'
})

Error: Application entry file "index.js" in the "/Users/pro/repository/test-project/dist/mac/Test Project.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration.

// index.js file exists:
$> asar list /Users/pro/repository/test-project/temp/asar/app.asar

/index.js
/package.json

Additional files in the asar folder were not copied to the Resources

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

Running this in cli

build --project temp/asar

TypeError: Cannot read property 'directories' of undefined
at /Users/pro/repository/test-project/node_modules/electron-builder/src/packager.ts:122:68

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

Would it not be simpler just to ignore the app folder packaging step if a specific flag is set, so we can include the .asar files via extraFiles / extraResources?

@develar
Copy link
Member

@develar develar commented Feb 2, 2017

@pauliusuza Is it possible to send me your directory with asar files to test?

@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 2, 2017

@develar I will send you an email shortly

develar added a commit to develar/electron-builder that referenced this issue Feb 3, 2017
develar added a commit to develar/electron-builder that referenced this issue Feb 3, 2017
develar added a commit that referenced this issue Feb 3, 2017
@pauliusuza
Copy link
Contributor Author

@pauliusuza pauliusuza commented Feb 3, 2017

Thanks @develar for checking out the code. Leaving a comment here if someone has the same issue (this should be documented somewhere eventually)

Important bit is to specify the electronVersion and projectDir parameters.
Working example:

import * as builder from 'electron-builder';
let config = {
    appId: 'com.asar.test',
    directories: {
        buildResources: './build_resources'
    },
    electronVersion : '1.5.0'
}
builder.build({
    projectDir: './path/to/folder/with/asar/files',
    config: config
}).then(() => {
    console.log('done');
}).catch((error) => {
    console.log(error);
})
@yansenlei
Copy link

@yansenlei yansenlei commented Nov 14, 2018

@pauliusuza Have you successfully build a separate app.asar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.