diff --git a/package-lock.json b/package-lock.json index 07c29d637..02d002f76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9864,16 +9864,16 @@ } }, "node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=14.17" } }, "node_modules/unbzip2-stream": { @@ -10981,7 +10981,7 @@ }, "packages/mcdoc-cli": { "name": "@spyglassmc/mcdoc-cli", - "version": "0.1.1", + "version": "0.1.3", "license": "MIT", "dependencies": { "fs-extra": "^11.1.1", @@ -10997,7 +10997,8 @@ "@types/klaw": "^3.0.4", "@types/line-column": "^1.0.0", "@types/node": "18.11.17", - "@types/yargs": "17.0.17" + "@types/yargs": "17.0.17", + "typescript": "^5.4.5" } }, "packages/mcdoc-cli/node_modules/@types/node": { @@ -12080,6 +12081,7 @@ "fs-extra": "^11.1.1", "klaw": "^4.1.0", "line-column": "^1.0.2", + "typescript": "^5.4.5", "yargs": "17.6.2" }, "dependencies": { @@ -18399,9 +18401,9 @@ } }, "typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", "dev": true }, "unbzip2-stream": { diff --git a/packages/core/src/parser/resourceLocation.ts b/packages/core/src/parser/resourceLocation.ts index 0d3f34826..38b25a637 100644 --- a/packages/core/src/parser/resourceLocation.ts +++ b/packages/core/src/parser/resourceLocation.ts @@ -127,7 +127,7 @@ export function resourceLocation( if (ans.isTag && !options.allowTag) { ctx.err.report( - localize('parser.resource-location.tag-diallowed'), + localize('parser.resource-location.tag-disallowed'), ans, ) } diff --git a/packages/java-edition/src/mcfunction/tree/patch.ts b/packages/java-edition/src/mcfunction/tree/patch.ts index 580fb9b81..6379cdd44 100644 --- a/packages/java-edition/src/mcfunction/tree/patch.ts +++ b/packages/java-edition/src/mcfunction/tree/patch.ts @@ -565,7 +565,7 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode { * 2. `teleport ` * 3. `teleport <...arguments>` * - * It is impossible for Spyglass to differentiate between (1) and (3) when it encouters a single entity + * It is impossible for Spyglass to differentiate between (1) and (3) when it encounters a single entity * at the position of the first argument, due to its lack of ability to backtrack. * * Therefore, we have compromised to patch the trees to something like this: diff --git a/packages/locales/src/locales/en.json b/packages/locales/src/locales/en.json index e255ca1f7..8742873c5 100644 --- a/packages/locales/src/locales/en.json +++ b/packages/locales/src/locales/en.json @@ -159,7 +159,7 @@ "parser.record.value": "a value", "parser.resource-location.illegal": "Illegal character(s): %0%", "parser.resource-location.namespace-expected": "Namespaces cannot be omitted here", - "parser.resource-location.tag-diallowed": "Tags are not allowed here", + "parser.resource-location.tag-disallowed": "Tags are not allowed here", "parser.string.illegal-brigadier": "Encountered non-[0-9A-Za-z_.+-] characters in %0%", "parser.string.illegal-escape": "Unexpected escape character %0%", "parser.string.illegal-quote": "Only %0% can be used to quote strings here", diff --git a/packages/locales/src/locales/fr.json b/packages/locales/src/locales/fr.json index b5e18123a..36ffa7c53 100644 --- a/packages/locales/src/locales/fr.json +++ b/packages/locales/src/locales/fr.json @@ -158,7 +158,7 @@ "parser.record.value": "une valeur", "parser.resource-location.illegal": "Caractère(s) inattendu(s) : %0%", "parser.resource-location.namespace-expected": "Les espaces de noms ne peuvent pas être omis ici", - "parser.resource-location.tag-diallowed": "Les tags ne sont pas autorisés ici", + "parser.resource-location.tag-disallowed": "Les tags ne sont pas autorisés ici", "parser.string.illegal-brigadier": "Des caractères autres que [0-9A-Za-z_.+-] ont été rencontrés dans %0%", "parser.string.illegal-escape": "Caractère d'échappement inattendu %0%", "parser.string.illegal-quote": "Seuls %0% peuvent être utilisés pour citer des chaînes de caractères", diff --git a/packages/locales/src/locales/pt-br.json b/packages/locales/src/locales/pt-br.json index c31c0796f..e371c04df 100644 --- a/packages/locales/src/locales/pt-br.json +++ b/packages/locales/src/locales/pt-br.json @@ -151,7 +151,7 @@ "parser.record.value": "um valor", "parser.resource-location.illegal": "Caráter(s) ilegal(is): %0%", "parser.resource-location.namespace-expected": "EspaçoDeNome não podem ser omitidos aqui", - "parser.resource-location.tag-diallowed": "Tags não são permitidas aqui", + "parser.resource-location.tag-disallowed": "Tags não são permitidas aqui", "parser.string.illegal-brigadier": "Encontrou não-[0-9A-Za-z_.+-] caracteres em %0%", "parser.string.illegal-escape": "Caráter de escape inesperado %0%", "parser.string.illegal-quote": "Apenas %0% pode ser usado para citar strings aqui", diff --git a/packages/locales/src/locales/zh-cn.json b/packages/locales/src/locales/zh-cn.json index 50c68e340..8f8f4a11a 100644 --- a/packages/locales/src/locales/zh-cn.json +++ b/packages/locales/src/locales/zh-cn.json @@ -148,7 +148,7 @@ "parser.record.value": "一个值", "parser.resource-location.illegal": "无效字符:%0%", "parser.resource-location.namespace-expected": "不可在此省略命名空间", - "parser.resource-location.tag-diallowed": "此处不允许使用标签", + "parser.resource-location.tag-disallowed": "此处不允许使用标签", "parser.string.illegal-brigadier": "在 %0% 中遇到了非 [0-9A-Za-z_.+-] 字符", "parser.string.illegal-escape": "预期外的转义字符 %0%", "parser.string.illegal-quote": "此处只允许使用 %0% 包裹字符串", diff --git a/packages/locales/src/locales/zh-tw.json b/packages/locales/src/locales/zh-tw.json index 94e6f5867..8070b9461 100644 --- a/packages/locales/src/locales/zh-tw.json +++ b/packages/locales/src/locales/zh-tw.json @@ -130,7 +130,7 @@ "parser.record.value": "一個值", "parser.resource-location.illegal": "無效字元:%0%", "parser.resource-location.namespace-expected": "不可在此省略命名空間", - "parser.resource-location.tag-diallowed": "此處不允許使用標籤", + "parser.resource-location.tag-disallowed": "此處不允許使用標籤", "parser.string.illegal-brigadier": "在 %0% 中遇到了非 [0-9A-Za-z_.+-] 字元", "parser.string.illegal-escape": "預期外的跳脫字元 %0%", "parser.string.illegal-quote": "此處只允許使用 %0% 包裹字串", diff --git a/packages/mcdoc-cli/package.json b/packages/mcdoc-cli/package.json index 1568337df..b7a13e6e9 100644 --- a/packages/mcdoc-cli/package.json +++ b/packages/mcdoc-cli/package.json @@ -1,16 +1,17 @@ { "name": "@spyglassmc/mcdoc-cli", - "version": "0.1.1", + "version": "0.1.3", "type": "module", "main": "lib/index.js", "types": "lib/index.d.ts", "contributors": [ { - "name": "Misode" + "name": "Misode", + "url": "https://github.com/misode" }, { "name": "MulverineX", - "url": "http://mulverine.dev" + "url": "https://mulverine.dev" } ], "license": "MIT", @@ -18,12 +19,12 @@ "test": "test/" }, "bin": { - "mcdoc": "./lib/index.js" + "mcdoc": "lib/index.js" }, "scripts": { "release": "npm publish", "release:dry": "npm publish --dry-run", - "test": "rm -rf vanilla-mcdoc && rm -rf src/out && git clone https://github.com/SpyglassMC/vanilla-mcdoc && cd src && ./index.ts generate ../vanilla-mcdoc/ -p -m -l" + "test": "rm -rf vanilla-mcdoc && rm -rf src/out && git clone https://github.com/SpyglassMC/vanilla-mcdoc && cd src && npx tsx src/index.mts generate ../vanilla-mcdoc/ -p -m -l" }, "dependencies": { "fs-extra": "^11.1.1", @@ -36,14 +37,15 @@ "@types/klaw": "^3.0.4", "@types/line-column": "^1.0.0", "@types/node": "18.11.17", - "@types/yargs": "17.0.17" + "@types/yargs": "17.0.17", + "typescript": "^5.4.5" }, "publishConfig": { "access": "public" }, "repository": { "type": "git", - "url": "https://github.com/SpyglassMC/Spyglass.git" + "url": "git+https://github.com/SpyglassMC/Spyglass.git" }, "homepage": "https://spyglassmc.com", "bugs": { diff --git a/packages/mcdoc-cli/src/index.ts b/packages/mcdoc-cli/src/index.mts old mode 100755 new mode 100644 similarity index 86% rename from packages/mcdoc-cli/src/index.ts rename to packages/mcdoc-cli/src/index.mts index 96e2b16d2..99e456f57 --- a/packages/mcdoc-cli/src/index.ts +++ b/packages/mcdoc-cli/src/index.mts @@ -1,4 +1,4 @@ -#!/usr/bin/env -S ts-node --esm +#!/usr/bin/env -S tsx import { dirname, join, parse, resolve } from 'path' import { fileURLToPath, pathToFileURL } from 'url' @@ -24,6 +24,11 @@ const cacheRoot = join(parentPath, 'cache') const CLI = yargs(hideBin(process.argv)) +function removeWindowsCruft(str: string) { + if (str.includes('\r')) return str.replaceAll('\r', '') + return str +} + await CLI.scriptName('mcdoc') .command( 'generate [source]', @@ -118,13 +123,16 @@ await CLI.scriptName('mcdoc') await service.project.ready() await service.project.cacheService.save() - const out = 'out' + const generated = join('out', 'generated') if (args.dry !== true) { - await fs.ensureDir(out) + await fs.ensureDir(generated) if (args.module) { - await fs.ensureDir(join(out, 'module')) + await fs.ensureDir(join(generated, 'module')) + } + if (args.locale) { + await fs.ensureDir(join('out', 'locale')) } } @@ -176,7 +184,7 @@ await CLI.scriptName('mcdoc') ) { const child: any = {} - let known_error = false + const known_error = false /* @ts-ignore */ child.self = self @@ -206,6 +214,13 @@ await CLI.scriptName('mcdoc') child.type = _child.type + if (child.type === 'resource_location') { + /* @ts-ignore */ + child.namespace = _child.namespace + /* @ts-ignore */ + child.path = _child.path + } + if (Object.hasOwn(_child, 'isOptional')) { /* @ts-ignore */ child.isOptional = _child.isOptional @@ -224,9 +239,11 @@ await CLI.scriptName('mcdoc') if (internal_locales[parent]) { locales[ `mcdoc.${ - resource.replace(/\//g, '.') + resource.replace(/[\/\\]/g, '.') }.${child.value}` - ] = internal_locales[parent].join('\n') + ] = removeWindowsCruft( + internal_locales[parent].join('').trimEnd(), + ) delete internal_locales[parent] } @@ -237,15 +254,19 @@ await CLI.scriptName('mcdoc') internal_locales[parent] ) { locales[ - `mcdoc.${resource.replace(/\//g, '.')}.map_key` - ] = internal_locales[parent].join('\n') + `mcdoc.${ + resource.replace(/[\/\\]/g, '.') + }.map_key` + ] = removeWindowsCruft( + internal_locales[parent].join('').trimEnd(), + ) delete internal_locales[parent] } if (Object.hasOwn(_child, 'comment')) { /* @ts-ignore */ - const comment: string = _child.comment.trim() + const comment: string = _child.comment child.comment = comment if ( @@ -254,17 +275,11 @@ await CLI.scriptName('mcdoc') ) { const key = parent.replace(/\[\d+\]$/, '') - if (!internal_locales.key) { + if (!internal_locales[key]) { internal_locales[key] = [] } - internal_locales[key].push(comment) - } else if (comment.startsWith('/ ')) { - child.type = 'error' - console.warn( - `known error: orphaned dispatch comment`, - ) - known_error = true + internal_locales[key].push(comment.slice(1)) } } @@ -343,19 +358,20 @@ await CLI.scriptName('mcdoc') symbols.push(symbol) if (!args.dry && args.module) { - const dir = parse(join(out, 'module', resource)).dir + const dir = + parse(join(generated, 'module', resource)).dir if (dir !== '') await fs.ensureDir(dir) await fs.writeFile( - join(out, 'module', `${resource}.mcdoc.json`), + join(generated, 'module', `${resource}.mcdoc.json`), JSON.stringify(symbol), ) if (args.pretty) { await fs.writeFile( join( - out, + generated, 'module', `${resource}.pretty.mcdoc.json`, ), @@ -370,20 +386,20 @@ await CLI.scriptName('mcdoc') if (!args.dry) { await fs.writeFile( - join(out, 'generated.mcdoc.json'), + join(generated, 'generated.mcdoc.json'), JSON.stringify(symbols), ) if (args.pretty) { await fs.writeFile( - join(out, 'generated.pretty.mcdoc.json'), + join(generated, 'generated.pretty.mcdoc.json'), JSON.stringify(symbols, undefined, 3), ) } if (args.module) { await fs.writeFile( - join(out, 'module', 'index.json'), + join(generated, 'module', 'index.json'), JSON.stringify(symbols.map(symbol => symbol.resource)), ) } @@ -397,7 +413,7 @@ await CLI.scriptName('mcdoc') console.warn(internal_locales) } await fs.writeFile( - join(out, 'locale.en-us.json'), + join('out', 'locale', 'locale.en-us.json'), JSON.stringify(locales, undefined, 3), ) } diff --git a/packages/mcdoc-cli/tsconfig.json b/packages/mcdoc-cli/tsconfig.json index 5b6e2a754..0551859ae 100644 --- a/packages/mcdoc-cli/tsconfig.json +++ b/packages/mcdoc-cli/tsconfig.json @@ -11,8 +11,5 @@ { "path": "src" }, - { - "path": "test" - } ] } diff --git a/packages/mcdoc/src/type/index.ts b/packages/mcdoc/src/type/index.ts index 9cd8416f4..4dcaa97fd 100644 --- a/packages/mcdoc/src/type/index.ts +++ b/packages/mcdoc/src/type/index.ts @@ -23,6 +23,7 @@ export const StaticIndexKeywords = Object.freeze( 'fallback', 'none', 'unknown', + 'spawnitem', ] as const, ) export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number]