Skip to content
This repository has been archived by the owner on Mar 23, 2018. It is now read-only.

First Character Of Filename Truncated #27

Closed
ghost opened this issue Feb 13, 2017 · 3 comments
Closed

First Character Of Filename Truncated #27

ghost opened this issue Feb 13, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 13, 2017

I recently incorporated webpack-cleanup-plugin into a Webpack project I've recently started.

The important part of my Webpack configuration, that which is related to the issue I am having, is shown below:

{
  output: {
    // Root directory for all build artifacts.
    path: path.join(process.cwd(), `dist/`),
  }
}

The value for path contains a trailing slash.

The resulting value of fromPath in getFiles would be C:\Users\hbetts\Workspace\application\dist\, with C:\Users\hbetts\Workspace\application\ being the directory of my Webpack-managed project.

The function that maps files located at that path, correctly returns files like - C:\Users\hbetts\Workspace\application\dist\application.js

I would expect webpack-cleanup-plugin to delete application.js.

What happens, though, is on the p.substr(npath.length + 1) line the length of my normalized fromPath, which is 43 characters, including the trailing slash, is incremented by 1, and then a substring of the full file path is taken, effectively removing the first 44 characters, which happens to be the last slash, plus that one extra character, the letter a.

Therefore I'm left with a substring of pplication.js.

Later, when the normalized fromPath is joined with the file name (the value of the substring operation), I get C:\Users\hbetts\Workspace\application\dist\pplication.js

An alternative approach would be to replace:

p.substr(npath.length + 1)

With:

require('path').basename(p)

basename returns the expected file name application.js.

cc @foxbunny

Also #23 may actually resolve this issue. I just haven't tried it yet.

@ghost ghost mentioned this issue Feb 13, 2017
@x-yuri
Copy link
Contributor

x-yuri commented Feb 25, 2017

Also #23 may actually resolve this issue. I just haven't tried it yet.

It totally does. But there's no easy way to use the fixed version.

@ghost
Copy link
Author

ghost commented Feb 27, 2017

@x-yuri thankfully I was able to work around the problem by removing the trailing slash from dist/.

Going forward, though, it would be less disruptive to consumers when webpack-cleanup-plugin supports the use of trailing slashes after accepting #23.

@gpbl
Copy link
Owner

gpbl commented Feb 27, 2017

This should be fixed in v0.5.1 – please comment back if you still have this issue as I can't really test on Windows...

@gpbl gpbl closed this as completed Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants