Move all upstream fig spec modifications into scripts

Part of #242798
This commit is contained in:
Daniel Imms
2025-03-06 04:25:33 -08:00
parent 4d9c7a94f4
commit 2c3b007405
18 changed files with 16130 additions and 16239 deletions

View File

@@ -14,8 +14,70 @@ const replaceStrings = [
[
'import { filepaths } from "@fig/autocomplete-generators";',
'import { filepaths } from \'../../helpers/filepaths\';'
]
]
],
];
const indentSearch = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].map(e => new RegExp('^' + ' '.repeat(e * 2), 'g'));
const indentReplaceValue = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].map(e => '\t'.repeat(e));
const specSpecificReplaceStrings = new Map([
['git', [
[
'import { ai } from "@fig/autocomplete-generators";',
'function ai(...args: any[]): undefined { return undefined; }'
], [
'const remoteURLs = out.split("\\n").reduce((dict, line) => {',
'const remoteURLs = out.split("\\n").reduce<Record<string, string>>((dict, line) => {',
], [
'prompt: async ({ executeCommand }) => {',
'prompt: async ({ executeCommand }: any) => {'
], [
'message: async ({ executeCommand }) =>',
'message: async ({ executeCommand }: any) =>'
]
]],
['kill', [[
'out.match(/\\w+/g)',
'out.match(/\\w+/g)?'
]]],
['node', [[
'const isAdonisJsonPresentCommand = "test -f .adonisrc.json";',
''
]]],
['npm', [
[
'keywords?.length > 0 ? `+keywords:${keywords.join(",")}` : "";',
'keywords && keywords.length > 0 ? `+keywords:${keywords.join(",")}` : "";'
], [
'return results.map((item) => ({',
'return results.map((item: any) => ({'
], [
'const suggestions = [];',
'const suggestions: Fig.Suggestion[] = [];'
]
]],
['nvm', [[
'const pattern: Fig.Arg = {\n\tname: "pattern",\n};',
''
]]],
['pnpm', [
[
'if (parts.length > 1) {',
'if (parts && parts.length > 1) {'
],
[
'const packages = postProcess(',
'const packages = postProcess?.('
]
]],
['ssh', [[
'const includeLines = await Promise.all(',
'const includeLines: any = await Promise.all('
]]],
['yarn', [[
'(item) =>',
'(item: any) =>'
]]],
]);
for (const spec of upstreamSpecs) {
const source = path.join(extRoot, `third_party/autocomplete/src/${spec}.ts`);
@@ -26,5 +88,15 @@ for (const spec of upstreamSpecs) {
for (const replaceString of replaceStrings) {
content = content.replaceAll(replaceString[0], replaceString[1]);
}
for (let i = 0; i < indentSearch.length; i++) {
content = content.replaceAll(indentSearch[i], indentReplaceValue[i]);
}
const thisSpecReplaceStrings = specSpecificReplaceStrings.get(spec);
if (thisSpecReplaceStrings) {
for (const replaceString of thisSpecReplaceStrings) {
content = content.replaceAll(replaceString[0], replaceString[1]);
}
}
fs.writeFileSync(destination, content);
}