简体   繁体   中英

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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