Skip to content

Commit b24b5ba

Browse files
authored
🔀 Merge #489: 🔖 v1.10.0-beta.5
2 parents d1814d7 + b7929c4 commit b24b5ba

268 files changed

Lines changed: 27925 additions & 26587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
14+
steps:
15+
- uses: actions/checkout@v5
16+
- uses: oven-sh/setup-bun@v2
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 24
20+
registry-url: https://registry.npmjs.org/
21+
22+
- name: Install dependencies
23+
run: bun install --frozen-lockfile
24+
25+
- name: Build
26+
run: bun run build
27+
28+
- name: Run tests
29+
run: bun test

tools/esbuild.ts renamed to .scripts/esbuild.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ if (process.argv.includes('--mode=dev')) {
77
process.env.FLAVOR ??= `local`
88

99
import * as esbuild from 'esbuild'
10+
import importFolderPlugin from 'esbuild-plugin-import-folder'
1011
import ImportGlobPlugin from 'esbuild-plugin-import-glob'
1112
import inlineImage from 'esbuild-plugin-inline-image'
1213
import * as fs from 'fs'
1314
import { load } from 'js-yaml'
1415
import vscodeProblemsPatch from 'node-modules-vscode-problems-patch'
15-
import * as path from 'path'
16-
import { isAbsolute, join } from 'path'
16+
import * as path from 'node:path'
17+
import { isAbsolute, join } from 'node:path'
18+
import {
19+
createBlockbenchSvelteConfig,
20+
esbuildPluginSvelte,
21+
} from 'svelte-patching-tools/esbuildPlugin'
1722
import { TextDecoder } from 'util'
18-
import svelteConfig from '../svelte.config.js'
1923
import assetOverridePlugin from './plugins/assetOverridePlugin'
2024
import bufferPatchPlugin from './plugins/bufferPatchFunction.js'
21-
import importFolderPlugin from './plugins/importFolder'
25+
import langPlugin from './plugins/lang'
2226
import mcbCompressionPlugin from './plugins/mcbCompressionPlugin'
2327
import packagerPlugin from './plugins/packagerPlugin'
24-
import sveltePlugin from './plugins/sveltePlugin'
2528
const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
2629

2730
const INFO_PLUGIN: esbuild.Plugin = {
@@ -134,34 +137,7 @@ function createBanner() {
134137
return '│ ' + ' '.repeat(l) + v + ' '.repeat(r) + ' │'
135138
})
136139

137-
const message = `
138-
# Animated Java does not work in Blockbench 5
139-
140-
You will need to install and use Blockbench v4.12.6 to use Animated Java until it is updated to support 5.
141-
142-
## How to install Blockbench v4.12.6
143-
144-
1. Download the portable version of Blockbench 4.12.6 [here](https://github.com/JannisX11/blockbench/releases/download/v4.12.6/Blockbench_4.12.6_portable.exe).
145-
2. Once it's finished downloading, double click the .exe file to run it.
146-
147-
If you're familiar with command line interfaces, you can use [Envbench](https://www.npmjs.com/package/envbench) to install and manage multiple Blockbench versions side by side.
148-
`
149-
150-
const startupCode = `(() => {
151-
if (!compareVersions('5.0.0', Blockbench.version)) {
152-
const message = \`${message}\`;
153-
Blockbench.showMessageBox({title: 'Animated Java - Incompatible Blockbench Version',message,width:600});
154-
requestAnimationFrame(() => Plugins.registered['animated_java'].uninstall());
155-
throw new Error(message);
156-
}
157-
})()`.trim()
158-
159-
const banner =
160-
'\n' +
161-
[header, ...lines, footer].map(v => `//?? ${v}`).join('\n') +
162-
'\n\n' +
163-
startupCode +
164-
'\n'
140+
const banner = '\n' + [header, ...lines, footer].map(v => `//?? ${v}`).join('\n')
165141

166142
return {
167143
js: banner,
@@ -205,17 +181,27 @@ const yamlPlugin: (opts: {
205181
},
206182
})
207183

184+
import VSCODE_SETTINGS from '../.vscode/settings.json'
185+
const IGNORED_SVELTE_WARNINGS = Object.keys(
186+
VSCODE_SETTINGS['svelte.plugin.svelte.compilerWarnings']
187+
)
188+
208189
const COMMON_CONFIG: esbuild.BuildOptions = {
209190
banner: createBanner(),
210191
entryPoints: ['./src/index.ts'],
211192
outfile: `./dist/${PACKAGE.name}.js`,
212193
bundle: true,
213-
platform: 'node',
194+
platform: 'browser',
195+
external: ['node:*'],
214196
loader: { '.svg': 'dataurl', '.ttf': 'binary', '.css': 'text' },
215197
plugins: [
198+
langPlugin({
199+
languageFolder: 'src/lang',
200+
}),
216201
// @ts-expect-error broken default import
217202
vscodeProblemsPatch.default(),
218-
importFolderPlugin,
203+
// @ts-expect-error broken default import
204+
importFolderPlugin.default(),
219205
// @ts-expect-error broken default import
220206
ImportGlobPlugin.default(),
221207
bufferPatchPlugin(),
@@ -224,15 +210,36 @@ const COMMON_CONFIG: esbuild.BuildOptions = {
224210
}),
225211
INFO_PLUGIN,
226212
yamlPlugin({}),
227-
sveltePlugin(svelteConfig),
213+
esbuildPluginSvelte(
214+
createBlockbenchSvelteConfig(PACKAGE.name, {
215+
compilerOptions: {
216+
warningFilter(warning: any) {
217+
return !IGNORED_SVELTE_WARNINGS.includes(warning.code)
218+
},
219+
compatibility: {
220+
componentApi: 4,
221+
},
222+
// @ts-expect-error - not typed correctly
223+
generate: 'client',
224+
},
225+
})
226+
),
228227
packagerPlugin(),
229228
assetOverridePlugin(),
230229
mcbCompressionPlugin(),
231230
DEPENDENCY_QUARKS,
232231
],
233-
alias: { svelte: 'svelte' },
232+
alias: {
233+
svelte: 'svelte',
234+
module: './.scripts/fakeModule.js',
235+
'node:module': './.scripts/fakeModule.js',
236+
},
234237
format: 'iife',
235238
define: DEFINES,
239+
inject: [
240+
// Blockbench does not provide access to the global process, but some of our dependencies expect it to exist.
241+
`./.scripts/fakeProcess.js`,
242+
],
236243
treeShaking: true,
237244
}
238245

.scripts/fakeModule.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Module = {
2+
createRequire() {
3+
return {}
4+
},
5+
}
6+
7+
export { Module as module }
8+
export default Module

.scripts/fakeProcess.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const process = {
2+
__NOTE: 'This is a fake process object added by Animated Java. It is not the actual Node.js process object.',
3+
cwd: () => '',
4+
env: {},
5+
version: 'v24.14.0',
6+
argv: '',
7+
}
8+
9+
export { process }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Plugin } from 'esbuild'
22
import * as fs from 'fs/promises'
3-
import * as pathjs from 'path'
3+
import * as pathjs from 'node:path'
44

55
const ASSET_OVERRIDES_PATH = 'src/assets/vanillaAssetOverrides/'
66

.scripts/plugins/lang.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
interface LangPluginOptions {
2+
languageFolder: string
3+
}
4+
5+
interface StructuredLanguageFile {
6+
[key: string]: string | StructuredLanguageFile
7+
}
8+
9+
interface LanguageDefinition {
10+
name: string
11+
structured: StructuredLanguageFile
12+
flattened: Record<string, string>
13+
}
14+
15+
declare module 'LANGUAGES' {
16+
export const LANGUAGES: Record<string, LanguageDefinition>
17+
export function flattenStructuredLanguageFile(
18+
file: StructuredLanguageFile
19+
): Record<string, string>
20+
}

.scripts/plugins/lang.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/// <reference path="./lang.d.ts"/>
2+
3+
import ESBuild from 'esbuild'
4+
import { existsSync } from 'fs'
5+
import { readdir, readFile } from 'fs/promises'
6+
import { load } from 'js-yaml'
7+
import { join } from 'path'
8+
9+
const filterYamlFiles = (file: string) => {
10+
return file.endsWith('.yml') || file.endsWith('.yaml')
11+
}
12+
13+
const flattenStructuredLanguageFile = (file: StructuredLanguageFile): Record<string, string> => {
14+
const result: Record<string, string> = {}
15+
for (const key in file) {
16+
if (typeof file[key] === 'string') {
17+
result[key] = file[key]
18+
continue
19+
}
20+
21+
for (const [subKey, value] of Object.entries(flattenStructuredLanguageFile(file[key]))) {
22+
result[`${key}.${subKey}`] = value
23+
}
24+
}
25+
return result
26+
}
27+
28+
const langPlugin = ({ languageFolder }: LangPluginOptions) =>
29+
({
30+
name: 'lang',
31+
setup(build) {
32+
if (!existsSync(languageFolder)) {
33+
throw new Error(`Language folder "${languageFolder}" does not exist.`)
34+
}
35+
36+
build.onResolve({ filter: /LANGUAGES/ }, () => {
37+
return {
38+
path: languageFolder,
39+
namespace: 'language-file',
40+
}
41+
})
42+
43+
build.onLoad({ filter: /.*/, namespace: 'language-file' }, async () => {
44+
const translations: Record<string, LanguageDefinition> = {}
45+
46+
const files = (await readdir(languageFolder)).filter(filterYamlFiles)
47+
if (files.length === 0) {
48+
console.warn(`No language files found in "${languageFolder}"`)
49+
}
50+
51+
const watchFiles: string[] = []
52+
53+
for (const file of files) {
54+
const path = join(languageFolder, file)
55+
watchFiles.push(path)
56+
57+
const name = file.replace(/\.(yml|yaml)$/, '')
58+
const structured: StructuredLanguageFile = await readFile(path, {
59+
encoding: 'utf-8',
60+
}).then(data => load(data, { filename: path }) as StructuredLanguageFile)
61+
const flattened = flattenStructuredLanguageFile(structured)
62+
63+
translations[name] = { name, structured, flattened }
64+
}
65+
66+
const contents =
67+
`export const LANGUAGES = ${JSON.stringify(translations)};` +
68+
`export const flattenStructuredLanguageFile = ${flattenStructuredLanguageFile.toString()};`
69+
70+
return {
71+
contents,
72+
loader: 'js',
73+
watchFiles,
74+
}
75+
})
76+
},
77+
}) satisfies ESBuild.Plugin
78+
79+
export default langPlugin
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Plugin } from 'esbuild'
2-
import * as fflate from 'fflate'
2+
import * as fflate from 'fflate/browser'
33
import { existsSync } from 'fs'
44
import * as fs from 'fs/promises'
5-
import * as pathjs from 'path'
5+
import * as pathjs from 'node:path'
66

77
function zip(data: fflate.AsyncZippable): Promise<Uint8Array> {
88
return new Promise((resolve, reject) => {
@@ -59,7 +59,7 @@ export default getZipFile('${localPath}')
5959
const data = Buffer.from(zipped).toString('base64')
6060
return {
6161
contents: `
62-
import * as fflate from 'fflate'
62+
import * as fflate from 'fflate/browser'
6363
const unzipped = fflate.unzipSync(Uint8Array.from(atob('${data}'), c => c.charCodeAt(0)))
6464
export default function getFile(path) {
6565
return Buffer.from(unzipped[path]).toString('utf-8')

0 commit comments

Comments
 (0)