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

replaces path to .asar.unpacked if cmd includes .asar/node_modules #155

Merged
merged 18 commits into from
Sep 4, 2017
Merged

replaces path to .asar.unpacked if cmd includes .asar/node_modules #155

merged 18 commits into from
Sep 4, 2017

Conversation

thisconnect
Copy link
Contributor

@thisconnect thisconnect commented Jun 22, 2017

js-ipfsd-ctl will not work inside an asar container, see #94.

A possible solution is to exclude the ipfs binary from asar, with the unpackDir option

electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep

(EDITED: changed go-ipfs-dep/** to go-ipfs-dep )

on MacOS: this will package everything expect go-ipfs-dep into <appname>.asar
and put go-ipfs-dep into <appname>.asar.unpacked/node_modules/go-ipfs-dep

This change request adds a check if .asar/ is part of the path and changes it to .asar.unpacked/

Edit:

How to test this change

Assuming you have a project using ipfsd-ctl, electron and electron-packager.

Install https:/thisconnect/js-ipfsd-ctl/tree/asar-unpacked

npm i thisconnect/js-ipfsd-ctl#asar-unpacked

build electron with --asar.unpackDir=node_modules/go-ipfs-dep

electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep

Test if your app works and if everything (but go-ipfs-dep) is bundled in an .asar file

@daviddias
Copy link
Member

@thisconnect I'm not sure if I understand all the implications here. If go-ipfs doesn't get bundled, then how would a standalone electron app that wants to use it work?

@thisconnect
Copy link
Contributor Author

thisconnect commented Jun 24, 2017

electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep does only exclude from the asar archive, but still bundle the files in the app. On MacOS I get

MyApp.app/Contents/Resources/app.asar
MyApp.app/Contents/Resources/app.asar.unpacked/node_modules/go-ipfs-dep

This PR checks if the path to the ipfs binary points to inside an asar archive and changes the path to asar.unpacked. It tests for .asar/node_modules which probably will not work on windows.

With this change It successfully bundle MyApp into an asar archive and am able to start the ipfsd-ctl deamon, that is in app.asar.unpacked.

At this point I think it should be done in the findIpfsExecutable function https:/thisconnect/js-ipfsd-ctl/blob/4453ea7caed94a00cac54d57c1e60d1e6420c1d7/src/node.js#L19

related docs https://electron.atom.io/docs/tutorial/application-packaging/#executing-binaries-inside-asar-archive

An other solution would be to be able to configure the path to the ipfs binary.

@thisconnect
Copy link
Contributor Author

The configuration could be done on as api or environment variable. As a ipfsd-ctl consumer I want to just use the api and not write my code differently for a packaging detail.

I am unsure if configuring the path with an env variable is possible and a good idea :/

@daviddias
Copy link
Member

Got it. I'm afraid I haven't used enough electron to know the full breadth of issues, but this PR doesn't seem to break our existing use cases so I'm fine trying it out :)

Could you add documentation of the issue and how to circumvent it with the packaging command you mention here so that others can try it too?

@kyledrake, you've been hacking on electron and going through the same issues, mind sharing your thoughts here?

@thisconnect
Copy link
Contributor Author

thisconnect commented Jun 24, 2017

Please do NOT merge this yet, it may not work on windows, due to forward slash. Not sure if that works with Node 4.x / npm 2.x when modules are not deduped.

I have not tried electron-builder yet. With electron-builder asar is enabled by default, see https:/electron-userland/electron-builder/wiki/Options#AsarOptions
also it seems electron-builder detects binaries and unpacks them automatically, though I am not sure how that works. I am going to try this soon.

edit: moved howto to PR description

@thisconnect
Copy link
Contributor Author

thisconnect commented Jul 2, 2017

Ok tested thisconnect/js-ipfsd-ctl#asar-unpacked on windows 10.

for windows

  • added os.platform check to set the executable filename to ipfs.exe
  • electron-packager wildcard (glob?) seems to work differently on windows, changed
    electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/**
    to
    electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep
    so that it includes the dir and the binary

Please review https:/ipfs/js-ipfsd-ctl/pull/155/files

@thisconnect thisconnect changed the title WIP: replaces path to .asar.unpacked if cmd includes .asar/node_modules replaces path to .asar.unpacked if cmd includes .asar/node_modules Jul 3, 2017
@daviddias daviddias added the status/in-progress In progress label Jul 3, 2017
@daviddias
Copy link
Member

@thisconnect is this ready for review and merge?

@thisconnect
Copy link
Contributor Author

@diasdavid yes please.

also please have a look at this line, https:/ipfs/js-ipfsd-ctl/pull/155/files#diff-6ff379484cbabad48301d485db111c08R32 that should have been a different PR.

in the meantime the power port of my windows laptop melted. Do you use appveyor for windows CI?

@daviddias
Copy link
Member

daviddias commented Aug 30, 2017

@thisconnect just enabled appveyor for this repo. Could you add the config file (Tutorial, Great example)

https://ci.appveyor.com/project/diasdavid/js-ipfsd-ctl-a9ywu

@daviddias
Copy link
Member

Also, just added you to the JS team. You can now create branches on the main repo and PR directly from them. This helps collaboration between multiple people

https:/orgs/ipfs/teams/javascript-team/members 🌟

@thisconnect
Copy link
Contributor Author

Thanks @diasdavid I'll find time over the weekend and will create a branch for appveyor.

@daviddias
Copy link
Member

Ok, I'll be more tranquil to merge this PR when I see the tests passing in Windows and in Linux CI :)

@daviddias daviddias mentioned this pull request Sep 2, 2017
@daviddias daviddias self-requested a review September 4, 2017 08:47
Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisconnect thank you for keeping on pushing on this front :) Can't wait to merge this PR!

// electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep
if (appRoot.includes(`.asar${path.sep}`)) {
appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add this to the README too? It is fine to leave it here, but I want to make sure it this note is searchable and linkable to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@thisconnect
Copy link
Contributor Author

@daviddias
Copy link
Member

@thisconnect ipfs-inactive/js-ipfs-http-client#408 shouldn't be an issue of this module specifically. Is there another test you can add to check that the module works?

@thisconnect
Copy link
Contributor Author

@diasdavid I have never built electron within CI, it should be possible but might take a long time. Not sure if it is worth right now.

I tried to add some info in the readme and a minimal example in examples/electron-asar, please have a look

@thisconnect
Copy link
Contributor Author

thisconnect commented Sep 4, 2017

The "checks response of ipfs.util.addFromFs for windows" now tests too much.

Do you prefer

A) the deep equal that should cover everything about the response https:/thisconnect/js-ipfsd-ctl/blob/46c422ebf1f5b11acecf81da74a553fbab4093d5/test/index.spec.js#L394-L406

B) or remove it and keep the rest https:/thisconnect/js-ipfsd-ctl/blob/46c422ebf1f5b11acecf81da74a553fbab4093d5/test/index.spec.js#L408-L418

C) or keep it as it was before

EDIT: other than that I think it should be ready, unfortunately my windows laptop's power supply burned so I can't test on windows.

@daviddias
Copy link
Member

daviddias commented Sep 4, 2017

@thisconnect given that addFromFs has issues in Windows, I don't believe it to be a good test case to have. Better to skip (add a .skip) it for now.

Update: Check process.env and if Windows skip that test with a comment describing that is waiting on the fix for js-ipfs-api

@@ -390,10 +390,32 @@ describe('daemons', () => {
if (err) throw err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is a temporary skip, is it ok if I just os.platform() === 'win32' ?

https://nodejs.org/api/os.html#os_os_platform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get https:/ipfs/npm-go-ipfs-dep/blob/master/src/index.js#L47-L60 sorry!! :( it also depends on another module (go-platform) and file https:/ipfs/npm-go-ipfs-dep/blob/master/src/check-support.js

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woot! Will just wait on CI!

@thisconnect
Copy link
Contributor Author

@daviddias
Copy link
Member

Seems like a go-ipfs thing, @Kubuxu ?

@thisconnect
Copy link
Contributor Author

thisconnect commented Sep 4, 2017

https:/thisconnect/js-ipfsd-ctl/blob/f3e49d54ecb143d130812dfc07ebd0788ae5aa72/test/index.spec.js#L438 checks for a repo.lock file in index.spec.js , something before did not close correctly?

@Kubuxu
Copy link
Member

Kubuxu commented Sep 4, 2017

Nothing changed in go-ipfs that could cause it. How does shutting down work? Does it wait for go-ipfs to shutdown? Is it station timeout or does it poll the process?

@daviddias
Copy link
Member

daviddias commented Sep 4, 2017

Nothing changed in go-ipfs that could cause it. How does shutting down work?

It is the first time we are enabling Windows testing in this module, so really anything is worth ;)

Sounds like that go-ipfs never really deleted the lock file but in windows (such as OS X or Linux) it just gives 0 frambroises and continues. Here, since we check for it, we actually saw it is there.

@thisconnect let's skip that check if in Windows as well :) This isn't a real issue.

Thanks for jumping in too @Kubuxu :)

@Kubuxu
Copy link
Member

Kubuxu commented Sep 4, 2017

It might be Windows, Windows is a bit neglected so it is possible that this is an issue.

if (fs.existsSync(path.join(dir, 'api'))) {
cb(new Error('api file not removed'))
}
cb()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to skip the whole test, just to skip the assertion for repo.lock

cb(new Error('api file not removed'))
// skip on windows
// https:/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530
if (isWindows) it.skip('start and stop')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add curly {}

@thisconnect
Copy link
Contributor Author

there was travis fail Uncaught TypeError: Cannot read property 'constructor' of null https://travis-ci.org/ipfs/js-ipfsd-ctl/builds/271713202?utm_source=github_status&utm_medium=notification

@thisconnect
Copy link
Contributor Author

}
if (fs.existsSync(path.join(dir, 'api'))) {
cb(new Error('api file not removed'))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@thisconnect
Copy link
Contributor Author

@daviddias daviddias changed the base branch from master to windows September 4, 2017 15:56
@daviddias daviddias merged commit abed2e4 into ipfs:windows Sep 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants