-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Change regex to avoid lookbehind #323
Conversation
I think it's buggy. Have you tested? |
I have ever used this in #308: const indexRE = /(^|\/)(index|readme)\.md$/i
// README.md -> /
// foo/README.md -> /foo/
const fileReplace = file.replace(indexRE, '')
return '/' + ( fileReplace === '' ? '' : fileReplace + '/') But I prefer to change a single line, so I chose lookbehind. |
I tested only with this input and it worked:
|
@whoan I tested your code in You can consider my code above, which I had tested well. |
@meteorlxy I had forgotten to remove a (now) duplicated slash because I am appending it in the replacement. |
@whoan Yours:
Expected:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change suggested
lib/prepare.js
Outdated
@@ -236,14 +236,14 @@ async function genComponentRegistrationFile ({ sourceDir }) { | |||
return `import Vue from 'vue'\n` + components.map(genImport).join('\n') | |||
} | |||
|
|||
const indexRE = /(?<=(^|\/))(index|readme)\.md$/i | |||
const indexRE = /^\/?([^/]+\/)*(index|readme)\.md$/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may help:
const indexRE = /(^\/?([^/]+\/)*)(index|readme)\.md$/i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And maybe this is enough:
const indexRE = /(^|.*\/)(index|readme)\.md$/i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one looks good, I just tested for it, so let me leverage it.
lib/prepare.js
Outdated
@@ -236,14 +236,14 @@ async function genComponentRegistrationFile ({ sourceDir }) { | |||
return `import Vue from 'vue'\n` + components.map(genImport).join('\n') | |||
} | |||
|
|||
const indexRE = /(?<=(^|\/))(index|readme)\.md$/i | |||
const indexRE = /^\/?([^/]+\/)*(index|readme)\.md$/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one looks good, I just tested for it, so let me leverage it.
An alternative to PR #321.
Also related to PR #308 to fix issue #306.
This is to avoid updating node to 8.10 to support Regex lookbehind.