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

Remove filename-unsafe but package-safe characters from bundle name #285

Merged
merged 4 commits into from
Dec 20, 2017

Conversation

chee
Copy link

@chee chee commented Dec 15, 2017

closes #283

Originally I was stripping off the namespace, and then hyphening everything else. Then I was using a module to strip out the filename unsafe characters.

but then, of course most filename-unsafe characters are already invalid package.json names, so now i'm only stripping out the remaining url/file unsafe characters which are still package.json safe. and that's only the / in the namespace and the * allowed in old package names.

so there

@@ -0,0 +1,5 @@
const unsafeRegex = /[/*]/g;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go ahead and replace all invalid filename characters to avoid future issues:

/, \, <, >, :, ", |, ?, *

On windows, a filename also cannot end in .

Copy link
Author

@chee chee Dec 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. if we want to create a more generic sanitizeFileName then we should use ‘sanitize-filename’ itself from npm, i think. as there are a bunch more illegal windows names.

i’ll do this tomorrow

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer the the approach of trusting the package name to be a valid package name. I understand the want for a more generic approach, in case at some point you'd want to use this for things other than the package name.
But, if that was to happen, it would take no more work to include the login then that it would now, and trusting the package name isn't locking us in to anything that is complex or would mean a lot of rework should a future decision mean it needs changed.
But, i'm also fine with it and have done it and it's done now.

@@ -0,0 +1,5 @@
const unsafeRegex = /[/*]/g;

module.exports = function sanitizePackageName(name, replacement = '-') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make this a more generic sanitizeFileName so that it can be used elsewhere if an issue presents itself.

const sanitizeFilename = require('sanitize-filename');

module.exports = function sanitize(name, replacement = '-') {
return sanitizeFilename(unsafeRegex, {replacement});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this un-tested?

unsafeRegex is no longer defined.
name is not passed to sanitizeFilename.

Doesn't look like this code would work as-is. The helper is probably unnecessary now, too. Can just use sanitize-filename directly.

Copy link
Author

@chee chee Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh shoot, it was unpushed ! i'd amended the commit, and had not forced push.

i thought it preferable to keep the indirection in case more was ever desired of a sanitized package name than simple replacement (such as removing the namespace, or simply removing all non alpha-numerics). but that makes less sense now that it is not about package names but a generic filename sanitizer.

@devongovett
Copy link
Member

Would be great to add a test for this! Can you follow up with that @chee? Thanks!!

@devongovett devongovett merged commit df02196 into parcel-bundler:master Dec 20, 2017
@chee
Copy link
Author

chee commented Dec 21, 2017

@devongovett sure thing !

@chee
Copy link
Author

chee commented Dec 21, 2017

@devongovett i'm not sure where this test should go !

devongovett pushed a commit that referenced this pull request Oct 15, 2018
…285)

* prettify the plugins test

* replace package-safe but non-filesafe characters in package name

* use the `sanitize-filename` module for entry name

* remove sanitizeFilename indirection
devongovett pushed a commit that referenced this pull request Oct 15, 2018
…285)

* prettify the plugins test

* replace package-safe but non-filesafe characters in package name

* use the `sanitize-filename` module for entry name

* remove sanitizeFilename indirection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Package.json name with "/" throws error
3 participants