Hi!
I'm getting a really weird side effect of using the ember-simple-auth plugin alongside a JS preprocessor.
I'm using LiveScript as a primary language for my frontend code, and https://github.com/avanov/ember-cli-livescript plugin for my Ember CLI apps.
When I put "ember-simple-auth": "1.0.1" into devDependencies of the project and start a development server, I get the following error (notice the unexpected file changed routes/application.js output):
$ ember serve
version: 1.13.14
Livereload server on http://localhost:49152
Serving on http://localhost:4200/
file changed routes/application.js
Build successful - 4331ms.
Slowest Trees | Total
----------------------------------------------+---------------------
ConcatWithMaps: Concat: Vendor | 2328ms
LiveScript | 398ms
CleanCSSFilter | 321ms
Slowest Trees (cumulative) | Total (avg)
----------------------------------------------+---------------------
ConcatWithMaps: Concat: Vendor (1) | 2328ms
LiveScript (2) | 402ms (201 ms)
CleanCSSFilter (2) | 341ms (170 ms)
Babel (13) | 332ms (25 ms)
EEXIST: file already exists, symlink '/Users/Maksim/projects/<project-name>/tmp/live_script-cache_path-IEPsxSAj.tmp/webclient/routes/application.js' -> '/Users/Maksim/projects/<project-name>/tmp/live_script-output_path-ecWgv6YH.tmp/webclient/routes/application.js'
Error: EEXIST: file already exists, symlink '/Users/Maksim/projects/<project-name>/tmp/live_script-cache_path-IEPsxSAj.tmp/webclient/routes/application.js' -> '/Users/Maksim/projects/<project-name>/tmp/live_script-output_path-ecWgv6YH.tmp/webclient/routes/application.js'
at Error (native)
at Object.fs.symlinkSync (fs.js:945:18)
at symlink (/Users/Maksim/projects/<project-name>/node_modules/symlink-or-copy/index.js:82:14)
at symlinkOrCopySync (/Users/Maksim/projects/<project-name>/node_modules/symlink-or-copy/index.js:58:5)
at symlinkOrCopyFromCache (/Users/Maksim/projects/<project-name>/node_modules/broccoli-filter/index.js:204:3)
at LiveScript.processAndCacheFile (/Users/Maksim/projects/<project-name>/node_modules/broccoli-filter/index.js:111:14)
at rebuildEntry (/Users/Maksim/projects/<project-name>/node_modules/broccoli-filter/index.js:69:21)
at /Users/Maksim/projects/<project-name>/node_modules/promise-map-series/index.js:11:14
at lib$rsvp$$internal$$tryCatch (/Users/Maksim/projects/<project-name>/node_modules/rsvp/dist/rsvp.js:493:16)
at lib$rsvp$$internal$$invokeCallback (/Users/Maksim/projects/<project-name>/node_modules/rsvp/dist/rsvp.js:505:17)
This is what I have in my app/routes/application.js equivalent written in LiveScript:
# app/routes/application.ls
``import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';``
ApplicationRoute = Ember.Route.extend ApplicationRouteMixin,
session: Ember.inject.service 'session'
# bunch of other definitions
``export default ApplicationRoute;``
I also noticed that under node_modules/ember-simple-auth/app there is some portion of my project, including routes/application.js which is a pre-processed version of my routes/application.ls script:
$ tree node_modules/ember-simple-auth/app
node_modules/ember-simple-auth/app
โโโ initializers
โย ย โโโ ember-simple-auth.js
โโโ instance-initializers
โย ย โโโ ember-simple-auth.js
โโโ routes
โย ย โโโ application.js
โโโ services
โย ย โโโ session.js
โโโ session-stores
โโโ application.js
5 directories, 5 files
Is there anything that can cause the error I'm getting?
This also happens when you have an existing application.js written in CoffeeScript. You'll have to convert that to plain JS.
@marcoow Why does a plugin impose on me the way I write my code as long as Ember CLI allows me to use preprocessors? It looks like an inconsistent policy with the framework.
That's not actually imposed by ESA - Ember CLI just doesn't support merging trees with files written in different languages (I guess because different extensions or so). You might want to check ember-cli/ember-cli.
And if this question is not debatable, why is there no warning on the title page of the plugin mentioning that inconsistency?
The README focusses on the most common use cases only as it would be lengthy and confusing if it covered everything there might be to know.
Ember CLI just doesn't support merging trees with files written in different languages
I have a project that uses CoffeeScript and LiveScript at the same time, but for different parts of the project (legacy code). So the statement is only correct in cases when there are two source files with the same name (i.e. application.js and application.ls). What I do not understand and would like to clarify to myself, is why ESA has to have its own version of routes/application.js that has to be merged with my project?
ESA needs to setup session restoration in the application route's beforeModel method: https://github.com/simplabs/ember-simple-auth/blob/master/addon/instance-initializers/setup-session-restoration.js
Ok, is it possible to alleviate the impact somehow apart rewriting sources to js? I still want to use the plugin and find it highly useful.
I'd be happy to merge a pull request if you find a solution.
As a workaround, you can delete ESA's application route as an NPM postinstall step:
from package.json:
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test",
"postinstall": "sh esa-coffee-workaround.sh"
},
and here's esa-coffee-workaround.sh:
# ember-simple-auth's routes/application.js conflicts with the routes/application.js
# that results from compilation of our routes/application.coffee.
# ESA's application route doesn't seem to be necessary.
# https://github.com/simplabs/ember-simple-auth/issues/851
echo "deleting ember-simple-auth's application route to workaround incompatibility with coffeescript..."
rm -f node_modules/ember-simple-auth/app/routes/application.js
I look forward to the day I can remove this!
Thanks @jrr !!
Moved the node_modules/ember-simple-auth/app/routes/application.js to a .bkp file and solved the problem.
Below the copy of problem to help other people on searches
โ my_app git:(master) โ ember serve
DEPRECATION: Addon files were detected in `~/my_app/node_modules/ember-load-initializers/addon`, but no JavaScript preprocessors were found for `ember-load-initializers`. Please make sure to add a preprocessor (most likely `ember-cli-babel`) to in `dependencies` (NOT `devDependencies`) in `ember-load-initializers`'s `package.json`.
DEPRECATION: ember-cli-test-loader should now be included as an NPM module with version 1.1.0 or greater.
Livereload server on http://localhost:49153
Serving on http://localhost:4200/
The Broccoli Plugin: [broccoli-persistent-filter:CoffeeScriptFilter] failed with:
Error: EEXIST: file already exists, symlink '~/my_app/node_modules/ember-simple-auth/app/routes/application.js' -> '~/my_app/tmp/broccoli_persistent_filtercoffee_script_filter-output_path-P1r2gs9E.tmp/lisweb-cli/routes/application.js'
at Error (native)
at Object.fs.symlinkSync (fs.js:897:18)
at symlink (~/my_app/node_modules/symlink-or-copy/index.js:98:14)
at symlinkOrCopySync (~/my_app/node_modules/symlink-or-copy/index.js:65:5)
at CoffeeScriptFilter.Filter._handleFile (~/my_app/node_modules/broccoli-persistent-filter/index.js:178:12)
at CoffeeScriptFilter.<anonymous> (~/my_app/node_modules/broccoli-persistent-filter/index.js:155:23)
at ~/my_app/node_modules/promise-map-series/index.js:11:14
at tryCatch (~/my_app/node_modules/rsvp/dist/rsvp.js:539:12)
at invokeCallback (~/my_app/node_modules/rsvp/dist/rsvp.js:554:13)
at publish (~/my_app/node_modules/rsvp/dist/rsvp.js:522:7)
at flush (~/my_app/node_modules/rsvp/dist/rsvp.js:2414:5)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
The broccoli plugin was instantiated at:
at CoffeeScriptFilter.Plugin (~/my_app/node_modules/broccoli-plugin/index.js:7:31)
at CoffeeScriptFilter.Filter [as constructor] (~/my_app/node_modules/broccoli-persistent-filter/index.js:62:10)
at new CoffeeScriptFilter (~/my_app/node_modules/broccoli-coffee/index.js:16:10)
at CoffeeScriptFilter (~/my_app/node_modules/broccoli-coffee/index.js:15:53)
at CoffeePreprocessor.toTree (~/my_app/node_modules/ember-cli-coffeescript/lib/coffee-preprocessor.js:23:10)
at ~/my_app/node_modules/ember-cli-preprocess-registry/preprocessors.js:180:26
at Array.forEach (native)
at processPlugins (~/my_app/node_modules/ember-cli-preprocess-registry/preprocessors.js:178:11)
at module.exports.preprocessJs (~/my_app/node_modules/ember-cli-preprocess-registry/preprocessors.js:171:10)
at EmberApp._notifyAddonIncluded.EmberApp.addonTreesFor.EmberApp.addonLintTree.EmberApp._podTemplatePatterns.EmberApp.appAndDependencies (~/my_app/node_modules/ember-cli/lib/broccoli/ember-app.js:1100:25)
at EmberApp._notifyAddonIncluded.EmberApp.addonTreesFor.EmberApp.addonLintTree.EmberApp._podTemplatePatterns.EmberApp.javascript (~/my_app/node_modules/ember-cli/lib/broccoli/ember-app.js:1231:28)
at EmberApp._notifyAddonIncluded.EmberApp.addonTreesFor.EmberApp.addonLintTree.EmberApp._podTemplatePatterns.EmberApp.javascript.EmberApp.styles.EmberApp.otherAssets.EmberApp._import.EmberApp.toArray (~/my_app/node_modules/ember-cli/lib/broccoli/ember-app.js:1668:10)
at EmberApp._notifyAddonIncluded.EmberApp.addonTreesFor.EmberApp.addonLintTree.EmberApp._podTemplatePatterns.EmberApp.javascript.EmberApp.styles.EmberApp.otherAssets.EmberApp._import.EmberApp.toTree (~/my_app/node_modules/ember-cli/lib/broccoli/ember-app.js:1690:30)
at module.exports (~/my_app/ember-cli-build.js:60:14)
at Builder.setupBroccoliBuilder (~/my_app/node_modules/ember-cli/lib/models/builder.js:54:19)
at new Builder (~/my_app/node_modules/ember-cli/lib/models/builder.js:33:10)
at ServeTask.run (~/my_app/node_modules/ember-cli/lib/tasks/serve.js:15:19)
at ~/my_app/node_modules/ember-cli/lib/commands/serve.js:78:29
at tryCatch (~/my_app/node_modules/rsvp/dist/rsvp.js:539:12)
at invokeCallback (~/my_app/node_modules/rsvp/dist/rsvp.js:554:13)
at ~/my_app/node_modules/rsvp/dist/rsvp.js:629:16
at flush (~/my_app/node_modules/rsvp/dist/rsvp.js:2414:5)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
Most helpful comment
As a workaround, you can delete ESA's application route as an NPM postinstall step:
from
package.json:and here's
esa-coffee-workaround.sh:I look forward to the day I can remove this!