mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-26 10:41:55 +00:00
chore: generate codemirror languages from linguist-languages package (#38624)
Replace the previous main-branch fetch with data from npm package [`linguist-languages`](https://github.com/ikatyang-collab/linguist-languages) and only run generate targets when actually needed. The removed `fileFilters` were leftovers from the nolyfill removal.
This commit is contained in:
1
assets/codemirror-languages.json
generated
1
assets/codemirror-languages.json
generated
@@ -453,7 +453,6 @@
|
||||
".htmlhintrc",
|
||||
".imgbotconfig",
|
||||
".nycrc",
|
||||
".secrets.baseline",
|
||||
".tern-config",
|
||||
".tern-project",
|
||||
".watchmanconfig",
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
"globals": "17.7.0",
|
||||
"happy-dom": "20.10.6",
|
||||
"jiti": "2.7.0",
|
||||
"linguist-languages": "9.4.0",
|
||||
"markdownlint-cli": "0.49.1",
|
||||
"material-icon-theme": "5.36.1",
|
||||
"postcss-html": "1.8.1",
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -276,6 +276,9 @@ importers:
|
||||
jiti:
|
||||
specifier: 2.7.0
|
||||
version: 2.7.0
|
||||
linguist-languages:
|
||||
specifier: 9.4.0
|
||||
version: 9.4.0
|
||||
markdownlint-cli:
|
||||
specifier: 0.49.1
|
||||
version: 0.49.1
|
||||
@@ -3190,6 +3193,9 @@ packages:
|
||||
lines-and-columns@1.2.4:
|
||||
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
|
||||
|
||||
linguist-languages@9.4.0:
|
||||
resolution: {integrity: sha512-mYnFVrsWg5Bex0Kl5EDcXhrjXZ5DqMlBDXo7EUWLMTLDpxbuHvgBb2aOvGWC5ZmMJ2HXEKJiuFie9NEs8NUMXg==}
|
||||
|
||||
linkify-it@5.0.2:
|
||||
resolution: {integrity: sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==}
|
||||
|
||||
@@ -7653,6 +7659,8 @@ snapshots:
|
||||
|
||||
lines-and-columns@1.2.4: {}
|
||||
|
||||
linguist-languages@9.4.0: {}
|
||||
|
||||
linkify-it@5.0.2:
|
||||
dependencies:
|
||||
uc.micro: 2.1.0
|
||||
|
||||
@@ -114,17 +114,22 @@
|
||||
{
|
||||
"matchManagers": ["npm"],
|
||||
"postUpdateOptions": ["pnpmDedupe"],
|
||||
},
|
||||
{
|
||||
"matchPackageNames": ["@primer/octicons", "material-icon-theme", "svgo"],
|
||||
"postUpgradeTasks": {
|
||||
"commands": ["make svg", "make generate-codemirror-languages"],
|
||||
"commands": ["make svg"],
|
||||
"fileFilters": [
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"pnpm-workspace.yaml",
|
||||
"public/assets/img/svg/**",
|
||||
"options/fileicon/**",
|
||||
"assets/codemirror-languages.json",
|
||||
],
|
||||
"executionMode": "branch",
|
||||
},
|
||||
},
|
||||
{
|
||||
"matchPackageNames": ["@codemirror/language-data", "linguist-languages"],
|
||||
"postUpgradeTasks": {
|
||||
"commands": ["make generate-codemirror-languages"],
|
||||
"fileFilters": ["assets/codemirror-languages.json"],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
import {load as parseYaml} from 'js-yaml';
|
||||
import {writeFile} from 'node:fs/promises';
|
||||
import {languages as cmLanguages} from '@codemirror/language-data';
|
||||
|
||||
const linguistUrl = 'https://raw.githubusercontent.com/github-linguist/linguist/main/lib/linguist/languages.yml';
|
||||
import * as linguist from 'linguist-languages';
|
||||
import type {Language} from 'linguist-languages';
|
||||
|
||||
const renames: Record<string, string> = {
|
||||
'Protocol Buffer': 'ProtoBuf',
|
||||
@@ -35,22 +34,12 @@ const extraExtensions: Record<string, string[]> = {
|
||||
'Properties files': ['conf'],
|
||||
};
|
||||
|
||||
type LinguistEntry = {
|
||||
type: string;
|
||||
extensions?: string[];
|
||||
filenames?: string[];
|
||||
};
|
||||
|
||||
type CmLanguage = {
|
||||
name: string;
|
||||
extensions: string[];
|
||||
filenames: string[];
|
||||
};
|
||||
|
||||
const res = await fetch(linguistUrl);
|
||||
if (!res.ok) throw new Error(`fetch ${linguistUrl} failed: ${res.status}`);
|
||||
const linguist = parseYaml(await res.text()) as Record<string, LinguistEntry>;
|
||||
|
||||
const cmByAlias = new Map<string, string>();
|
||||
// Map of extension -> the CM language that originally owns it. Used to prevent Linguist
|
||||
// from broadening one language's extension claim into another's territory (e.g. Linguist's
|
||||
@@ -66,7 +55,7 @@ for (const lang of cmLanguages) {
|
||||
|
||||
const out: CmLanguage[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const [linguistName, entry] of Object.entries(linguist)) {
|
||||
for (const [linguistName, entry] of Object.entries(linguist as Record<string, Language>)) {
|
||||
const cmName = renames[linguistName] ?? cmByAlias.get(linguistName.toLowerCase());
|
||||
// Multiple Linguist entries can alias to the same CM language (e.g. JSON5 → JSON).
|
||||
if (!cmName || skipNames.has(cmName) || seen.has(cmName)) continue;
|
||||
|
||||
Reference in New Issue
Block a user