gulpjs / vinyl

Virtual file format.
MIT License
1.28k stars 105 forks source link

Re-hydrating a cloned file from disk #35

Closed jgable closed 10 years ago

jgable commented 10 years ago

It looks like wearefractal/vinyl#24 significantly changed the way path is stored on a File instance. Ever since this change, you can't re-"hydrate" a File object from a clone because the clone result doesn't include the path property, but the File constructor requires a path and won't respect the passed in history.

I'm left with a sort of hacky

// Storing a copy of the file to disk for later "hydration"
var copy = _.clone(file);

if (_.has(file, 'path') && !_.has(copy, 'path')) {
  copy.path = file.path
}

// .. write the file

I think you should check for the passed in history and use it if present, otherwise fall back to your current this.history = file.path ? [file.path] : []; line.

yocontra commented 10 years ago

file.clone() exists for this reason - why not use it? It clones history

jgable commented 10 years ago

Same problem exists with your file.clone().

yocontra commented 10 years ago

https://github.com/wearefractal/vinyl/blob/master/index.js#L67

https://github.com/wearefractal/vinyl/blob/master/index.js#L160

History (and thus the path var) gets cloned fine - there are tests for it in the clone tests

jgable commented 10 years ago

This issue is not about cloning, it's about re-hydrating a cloned File from after serializing to disk.

After cloning, yes, the history is preserved, but if I want to create a new file and all I have is a file's enumerable properties from a JSON.stringify stored to disk I have to have special cases to pluck off the last history item from the files properties. This is dirty because I have to know about the internal workings of the File class and how it calculates that path property.

yocontra commented 10 years ago

Published as 0.4.3