New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#425] new tech "write-file" #426
Conversation
@blond посмотри верно ли сделан тест? |
.then(function () { | ||
|
||
// При оспользовании "mockFS.fs().statSync" выскакивает ошибка | ||
// mockFS.fs().statSync('bundle/bundle.txt').isFile().should.be.ok; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я к сожалению так и не разобрался почему mockFS.fs() фейлится но основная проблема как мне кажется в другом. MockFS манки патчит родной fs модуль ( для этого мы вызываем mockFs() и mockFs.restore() - чтобы добавить/удалить манки патчинг )
Заменив
mockFS.fs().statSync('bundle/bundle.txt').isFile().should.be.ok;
на
require('fs').statSync('bundle/bundle.txt').isFile().should.be.ok;
Все начинает работать как нужно
Также можно убедиться в том что нужно использовать fs модуль посмотрев тесты самого mockFs
https://github.com/tschaub/mock-fs/blob/master/test/integration/filecount.js#L3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AiBoy спасибо за ревью! Действительно, так тест проходит!
enb = require('../lib/api'), | ||
vfs = enb.asyncFs; | ||
|
||
module.exports = inherit(enb.BaseTech, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно проще переписать технологию с помощью build-flow
.
@pavelpower написал замечания. И ещё надо добавить документацию в |
@blond спасибо, поправлю |
@blond попробовал сделать так var enb = require('../lib/api'),
vfs = enb.asyncFs;
module.exports = enb.buildFlow.create()
.name('write-file')
.target('target', '?.target')
.defineRequiredOption('target')
.defineRequiredOption('content')
.defineOption('fileOptions', { encoding: 'utf8' })
.builder(function () {
var node = this.node,
target = node.unmaskTargetName(this._target),
filename = node.resolvePath(target);
return vfs.write(filename, this._content, this._fileOptions)
.then(function () {
node.resolveTarget(target);
}, function () {
node.rejectTarget(target, new Error('file not write: ' + filename));
});
})
.createTech(); Но возникла проблема в том, что такая реализация вызывает 'vfs.write' много раз. Сделал тестовый проектик, для того, чтобы понять почему не проходит тест на проверку контента.
module.exports = function(config) {
// Настраиваем сборку бандла
config.node('bundle', function(nodeConfig) {
// Декларируем модули технологий,
// которые могут участвовать в сборке таргетов.
nodeConfig.addTechs([
[require('enb/techs/write-file'), {
content: 'R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
target: '?.png',
fileOptions: {
encoding: 'base64'
}
}],
[require('enb/techs/write-file'), {
content: '## Test \n this a test text',
target: '?.md',
fileOptions: {
encoding: 'utf8'
}
}]
]);
// Объявляем таргеты, которые хотим собрать.
nodeConfig.addTargets(['?.png', '?.md']);
});
}; Оказалось, что в целевых файлах В рамках проекта поставил Вот, что получил: enb make
[ ‘~/Projects/opensource/test-enb/.enb/tmp',
undefined,
[Function] ]
[ ‘~/Projects/opensource/test-enb/.enb/tmp',
[Function] ]
02:54:06.249 - build started
[ ‘~/Projects/opensource/test-enb/bundle',
undefined,
[Function] ]
[ ‘~/Projects/opensource/test-enb/bundle',
[Function] ]
[ ‘~/Projects/opensource/test-enb/bundle/bundle.png',
'R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
{ encoding: 'base64' },
[Function] ]
[ ‘~/Projects/opensource/test-enb/bundle/bundle.md',
'## Test \n this a test text',
{ encoding: 'utf8' },
[Function] ]
02:54:06.276 - [rebuild] [bundle/bundle.png] write-file
02:54:06.276 - [rebuild] [bundle/bundle.md] write-file
[ ‘~/Projects/opensource/test-enb/bundle/bundle.png',
'undefined',
'utf8',
[Function] ]
[ ‘~/Projects/opensource/test-enb/bundle/bundle.md',
'undefined',
'utf8',
[Function] ] Заметь сколько раз вызывается плагин! Может вариант использования Или ее надо готовить иначе? |
Сделал трейс вызова writeFile: Trace: [ '~/Projects/opensource/test-enb/bundle/bundle.md',
'## Test \n this a test text',
{ encoding: 'utf8' },
[Function] ]
at Object.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:46:35
at Object.vow.invoke (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:1050:20)
at Object.Queue._runTask (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:204:27)
at Object.Queue._run (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:186:18)
at processImmediate [as _immediateCallback] (timers.js:383:17)
03:00:16.378 - [rebuild] [bundle/bundle.md] write-file
Trace: [ '~/Projects/opensource/test-enb/bundle/bundle.md',
'undefined',
'utf8',
[Function] ]
at Object.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:46:35
at Object.vow.invoke (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:1050:20)
at Object.Queue._runTask (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:204:27)
at Object.Queue._run (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:186:18)
at processImmediate [as _immediateCallback] (timers.js:383:17)
|
@blond кстати при текущей реализации тот же Выглядит так: > enb make
Trace: [ '~/Projects/opensource/test-enb/.enb/tmp',
undefined,
[Function] ]
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:316:24
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Trace: [ '~/Projects/opensource/test-enb/.enb/tmp',
[Function] ]
at Object.stat (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at Object.module.exports.isDir (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:234:21)
at onFailed (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:307:28)
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
03:19:37.083 - build started
Trace: [ '~/Projects/opensource/test-enb/bundle',
undefined,
[Function] ]
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:316:24
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Trace: [ '~/Projects/opensource/test-enb/bundle',
[Function] ]
at Object.stat (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at Object.module.exports.isDir (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:234:21)
at onFailed (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:307:28)
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Trace: [ '~/Projects/opensource/test-enb/bundle/bundle.md',
'## Test \n this a test text',
{ encoding: 'utf8' },
[Function] ]
at Object.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:46:35
at Object.vow.invoke (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:1050:20)
at Object.Queue._runTask (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:204:27)
at Object.Queue._run (~/Projects/opensource/test-enb/node_modules/vow-queue/lib/queue.js:186:18)
at processImmediate [as _immediateCallback] (timers.js:383:17) |
Это логичное поведение для Чтобы переопределить это поведение, нужно задекларировать метод var enb = require('../lib/api'),
vfs = enb.asyncFs;
module.exports = enb.buildFlow.create()
.name('write-file')
.target('target', '?.target')
.defineRequiredOption('target')
.defineRequiredOption('content')
.defineOption('fileOptions', { encoding: 'utf8' })
.builder(function () {
return this._content;
})
.saver(function (filename, content) {
return vfs.write(filename, content, this._fileOptions);
})
.createTech(); |
Это связано с технологией |
@blond Решение с
Похоже на то, что это связано не с технологией Бандлы для нод так же создаются по два раза: .enb/make.js: module.exports = function(config) {
// Настраиваем сборку бандла
config.node('bundle', function(nodeConfig) {
});
}; console: > enb make
Trace: ----> [ '~/Projects/opensource/test-enb/.enb/tmp',
undefined,
[Function] ]
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:316:24
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Trace: ----> [ '~/Projects/opensource/test-enb/.enb/tmp',
[Function] ]
at Object.stat (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at Object.module.exports.isDir (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:234:21)
at onFailed (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:307:28)
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
01:04:53.166 - build started
Trace: ----> [ '~/Projects/opensource/test-enb/bundle',
undefined,
[Function] ]
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25
at ~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:316:24
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Trace: ----> [ '~/Projects/opensource/test-enb/bundle',
[Function] ]
at Object.stat (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:28:25)
at Object.module.exports.isDir (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:234:21)
at onFailed (~/Projects/opensource/test-enb/node_modules/vow-fs/lib/fs.js:307:28)
at Array.<anonymous> (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:712:56)
at Immediate.callFns [as _onImmediate] (~/Projects/opensource/test-enb/node_modules/vow/lib/vow.js:23:35)
at processImmediate [as _immediateCallback] (timers.js:383:17) |
Почему так мыслей нет, предлагаю поискать это отдельно. Например, может кто-то вызывает |
@blond у меня предположение, что проблема в |
|
||
bundle = new MockNode('bundle'); | ||
resolveSpy = sinon.spy(bundle, 'resolveTarget'); | ||
rejectSpy = sinon.spy(bundle, 'rejectTarget'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolveSpy
и rejectSpy
не нужены
Написал замечания по коду. |
@pavelpower, не очень понимаю как это связано =) |
Они всегда вызываются по 2 раза, воспроизводится давно и при любых вариациях конфига. |
Соскваш коммиты и вливаем. |
:okay: |
5f5690c
to
4812715
Compare
@blond done |
👍 |
No description provided.