glimmerjs / resolution-map-builder

MIT License
4 stars 7 forks source link

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

Open chadhietala opened 7 years ago

chadhietala commented 7 years ago

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 commented 7 years ago

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

chadhietala commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

BTW, here is the default module configuration: https://github.com/glimmerjs/glimmer-application-pipeline/blob/master/lib/broccoli/default-module-configuration.ts

dgeb commented 7 years ago

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

noslouch commented 7 years ago

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 commented 6 years ago

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;
};