Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d53db4f

Browse files
committed
fix(windows): Fix min dev to generate page path problem; min init initialization problem
1 parent b26e490 commit d53db4f

5 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/class/WxSFMScript.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NodePath = traverse.NodePath
1313

1414
const CONFIG_KEY = 'config'
1515
const DATA_KEY = 'data'
16+
const PATH_SEP = path.sep
1617

1718
export namespace WxSFMScript {
1819

@@ -168,7 +169,7 @@ export class WxSFMScript extends WxSFM {
168169
request = path.relative(path.dirname(this.dest), path.dirname(useRequest.dest))
169170
request = path.join(request, path.basename(useRequest.dest, useRequest.ext))
170171
request = request.charAt(0) !== '.' ? `./${request}` : request
171-
172+
request = request.split(path.sep).join('/')
172173
switch (depend.requestType) {
173174
case RequestType.SCRIPT:
174175
depend.$node.value = request
@@ -342,11 +343,15 @@ export class WxSFMScript extends WxSFM {
342343
}
343344

344345
let properties: Array<t.ObjectProperty> = []
346+
// [['src', 'pages'], ['abnor', 'index.wxp']] => ['src', 'pages', 'abnor', 'index.wxp'] => 'src\/pages\/abnor\/index.wxp'
347+
let pattern = Array.prototype.concat.apply([], [config.pages.split('/'), ['([a-z]+)', `index${config.ext.wxp}`]]).join(`\\${PATH_SEP}`)
348+
345349
// src/pages/abnor/index.wxp => ['src/pages/abnor/index.wxp', 'abnor']
346-
let matchs = this.request.srcRelative.match(`^${config.pages}/([a-z]+)/index${config.ext.wxp}`)
350+
let matchs = this.request.srcRelative.match(new RegExp(`^${pattern}$`))
347351
if (!matchs || matchs.length < 2) {
348352
return
349353
}
354+
350355
// abnor => wxc-abnor
351356
let pkgDirName = `${config.prefix}${matchs[1]}`
352357
// ~/you_project_path/src/packages/wxc-abnor/README.md

src/class/WxSFMStyle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export class WxSFMStyle extends WxSFM {
240240
request = path.relative(path.dirname(this.dest), path.dirname(useRequest.dest))
241241
request = path.join(request, path.basename(useRequest.dest, useRequest.ext))
242242
request = request.charAt(0) !== '.' ? `./${request}` : request
243+
request = request.split(path.sep).join('/')
243244
request += config.ext.wxss
244245

245246
switch (depend.requestType) {

src/class/XcxTraverse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as _ from 'lodash'
2+
import * as path from 'path'
23
import { XcxNode } from '../class'
34
import { RequestType } from '../declare'
45
import { config } from '../util'
@@ -181,8 +182,8 @@ export class XcxTraverse {
181182
* @memberof XcxTraverse
182183
*/
183184
private pageReplacer (destRelative: string): string {
184-
let regExp = new RegExp(`(^${config.dest}/)|(${config.ext.wxp}$)`, 'g')
185-
return destRelative.replace(regExp, '')
185+
let regExp = new RegExp(`(^${config.dest}\\${path.sep})|(${config.ext.wxp}$)`, 'g')
186+
return destRelative.replace(regExp, '').split(path.sep).join('/')
186187
}
187188

188189
/**
@@ -194,8 +195,8 @@ export class XcxTraverse {
194195
* @memberof XcxTraverse
195196
*/
196197
private componentReplacer (destRelative: string): string {
197-
let regExp = new RegExp(`(^${config.dest}/)|(${config.ext.wxc}$)`, 'g')
198-
return destRelative.replace(regExp, '')
198+
let regExp = new RegExp(`(^${config.dest}\\${path.sep})|(${config.ext.wxc}$)`, 'g')
199+
return destRelative.replace(regExp, '').split(path.sep).join('/')
199200
}
200201

201202
/**

src/util/exec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function exec (command: string, args: string[], verbose: boolean = false,
1212
stdio: 'inherit'
1313
})
1414
}
15+
command = /^win/.test(process.platform) ? `${command}.cmd` : command
1516
const child = spawn(command, args, options)
1617

1718
let stdout = ''

src/util/resolveDep.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,25 @@ function src2destRelative (srcRelative: string, isPublish?: boolean) {
140140

141141
// node_modules => dist/npm/wxcs
142142
// path/node_modules => path/npm/wxcs
143-
destRelative = destRelative.replace(new RegExp(`(^|\/)${config.npm.src}`, 'ig'), (match, $1) => {
143+
destRelative = destRelative.replace(new RegExp(`(^|\\${path.sep})${config.npm.src}`, 'ig'), (match, $1) => {
144144
// let npm = ext === config.ext.wxc ? config.npm.dest.wxcs : config.npm.dest.modules
145145
let npmDest = config.npm.dest
146146

147147
if ($1 === '') {
148148
// node_modules => dist/npm/wxcs
149149
// node_modules => dist/npm/modules
150150
return npmDest
151-
} else if ($1 === '/') {
151+
} else if ($1 === path.sep) {
152152
// path/node_modules => path/npm/wxcs
153153
// path/node_modules => path/npm/modules
154-
return npmDest.split('/').slice(1).join('/')
154+
return npmDest.split(path.sep).slice(1).join(path.sep)
155155
} else {
156156
return match
157157
}
158158
})
159159

160160
// /wxc-hello/src/ => /wxc-hello/dist/
161-
destRelative = destRelative.replace(new RegExp(`(/${config.prefix}[a-z-]+/)([a-z]+)`), (match, $1, $2) => {
161+
destRelative = destRelative.replace(new RegExp(`(${path.sep}${config.prefix}[a-z-]+\\${path.sep})([a-z]+)`), (match, $1, $2) => {
162162
if ($2 === config.package.src) {
163163
return `${$1}${config.package.dest}`
164164
}
@@ -332,13 +332,13 @@ function resolveLookupNpmPaths (parent: string) {
332332
let relPath = path.relative(config.cwd, parent)
333333

334334
// 相对路径起始不包含 node_modules 或 source/packages,返回默认
335-
if (!new RegExp(`^(node_modules|${config.packages})/`).test(relPath)) {
335+
if (!new RegExp(`^(node_modules|${config.packages})\\${path.sep}`).test(relPath)) {
336336
return paths
337337
}
338338

339339
// ['node_modules', '@scope', 'wxc-hello']
340340
// ['source', 'packages', 'wxc-hello']
341-
let spes = relPath.split('/')
341+
let spes = relPath.split(path.sep)
342342

343343
for (let i = 0; i < spes.length; i++) {
344344
let name = spes[i]
@@ -348,7 +348,7 @@ function resolveLookupNpmPaths (parent: string) {
348348
continue
349349
}
350350

351-
let lookup = spes.slice(0, i + 1).join('/')
351+
let lookup = spes.slice(0, i + 1).join(path.sep)
352352

353353
// 'source'
354354
// 'source/packages'

0 commit comments

Comments
 (0)