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

Better package structure for require commands #104

Open
prasadtalasila opened this issue Nov 18, 2018 · 5 comments
Open

Better package structure for require commands #104

prasadtalasila opened this issue Nov 18, 2018 · 5 comments
Labels

Comments

@prasadtalasila
Copy link
Member

Description

The sub-directories must contain better package.json files so that the require() can allow us to directly import the targeted sub-module.

Steps to Reproduce

Expected behavior: [What you expect to happen]

Actual behavior: [What actually happens]

Reproduces how often: [What percentage of the time does it reproduce?]

Additional Information

@prasadtalasila
Copy link
Member Author

I have a few ways to go about it :

The suggestions made by branneman seem better. Of the alternatives given, the alias and startup script seem close to what we are doing in other places in AutolabJS project. Of course, we need to make the alias work with the linting and test setup.

@mukkachaitanya mukkachaitanya pinned this issue Dec 22, 2018
@mukkachaitanya mukkachaitanya unpinned this issue Dec 22, 2018
@prasadtalasila
Copy link
Member Author

prasadtalasila commented Jan 19, 2019

The problem requirements

  • remove relative paths
  • application-level configurability of view
  • interface-level (object-level) compatibility between the views
  • dependency injection of view into controller
    • Right number of view objects -- not one global view, or not too many small view objects
  • Application working both as a standalone cli and also as a library-level dependency

@prasadtalasila
Copy link
Member Author

prasadtalasila commented Jan 21, 2019

@ishitamed19 and @mukkachaitanya

There is a tutorial on require which is relevant to this issue. Node.js also allows require.resolve() function which allows us to specify the path names of resolution. We can construct the path name based on the view taken from a config file and give that as an option to require.resolve() function. The require.resolve() function gives us the full path name of the module which can be used to load the module. See a simplistic tutorial here

Also there is now ES6 modules which are supported on Node.js via esm. ES6 modules are like Java packages which provide a nice design flexibility. Another side benefit is the destructuring of necessary named imports from an ES6 module. The only disadvantage vis-a-vis commonJS modules (require()) is that we can't have imports from dynamic paths. Here is a brief summary.

@prasadtalasila
Copy link
Member Author

It might be prudent to just target the following changes.

  • remove relative paths
  • application-level configurability of view

The rest of the requirements demand deep design changes. We can take them up later.

@prasadtalasila
Copy link
Member Author

prasadtalasila commented Jan 21, 2019

The solution of putting something in package.json would limit us from configuring a view. Instead, if we create a require.js in utils which uses the wrapper idea, then we can simply use the following functions.

  • viewRequire()
  • modelRequire()
  • utilsRequire()

We can still read the view from configuration and use require.resolve() to identify the right view files.

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

No branches or pull requests

2 participants