ember-cli icon indicating copy to clipboard operation
ember-cli copied to clipboard

Usage of files nested in directories in filesToRemove cause issue when installing a file to the same directory

Open synaptiko opened this issue 8 years ago • 3 comments

Environment

Output from ember version --verbose && npm --version && yarn --version:

ember-cli: 2.13.3
http_parser: 2.7.0
node: 6.11.0
v8: 5.1.281.102
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
icu: 58.2
modules: 48
openssl: 1.0.2k
os: linux x64
3.6.0
1.2.1

Steps

  1. generate new addon ember addon some-addon
  2. generate new application ember new some-app
  3. cd some-addon
  4. ember generate blueprint some-blueprint
  5. vim blueprints/some-blueprint/index.js with content
/* eslint-env node */
module.exports = {
  filesToRemove: ['app/styles/app.css']
};
  1. mkdir -p blueprints/some-blueprint/files/app/styles && touch blueprints/some-blueprint/files/app/styles/app.scss
  2. cd ../some-app
  3. ember install <path-to-some-addon>
  4. ember generate some-blueprint entity-name

Actual result

installing some-blueprint
  create app/styles/app.scss
  remove app/styles/app.css
ENOENT: no such file or directory, open '/home/jprokop/work/sandbox/some-app/app/styles/app.scss'
Error: ENOENT: no such file or directory, open '/home/jprokop/work/sandbox/some-app/app/styles/app.scss'
    at Error (native)

Expected result

I would expect that this use-case is possible to perform. While debugging this issue I noticed that ember-cli uses fs-extra which is probably the root cause of the issue. Looks like "race-condition" because calls are async.

synaptiko avatar Oct 24 '17 08:10 synaptiko

Are you sure it's not your blueprint code that creates app.scss expected the "styles" folder to exist?

kellyselden avatar Oct 24 '17 18:10 kellyselden

The result of the blueprint should be to "replace" default app.css with app.scss. If I just include files/app/styles/app.scss it works fine because there is already app.css in the same folder. Problem is that when you want to delete the app.css file by usage of filesToRemove it will also remove the folders on the path if they are empty. But according to this line and documentation of fs-extra.outputFile the outputFile method should create the parent directory if it doesn't exist. But in this case it will fail.

synaptiko avatar Oct 25 '17 05:10 synaptiko

Ah I understand now. You weren't manually creating the file via fs.writeFile, but by placing the file in the blueprint, ember-cli was trying to create it for you, but it already conveniently removed the folder for you. This is definitely a bug. I don't have an estimate when it will be fixed, but if you could submit a failing test all the existing tests for the filesToRemove feature, that would expedite it. And of course, if you have to time to submit the fix as well, that would be greatly appreciated.

kellyselden avatar Oct 25 '17 16:10 kellyselden

Closing as stale since I couldn't find a PR for a failing test.

locks avatar Jul 25 '23 00:07 locks