首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Yeoman / grunt .readJSON()

Yeoman / grunt .readJSON()
EN

Stack Overflow用户
提问于 2014-07-01 05:55:40
回答 1查看 508关注 0票数 0

我确信我错过了一些简单的东西,但是谁能解释一下为什么在this.dest.readJSON之后会发生this.src.copy:

代码语言:javascript
复制
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

导致以下错误:

代码语言:javascript
复制
/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

EN

回答 1

Stack Overflow用户

发布于 2014-07-01 16:06:43

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24499565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档