fix(types): PKG-CHAPTER-04 preserve CJS ESM and legacy consumer contracts

This commit is contained in:
Harvey Zhao committed 2026-09-10 23:29:06 +08:00
1 parent 48660c4e12
commit bab80ff886
41 files changed
+1087 -119

No files matched your search

+3 -1
View File
@@ -57,7 +57,9 @@ console.log(`✨ Built ${artplayerTSoutput}`);
}
pluginFiles.sort()
const allFiles = [...pluginFiles, 'artplayer.d.ts']
const languageFile = 'artplayer-i18n.d.ts'
fs.writeFileSync(path.join('docs/assets/ts', languageFile), `declare module 'artplayer/i18n/*' {\n const language: NonNullable<Artplayer.I18n['en']>\n export default language\n}\n`)
const allFiles = [...pluginFiles, 'artplayer.d.ts', languageFile]
const eslint = new ESLint({ fix: true, fixTypes: ['layout'] })
const results = await eslint.lintFiles(allFiles.map(file => path.join('docs/assets/ts', file)))
await ESLint.outputFixes(results)
+4 -2
View File
@@ -38,11 +38,13 @@ export function typeConsumers(dir) {
for (const [compiler, mode] of [[ts, 'node10-commonjs'], [ts, 'nodenext-cjs'], [ts, 'bundler-esm'], [compat, 'node10-commonjs'], [ts, 'nodenext-esm']]) {
const next = mode.startsWith('nodenext')
const extension = next ? (mode.endsWith('-cjs') ? 'cts' : 'mts') : 'ts'
const inputs = [...(mode === 'nodenext-esm' ? ['public'] : ['public', 'chapter-options']), 'language', 'legacy-plugin']
const inputs = ['public', 'chapter-options', 'chapter-exports', 'language-value', 'language', 'legacy-plugin']
if (mode === 'nodenext-cjs')
inputs.push('commonjs')
const files = inputs.map((name) => {
const file = path.join(dir, `${name}.${extension}`)
const folder = ['language', 'legacy-plugin'].includes(name) ? 'refactor/fixtures/consumers' : 'test/types'
fs.copyFileSync(path.join(workspace, folder, `${name}.ts`), file)
fs.copyFileSync(path.join(workspace, folder, `${name}.${name === 'commonjs' ? 'cts' : 'ts'}`), file)
return file
})
const options = {
+7 -9
View File
@@ -70,16 +70,14 @@ export function runTypechecks() {
sourceCount += result.files.filter(file => relative(file).includes('/src/') && !/\.d\.[cm]?ts$/.test(file)).length
console.log(`Strict project passed: ${relative(config)} (${result.files.length} root files)`)
}
for (const mode of ['node10-commonjs', 'nodenext-cjs', 'bundler-esm']) {
assert.deepEqual(checkConsumer(ts, mode), [], `Current consumer failed: ${mode}`)
console.log(`Consumer passed: TS ${ts.version} ${mode}`)
for (const [compiler, mode] of [[ts, 'node10-commonjs'], [ts, 'nodenext-cjs'], [ts, 'bundler-esm'], [ts, 'nodenext-esm'], [compat, 'node10-commonjs']]) {
for (const fixture of ['test/types/public.ts', 'test/types/chapter-options.ts', 'test/types/chapter-exports.ts', 'test/types/language-value.ts', 'refactor/fixtures/consumers/language.ts', 'refactor/fixtures/consumers/legacy-plugin.ts']) {
assert.deepEqual(checkConsumer(compiler, mode, fs.readFileSync(path.join(root, fixture), 'utf8')), [], `Consumer failed: TS ${compiler.version} ${mode} ${fixture}`)
}
if (mode === 'nodenext-cjs')
assert.deepEqual(checkConsumer(compiler, mode, fs.readFileSync(path.join(root, 'test/types/commonjs.cts'), 'utf8')), [], 'CommonJS export assignment consumer failed')
console.log(`Consumers passed: TS ${compiler.version} ${mode}`)
}
assert.deepEqual(checkConsumer(compat, 'node10-commonjs'), [], 'Old compiler consumer failed')
console.log(`Consumer passed: TS ${compat.version} node10-commonjs`)
const expected = read('test/types/known-diagnostics.json')
const diagnostics = checkConsumer(ts, 'nodenext-esm')
assert.deepEqual(diagnostics, expected.diagnostics, 'NodeNext ESM changed: review BASE-TYPE-01; a fix needs updated success assertions')
console.log(`Historical failure retained: ${expected.risk}, ${diagnostics.length} NodeNext ESM diagnostics; this is not candidate approval`)
console.log(`TypeScript production source files checked: ${sourceCount}; unmigrated JS is not counted`)
}