Skip to content

Commit 1006330

Browse files
committed
fix: 修复git-actions流水线报错问题
1 parent 5e9a244 commit 1006330

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

packages/theme-mobile/build/gulp-dist.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,27 @@ const dist = '../dist'
1414

1515
function resolveVueTheme(importPath) {
1616
const candidates = [
17-
'@opentiny/vue-theme/' + importPath,
18-
'@opentiny/vue-theme/' + importPath.replace(/\.css$/, '.less')
17+
'@opentiny/vue-theme/' + importPath.replace(/\.css$/, '.less'),
18+
'@opentiny/vue-theme/' + importPath
1919
]
2020
for (const c of candidates) {
2121
try {
22-
return require.resolve(c, {
22+
const resolved = require.resolve(c, {
2323
paths: [
2424
path.resolve(__dirname, '../'),
2525
path.resolve(__dirname, '../../')
2626
]
2727
})
28+
if (fs.existsSync(resolved)) {
29+
return resolved.replace(/\\/g, '/')
30+
}
2831
} catch (e) {
2932
continue
3033
}
3134
}
3235
return null
3336
}
3437

35-
// 将所有组件下的index.less合并到src下的index.less
36-
const fileList = fg.sync('../src/*/index.less')
37-
const importStr = fileList
38-
.map((filePath) => filePath.replace('../src/', './'))
39-
.map((p) => `@import '${p}';`)
40-
.join('\n')
41-
const note = fs.readFileSync('../src/index.less', { encoding: 'utf-8' }).match(/(^\/\*\*.+?\*\/)/s)[0]
42-
fs.writeFileSync('../src/index.less', `${note}\n\n${importStr}`)
43-
4438
const VueThemeResolver = {
4539
install: function(less, pluginManager) {
4640
pluginManager.addPreProcessor({
@@ -50,7 +44,7 @@ const VueThemeResolver = {
5044
function(match, importPath) {
5145
const resolved = resolveVueTheme(importPath)
5246
if (resolved) {
53-
return '@import "' + resolved.replace(/\\/g, '/') + '"'
47+
return '@import "' + resolved + '"'
5448
}
5549
console.warn('Warning: Cannot resolve @opentiny/vue-theme/' + importPath)
5650
return match
@@ -63,35 +57,35 @@ const VueThemeResolver = {
6357

6458
function mergeIndexLess() {
6559
const indexLessPath = path.resolve(__dirname, '../src/index.less')
66-
67-
// 防御性检查:文件必须存在
60+
6861
if (!fs.existsSync(indexLessPath)) {
6962
throw new Error(`index.less not found at ${indexLessPath}`)
7063
}
71-
72-
const fileList = fg.sync('../src/*/index.less', { cwd: __dirname })
64+
65+
// 使用绝对路径匹配,避免 fast-glob 的 cwd 解析差异
66+
const fileList = fg.sync(path.resolve(__dirname, '../src/*/index.less'))
7367
const importStr = fileList
74-
.map((filePath) => filePath.replace('../src/', './'))
75-
.map((p) => `@import '${p}';`)
68+
.map((filePath) => path.relative(path.dirname(indexLessPath), filePath))
69+
.map((p) => `@import './${p.replace(/\\/g, '/')}';`)
7670
.join('\n')
77-
71+
7872
const content = fs.readFileSync(indexLessPath, { encoding: 'utf-8' })
7973
const match = content.match(/(^\/\*\*.+?\*\/)/s)
80-
74+
8175
let note = ''
8276
if (match) {
8377
note = match[0]
8478
} else {
85-
console.warn('Warning: No JSDoc comment block found at top of index.less, proceeding without header')
79+
console.warn('Warning: No JSDoc comment block found at top of index.less')
8680
}
87-
88-
fs.writeFileSync(indexLessPath, `${note}\n\n${importStr}`)
81+
82+
const output = `${note}\n\n${importStr}`.trim() + '\n'
83+
fs.writeFileSync(indexLessPath, output)
8984
}
9085

91-
gulp.task('compile', (done) => {
92-
// 在 task 执行时才合并,而不是模块加载时
86+
gulp.task('compile', () => {
9387
mergeIndexLess()
94-
88+
9589
return gulp
9690
.src([`${source}/**/index.less`, `${source}/index.less`])
9791
.pipe(

0 commit comments

Comments
 (0)