Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

support requiring json files #62

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

Closed
wants to merge 1 commit into from

Conversation

karlbohlmark
Copy link
Contributor

I think json support is quite natural, partly because it is supported in npm, but also because in practice, it is a core part of javascript.

My use case:

In my component.json for my tests i have

{
 "scripts": [
    "index.js",
    "test-this.js",
    "test-that.js",
    "test-alot-more-like-this.js",
    "component.json"
  ]
}

and I'd like to be able to do this in index.js

require('./component').scripts.forEach(function (script) {
  if (script.startsWith('test-')) require('./' + script);
})

@karlbohlmark
Copy link
Contributor Author

Hmm, in this particular case, maybe it's me being stuck in my old test-layout. I should probably move the tests into the respective components instead.

I still imagine json support to be quite nice though.

@eldargab
Copy link
Contributor

+1 for this
I have few modules kinda

"scripts": [
  "index.js",
  "data.json"
]

@karlbohlmark
Copy link
Contributor Author

I closed it because it seemed nobody was interested and I solved my particular issue another way. I still think it would be quite useful and natural though

@eldargab
Copy link
Contributor

May be reopen?

@karlbohlmark
Copy link
Contributor Author

Yeah maybe, but I'm not sure tj wants it, and I think there's plans for bigger changes in the builder right now that makes it unlikely to get a pull request merged for the time being.

@tj
Copy link
Contributor

tj commented Feb 22, 2013

im ok with it, we'd probably want to add a json: prop instead of scripts for parity with the other types of assets. Alternatively it would be super trivial to have a little plugin that translates json to a .js for the same result, only downside then is that you couldn't disambiguate with require('data.json') over require('data')

@eldargab
Copy link
Contributor

Plugin option means that component-build will fail to build json, right? But it should be possible to build such components with a standard command!

@tj
Copy link
Contributor

tj commented Feb 22, 2013

yeah, I dont disagree, just mentioning the options. I don't think it's crucial json is valid js, just stick a module.exports = in front haha, but might as well add it I guess

@tj tj reopened this Feb 22, 2013
@vendethiel
Copy link

Lib for builder's new -u flag?

@bergie
Copy link

bergie commented Apr 12, 2013

I would also find JSON support useful for NoFlo. We need a way for components to declare what NoFlo components and graphs they provide, and at what include paths. On Node.js we utilize package.json for that:

{
  "name": "noflo-something",
  ...
  "noflo": {
    "components": {
      "MyComponent": "./something/some/path/MyComponent.js"
    }
  }
}

Since some components are bound to be available only for browser, and others only for Node.js, it would make sense to expose the Node-compatible components in package.json, and browser-compatible components in component.json, and then just add the component JSON into the "scripts" or "json" key of itself.

So, two things I'd need here:

  1. a way to declare JSON files that will be buildt into the JS file
  2. a way to get a list of all the declared JSON files (from the main project and dependencies)

One acceptable solution to 2. would be to make require.modules public.

@bergie
Copy link

bergie commented Apr 25, 2013

Related: componentjs/component#275

In the meanwhile, https://github.com/CamShaft/component-json may work as a workaround.

@micky2be
Copy link
Contributor

I'm not against the idea but why don't you use javascript by sticking an object on module.exports?
You could even put comment in your file, which you can't with json.

@cristiandouce
Copy link

👍 For the json key!

@karlbohlmark
Copy link
Contributor Author

I actually had one more usecase for this today. I was making a (third party) node module into a component (again..) and it happened to do a require('package.json').

With json support in component I would only need to maintain a patch to add a component.json file, without it it gets a bit more ugly.

@jonathanong
Copy link
Contributor

#128

@jonathanong jonathanong closed this Nov 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.