romulomachado / ember-cli-string-helpers

Set of the String helpers extracted from DockYard's ember-composable-helpers.
Other
73 stars 30 forks source link

Compatibility with Embroider #308

Closed patocallaghan closed 3 years ago

patocallaghan commented 3 years ago

I'm not sure if there's much to do here besides some documentation around Embroider but thought I'd raise it anyway.

Problem

It appears things are stabilising around Embroider because since ember-cli 3.25.0 all newly-created addons will have Embroider testing baked into ember-try by default. I've been experimenting with Embroider and various addons and it appears that ember-cli-string-helpers is incompatible with an Embroider app when you use the only or except configuration.

If you try and run a build using the following configuration it fails with the

'ember-cli-string-helpers': {
  only: ['dasherize', 'underscore'],
  except: ['titleize', 'capitalize'],
},
ERROR Summary:

  - broccoliBuilderErrorStack: ModuleNotFoundError: Module not found: Error: Can't resolve '../node_modules/ember-cli-string-helpers/helpers/capitalize' in '$TMPDIR/embroider/f661dd/helpers'
    at /Users/pat/hacking/string-helpers-embroider/node_modules/webpack/lib/Compilation.js:925:10
    at /Users/pat/hacking/string-helpers-embroider/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /Users/pat/hacking/string-helpers-embroider/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /Users/pat/hacking/string-helpers-embroider/node_modules/webpack/lib/NormalModuleFactory.js:224:22
    at /Users/pat/hacking/string-helpers-embroider/node_modules/neo-async/async.js:2830:7
    at /Users/pat/hacking/string-helpers-embroider/node_modules/neo-async/async.js:6877:13
    at /Users/pat/hacking/string-helpers-embroider/node_modules/webpack/lib/NormalModuleFactory.js:214:25
    at /Users/pat/hacking/string-helpers-embroider/node_modules/enhanced-resolve/lib/Resolver.js:213:14
    at /Users/pat/hacking/string-helpers-embroider/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/pat/hacking/string-helpers-embroider/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)

I have a reproduction in this repo here. You can see the configuration used in https://github.com/patocallaghan/string-helpers-embroider/commit/39003b207455995d48f3d65a31239e0c77b4f33a

Embroider support

It's worth calling out that the use case for using the only and except configuration will no longer be required by Embroider "Optimized" mode, i.e. tree-shaking enabled, as that will only load the helpers in your build that you specifically use.

I guess the problem with this addon is if folks are using Embroider "Safe" mode which aims to offer full backwards compatibility with the existing Ember CLI pipeline.

Fix?

I'm not sure if it's worth fixing this as personally I'm just going to remove the only and except config while we are experimenting with Embroider "Safe" mode. Maybe all that is required is some documentation on Embroider compatibility in the README. With Embroider "Optimized" mode the use case for only and except is no longer needed.

ctjhoa commented 3 years ago

ember-composable-helpers use the same only / except system and doesn't break with Embroider. I think this is because of those changes: https://github.com/DockYard/ember-composable-helpers/pull/316

I'll try to replicate this here