mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 04:36:15 -08:00
refactor(tooling): [MOD-02] split library build and development into typed modules
This commit is contained in:
1 parent
28c7abb2bb
commit
401d4cdd65
36 files changed
+1644
-427
No files matched your search
@@ -75,6 +75,10 @@ test('Normal build CLI compiles TypeScript, JS, Less, SVG and inline worker into
|
||||
assert.equal(run([name]).status, 1)
|
||||
assert(fs.existsSync(path.join(dist, 'preserve.txt')))
|
||||
fs.unlinkSync(path.join(project, 'src/index.js'))
|
||||
fs.writeFileSync(path.join(project, 'package.json'), JSON.stringify({ name, version: 1 }))
|
||||
assert.equal(run([name]).status, 1, 'Malformed version must fail before dist is cleaned')
|
||||
assert(fs.existsSync(path.join(dist, 'preserve.txt')))
|
||||
fs.writeFileSync(path.join(project, 'package.json'), JSON.stringify({ name, version: '1.0.0' }))
|
||||
execFileSync(process.execPath, [path.join(root, 'scripts/build.js'), name], { cwd: directory, env: { ...process.env, NODE_ENV: 'production' }, encoding: 'utf8', timeout: 60000 })
|
||||
assert.deepEqual(fs.readdirSync(dist).sort(), [`${name}.js`, `${name}.legacy.js`, `${name}.mjs`])
|
||||
function check(factory) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { createHash } from 'node:crypto'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const root = fileURLToPath(new URL('../../', import.meta.url))
|
||||
const baseline = '28c7abb2bb8dfb7c84acfc7c5ec05c5882623069'
|
||||
const directory = fs.mkdtempSync(path.join(root, 'refactor/.cache/library-comparison-'))
|
||||
const names = fs.readdirSync(path.join(root, 'packages')).filter(name => name !== 'artplayer-vitepress' && fs.existsSync(path.join(root, 'packages', name, 'package.json'))).sort()
|
||||
const sha = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex')
|
||||
fs.mkdirSync(path.join(directory, 'scripts'))
|
||||
fs.writeFileSync(path.join(directory, 'package.json'), '{"type":"module"}\n')
|
||||
for (const file of ['build.js', 'utils.js', 'projects.js', 'build-analysis.mjs'])
|
||||
fs.writeFileSync(path.join(directory, 'scripts', file), execFileSync('git', ['show', `${baseline}:scripts/${file}`], { cwd: root }))
|
||||
for (const name of names) {
|
||||
const target = path.join(directory, 'packages', name)
|
||||
fs.mkdirSync(target, { recursive: true })
|
||||
for (const file of ['src', 'public', 'package.json', 'THIRD_PARTY_NOTICES']) {
|
||||
const source = path.join(root, 'packages', name, file)
|
||||
if (fs.existsSync(source))
|
||||
fs.cpSync(source, path.join(target, file), { recursive: true })
|
||||
}
|
||||
}
|
||||
const artifacts = () => names.flatMap(name => ['.js', '.legacy.js', '.mjs'].map(extension => {
|
||||
const relative = `packages/${name}/dist/${name}${extension}`
|
||||
return { path: relative, sha256: sha(path.join(directory, relative)) }
|
||||
}))
|
||||
function build(script, label) {
|
||||
const log = fs.openSync(path.join(directory, `${label}.log`), 'w')
|
||||
try {
|
||||
execFileSync(process.execPath, [script, 'all'], { cwd: directory, stdio: ['ignore', log, log], timeout: 300000 })
|
||||
}
|
||||
finally {
|
||||
fs.closeSync(log)
|
||||
}
|
||||
}
|
||||
console.log(`Library comparison fixture: ${directory}`)
|
||||
build(path.join(directory, 'scripts/build.js'), 'before')
|
||||
const before = artifacts()
|
||||
fs.writeFileSync(path.join(directory, 'before.json'), `${JSON.stringify(before, null, 2)}\n`)
|
||||
build(path.join(root, 'scripts/build.js'), 'candidate')
|
||||
const candidate = artifacts()
|
||||
const differences = candidate.filter((item, index) => item.sha256 !== before[index].sha256)
|
||||
const report = { task: 'MOD-02', baseline, node: process.version, names, before, candidate, differences }
|
||||
fs.writeFileSync(path.join(directory, 'report.json'), `${JSON.stringify(report, null, 2)}\n`)
|
||||
assert.deepEqual(differences, [], 'Production bytes changed across the tooling migration')
|
||||
console.log(`Compared ${names.length} libraries / ${candidate.length} artifacts: identical SHA-256. Report: ${directory}/report.json`)
|
||||
@@ -0,0 +1,35 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { once } from 'node:events'
|
||||
import fs from 'node:fs'
|
||||
import net from 'node:net'
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const root = fileURLToPath(new URL('../../', import.meta.url))
|
||||
const server = net.createServer()
|
||||
server.listen(0)
|
||||
await once(server, 'listening')
|
||||
const { port } = server.address()
|
||||
try {
|
||||
const child = spawn(process.execPath, ['--input-type=module', '--eval', "import servor from 'servor'; await servor({port:Number(process.env.ARTPLAYER_PROBE_PORT),reload:false}); process.exit(7)"], {
|
||||
cwd: root,
|
||||
env: { ...process.env, ARTPLAYER_PROBE_PORT: String(port) },
|
||||
windowsHide: true,
|
||||
timeout: 10000,
|
||||
})
|
||||
let output = ''
|
||||
child.stdout.on('data', (data) => { output += data })
|
||||
child.stderr.on('data', (data) => { output += data })
|
||||
const [code, signal] = await once(child, 'exit')
|
||||
const version = JSON.parse(fs.readFileSync(path.join(root, 'node_modules/servor/package.json'), 'utf8')).version
|
||||
const result = { task: 'MOD-DEV-01', node: process.version, servor: version, occupiedPort: port, code, signal, output, interpretation: 'Historical upstream defect reproduction, not candidate success: an occupied requested port exits the entire process with status zero.' }
|
||||
fs.writeFileSync(path.join(root, 'refactor/.cache/servor-port-probe.json'), `${JSON.stringify(result, null, 2)}\n`)
|
||||
assert.match(output, /port.*already in use/)
|
||||
assert.equal(code, 0, 'Pinned Servor no longer reproduces its historical successful failure exit')
|
||||
console.log(JSON.stringify(result, null, 2))
|
||||
}
|
||||
finally {
|
||||
await new Promise(resolve => server.close(resolve))
|
||||
}
|
||||
Reference in new issue
Block a user