create-uni-app-tailwindcss 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/dist/templates/default/README.md +17 -4
- package/dist/templates/default/package.json +28 -32
- package/dist/templates/default/pnpm-workspace.yaml +15 -0
- package/package.json +7 -3
- package/dist/templates/default/scripts/app-css-smoke.mjs +0 -69
- package/dist/templates/default/scripts/hmr-smoke.mjs +0 -252
package/README.md
CHANGED
|
@@ -14,10 +14,4 @@ pnpm create uni-app-tailwindcss my-app --template default
|
|
|
14
14
|
|
|
15
15
|
When multiple templates are bundled and `--template` is omitted, the CLI prompts for one in interactive terminals and uses the registry default otherwise.
|
|
16
16
|
|
|
17
|
-
For
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pnpm install
|
|
21
|
-
pnpm create
|
|
22
|
-
pnpm test:e2e
|
|
23
|
-
```
|
|
17
|
+
For repository development, testing, and releases, see the root [CONTRIBUTING.md](https://github.com/sonofmagic/uni-app-tailwindcss-template/blob/main/CONTRIBUTING.md).
|
|
@@ -97,7 +97,6 @@ pnpm dev:app
|
|
|
97
97
|
pnpm build:app
|
|
98
98
|
pnpm launch:app:android
|
|
99
99
|
pnpm launch:app:ios
|
|
100
|
-
pnpm test:app-css
|
|
101
100
|
pnpm open:dev
|
|
102
101
|
pnpm open:build
|
|
103
102
|
pnpm lint
|
|
@@ -116,12 +115,26 @@ pnpm lint
|
|
|
116
115
|
|
|
117
116
|
- Tailwind CSS 由 `weapp-tailwindcss@5` 在构建运行时生成,无需安装后补丁
|
|
118
117
|
- App WebView 兼容由 `weapp-tailwindcss` 内置的 `legacy-web` 处理链提供;模板不再维护额外的 PostCSS 兼容插件,并保留 Tailwind CSS v4 的运行时 `--spacing` 语义
|
|
119
|
-
- `pnpm test:app-css` 会构建 App 资源,并回归检查间距变量、`space-y` 反转公式、渐变文字 WebKit 前缀和 Android/iOS 平台声明
|
|
120
118
|
- 样式条件编译示例使用 `@custom-variant wx` / `@custom-variant not-wx`
|
|
121
119
|
- 请先把 `src/manifest.json` 中的 AppID 替换成自己的配置
|
|
122
|
-
-
|
|
120
|
+
- 模板内提供 `pnpm update:deps` 和 `pnpm update:uni-app`,用于分别升级通用依赖和 `uni-app` 依赖
|
|
123
121
|
- 推荐在 VS Code 中安装 `Tailwind CSS IntelliSense`、ESLint、Stylelint
|
|
124
|
-
|
|
122
|
+
|
|
123
|
+
## 依赖升级
|
|
124
|
+
|
|
125
|
+
交互式升级除 uni-app 编译工具链之外的所有直接依赖:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm update:deps
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
升级 DCloud 官方 UVM 管理的整套 uni-app 依赖:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pnpm update:uni-app
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
uni-app 的兼容性集合不仅包括 `@dcloudio/*`,还包括 `vue`、`vue-i18n`、`@vue/runtime-core`、`@vue/shared`、`vite` 和 `rollup`。不要用通用更新命令单独升级这些包;`update:uni-app` 会通过 UVM 让编译器相关版本保持一致。
|
|
125
138
|
|
|
126
139
|
## 项目级技能
|
|
127
140
|
|
|
@@ -44,33 +44,30 @@
|
|
|
44
44
|
"weapp:login": "weapp login",
|
|
45
45
|
"upload:dev": "weapp upload -p dist/dev/mp-weixin -v 1.0.0 -d \"dev version\"",
|
|
46
46
|
"upload:build": "weapp upload -p dist/build/mp-weixin -v 1.0.0 -d \"release version\"",
|
|
47
|
-
"test:hmr": "node scripts/hmr-smoke.mjs",
|
|
48
|
-
"test:hmr:mp-weixin": "pnpm run test:hmr -- --platform mp-weixin --script dev:mp-weixin",
|
|
49
|
-
"test:app-css": "pnpm build:app && node scripts/app-css-smoke.mjs",
|
|
50
47
|
"lint": "eslint .",
|
|
51
48
|
"lint:fix": "eslint ./src --fix",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
49
|
+
"update:deps": "pnpm up --latest --interactive \"!@dcloudio/*\" \"!@vue/runtime-core\" \"!@vue/shared\" \"!rollup\" \"!vite\" \"!vue\" \"!vue-i18n\"",
|
|
50
|
+
"update:uni-app": "pnpm dlx @dcloudio/uvm@latest --manager pnpm"
|
|
54
51
|
},
|
|
55
52
|
"dependencies": {
|
|
56
|
-
"@dcloudio/uni-app": "3.0.0-
|
|
57
|
-
"@dcloudio/uni-app-harmony": "3.0.0-
|
|
58
|
-
"@dcloudio/uni-app-plus": "3.0.0-
|
|
59
|
-
"@dcloudio/uni-components": "3.0.0-
|
|
60
|
-
"@dcloudio/uni-h5": "3.0.0-
|
|
61
|
-
"@dcloudio/uni-mp-alipay": "3.0.0-
|
|
62
|
-
"@dcloudio/uni-mp-baidu": "3.0.0-
|
|
63
|
-
"@dcloudio/uni-mp-harmony": "3.0.0-
|
|
64
|
-
"@dcloudio/uni-mp-jd": "3.0.0-
|
|
65
|
-
"@dcloudio/uni-mp-kuaishou": "3.0.0-
|
|
66
|
-
"@dcloudio/uni-mp-lark": "3.0.0-
|
|
67
|
-
"@dcloudio/uni-mp-qq": "3.0.0-
|
|
68
|
-
"@dcloudio/uni-mp-toutiao": "3.0.0-
|
|
69
|
-
"@dcloudio/uni-mp-weixin": "3.0.0-
|
|
70
|
-
"@dcloudio/uni-mp-xhs": "3.0.0-
|
|
71
|
-
"@dcloudio/uni-quickapp-webview": "3.0.0-
|
|
53
|
+
"@dcloudio/uni-app": "3.0.0-5020420260813003",
|
|
54
|
+
"@dcloudio/uni-app-harmony": "3.0.0-5020420260813003",
|
|
55
|
+
"@dcloudio/uni-app-plus": "3.0.0-5020420260813003",
|
|
56
|
+
"@dcloudio/uni-components": "3.0.0-5020420260813003",
|
|
57
|
+
"@dcloudio/uni-h5": "3.0.0-5020420260813003",
|
|
58
|
+
"@dcloudio/uni-mp-alipay": "3.0.0-5020420260813003",
|
|
59
|
+
"@dcloudio/uni-mp-baidu": "3.0.0-5020420260813003",
|
|
60
|
+
"@dcloudio/uni-mp-harmony": "3.0.0-5020420260813003",
|
|
61
|
+
"@dcloudio/uni-mp-jd": "3.0.0-5020420260813003",
|
|
62
|
+
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020420260813003",
|
|
63
|
+
"@dcloudio/uni-mp-lark": "3.0.0-5020420260813003",
|
|
64
|
+
"@dcloudio/uni-mp-qq": "3.0.0-5020420260813003",
|
|
65
|
+
"@dcloudio/uni-mp-toutiao": "3.0.0-5020420260813003",
|
|
66
|
+
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
|
|
67
|
+
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
|
|
68
|
+
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
|
|
72
69
|
"@vue/shared": "3.4.21",
|
|
73
|
-
"@weapp-tailwindcss/merge": "^2.2.
|
|
70
|
+
"@weapp-tailwindcss/merge": "^2.2.2",
|
|
74
71
|
"pinia": "2.2.4",
|
|
75
72
|
"vue": "^3.4.21",
|
|
76
73
|
"vue-i18n": "^9.1.9"
|
|
@@ -78,28 +75,27 @@
|
|
|
78
75
|
"devDependencies": {
|
|
79
76
|
"@dcloudio/hbuilderx-cli": "^1.2.0",
|
|
80
77
|
"@dcloudio/types": "^3.4.8",
|
|
81
|
-
"@dcloudio/uni-
|
|
82
|
-
"@dcloudio/uni-
|
|
83
|
-
"@dcloudio/uni
|
|
84
|
-
"@
|
|
85
|
-
"@icebreakers/
|
|
86
|
-
"@icebreakers/stylelint-config": "^5.0.3",
|
|
78
|
+
"@dcloudio/uni-cli-shared": "3.0.0-5020420260813003",
|
|
79
|
+
"@dcloudio/uni-stacktracey": "3.0.0-5020420260813003",
|
|
80
|
+
"@dcloudio/vite-plugin-uni": "3.0.0-5020420260813003",
|
|
81
|
+
"@icebreakers/eslint-config": "^7.0.4",
|
|
82
|
+
"@icebreakers/stylelint-config": "^5.0.5",
|
|
87
83
|
"@iconify-json/mdi": "^1.2.3",
|
|
88
84
|
"@iconify-json/svg-spinners": "^1.2.4",
|
|
89
85
|
"@iconify/tailwind4": "^1.2.3",
|
|
90
86
|
"@types/node": "^26.2.0",
|
|
91
87
|
"@vue/runtime-core": "^3.4.21",
|
|
92
88
|
"autoprefixer": "^10.5.4",
|
|
93
|
-
"eslint": "^10.
|
|
89
|
+
"eslint": "^10.9.0",
|
|
94
90
|
"postcss": "^8.5.26",
|
|
95
91
|
"rollup": "4.14.3",
|
|
96
|
-
"sass": "^1.
|
|
92
|
+
"sass": "^1.103.1",
|
|
97
93
|
"stylelint": "^17.14.1",
|
|
98
94
|
"tailwindcss": "^4.3.3",
|
|
99
95
|
"typescript": "^6.0.3",
|
|
100
96
|
"unplugin-auto-import": "^20.3.0",
|
|
101
97
|
"vite": "5.2.8",
|
|
102
|
-
"weapp-ide-cli": "^6.0.
|
|
103
|
-
"weapp-tailwindcss": "^5.
|
|
98
|
+
"weapp-ide-cli": "^6.0.7",
|
|
99
|
+
"weapp-tailwindcss": "^5.3.4"
|
|
104
100
|
}
|
|
105
101
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
packages:
|
|
2
|
+
- .
|
|
3
|
+
|
|
4
|
+
allowBuilds:
|
|
5
|
+
'@dcloudio/hbuilderx-cli': false
|
|
6
|
+
'@parcel/watcher': true
|
|
7
|
+
core-js: true
|
|
8
|
+
core-js-pure: true
|
|
9
|
+
esbuild: true
|
|
10
|
+
vue-demi: true
|
|
11
|
+
|
|
12
|
+
onlyBuiltDependencies:
|
|
13
|
+
- '@weapp-tailwindcss/merge'
|
|
14
|
+
|
|
15
|
+
minimumReleaseAge: 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-uni-app-tailwindcss",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Create a uni-app project with Vite, Vue 3, Tailwind CSS, and weapp-tailwindcss.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -42,12 +42,16 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@playwright/test": "^1.55.0",
|
|
45
|
+
"@types/node": "^26.2.0",
|
|
46
|
+
"@types/prompts": "^2.4.9",
|
|
45
47
|
"tsup": "^8.5.0",
|
|
46
48
|
"typescript": "^6.0.3"
|
|
47
49
|
},
|
|
48
50
|
"scripts": {
|
|
49
|
-
"build": "node scripts/build-package.mjs",
|
|
51
|
+
"build": "pnpm run typecheck && node scripts/build-package.mjs",
|
|
50
52
|
"start": "pnpm run build && node dist/cli.js",
|
|
51
|
-
"test:e2e": "playwright test"
|
|
53
|
+
"test:e2e": "playwright test",
|
|
54
|
+
"test:e2e:daily": "node scripts/run-daily-e2e.mjs",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
import postcss from 'postcss'
|
|
3
|
-
|
|
4
|
-
const appCssUrl = new URL('../dist/build/app/app.css', import.meta.url)
|
|
5
|
-
const manifestUrl = new URL('../dist/build/app/manifest.json', import.meta.url)
|
|
6
|
-
|
|
7
|
-
const css = await readFile(appCssUrl, 'utf8')
|
|
8
|
-
const manifest = JSON.parse(await readFile(manifestUrl, 'utf8'))
|
|
9
|
-
const root = postcss.parse(css)
|
|
10
|
-
|
|
11
|
-
function assert(condition, message) {
|
|
12
|
-
if (!condition) {
|
|
13
|
-
throw new Error(message)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function findRule(selectorFragment) {
|
|
18
|
-
let match
|
|
19
|
-
root.walkRules((rule) => {
|
|
20
|
-
if (!match && rule.selector.includes(selectorFragment)) {
|
|
21
|
-
match = rule
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
assert(match, `Missing App CSS rule containing ${selectorFragment}`)
|
|
25
|
-
return match
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function declarationValues(rule) {
|
|
29
|
-
const values = new Map()
|
|
30
|
-
rule.walkDecls((declaration) => {
|
|
31
|
-
const existing = values.get(declaration.prop) ?? []
|
|
32
|
-
existing.push(declaration.value)
|
|
33
|
-
values.set(declaration.prop, existing)
|
|
34
|
-
})
|
|
35
|
-
return values
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let hasSpacingTheme = false
|
|
39
|
-
root.walkDecls('--spacing', (declaration) => {
|
|
40
|
-
hasSpacingTheme ||= declaration.value === '0.25rem'
|
|
41
|
-
})
|
|
42
|
-
assert(hasSpacingTheme, 'Missing Tailwind --spacing theme variable')
|
|
43
|
-
|
|
44
|
-
const paddingValues = declarationValues(findRule('.p-5'))
|
|
45
|
-
assert(
|
|
46
|
-
paddingValues.get('padding')?.includes('calc(var(--spacing) * 5)'),
|
|
47
|
-
'p-5 must preserve its runtime --spacing calculation',
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const spaceYValues = declarationValues(findRule('.space-y-5'))
|
|
51
|
-
assert(spaceYValues.get('--tw-space-y-reverse')?.includes('0'), 'space-y-5 must initialize its reverse variable')
|
|
52
|
-
assert(
|
|
53
|
-
spaceYValues.get('margin-block-start')?.includes('calc(calc(var(--spacing) * 5) * var(--tw-space-y-reverse))'),
|
|
54
|
-
'space-y-5 must preserve its start-margin reverse formula',
|
|
55
|
-
)
|
|
56
|
-
assert(
|
|
57
|
-
spaceYValues.get('margin-block-end')?.includes('calc(calc(var(--spacing) * 5) * calc(1 - var(--tw-space-y-reverse)))'),
|
|
58
|
-
'space-y-5 must preserve its end-margin reverse formula',
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const clipValues = declarationValues(findRule('.bg-clip-text'))
|
|
62
|
-
assert(clipValues.get('-webkit-background-clip')?.includes('text'), 'bg-clip-text must include the WebKit fallback')
|
|
63
|
-
assert(clipValues.get('background-clip')?.includes('text'), 'bg-clip-text must retain the standard declaration')
|
|
64
|
-
|
|
65
|
-
for (const platform of ['android', 'iPhone', 'iPad']) {
|
|
66
|
-
assert(manifest['@platforms']?.includes(platform), `App manifest must include ${platform}`)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log('App CSS compatibility smoke test passed')
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawn } from 'node:child_process'
|
|
4
|
-
import { existsSync, promises as fs } from 'node:fs'
|
|
5
|
-
import path from 'node:path'
|
|
6
|
-
import process from 'node:process'
|
|
7
|
-
|
|
8
|
-
const cwd = process.cwd()
|
|
9
|
-
const args = parseArgs(process.argv.slice(2))
|
|
10
|
-
const platform = args.platform
|
|
11
|
-
const devScript = args.script ?? `dev:${platform}`
|
|
12
|
-
const timeoutMs = Number(args.timeout ?? 180_000)
|
|
13
|
-
const pollMs = Number(args.poll ?? 700)
|
|
14
|
-
|
|
15
|
-
const targetVueFile = path.join(cwd, 'src', 'components', 'WeappTailwindcss.vue')
|
|
16
|
-
const initialContent = 'before:content-[\'现在,让我们开始神奇的_tailwindcss_开发之旅吧!\']'
|
|
17
|
-
const updatedContent = 'before:content-[\'现在,让我们继续神奇的_tailwindcss_HMR_回归之旅吧!\']'
|
|
18
|
-
const initialCssContent = '现在,让我们开始神奇的 tailwindcss 开发之旅吧!'
|
|
19
|
-
const updatedCssContent = '现在,让我们继续神奇的 tailwindcss HMR 回归之旅吧!'
|
|
20
|
-
const iconNeedles = ['github-circle', 'mdi--star']
|
|
21
|
-
const styleExtensions = new Set(['.css', '.wxss', '.acss', '.ttss', '.qss'])
|
|
22
|
-
|
|
23
|
-
let devProcess
|
|
24
|
-
let originalTargetContent
|
|
25
|
-
|
|
26
|
-
main().catch((error) => {
|
|
27
|
-
console.error(`\n[hmr-smoke] FAILED: ${error instanceof Error ? error.message : String(error)}`)
|
|
28
|
-
process.exitCode = 1
|
|
29
|
-
}).finally(async () => {
|
|
30
|
-
await restoreTargetFile()
|
|
31
|
-
await stopDevProcess()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
async function main() {
|
|
35
|
-
if (!platform) {
|
|
36
|
-
throw new Error('Missing required argument: --platform <platform>')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
originalTargetContent = await fs.readFile(targetVueFile, 'utf8')
|
|
40
|
-
if (!originalTargetContent.includes(initialContent)) {
|
|
41
|
-
throw new Error(`Cannot find Iconify content HMR fixture in ${path.relative(cwd, targetVueFile)}`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
console.log(`[hmr-smoke] platform=${platform}`)
|
|
45
|
-
console.log(`[hmr-smoke] script=${devScript}`)
|
|
46
|
-
|
|
47
|
-
const outputDir = path.join(cwd, 'dist', 'dev', platform)
|
|
48
|
-
await fs.rm(outputDir, { recursive: true, force: true })
|
|
49
|
-
devProcess = runDevScript(devScript)
|
|
50
|
-
|
|
51
|
-
const initialSnapshot = await waitForCssSnapshot(outputDir, cssIncludesInitialFixture, 'initial Iconify CSS')
|
|
52
|
-
console.log(`[hmr-smoke] initial css files=${initialSnapshot.files.length}`)
|
|
53
|
-
|
|
54
|
-
const beforeMtime = await getLatestMtimeMs(outputDir)
|
|
55
|
-
await fs.writeFile(targetVueFile, originalTargetContent.replace(initialContent, updatedContent), 'utf8')
|
|
56
|
-
console.log(`[hmr-smoke] updated ${path.relative(cwd, targetVueFile)} content fixture`)
|
|
57
|
-
|
|
58
|
-
await waitForDirMtimeBump(outputDir, beforeMtime)
|
|
59
|
-
const updatedSnapshot = await waitForCssSnapshot(outputDir, cssIncludesUpdatedFixture, 'updated Iconify CSS')
|
|
60
|
-
console.log(`[hmr-smoke] updated css files=${updatedSnapshot.files.length}`)
|
|
61
|
-
console.log('[hmr-smoke] PASS')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function runDevScript(scriptName) {
|
|
65
|
-
const pnpmCommand = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'
|
|
66
|
-
const child = spawn(pnpmCommand, ['run', scriptName], {
|
|
67
|
-
cwd,
|
|
68
|
-
detached: process.platform !== 'win32',
|
|
69
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
70
|
-
env: {
|
|
71
|
-
...process.env,
|
|
72
|
-
FORCE_COLOR: '0',
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
child.stdout.on('data', (chunk) => {
|
|
77
|
-
process.stdout.write(`[dev:${platform}] ${chunk}`)
|
|
78
|
-
})
|
|
79
|
-
child.stderr.on('data', (chunk) => {
|
|
80
|
-
process.stderr.write(`[dev:${platform}:err] ${chunk}`)
|
|
81
|
-
})
|
|
82
|
-
child.on('exit', (code, signal) => {
|
|
83
|
-
if (code !== null) {
|
|
84
|
-
console.log(`[hmr-smoke] dev exited with code=${code}`)
|
|
85
|
-
}
|
|
86
|
-
if (signal) {
|
|
87
|
-
console.log(`[hmr-smoke] dev terminated by signal=${signal}`)
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
return child
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function waitForCssSnapshot(dir, predicate, phase) {
|
|
95
|
-
const startedAt = Date.now()
|
|
96
|
-
let lastSnapshot = { files: [], css: '' }
|
|
97
|
-
|
|
98
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
99
|
-
lastSnapshot = await readCssSnapshot(dir)
|
|
100
|
-
if (lastSnapshot.files.length > 0 && predicate(lastSnapshot.css)) {
|
|
101
|
-
console.log(`[hmr-smoke] ${phase}: expected Iconify/content markers found`)
|
|
102
|
-
return lastSnapshot
|
|
103
|
-
}
|
|
104
|
-
await sleep(pollMs)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
throw new Error(
|
|
108
|
-
`${phase}: timed out under ${path.relative(cwd, dir)}; files=${lastSnapshot.files.join(', ')}; cssTail=${lastSnapshot.css.slice(-1000)}`,
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function readCssSnapshot(dir) {
|
|
113
|
-
if (!existsSync(dir)) {
|
|
114
|
-
return { files: [], css: '' }
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const files = []
|
|
118
|
-
const stack = [dir]
|
|
119
|
-
|
|
120
|
-
while (stack.length > 0) {
|
|
121
|
-
const current = stack.pop()
|
|
122
|
-
const entries = await fs.readdir(current, { withFileTypes: true })
|
|
123
|
-
for (const entry of entries) {
|
|
124
|
-
const fullPath = path.join(current, entry.name)
|
|
125
|
-
if (entry.isDirectory()) {
|
|
126
|
-
stack.push(fullPath)
|
|
127
|
-
continue
|
|
128
|
-
}
|
|
129
|
-
if (styleExtensions.has(path.extname(entry.name))) {
|
|
130
|
-
files.push(fullPath)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const cssParts = await Promise.all(files.sort().map(async file => await fs.readFile(file, 'utf8')))
|
|
136
|
-
return {
|
|
137
|
-
files: files.map(file => path.relative(cwd, file)),
|
|
138
|
-
css: cssParts.join('\n'),
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function cssIncludesInitialFixture(css) {
|
|
143
|
-
return cssIncludesIcons(css) && css.includes(initialCssContent)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function cssIncludesUpdatedFixture(css) {
|
|
147
|
-
return cssIncludesIcons(css) && css.includes(updatedCssContent)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function cssIncludesIcons(css) {
|
|
151
|
-
return iconNeedles.every(needle => css.includes(needle))
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function waitForDirMtimeBump(dir, beforeMtime) {
|
|
155
|
-
const startedAt = Date.now()
|
|
156
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
157
|
-
const currentMtime = await getLatestMtimeMs(dir)
|
|
158
|
-
if (currentMtime > beforeMtime) {
|
|
159
|
-
console.log('[hmr-smoke] platform artifacts updated')
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
await sleep(Math.min(pollMs, 500))
|
|
163
|
-
}
|
|
164
|
-
throw new Error(`Timed out waiting for incremental rebuild under ${path.relative(cwd, dir)}`)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function getLatestMtimeMs(dir) {
|
|
168
|
-
if (!existsSync(dir)) {
|
|
169
|
-
return 0
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let latest = 0
|
|
173
|
-
const stack = [dir]
|
|
174
|
-
while (stack.length > 0) {
|
|
175
|
-
const current = stack.pop()
|
|
176
|
-
const entries = await fs.readdir(current, { withFileTypes: true })
|
|
177
|
-
for (const entry of entries) {
|
|
178
|
-
const fullPath = path.join(current, entry.name)
|
|
179
|
-
if (entry.isDirectory()) {
|
|
180
|
-
stack.push(fullPath)
|
|
181
|
-
continue
|
|
182
|
-
}
|
|
183
|
-
const stat = await fs.stat(fullPath)
|
|
184
|
-
latest = Math.max(latest, stat.mtimeMs)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return latest
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function restoreTargetFile() {
|
|
191
|
-
if (!originalTargetContent) {
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
await fs.writeFile(targetVueFile, originalTargetContent, 'utf8')
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function stopDevProcess() {
|
|
198
|
-
if (!devProcess || devProcess.exitCode !== null) {
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (process.platform !== 'win32' && devProcess.pid) {
|
|
203
|
-
try {
|
|
204
|
-
process.kill(-devProcess.pid, 'SIGTERM')
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
devProcess.kill('SIGTERM')
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
devProcess.kill('SIGTERM')
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
await waitForExit(devProcess, 8_000)
|
|
215
|
-
if (devProcess.exitCode === null && devProcess.pid) {
|
|
216
|
-
devProcess.kill('SIGKILL')
|
|
217
|
-
await waitForExit(devProcess, 3_000)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function waitForExit(child, timeout) {
|
|
222
|
-
return new Promise((resolve) => {
|
|
223
|
-
const timer = setTimeout(resolve, timeout)
|
|
224
|
-
child.once('exit', () => {
|
|
225
|
-
clearTimeout(timer)
|
|
226
|
-
resolve()
|
|
227
|
-
})
|
|
228
|
-
})
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function parseArgs(rawArgs) {
|
|
232
|
-
const parsed = {}
|
|
233
|
-
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
234
|
-
const arg = rawArgs[index]
|
|
235
|
-
if (!arg.startsWith('--') || arg === '--') {
|
|
236
|
-
continue
|
|
237
|
-
}
|
|
238
|
-
const key = arg.slice(2)
|
|
239
|
-
const value = rawArgs[index + 1]
|
|
240
|
-
if (!value || value.startsWith('--')) {
|
|
241
|
-
parsed[key] = true
|
|
242
|
-
continue
|
|
243
|
-
}
|
|
244
|
-
parsed[key] = value
|
|
245
|
-
index += 1
|
|
246
|
-
}
|
|
247
|
-
return parsed
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function sleep(ms) {
|
|
251
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
252
|
-
}
|