Yeoman / grunt .readJSON()

时间:2014-06-30 21:55:40

标签: javascript node.js gruntjs yeoman

我确定我错过了一些简单的东西,但有人可以解释为什么this.src.copy发生在this.dest.readJSON之后:

var yeoman = require('yeoman-generator')
  , TestGenerator

TestGenerator = yeoman.generators.Base.extend(
  { writing: function () {
      this.src.copy('package.json', 'package.json')
      this.pkg = this.dest.readJSON('package.json')
    }
  }
)

module.exports = TestGenerator

导致以下错误:

/tmp/test/node_modules/yeoman-generator/node_modules/file-utils/lib/file.js:252
    throw new Error('Unable to read "' + filepath + '" file (Error code: ' + e
          ^
Error: Unable to read "/tmp/test-run/package.json" file (Error code: ENOENT).
    at Env.File.read (/tmp/test/node_modules/yeoman-generator/node_modules/file-utils/lib/file.js:252:11)
    at Env.(anonymous function) [as read] (/tmp/test/node_modules/yeoman-generator/node_modules/file-utils/lib/env.js:24:41)
    at Env.File.readJSON (/tmp/test/node_modules/yeoman-generator/node_modules/file-utils/lib/file.js:258:18)
    at Env.(anonymous function) [as readJSON] (/tmp/test/node_modules/yeoman-generator/node_modules/file-utils/lib/env.js:24:41)
    at yeoman.generators.Base.extend.writing (/tmp/test/jim/index.js:7:28)
    at /tmp/test/node_modules/yeoman-generator/lib/base.js:381:14
    at processImmediate [as _immediateCallback] (timers.js:336:15)

我无法在任何一个文档中找到任何说明这些函数不同步的内容:

http://gruntjs.com/api/grunt.file https://github.com/SBoudrias/file-utils

1 个答案:

答案 0 :(得分:0)

看起来在复制的写入部分中可能会运行一些异步代码:

https://github.com/SBoudrias/file-utils/blob/master/lib/env.js#L129