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

queueTransformStream doesn't seem to work properly with gulp-rename #1292

Closed
jvoccia opened this issue May 3, 2021 · 2 comments
Closed

queueTransformStream doesn't seem to work properly with gulp-rename #1292

jvoccia opened this issue May 3, 2021 · 2 comments
Labels
needs triage Awaiting triage

Comments

@jvoccia
Copy link

jvoccia commented May 3, 2021

I recently updated to the latest yeoman generator - 5.2.0, and was using gulp-rename 2.0.0 to rename files on output.

const rename = require('gulp-rename');
...
writing () {
        this.queueTransformStream(rename((path) => {
            path.basename = path.basename.replace(/(nameNoDashesCamel)/g, this.props.nameNoDashesCamel);
            path.dirname = path.dirname.replace(/(nameNoDashesCamel)/g, this.props.nameNoDashesCamel);
        }));
       //...
}
...

This was working in generator 4.12.0 and yo version 3.1.1 (when using registerTransformStream).

However, I see when I upgrade "yo" to 4.1.0, and keep the generator at 4.12.0 it makes a file copy instead of rename. Meaning I get two files output. One with the pre-renamed name and a second with the rename.

See Proj1.zip

When I then upgrade from yeoman generator - 4.12.0 -> 5.2.0 change to queueTransformStream and run the same project (with yo 4.1.0), I don't see any rename, it is as if the transform didn't run at all.

See Proj2.zip

I see that the transform is being called and it does seem to change the basename and path in the transform returned from rename, but somewhere, it is lost when written to disk.

My goal is to change the names of a bunch of files and directories being output, so I am certainly open to better ways of doing this, but I was surprised to see this fail on the upgrade.

@jvoccia jvoccia added the needs triage Awaiting triage label May 3, 2021
@mshima
Copy link
Member

mshima commented May 4, 2021

This is a known gulp-rename bug: hparra/gulp-rename#84
It won't work as it is because it clones the file, loosing mem-fs/mem-fs-editor/conflicter custom fields.

@jvoccia
Copy link
Author

jvoccia commented May 4, 2021

Thanks Marcelo!

I ran across hparra/gulp-rename#84, but didn't experience the Error [ERR_STREAM_WRITE_AFTER_END]: write after end. I also had this working with gulp rename 2.0.0 and yeoman before I upgraded. Between both of those, I didn't think I was running into the error reported.
It is good to know it is still outstanding, and is probably the source of the issue.

While I did not get this working in the latest yo version with gulp-rename, I did find an alternative to renaming files.

I found that I could rename using processDestinationPath to do the renames:

// I pulled out and simplified some of the relevant parts below:
let orig= 'oldStr';
let replacement = 'newStr';
let replaceFn = (destinationPath) => {
        let basename = path.basename(destinationPath);
        let dirname = path.dirname(destinationPath);

        basename = basename.replaceAll(orig, replacement);
        dirname = dirname.replaceAll(orig, replacement);
        return path.join(dirname, basename);
    };

    this.fs.copyTpl(
            this.templatePath('module/**'),
            this.destinationPath(path),
            { ...templateObj },
            null,
            {
                processDestinationPath: replaceFn 
            }
    );

Since this appears to be something to fix in gulp-rename, I am going to close out this issue for now.

@jvoccia jvoccia closed this as completed May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Awaiting triage
Projects
None yet
Development

No branches or pull requests

2 participants