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

Should not throw when non mondule-unification directories are added #8

Open
chadhietala opened this issue Apr 4, 2017 · 8 comments

Comments

@chadhietala
Copy link
Member

If you try to add a directory to the module unification file structure it should not throw. Currently if you write some TS file and import it into the a MU directory an error is thrown:

Error: The type of module 'api/foo' could not be identified
    at module.exports (/Users/chietala/workspace/mw-lite/node_modules/@glimmer/resolution-map-builder/lib/get-module-specifier.js:72:15)
    at mappedPaths.forEach.modulePath (/Users/chietala/workspace/mw-lite/node_modules/@glimmer/resolution-map-builder/index.js:66:21)
    at Array.forEach (native)
    at ResolutionMapBuilder.build (/Users/chietala/workspace/mw-lite/node_modules/@glimmer/resolution-map-builder/index.js:63:15)
    at /Users/chietala/workspace/mw-lite/node_modules/@glimmer/resolution-map-builder/node_modules/broccoli-plugin/read_compat.js:93:34
    at tryCatch (/Users/chietala/workspace/mw-lite/node_modules/rsvp/dist/rsvp.js:539:12)
    at invokeCallback (/Users/chietala/workspace/mw-lite/node_modules/rsvp/dist/rsvp.js:554:13)
    at publish (/Users/chietala/workspace/mw-lite/node_modules/rsvp/dist/rsvp.js:522:7)
    at flush (/Users/chietala/workspace/mw-lite/node_modules/rsvp/dist/rsvp.js:2414:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
@rwjblue
Copy link
Member

rwjblue commented Apr 4, 2017

@chadhietala Where was the directory created? If it was within src/ I think an error is appropriate...

@chadhietala
Copy link
Member Author

@rwjblue How does one add a directory for say Redux reducers? As of today it won't be watched and basically makes experimentation very difficult if the answer is "write a custom Broccoli thing". That is a barrier to entry that we likely need to remove.

@rwjblue
Copy link
Member

rwjblue commented Apr 4, 2017

You put files that will be used via import only in src/utils (e.g. not expected to be auto-resolved) or you can add a local -utils collection in any other collection.

@dgeb
Copy link
Member

dgeb commented Apr 4, 2017

Also, if you want to register custom types / collections, you can add your own moduleConfiguration in config/environment.js.

However, this currently overrides (rather than merges with) the defaults, so it would need to be complete. We should consider a merge strategy too, since that will probably be used most often.

@dgeb
Copy link
Member

dgeb commented Apr 4, 2017

@dgeb
Copy link
Member

dgeb commented Apr 4, 2017

And the structure is defined in glimmer-resolver: https://github.com/glimmerjs/glimmer-resolver/blob/master/src/resolver-configuration.ts

@noslouch
Copy link

As a regular joe userland person, I was confused by this error.

I opened an issue on glimmer-application because I wasn't sure why I couldn't add an arbitrary file to my glimmer project. There's nothing stated in the docs (as far as I could tell) that instructs me to avoid doing so.

@michaelwills
Copy link

michaelwills commented Oct 27, 2017

I hit this, too. This would be a great place to mention this:

https://glimmerjs.com/guides/filesystem-layout

I don't know if this is a convention from the ember ecosystem but it makes it harder for new folks to build. The framework itself is very impressive. I was duly shocked at the performance and build size but a guide on how to import your own modules is helpful. Not knowing ember's DI this is the example I have found from @toranb:

https://github.com/glimmer-redux/glimmer-redux-example/blob/master/config/environment.js

Right now I am attempting something like the below. [edit] Turns out it can be simplified a bit more. Adding unresolved: true also eliminates the need to have export default, presumably if broccoli is configured to use commonjs.

'use strict';
const merge = require('lodash.merge');

const fs = require('fs');
const defaultModuleConfigurationPath = __dirname + '/../node_modules/@glimmer/application-pipeline/lib/broccoli/default-module-configuration.ts';
const defaultModuleConfigurationString = fs.readFileSync(defaultModuleConfigurationPath, 'utf-8');

let moduleConfiguration = eval('(' + defaultModuleConfigurationString.replace('export default', '').replace(';', '') + ')');

moduleConfiguration = merge(moduleConfiguration, {
  types: {
    common: { definitiveCollection: 'commons' },
    feature: { definitiveCollection: 'features' },
  },
  collections: {
    common: { unresolvable: true },
    feature: { unresolvable: true }
  }
})

module.exports = function(environment) {
  let ENV = {
    modulePrefix: 'glimmer-tribescribe',
    environment,
    moduleConfiguration
  };

  return ENV;
};

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

No branches or pull requests

5 participants