nomadro/apps/miniprogram/weapp/scripts/_test-sanitize.mjs
Eric 4389ebe6cb Ship WeChat audit release 2026-11-02: realtime config, audit vip-ebook shell, admin ops.
Document test9 tag 2026-11-02 for upload; POST config pull + WS, fixed dark home, no debug bar.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 16:12:57 +08:00

44 lines
1.5 KiB
JavaScript

import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const { sanitizeWxssSource, sanitizeDir } = require('./sanitize-wxss-plugin.cjs')
const fs = require('fs')
const path = require('path')
const sample = `/* MUST stay in layer base. Unlayered * { padding:0; margin:0 } beats Tailwind */
@layer base {
*, *::before, *::after {
margin: 0;
padding: 0;
}
}
@media (max-width: 900px) {
.social-home .social-panel-meta > :is(span, time) { font-size: 8px; }
html:has(.social-home) { scroll-behavior: auto; }
.ok { color: red; }
}
`
const out = sanitizeWxssSource(sample)
console.log(out)
console.log('---counts---', {
layer: (out.match(/@layer/g) || []).length,
has: (out.match(/:has\s*\(/g) || []).length,
is: (out.match(/:is\s*\(/g) || []).length,
star: /\*, \*::before/.test(out),
ok: out.includes('.ok'),
pageReset: out.includes('page, .soc-taro-root'),
})
const dist = path.resolve('dist')
if (fs.existsSync(path.join(dist, 'pages/social/sub-vendors.wxss'))) {
const raw = fs.readFileSync(path.join(dist, 'pages/social/sub-vendors.wxss'), 'utf8')
const cleaned = sanitizeWxssSource(raw)
fs.writeFileSync(path.join(dist, 'pages/social/sub-vendors.wxss'), cleaned)
console.log('dist cleaned', {
layer: (cleaned.match(/@layer/g) || []).length,
has: (cleaned.match(/:has\s*\(/g) || []).length,
is: (cleaned.match(/:is\s*\(/g) || []).length,
star: /\*, \*::before/.test(cleaned),
})
}
console.log(sanitizeDir(dist))