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

Search for module from app path when URL is not file protocol #9095

Merged
merged 10 commits into from Apr 20, 2017

Conversation

Projects
None yet
4 participants
@seanchas116
Contributor

seanchas116 commented Apr 3, 2017

This PR makes require()to search for modules from app directory when the URL is not file protocol (such as http, data or about:blank).

I think this would be more intuitive solution for #8425 and #8963 (comment).

@seanchas116

This comment has been minimized.

Show comment
Hide comment
@seanchas116

seanchas116 Apr 4, 2017

Contributor

Updated, thank you 👍

Contributor

seanchas116 commented Apr 4, 2017

Updated, thank you 👍

@kevinsawicki

Left some very minor comments, looks good overall though 👍

Show outdated Hide outdated spec/modules-spec.js
Show outdated Hide outdated spec/modules-spec.js
@kevinsawicki

This comment has been minimized.

Show comment
Hide comment
@kevinsawicki

kevinsawicki Apr 20, 2017

Contributor

Thanks for this @seanchas116 👍 🎆

Contributor

kevinsawicki commented Apr 20, 2017

Thanks for this @seanchas116 👍 🎆

@kevinsawicki kevinsawicki merged commit a004cad into electron:master Apr 20, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@seanchas116

This comment has been minimized.

Show comment
Hide comment
@seanchas116

seanchas116 Apr 21, 2017

Contributor

Thanks too 👍 🎉

Contributor

seanchas116 commented Apr 21, 2017

Thanks too 👍 🎉

@lastmjs

This comment has been minimized.

Show comment
Hide comment
@lastmjs

lastmjs May 10, 2017

@seanchas116 I'm just trying to understand how to use this in my app. I load an HTML file from a local HTTP server with Electron, and I would like to require my modules relative to the index.html file that I load. Will this help me achieve that? So far with my experimenting it doesn't seem to help, the app root is set to some strange location in node_modules/electron/bla/bla, which doesn't help get to any of the node_modules that my application would actually use. Any insight would be appreciated

lastmjs commented May 10, 2017

@seanchas116 I'm just trying to understand how to use this in my app. I load an HTML file from a local HTTP server with Electron, and I would like to require my modules relative to the index.html file that I load. Will this help me achieve that? So far with my experimenting it doesn't seem to help, the app root is set to some strange location in node_modules/electron/bla/bla, which doesn't help get to any of the node_modules that my application would actually use. Any insight would be appreciated

@seanchas116

This comment has been minimized.

Show comment
Hide comment
@seanchas116

seanchas116 May 10, 2017

Contributor

the app root is set to some strange location in node_modules/electron/bla/bla

The app path (which you can get by app.getAppPath()) would be usually the directory of the package.json you provide on Electron launch.
Probably Electron is launched without package.json?
If so you could provide package.json to require modules relative to it.

Contributor

seanchas116 commented May 10, 2017

the app root is set to some strange location in node_modules/electron/bla/bla

The app path (which you can get by app.getAppPath()) would be usually the directory of the package.json you provide on Electron launch.
Probably Electron is launched without package.json?
If so you could provide package.json to require modules relative to it.

@lastmjs

This comment has been minimized.

Show comment
Hide comment
@lastmjs

lastmjs May 10, 2017

Thanks! I still have a couple questions:

The app path (which you can get by app.getAppPath()) would be usually the directory of the package.json you provide on Electron launch.

What do you mean by the package.json I provide on Electron launch? Here is my package.json:

{
  "name": "jfive-web-components",
  "version": "0.0.8",
  "description": "Web components for controlling hardware with the Johnny-Five JavaScript Robotics & IoT platform.",
  "scripts": {
    "test": "electron --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/scramjs/jfive-web-components.git"
  },
  "author": "Jordan Last <jordan.michael.last@gmail.com>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/scramjs/jfive-web-components/issues"
  },
  "homepage": "https://github.com/scramjs/jfive-web-components#readme",
  "dependencies": {
    "johnny-five": "^0.10.10"
  },
  "devDependencies": {
    "jsverify": "^0.8.2",
    "mocha": "^3.3.0",
    "scram-engine": "git+ssh://git@github.com/scramjs/scram-engine.git",
    "sinon": "^2.2.0",
    "tape": "^4.6.3"
  }
}

When I log app.getAppPath() I get:

/home/lastmj/development/scramjs/jfive-web-components/node_modules/electron/dist/resources/default_app.asar

I think I would like it to be:

/home/lastmj/development/scramjs/jfive-web-components

Am I thinking about it incorrectly?

lastmjs commented May 10, 2017

Thanks! I still have a couple questions:

The app path (which you can get by app.getAppPath()) would be usually the directory of the package.json you provide on Electron launch.

What do you mean by the package.json I provide on Electron launch? Here is my package.json:

{
  "name": "jfive-web-components",
  "version": "0.0.8",
  "description": "Web components for controlling hardware with the Johnny-Five JavaScript Robotics & IoT platform.",
  "scripts": {
    "test": "electron --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/scramjs/jfive-web-components.git"
  },
  "author": "Jordan Last <jordan.michael.last@gmail.com>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/scramjs/jfive-web-components/issues"
  },
  "homepage": "https://github.com/scramjs/jfive-web-components#readme",
  "dependencies": {
    "johnny-five": "^0.10.10"
  },
  "devDependencies": {
    "jsverify": "^0.8.2",
    "mocha": "^3.3.0",
    "scram-engine": "git+ssh://git@github.com/scramjs/scram-engine.git",
    "sinon": "^2.2.0",
    "tape": "^4.6.3"
  }
}

When I log app.getAppPath() I get:

/home/lastmj/development/scramjs/jfive-web-components/node_modules/electron/dist/resources/default_app.asar

I think I would like it to be:

/home/lastmj/development/scramjs/jfive-web-components

Am I thinking about it incorrectly?

@seanchas116

This comment has been minimized.

Show comment
Hide comment
@seanchas116

seanchas116 May 10, 2017

Contributor

Probably
electron --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window
would have to be
electron . --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window
to specify app path.

Contributor

seanchas116 commented May 10, 2017

Probably
electron --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window
would have to be
electron . --enable-logging node_modules/scram-engine/main.js --entry-file test/index.html --window
to specify app path.

@lastmjs

This comment has been minimized.

Show comment
Hide comment
@lastmjs

lastmjs May 10, 2017

electron . doesn't work for me, but I just found in the commit app.setAppPath, and using that function it seems to be working, so thanks!

lastmjs commented May 10, 2017

electron . doesn't work for me, but I just found in the commit app.setAppPath, and using that function it seems to be working, so thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment