Comments (7)
FYI: Accessing the main module
Also, consider that this breaks down when process managers are involved. For example, when using PM2 the main module is not the file you think it is.
Additionally, this was built to start in the current directory and traverse upward, looking for a valid kraken application to support the experimental mounting of apps. If you'll notice, it explicitly DOESN'T use process.cwd(), but starts with the current file location (inside node_modules
, hence the .
); Please see the root resolver to get a better understanding of what's going on here.
EDIT: It doesn't use process.cwd() unless a valid kraken app isn't found. If there's a bug, it might be there.
from kraken-js.
Yep, I was just going to point out what you edited.
I was looking through rootResolver
and I think the issue might be with how we're using the isKraken(obj)
function in this loop.
The parameter being passed by rootResolver
wants to compare the prototype of module.exports
for whatever module is being evaluated in the loop, against the kraken
object (Or the unicode yingyang).
Because of this, I don't think this condition will evaluate to true during the loop, so it eventually stops when there are no more modules to traverse (current.parent=null
).
At this point, since root
was never defined, the function returns process.cwd()
On my solution, I had not considered other startup methods for the app, so good callout.
Will continue looking at this tomorrow.
from kraken-js.
rootResolver
seems like a pretty heavy way to determine the location of the app's root directory. Why not examine module.parent.filename
from within kraken to get the directory of the file which required kraken?
from kraken-js.
Also, is pm2 the recommended way to deploy kraken to a live server? Do you prefer it over, say, node-forever? And are there other such tools worth considering as well?
from kraken-js.
rootResolver
is heavy because it was intended to support more complex application composition. If we choose not to pursue composable, mountable apps then much of this code can be deleted (with no argument from me). module.parent.filename
is not necessarily the module that required a file, but the file that required said file/module, and with composition, depending on the version of kraken, it might not be what you're looking for.
The rub here is composition. If I create a kraken application and publish it as a module, depending on the version of kraken I depend on, I may have my own "application root" (with my own copy of kraken, templates, etc.) which is in a nested directory of the actual application root, but this nested directory (within the top level node_modules
) contains all my application context. @jasisk and I spent a good amount of time working through possible scenarios creating the "heavy" resolver to be resilient to arbitrarily composed applications. The complexity was added for a specific use-case, but if it's deemed unnecessary, I'm more than happy to remove it.
Also, pm2 isn't necessarily the recommended solution, but it's an example of a situation where a script or application runner defines an alternate require.main.filename
crushing all assumptions of what truly is the application root. BTW, there is a flag in pm2 which indicates it may patch require.main.filename
, but last I checked it wasn't available for use.
from kraken-js.
Is this an issue anymore as of 0.7
?
from kraken-js.
Nope...
from kraken-js.
Related Issues (20)
- How to access image from directory located outside the workspace? HOT 1
- Uglify-js has security issues HOT 1
- Templates in public directory? HOT 2
- remove bluebird 🔥 HOT 5
- Support Async Middleware HOT 6
- Is it alive? HOT 3
- remove domains? HOT 16
- formidable events not firing properly in kraken HOT 1
- Koa port HOT 1
- Ajax with krakenjs HOT 1
- Upload multiple images krakenjs using ajax HOT 1
- Creating New Project using yo for Ubuntu 16.04 HOT 6
- Server is starting (status 503) HOT 3
- Dead? HOT 6
- Add node 12 in travis CI
- [Devdeps][security] replace jade with pug
- Yo Kraken Error HOT 9
- Kraken.js - yo kraken Error kraken primordials is not defined HOT 3
- Name of this library HOT 1
- Feature request: ability to use `config/*.js` instead of json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kraken-js.