If you try to use SVGO as nodejs module in tests, where you have mock-fs for any targets you will see this error:
ENOENT, no such file or directory '/Users/username/Sources/project/node_modules/svgo/lib/svgo/../../.svgo.yml'
at Binding.<anonymous> (/Users/username/Sources/project/node_modules/mock-fs/lib/binding.js:353:15)
at maybeCallback (/Users/username/Sources/project/node_modules/mock-fs/lib/binding.js:43:17)
at Binding.open (/Users/username/Sources/project/node_modules/mock-fs/lib/binding.js:327:10)
at Object.fs.openSync (/Users/username/Sources/project/node_modules/mock-fs/node/fs-6.3.0.js:598:18)
at Object.fs.readFileSync (/Users/username/Sources/project/node_modules/mock-fs/node/fs-6.3.0.js:466:33)
at Object.readFileSync (/Users/username/Sources/project/node_modules/mock-fs/lib/index.js:59:31)
at module.exports (/Users/username/Sources/project/node_modules/svgo/lib/svgo/config.js:31:48)
at new module.exports (/Users/username/Sources/project/node_modules/svgo/lib/svgo.js:21:19)
at Object.exports.html (/Users/username/Sources/project/src/lib/compilers/index.js:45:16)
at Promise.resolve.then.screen (/Users/username/Sources/project/src/submodule/screen/actions/index.js:43:37)
at process._tickCallback (internal/process/next_tick.js:103:7)
node v6.2.1
npm 3.9.3
svgo 0.6.6
SVGO fails to read the default config.
yep
So what the point of the issue?
So, svgo doesn't work if u try to use it with mock-fs. I think it's necessary in general and for me, because many users use mock-fs in tests. Now I can't use svgo and I need to find another tool, but I don't want to do it. I like svgo and I think u can solve this problem. I think problem can be in yml parser, but I'm not sure.
Sent from my iPhone
On 20 Aug 2016, at 21:31, Lev Solntsev [email protected] wrote:
So what the point of the issue?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@awinogradov have you manually confirmed the file exists?
It's not yml parser, it's svgo/lib/svgo/config.js:31:48 as stack trace says. It tries to read the default config file as I said above.
It's not yml parser, it's svgo/lib/svgo/config.js:31:48 as stack trace says. It tries to read the default config file as I said above.
Yeah, but why can't it read .svgo.yml? Is that because of mock-fs or because of something else? That's why I asked @awinogradov wether he can confirm manually that the file exists.
@derhuerst I'm absolutely sure. I've made example for exception demo https://github.com/awinogradov/svgo-ex. You can repeat it:
git clone [email protected]:awinogradov/svgo-ex.git
npm i
node .
Your example doesn't seem to "copy" the files into the mock fs:
const mock = require('mock-fs');
const SVGO = require('svgo');
mock({[process.cwd()]: mock.directory()});
const svgo = new SVGO();
Also, svgo loads the yaml file relative to the _current file_, not to the current working directory. This looks like it might be another reason it fails.
U can do any operations with mock-fs. SVGO fails anyway :(
Sent from my iPhone
On 21 Aug 2016, at 01:17, Jannis Redmann [email protected] wrote:
Your example doesn't seem to "copy" the files into the mock fs:
const mock = require('mock-fs');
const SVGO = require('svgo');mock({[process.cwd()]: mock.directory()});
const svgo = new SVGO();
Also, svgo loads the yaml file relative to the current file, not to the current working directory. This looks like it might be another reason it fails.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@awinogradov
I think this issue isn't related to SVGO.
You first have to tell mock-fs which files should be available in the mocked fs. The following code fails (even though it doesn't even use SVGO):
'use strict'
const mock = require('mock-fs')
const fs = require('fs')
const path = require('path')
mock({[process.cwd()]: mock.directory()});
fs.readFileSync(path.join(__dirname, 'package.json'))
@derhuerst yep. I'm going to mock-fs issues)
@adamdicarlo
It might be caused by .yarnclean file.
This file include .*.yml, when you yarn install, match files will be ignore.
To get rid of this problem temporarily, edit ./node_modules/svgo/lib/svgo/config.js
Line 31, set defaults var:
defaults = { plugins: [] }
Yarn is fast, but f*ks up sometimes.
Most helpful comment
@adamdicarlo
It might be caused by .yarnclean file.
This file include
.*.yml, when you yarn install, match files will be ignore.