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

fix: support windows separator #1

Merged
merged 1 commit into from Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/generate-history-method-webpack-plugin.ts
Expand Up @@ -106,6 +106,10 @@
this.historyModuleName = historyModuleName
this.originHistoryModuleName = originHistoryModuleName
this.pagesRootPath = pagesRootPath
if (this.pagesRootPath.includes('\\'))
this.pagesRootPath = this.pagesRootPath.replace(/\\/g, '\/')


this.mode = mode
this.reactRouterVersion = reactRouterVersion
this.exportHistoryName = exportHistoryName
Expand Down Expand Up @@ -243,7 +247,7 @@
getParamsMapAndUrlObj(files: string[]) {
// { formatPath => paramsPath }
const paramsMap: Record<string, string> = {}
const regExp = new RegExp(`\/${this.pageName.replace(/(?=\.)/g, '\\')}\.(tsx|jsx?)$`)
const regExp = new RegExp(`[\/\\\\]${this.pageName.replace(/(?=\.)/g, '\\')}\.(tsx|jsx?)$`)
// { formatPath => urlPath }
const urlObj = files.reduce<Record<string, string>>((pre, path) => {
// eg: path: Users/xxx/project/src/pages/order/ ~ q/index.page.tsx
Expand All @@ -263,15 +267,14 @@
.replace(/[^\w]/g, '_')
// eg: ORDER__Q => ORDER_Q
.replace(/_{2,}/g, '_') || '$INDEX' // 首页

pre[formatPath] = urlPath
const dir = dirname(path)
const possibleParamsPath = resolve(
dir,
`${this.paramsName}.ts`,
)
if (existsSync(possibleParamsPath))
paramsMap[formatPath] = possibleParamsPath.replace('.ts', '')
paramsMap[formatPath] = possibleParamsPath.replace(/\\/g, '\/').replace('.ts', '')
return pre
}, {})
return { paramsMap, urlObj }
Expand Down Expand Up @@ -333,7 +336,7 @@
}

generateFile() {
const contentStr = this.contents.join('\n')

Check warning on line 339 in src/generate-history-method-webpack-plugin.ts

View workflow job for this annotation

GitHub Actions / lint

'possibleOutputPath' is assigned a value but never used. Allowed unused vars must match /^_/u
const possibleOutputPath = ['tsx', 'js'].map(ext => resolve(
cwdPath,
`node_modules/${this.historyModuleName}.${ext}`,
Expand All @@ -353,4 +356,4 @@
}
}

export default GenerateHistoryMethodWebpackPlugin
export default GenerateHistoryMethodWebpackPlugin