mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-10 05:24:18 +09: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:
Generated
-1
@@ -453,7 +453,6 @@
|
|||||||
".htmlhintrc",
|
".htmlhintrc",
|
||||||
".imgbotconfig",
|
".imgbotconfig",
|
||||||
".nycrc",
|
".nycrc",
|
||||||
".secrets.baseline",
|
|
||||||
".tern-config",
|
".tern-config",
|
||||||
".tern-project",
|
".tern-project",
|
||||||
".watchmanconfig",
|
".watchmanconfig",
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
"globals": "17.7.0",
|
"globals": "17.7.0",
|
||||||
"happy-dom": "20.10.6",
|
"happy-dom": "20.10.6",
|
||||||
"jiti": "2.7.0",
|
"jiti": "2.7.0",
|
||||||
|
"linguist-languages": "9.4.0",
|
||||||
"markdownlint-cli": "0.49.1",
|
"markdownlint-cli": "0.49.1",
|
||||||
"material-icon-theme": "5.36.1",
|
"material-icon-theme": "5.36.1",
|
||||||
"postcss-html": "1.8.1",
|
"postcss-html": "1.8.1",
|
||||||
|
|||||||
Generated
+8
@@ -276,6 +276,9 @@ importers:
|
|||||||
jiti:
|
jiti:
|
||||||
specifier: 2.7.0
|
specifier: 2.7.0
|
||||||
version: 2.7.0
|
version: 2.7.0
|
||||||
|
linguist-languages:
|
||||||
|
specifier: 9.4.0
|
||||||
|
version: 9.4.0
|
||||||
markdownlint-cli:
|
markdownlint-cli:
|
||||||
specifier: 0.49.1
|
specifier: 0.49.1
|
||||||
version: 0.49.1
|
version: 0.49.1
|
||||||
@@ -3190,6 +3193,9 @@ packages:
|
|||||||
lines-and-columns@1.2.4:
|
lines-and-columns@1.2.4:
|
||||||
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
|
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
|
||||||
|
|
||||||
|
linguist-languages@9.4.0:
|
||||||
|
resolution: {integrity: sha512-mYnFVrsWg5Bex0Kl5EDcXhrjXZ5DqMlBDXo7EUWLMTLDpxbuHvgBb2aOvGWC5ZmMJ2HXEKJiuFie9NEs8NUMXg==}
|
||||||
|
|
||||||
linkify-it@5.0.2:
|
linkify-it@5.0.2:
|
||||||
resolution: {integrity: sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==}
|
resolution: {integrity: sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==}
|
||||||
|
|
||||||
@@ -7653,6 +7659,8 @@ snapshots:
|
|||||||
|
|
||||||
lines-and-columns@1.2.4: {}
|
lines-and-columns@1.2.4: {}
|
||||||
|
|
||||||
|
linguist-languages@9.4.0: {}
|
||||||
|
|
||||||
linkify-it@5.0.2:
|
linkify-it@5.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
uc.micro: 2.1.0
|
uc.micro: 2.1.0
|
||||||
|
|||||||
+11
-6
@@ -114,17 +114,22 @@
|
|||||||
{
|
{
|
||||||
"matchManagers": ["npm"],
|
"matchManagers": ["npm"],
|
||||||
"postUpdateOptions": ["pnpmDedupe"],
|
"postUpdateOptions": ["pnpmDedupe"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchPackageNames": ["@primer/octicons", "material-icon-theme", "svgo"],
|
||||||
"postUpgradeTasks": {
|
"postUpgradeTasks": {
|
||||||
"commands": ["make svg", "make generate-codemirror-languages"],
|
"commands": ["make svg"],
|
||||||
"fileFilters": [
|
"fileFilters": [
|
||||||
"package.json",
|
|
||||||
"pnpm-lock.yaml",
|
|
||||||
"pnpm-workspace.yaml",
|
|
||||||
"public/assets/img/svg/**",
|
"public/assets/img/svg/**",
|
||||||
"options/fileicon/**",
|
"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
|
#!/usr/bin/env node
|
||||||
import {load as parseYaml} from 'js-yaml';
|
|
||||||
import {writeFile} from 'node:fs/promises';
|
import {writeFile} from 'node:fs/promises';
|
||||||
import {languages as cmLanguages} from '@codemirror/language-data';
|
import {languages as cmLanguages} from '@codemirror/language-data';
|
||||||
|
import * as linguist from 'linguist-languages';
|
||||||
const linguistUrl = 'https://raw.githubusercontent.com/github-linguist/linguist/main/lib/linguist/languages.yml';
|
import type {Language} from 'linguist-languages';
|
||||||
|
|
||||||
const renames: Record<string, string> = {
|
const renames: Record<string, string> = {
|
||||||
'Protocol Buffer': 'ProtoBuf',
|
'Protocol Buffer': 'ProtoBuf',
|
||||||
@@ -35,22 +34,12 @@ const extraExtensions: Record<string, string[]> = {
|
|||||||
'Properties files': ['conf'],
|
'Properties files': ['conf'],
|
||||||
};
|
};
|
||||||
|
|
||||||
type LinguistEntry = {
|
|
||||||
type: string;
|
|
||||||
extensions?: string[];
|
|
||||||
filenames?: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type CmLanguage = {
|
type CmLanguage = {
|
||||||
name: string;
|
name: string;
|
||||||
extensions: string[];
|
extensions: string[];
|
||||||
filenames: 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>();
|
const cmByAlias = new Map<string, string>();
|
||||||
// Map of extension -> the CM language that originally owns it. Used to prevent Linguist
|
// 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
|
// 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 out: CmLanguage[] = [];
|
||||||
const seen = new Set<string>();
|
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());
|
const cmName = renames[linguistName] ?? cmByAlias.get(linguistName.toLowerCase());
|
||||||
// Multiple Linguist entries can alias to the same CM language (e.g. JSON5 → JSON).
|
// Multiple Linguist entries can alias to the same CM language (e.g. JSON5 → JSON).
|
||||||
if (!cmName || skipNames.has(cmName) || seen.has(cmName)) continue;
|
if (!cmName || skipNames.has(cmName) || seen.has(cmName)) continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user