do not bundle large assets package, cleanup esbuildPlugins

This commit is contained in:
Vitaly 2023-09-03 17:27:20 +03:00
commit d6824aad2e
4 changed files with 14 additions and 79 deletions

View file

@ -3,5 +3,5 @@ module.exports = {
standalone: require('./lib/standalone'),
headless: require('./lib/headless'),
viewer: require('./viewer'),
supportedVersions: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.1', '1.16.4', '1.17.1', '1.18.1']
supportedVersions: require('./viewer/supportedVersions.json')
}

View file

@ -0,0 +1 @@
["1.8.8", "1.9.4", "1.10.2", "1.11.2", "1.12.2", "1.13.2", "1.14.4", "1.15.2", "1.16.1", "1.16.4", "1.17.1", "1.18.1"]

View file

@ -38,28 +38,11 @@ const plugins = [
loader: 'js',
}
})
// build.onResolve({
// filter: /^minecraft-assets$/,
// }, ({ resolveDir, path }) => {
// // if (!resolveDir.endsWith('minecraft-data')) return
// return {
// namespace: 'load-global-minecraft-assets',
// path
// }
// })
// build.onLoad({
// filter: /.+/,
// namespace: 'load-global-minecraft-assets',
// }, async () => {
// const resolvedPath = await build.resolve('minecraft-assets/index.js', { kind: 'require-call', resolveDir: process.cwd() })
// let contents = (await fs.promises.readFile(resolvedPath.path, 'utf8'))
// contents = contents.slice(0, contents.indexOf('const data = ')) + 'const data = window.minecraftAssets;' + contents.slice(contents.indexOf('module.exports.versions'))
// return {
// contents,
// loader: 'js',
// resolveDir: dirname(resolvedPath.path),
// }
// })
build.onResolve({
filter: /^minecraft-assets$/,
}, () => {
throw new Error('hit banned package')
})
}
},
{
@ -71,10 +54,7 @@ const plugins = [
filter: /.*/,
}, async ({ path, ...rest }) => {
if (join(rest.resolveDir, path).replaceAll('\\', '/').endsWith('minecraft-data/data.js')) {
return {
namespace: customMcDataNs,
path
}
throw new Error('Should not hit')
}
if (['.woff', '.woff2', '.ttf'].some(ext => path.endsWith(ext))) {
return {
@ -85,52 +65,6 @@ const plugins = [
}
})
build.onLoad({
filter: /.*/,
namespace: customMcDataNs,
}, async ({ path, ...rest }) => {
throw new Error('unreachable')
const resolvedPath = await build.resolve('minecraft-data/minecraft-data/data/dataPaths.json', { kind: 'require-call', resolveDir: process.cwd() })
const dataPaths = JSON.parse(await fs.promises.readFile(resolvedPath.path, 'utf8'))
// bedrock unsupported
delete dataPaths.bedrock
const allowOnlyList = process.env.ONLY_MC_DATA?.split(',') ?? []
// skip data for 0.30c, snapshots and pre-releases
const ignoredVersionsRegex = /(^0\.30c$)|w|-pre|-rc/
const includedVersions = []
let contents = 'module.exports =\n{\n'
for (const platform of Object.keys(dataPaths)) {
contents += ` '${platform}': {\n`
for (const version of Object.keys(dataPaths[platform])) {
if (allowOnlyList.length && !allowOnlyList.includes(version)) continue
if (ignoredVersionsRegex.test(version)) continue
includedVersions.push(version)
contents += ` '${version}': {\n`
for (const dataType of Object.keys(dataPaths[platform][version])) {
const loc = `minecraft-data/data/${dataPaths[platform][version][dataType]}/`
contents += ` get ${dataType} () { return require("./${loc}${dataType}.json") },\n`
}
contents += ' },\n'
}
contents += ' },\n'
}
contents += '}\n'
if (prod) {
console.log('Included mc-data versions:', includedVersions)
}
return {
contents,
loader: 'js',
resolveDir: join(dirname(resolvedPath.path), '../..'),
}
})
build.onEnd(async ({ metafile, outputFiles }) => {
// write outputFiles
for (const file of outputFiles) {

View file

@ -1,12 +1,12 @@
//@ts-check
const { LitElement, html, css } = require('lit')
const { commonCss } = require('./components/common')
const { hideCurrentModal } = require('../globalState')
const mcAssets = require("minecraft-assets")
const data = require('minecraft-data')
const mineflayer = require('mineflayer')
const viewerSupportedVersions = require('prismarine-viewer/viewer/supportedVersions.json')
const fullySupporedVersions = mcAssets.versions
const partialSupportVersions = mineflayer.supportedVersions
const fullySupporedVersions = viewerSupportedVersions
const partiallySupportVersions = mineflayer.supportedVersions
class PlayScreen extends LitElement {
static get styles () {
@ -175,8 +175,8 @@ class PlayScreen extends LitElement {
pmui-id="botversion"
pmui-value="${this.version}"
pmui-inputmode="decimal"
state="${this.version && (fullySupporedVersions.includes(this.version) ? '' : /* TODO improve check: check exact including all */ partialSupportVersions.some(v => this.version.startsWith(v)) ? 'warning' : 'invalid')}"
.autocompleteValues=${mcAssets.versions}
state="${this.version && (fullySupporedVersions.includes(/** @type {any} */(this.version)) ? '' : /* TODO improve check: check exact including all */ partiallySupportVersions.some(v => this.version.startsWith(v)) ? 'warning' : 'invalid')}"
.autocompleteValues=${fullySupporedVersions}
@input=${e => { this.version = e.target.value }}
></pmui-editbox>
</div>