Skip to content

graceful-fs included by grunt-assemble v0.6.3 breaks system fs.readdir globally #72

Description

@iosart

Took me a while to get to the bottom of it, but if you try to run:
fs.readdir('./', {withFileTypes: true}, callback) or
fs.readdir('./', {}, callback)
the call will fail and the callback will never be called.

The reason: the latest version of grunt-assemble (0.6.3), depends on a very old version of gray-matter (0.4.2, while the latest is 4.0.3). This old gray-matter v0.4.2 depends on old fs-utils 0.4.3, which in turn depends on an old version of graceful-fs (v2.0.3).

This very old version of graceful-fs monkey patches fs.readdir (along with a handful other fs methods). The overriden version does not support fs.readdir( path, options, callback ) format only the older fs.readdir( path, callback ), breaking many recent libraries.

Updating grunt-assemble to use the latest gray-matter will solve the issue, as I believe they are no longer using fs-utils / graceful-fs.

My temporary fix for Gruntfile.js, is to un-monkey patch the affected methods:

  const fs = require('fs');
  const { readdir, close, closeSync, open } = fs;
  .
  .
  .
  grunt.loadNpmTasks('grunt-assemble');
  Object.assign(fs, { readdir, close, closeSync, open });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions