简体   繁体   English

Yeoman / grunt .readJSON()

[英]Yeoman / grunt .readJSON()

I'm sure I've missed something simple but can anyone explain why this.src.copy happens after this.dest.readJSON here: 我敢肯定我错过了一些简单的东西,但是谁能解释为什么this.dest.readJSON之后发生this.src.copy:

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

Resulting in the following error: 导致以下错误:

/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)

I can't find anything in either of the docs to say these functions aren't synchronous: 我在两个文档中都找不到任何内容来说明这些功能不同步:

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

Looks like there might be some async code running in the write part of the copying: 看起来在复制的写部分中可能正在运行一些异步代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM