Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Prefer symlink property set on Vinyl object over its path #345

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/symlink/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function prepareSymlink(folderResolver, optResolver) {
file.cwd = cwd;
file.base = basePath;
// This is the path we are linking *TO*
file.symlink = file.path;
// Use `file.symlink` if it was set in the pipeline
file.symlink = file.symlink || file.path;
file.path = writePath;
// We have to set contents to null for a link
// Otherwise `isSymbolic()` returns false
Expand Down
2 changes: 1 addition & 1 deletion test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ describeStreams('.dest()', function (stream) {
pipeline([from([file]), vfs.dest(outputBase)], assert);
});

it('does not pass options on to stream.Tranform', function (done) {
it('does not pass options on to stream', function (done) {
var file = new File({
base: inputBase,
path: inputPath,
Expand Down
2 changes: 1 addition & 1 deletion test/src.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ describeStreams('.src()', function (stream) {
);
});

it('does not pass options on to stream.Transform', function (done) {
it('does not pass options on to stream', function (done) {
// Reference: https://github.com/gulpjs/vinyl-fs/issues/153
var read = sinon.fake.returns(false);

Expand Down
47 changes: 46 additions & 1 deletion test/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,51 @@ describeStreams('symlink stream', function (stream) {
);
});

it('will create symlinks with different names if property set in pipeline', function (done) {
var file = new File({
base: inputBase,
path: inputPath,
contents: null,
});

var renamed = 'renamed-symlink.txt';

function assert(files) {
var outputLink = fs.readlinkSync(path.join(outputBase, renamed));

expect(files.length).toEqual(1);
expect(files).toContain(file);
expect(files[0].base).toEqual(outputBase);
expect(files[0].path).toEqual(path.join(outputBase, renamed));
expect(files[0].symlink).toEqual(outputLink);
expect(files[0].isSymbolic()).toBe(true);
expect(outputLink).toEqual(inputPath);
}

pipeline(
[
from([file]),
new stream.Transform({
objectMode: true,
transform: function (file, enc, cb) {
if (typeof enc === 'function') {
cb = enc;
}

// User can stash the file.path on the symlink before they rename the file
file.symlink = file.path;
// Then they can rename the file
file.basename = renamed;
cb(null, file);
},
}),
vfs.symlink(outputBase),
concatArray(assert),
],
done
);
});

it('creates a link for a file with streaming contents', function (done) {
var file = new File({
base: inputBase,
Expand Down Expand Up @@ -971,7 +1016,7 @@ describeStreams('symlink stream', function (stream) {
});
});

it('does not pass options on to through2', function (done) {
it('does not pass options on to stream', function (done) {
var file = new File({
base: inputBase,
path: inputPath,
Expand Down
Loading