From 10a5bbd0048e82299ae38715b78a8aed391ad70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 04:00:50 +0900 Subject: [PATCH 01/10] chore: refactor plugin management, enhance manifest fetching and config rendering --- static/scripts/fetch-manifest.ts | 6 +-- static/scripts/rendering/config-editor.ts | 51 ++++++++++++++++++----- static/scripts/rendering/plugin-select.ts | 34 +++++++++++++-- static/utils/strings.ts | 23 ++++++++-- 4 files changed, 92 insertions(+), 22 deletions(-) diff --git a/static/scripts/fetch-manifest.ts b/static/scripts/fetch-manifest.ts index 9a02094..6ead971 100644 --- a/static/scripts/fetch-manifest.ts +++ b/static/scripts/fetch-manifest.ts @@ -1,6 +1,6 @@ import { Octokit } from "@octokit/rest"; +import { CONFIG_FULL_PATH, CONFIG_ORG_REPO, DEV_CONFIG_FULL_PATH } from "@ubiquity-os/plugin-sdk/constants"; import { Manifest, ManifestPreDecode } from "../types/plugins"; -import { DEV_CONFIG_FULL_PATH, CONFIG_FULL_PATH, CONFIG_ORG_REPO } from "@ubiquity-os/plugin-sdk/constants"; import { getOfficialPluginConfig } from "../utils/storage"; /** @@ -37,7 +37,7 @@ export class ManifestFetcher { for (const repo of repos.data) { const manifestUrl = this.createGithubRawEndpoint(org, repo.name, "development", "manifest.json"); const manifest = await this.fetchPluginManifest(manifestUrl); - const decoded = this.decodeManifestFromFetch(manifest); + const decoded = this.decodeManifestFromFetch(manifest, repo.name); const readme = await this.fetchPluginReadme(this.createGithubRawEndpoint(org, repo.name, "development", "README.md")); if (decoded) { @@ -190,7 +190,7 @@ export class ManifestFetcher { } } - decodeManifestFromFetch(manifest: ManifestPreDecode) { + decodeManifestFromFetch(manifest: ManifestPreDecode, repoName: string) { if (manifest.error) { return null; } diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 259c25d..754acfb 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -6,6 +6,7 @@ import { addTrackedEventListener, getTrackedEventListeners, normalizePluginName, import { handleResetToDefault, writeNewConfig } from "./write-add-remove"; import MarkdownIt from "markdown-it"; import { getManifestCache } from "../../utils/storage"; +import { extractPluginIdentifier } from "../../utils/strings"; const md = new MarkdownIt(); /** @@ -84,8 +85,45 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } const parsedConfig = renderer.configParser.parseConfig(renderer.configParser.repoConfig || localStorage.getItem("config")); - // for when `resetToDefault` is called and no plugin gets passed in, we still want to show the remove button - const isInstalled = parsedConfig.plugins?.find((p) => p.uses[0].plugin.includes(normalizePluginName(pluginManifest?.name || ""))); + console.log('All installed plugins:', parsedConfig.plugins); + + // Get the repository URL for the current plugin from the manifest cache + const manifestCache = getManifestCache(); + const pluginUrls = Object.keys(manifestCache); + const pluginUrl = pluginUrls.find((url) => { + return manifestCache[url].name === pluginManifest?.name; + }); + + if (!pluginUrl) { + throw new Error("Plugin URL not found"); + } + + console.log('\nProcessing plugin:', pluginManifest?.name); + console.log('Original URL:', pluginUrl); + const manifestPluginId = extractPluginIdentifier(pluginUrl); + console.log('Manifest plugin identifier:', manifestPluginId); + + // Check if plugin is installed by looking for any URL that matches + const isInstalled = parsedConfig.plugins?.find((p) => { + const pluginUrl = p.uses[0].plugin; + console.log('Checking against installed plugin URL:', pluginUrl); + + // If the installed plugin is a GitHub URL, extract its identifier + const installedPluginId = extractPluginIdentifier(pluginUrl); + console.log('Installed plugin identifier:', installedPluginId); + + // If both are GitHub URLs, compare the repo names + if (pluginUrl.includes('github') && pluginUrl.includes('github')) { + const isMatch = manifestPluginId === installedPluginId; + console.log('GitHub match?', isMatch); + return isMatch; + } + + // Otherwise check if the installed URL contains the repo name + const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); + console.log('URL match?', isMatch); + return isMatch; + }); loadListeners({ renderer, @@ -105,15 +143,6 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } resetToDefaultButton.hidden = !!(plugin || isInstalled); - const manifestCache = getManifestCache(); - const pluginUrls = Object.keys(manifestCache); - const pluginUrl = pluginUrls.find((url) => { - return manifestCache[url].name === pluginManifest?.name; - }); - - if (!pluginUrl) { - throw new Error("Plugin URL not found"); - } const readme = manifestCache[pluginUrl].readme; if (readme) { diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index a7ee070..02f1914 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -1,7 +1,7 @@ import { ManifestCache, ManifestPreDecode, Plugin } from "../../types/plugins"; import { createElement } from "../../utils/element-helpers"; import { getManifestCache } from "../../utils/storage"; -import { STRINGS } from "../../utils/strings"; +import { STRINGS, extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; import { renderConfigEditor } from "./config-editor"; import { controlButtons } from "./control-buttons"; @@ -30,6 +30,7 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (userConfig) { installedPlugins = renderer.configParser.parseConfig(userConfig).plugins; + console.log('All installed plugins:', installedPlugins); } const cleanManifestCache = Object.keys(manifestCache).reduce((acc, key) => { @@ -62,9 +63,34 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (!cleanManifestCache[url]?.name) { return; } - const normalizedName = normalizePluginName(cleanManifestCache[url].name); - const reg = new RegExp(normalizedName, "i"); - const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => plugin.uses[0].plugin.match(reg)); + + console.log('\nProcessing plugin:', cleanManifestCache[url].name); + console.log('Original URL:', url); + const manifestPluginId = extractPluginIdentifier(url); + console.log('Manifest plugin identifier:', manifestPluginId); + + // Check if plugin is installed by looking for any URL that matches + const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { + const pluginUrl = plugin.uses[0].plugin; + console.log('Checking against installed plugin URL:', pluginUrl); + + // If the installed plugin is a GitHub URL, extract its identifier + const installedPluginId = extractPluginIdentifier(pluginUrl); + console.log('Installed plugin identifier:', installedPluginId); + + // If both are GitHub URLs, compare the repo names + if (url.includes('github') && pluginUrl.includes('github')) { + const isMatch = manifestPluginId === installedPluginId; + console.log('GitHub match?', isMatch); + return isMatch; + } + + // Otherwise check if the installed URL contains the repo name + const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); + console.log('URL match?', isMatch); + return isMatch; + }); + const defaultForInstalled: ManifestPreDecode | null = cleanManifestCache[url]; const optionText = defaultForInstalled.name; const indicator = installedPlugin ? "🟢" : "🔴"; diff --git a/static/utils/strings.ts b/static/utils/strings.ts index bb65ebe..c54b169 100644 --- a/static/utils/strings.ts +++ b/static/utils/strings.ts @@ -1,8 +1,23 @@ export const STRINGS = { - TDV_CENTERED: "table-data-value centered", - SELECT_ITEMS: ".select-items", - SELECT_SELECTED: ".select-selected", + TDV_CENTERED: "tdv-centered", SELECT_HIDE: "select-hide", SELECT_ARROW_ACTIVE: "select-arrow-active", - PICKER_SELECT: "picker-select", }; + +/** + * For manifest URLs from GitHub, extracts just the repo name. + * For all other URLs (workers, actions, etc), returns the full URL. + * This allows for flexible matching without assuming URL formats. + */ +export function extractPluginIdentifier(url: string): string { + // For GitHub manifest URLs, extract just the repo name + if (url.includes('github.com/') || url.includes('githubusercontent.com/')) { + const parts = url.split('/'); + if (parts.length >= 5) { + return parts[4].split('@')[0].split('?')[0]; // Get repo name without branch or query params + } + } + + // For all other URLs (workers, actions, etc), use the full URL + return url; +} From d2c7f62b86adf98985e1a06f6ce6ea78d9d81b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 04:16:21 +0900 Subject: [PATCH 02/10] fix: accidentally removed selector --- static/utils/strings.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/static/utils/strings.ts b/static/utils/strings.ts index c54b169..27a05ab 100644 --- a/static/utils/strings.ts +++ b/static/utils/strings.ts @@ -1,7 +1,10 @@ export const STRINGS = { - TDV_CENTERED: "tdv-centered", + TDV_CENTERED: "table-data-value centered", + SELECT_ITEMS: ".select-items", + SELECT_SELECTED: ".select-selected", SELECT_HIDE: "select-hide", SELECT_ARROW_ACTIVE: "select-arrow-active", + PICKER_SELECT: "picker-select", }; /** @@ -11,10 +14,10 @@ export const STRINGS = { */ export function extractPluginIdentifier(url: string): string { // For GitHub manifest URLs, extract just the repo name - if (url.includes('github.com/') || url.includes('githubusercontent.com/')) { - const parts = url.split('/'); + if (url.includes("github.com/") || url.includes("githubusercontent.com/")) { + const parts = url.split("/"); if (parts.length >= 5) { - return parts[4].split('@')[0].split('?')[0]; // Get repo name without branch or query params + return parts[4].split("@")[0].split("?")[0]; // Get repo name without branch or query params } } From 15c120322997760be6cbbfc0361b3843a4f421fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 04:20:09 +0900 Subject: [PATCH 03/10] chore: remove verbose logging --- static/scripts/rendering/config-editor.ts | 20 ++++++-------------- static/scripts/rendering/plugin-select.ts | 12 ++---------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 754acfb..3151649 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -1,12 +1,12 @@ +import MarkdownIt from "markdown-it"; import { Manifest, Plugin } from "../../types/plugins"; -import { controlButtons } from "./control-buttons"; +import { getManifestCache } from "../../utils/storage"; +import { extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; +import { controlButtons } from "./control-buttons"; import { processProperties } from "./input-parsing"; -import { addTrackedEventListener, getTrackedEventListeners, normalizePluginName, removeTrackedEventListener, updateGuiTitle } from "./utils"; +import { addTrackedEventListener, getTrackedEventListeners, removeTrackedEventListener, updateGuiTitle } from "./utils"; import { handleResetToDefault, writeNewConfig } from "./write-add-remove"; -import MarkdownIt from "markdown-it"; -import { getManifestCache } from "../../utils/storage"; -import { extractPluginIdentifier } from "../../utils/strings"; const md = new MarkdownIt(); /** @@ -85,7 +85,6 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } const parsedConfig = renderer.configParser.parseConfig(renderer.configParser.repoConfig || localStorage.getItem("config")); - console.log('All installed plugins:', parsedConfig.plugins); // Get the repository URL for the current plugin from the manifest cache const manifestCache = getManifestCache(); @@ -98,30 +97,23 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M throw new Error("Plugin URL not found"); } - console.log('\nProcessing plugin:', pluginManifest?.name); - console.log('Original URL:', pluginUrl); const manifestPluginId = extractPluginIdentifier(pluginUrl); - console.log('Manifest plugin identifier:', manifestPluginId); // Check if plugin is installed by looking for any URL that matches const isInstalled = parsedConfig.plugins?.find((p) => { const pluginUrl = p.uses[0].plugin; - console.log('Checking against installed plugin URL:', pluginUrl); // If the installed plugin is a GitHub URL, extract its identifier const installedPluginId = extractPluginIdentifier(pluginUrl); - console.log('Installed plugin identifier:', installedPluginId); // If both are GitHub URLs, compare the repo names - if (pluginUrl.includes('github') && pluginUrl.includes('github')) { + if (pluginUrl.includes("github") && pluginUrl.includes("github")) { const isMatch = manifestPluginId === installedPluginId; - console.log('GitHub match?', isMatch); return isMatch; } // Otherwise check if the installed URL contains the repo name const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - console.log('URL match?', isMatch); return isMatch; }); diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index 02f1914..ed4856c 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -5,7 +5,7 @@ import { STRINGS, extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; import { renderConfigEditor } from "./config-editor"; import { controlButtons } from "./control-buttons"; -import { closeAllSelect, normalizePluginName, updateGuiTitle } from "./utils"; +import { closeAllSelect, updateGuiTitle } from "./utils"; /** * Renders a dropdown of plugins taken from the marketplace with an installed indicator. @@ -30,7 +30,6 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (userConfig) { installedPlugins = renderer.configParser.parseConfig(userConfig).plugins; - console.log('All installed plugins:', installedPlugins); } const cleanManifestCache = Object.keys(manifestCache).reduce((acc, key) => { @@ -64,30 +63,23 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { return; } - console.log('\nProcessing plugin:', cleanManifestCache[url].name); - console.log('Original URL:', url); const manifestPluginId = extractPluginIdentifier(url); - console.log('Manifest plugin identifier:', manifestPluginId); // Check if plugin is installed by looking for any URL that matches const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { const pluginUrl = plugin.uses[0].plugin; - console.log('Checking against installed plugin URL:', pluginUrl); // If the installed plugin is a GitHub URL, extract its identifier const installedPluginId = extractPluginIdentifier(pluginUrl); - console.log('Installed plugin identifier:', installedPluginId); // If both are GitHub URLs, compare the repo names - if (url.includes('github') && pluginUrl.includes('github')) { + if (url.includes("github") && pluginUrl.includes("github")) { const isMatch = manifestPluginId === installedPluginId; - console.log('GitHub match?', isMatch); return isMatch; } // Otherwise check if the installed URL contains the repo name const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - console.log('URL match?', isMatch); return isMatch; }); From e78d17ab4732ba43bb7078de74a12fd24cb9e630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 04:27:06 +0900 Subject: [PATCH 04/10] fix: github url comparison --- static/scripts/rendering/config-editor.ts | 13 ++++++------- static/scripts/rendering/plugin-select.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 3151649..5f15d7b 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -101,20 +101,19 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M // Check if plugin is installed by looking for any URL that matches const isInstalled = parsedConfig.plugins?.find((p) => { - const pluginUrl = p.uses[0].plugin; + const installedUrl = p.uses[0].plugin; // If the installed plugin is a GitHub URL, extract its identifier - const installedPluginId = extractPluginIdentifier(pluginUrl); + const installedPluginId = extractPluginIdentifier(installedUrl); // If both are GitHub URLs, compare the repo names - if (pluginUrl.includes("github") && pluginUrl.includes("github")) { - const isMatch = manifestPluginId === installedPluginId; - return isMatch; + const isBothGithubUrls = pluginUrl.includes("github") && installedUrl.includes("github"); + if (isBothGithubUrls) { + return manifestPluginId === installedPluginId; } // Otherwise check if the installed URL contains the repo name - const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - return isMatch; + return installedUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); }); loadListeners({ diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index ed4856c..5ba7de3 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -67,20 +67,19 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { // Check if plugin is installed by looking for any URL that matches const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { - const pluginUrl = plugin.uses[0].plugin; + const installedUrl = plugin.uses[0].plugin; // If the installed plugin is a GitHub URL, extract its identifier - const installedPluginId = extractPluginIdentifier(pluginUrl); + const installedPluginId = extractPluginIdentifier(installedUrl); // If both are GitHub URLs, compare the repo names - if (url.includes("github") && pluginUrl.includes("github")) { - const isMatch = manifestPluginId === installedPluginId; - return isMatch; + const isBothGithubUrls = url.includes("github") && installedUrl.includes("github"); + if (isBothGithubUrls) { + return manifestPluginId === installedPluginId; } // Otherwise check if the installed URL contains the repo name - const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - return isMatch; + return installedUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); }); const defaultForInstalled: ManifestPreDecode | null = cleanManifestCache[url]; From f5a4ff82067a279934f194370e7aec8b05d5a3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:01:42 +0900 Subject: [PATCH 05/10] fix(eslint): config to ignore dist and js --- eslint.config.mjs | 259 ++++++++++++++++--------------- static/scripts/fetch-manifest.ts | 4 +- 2 files changed, 132 insertions(+), 131 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index c56fce8..75d1225 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,137 +1,138 @@ -// @ts-check -import tsEslint from "typescript-eslint"; import eslint from "@eslint/js"; -import sonarjs from "eslint-plugin-sonarjs"; import checkFile from "eslint-plugin-check-file"; +import sonarjs from "eslint-plugin-sonarjs"; +import tsEslint from "typescript-eslint"; -export default tsEslint.config({ - plugins: { - "@typescript-eslint": tsEslint.plugin, - "check-file": checkFile, +export default [ + { + ignores: ["dist/**/*", "**/*.js", ".github/*.ts", "cypress.config.ts"], }, - // static\dist\main.js - ignores: [".github/*.ts", "static/dist/*.js", "static/dist/*.ts", "static/dist/*.d.ts", "cypress.config.ts", "coverage/*"], - extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended], - languageOptions: { - parser: tsEslint.parser, - parserOptions: { - projectService: { - defaultProject: "tsconfig.json", - allowDefaultProject: ["*.mjs"], - }, - tsconfigRootDir: import.meta.dirname, + eslint.configs.recommended, + ...tsEslint.configs.recommended, + sonarjs.configs.recommended, + { + plugins: { + "@typescript-eslint": tsEslint.plugin, + "check-file": checkFile, }, - }, - rules: { - "check-file/filename-naming-convention": [ - "error", - { - "**/*.{js,ts}": "+([-._a-z0-9])", - }, - ], - "prefer-arrow-callback": [ - "warn", - { - allowNamedFunctions: true, - }, - ], - "func-style": [ - "warn", - "declaration", - { - allowArrowFunctions: false, - }, - ], - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/no-non-null-assertion": "error", - "constructor-super": "error", - "no-invalid-this": "off", - "@typescript-eslint/no-invalid-this": ["error"], - "no-restricted-syntax": ["error", "ForInStatement"], - "use-isnan": "error", - "no-unneeded-ternary": "error", - "no-nested-ternary": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { - args: "after-used", - ignoreRestSiblings: true, - vars: "all", - varsIgnorePattern: "^_", - argsIgnorePattern: "^_", + languageOptions: { + parser: tsEslint.parser, + parserOptions: { + project: "./tsconfig.json", + tsconfigRootDir: import.meta.dirname, }, - ], - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "sonarjs/no-all-duplicated-branches": "error", - "sonarjs/no-collection-size-mischeck": "error", - "sonarjs/no-duplicated-branches": "error", - "sonarjs/no-element-overwrite": "error", - "sonarjs/no-identical-conditions": "error", - "sonarjs/no-identical-expressions": "error", - "sonarjs/new-cap": "off", - "sonarjs/different-types-comparison": "off", - "sonarjs/sonar-prefer-regexp-exec": "off", - "sonarjs/function-return-type": "off", - "sonarjs/no-misleading-array-reverse": "off", - "sonarjs/slow-regex": "off", - "@typescript-eslint/naming-convention": [ - "error", - { - selector: "interface", - format: ["StrictPascalCase"], - custom: { - regex: "^I[A-Z]", - match: false, + }, + rules: { + "check-file/filename-naming-convention": [ + "error", + { + "**/*.{js,ts}": "+([-._a-z0-9])", }, - }, - { - selector: "memberLike", - modifiers: ["private"], - format: ["strictCamelCase"], - leadingUnderscore: "require", - }, - { - selector: "typeLike", - format: ["StrictPascalCase"], - }, - { - selector: "typeParameter", - format: ["StrictPascalCase"], - prefix: ["T"], - }, - { - selector: "variable", - format: ["strictCamelCase", "UPPER_CASE"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "variable", - format: ["strictCamelCase"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "variable", - modifiers: ["destructured"], - format: null, - }, - { - selector: "variable", - types: ["boolean"], - format: ["StrictPascalCase"], - prefix: ["is", "should", "has", "can", "did", "will", "does"], - }, - { - selector: "variableLike", - format: ["strictCamelCase"], - }, - { - selector: ["function", "variable"], - format: ["strictCamelCase"], - }, - ], + ], + "prefer-arrow-callback": [ + "warn", + { + allowNamedFunctions: true, + }, + ], + "func-style": [ + "warn", + "declaration", + { + allowArrowFunctions: false, + }, + ], + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "constructor-super": "error", + "no-invalid-this": "off", + "@typescript-eslint/no-invalid-this": ["error"], + "no-restricted-syntax": ["error", "ForInStatement"], + "use-isnan": "error", + "no-unneeded-ternary": "error", + "no-nested-ternary": "error", + "@typescript-eslint/no-unused-vars": [ + "error", + { + args: "after-used", + ignoreRestSiblings: true, + vars: "all", + varsIgnorePattern: "^_", + argsIgnorePattern: "^_", + }, + ], + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/restrict-plus-operands": "error", + "sonarjs/no-all-duplicated-branches": "error", + "sonarjs/no-collection-size-mischeck": "error", + "sonarjs/no-duplicated-branches": "error", + "sonarjs/no-element-overwrite": "error", + "sonarjs/no-identical-conditions": "error", + "sonarjs/no-identical-expressions": "error", + "sonarjs/new-cap": "off", + "sonarjs/different-types-comparison": "off", + "sonarjs/sonar-prefer-regexp-exec": "off", + "sonarjs/function-return-type": "off", + "sonarjs/no-misleading-array-reverse": "off", + "sonarjs/slow-regex": "off", + "@typescript-eslint/naming-convention": [ + "error", + { + selector: "interface", + format: ["StrictPascalCase"], + custom: { + regex: "^I[A-Z]", + match: false, + }, + }, + { + selector: "memberLike", + modifiers: ["private"], + format: ["strictCamelCase"], + leadingUnderscore: "require", + }, + { + selector: "typeLike", + format: ["StrictPascalCase"], + }, + { + selector: "typeParameter", + format: ["StrictPascalCase"], + prefix: ["T"], + }, + { + selector: "variable", + format: ["strictCamelCase", "UPPER_CASE"], + leadingUnderscore: "allow", + trailingUnderscore: "allow", + }, + { + selector: "variable", + format: ["strictCamelCase"], + leadingUnderscore: "allow", + trailingUnderscore: "allow", + }, + { + selector: "variable", + modifiers: ["destructured"], + format: null, + }, + { + selector: "variable", + types: ["boolean"], + format: ["StrictPascalCase"], + prefix: ["is", "should", "has", "can", "did", "will", "does"], + }, + { + selector: "variableLike", + format: ["strictCamelCase"], + }, + { + selector: ["function", "variable"], + format: ["strictCamelCase"], + }, + ], + }, }, -}); +]; diff --git a/static/scripts/fetch-manifest.ts b/static/scripts/fetch-manifest.ts index 6ead971..a7d3a0e 100644 --- a/static/scripts/fetch-manifest.ts +++ b/static/scripts/fetch-manifest.ts @@ -37,7 +37,7 @@ export class ManifestFetcher { for (const repo of repos.data) { const manifestUrl = this.createGithubRawEndpoint(org, repo.name, "development", "manifest.json"); const manifest = await this.fetchPluginManifest(manifestUrl); - const decoded = this.decodeManifestFromFetch(manifest, repo.name); + const decoded = this.decodeManifestFromFetch(manifest); const readme = await this.fetchPluginReadme(this.createGithubRawEndpoint(org, repo.name, "development", "README.md")); if (decoded) { @@ -190,7 +190,7 @@ export class ManifestFetcher { } } - decodeManifestFromFetch(manifest: ManifestPreDecode, repoName: string) { + decodeManifestFromFetch(manifest: ManifestPreDecode) { if (manifest.error) { return null; } From 7c9cfd9ed6aeffed2bb236f5b9cedda42a3d1a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:04:30 +0900 Subject: [PATCH 06/10] chore: refactor plugin management, enhance manifest fetching and config rendering --- static/scripts/fetch-manifest.ts | 6 +-- static/scripts/rendering/config-editor.ts | 51 ++++++++++++++++++----- static/scripts/rendering/plugin-select.ts | 34 +++++++++++++-- static/utils/strings.ts | 23 ++++++++-- 4 files changed, 92 insertions(+), 22 deletions(-) diff --git a/static/scripts/fetch-manifest.ts b/static/scripts/fetch-manifest.ts index 9a02094..6ead971 100644 --- a/static/scripts/fetch-manifest.ts +++ b/static/scripts/fetch-manifest.ts @@ -1,6 +1,6 @@ import { Octokit } from "@octokit/rest"; +import { CONFIG_FULL_PATH, CONFIG_ORG_REPO, DEV_CONFIG_FULL_PATH } from "@ubiquity-os/plugin-sdk/constants"; import { Manifest, ManifestPreDecode } from "../types/plugins"; -import { DEV_CONFIG_FULL_PATH, CONFIG_FULL_PATH, CONFIG_ORG_REPO } from "@ubiquity-os/plugin-sdk/constants"; import { getOfficialPluginConfig } from "../utils/storage"; /** @@ -37,7 +37,7 @@ export class ManifestFetcher { for (const repo of repos.data) { const manifestUrl = this.createGithubRawEndpoint(org, repo.name, "development", "manifest.json"); const manifest = await this.fetchPluginManifest(manifestUrl); - const decoded = this.decodeManifestFromFetch(manifest); + const decoded = this.decodeManifestFromFetch(manifest, repo.name); const readme = await this.fetchPluginReadme(this.createGithubRawEndpoint(org, repo.name, "development", "README.md")); if (decoded) { @@ -190,7 +190,7 @@ export class ManifestFetcher { } } - decodeManifestFromFetch(manifest: ManifestPreDecode) { + decodeManifestFromFetch(manifest: ManifestPreDecode, repoName: string) { if (manifest.error) { return null; } diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 259c25d..754acfb 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -6,6 +6,7 @@ import { addTrackedEventListener, getTrackedEventListeners, normalizePluginName, import { handleResetToDefault, writeNewConfig } from "./write-add-remove"; import MarkdownIt from "markdown-it"; import { getManifestCache } from "../../utils/storage"; +import { extractPluginIdentifier } from "../../utils/strings"; const md = new MarkdownIt(); /** @@ -84,8 +85,45 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } const parsedConfig = renderer.configParser.parseConfig(renderer.configParser.repoConfig || localStorage.getItem("config")); - // for when `resetToDefault` is called and no plugin gets passed in, we still want to show the remove button - const isInstalled = parsedConfig.plugins?.find((p) => p.uses[0].plugin.includes(normalizePluginName(pluginManifest?.name || ""))); + console.log('All installed plugins:', parsedConfig.plugins); + + // Get the repository URL for the current plugin from the manifest cache + const manifestCache = getManifestCache(); + const pluginUrls = Object.keys(manifestCache); + const pluginUrl = pluginUrls.find((url) => { + return manifestCache[url].name === pluginManifest?.name; + }); + + if (!pluginUrl) { + throw new Error("Plugin URL not found"); + } + + console.log('\nProcessing plugin:', pluginManifest?.name); + console.log('Original URL:', pluginUrl); + const manifestPluginId = extractPluginIdentifier(pluginUrl); + console.log('Manifest plugin identifier:', manifestPluginId); + + // Check if plugin is installed by looking for any URL that matches + const isInstalled = parsedConfig.plugins?.find((p) => { + const pluginUrl = p.uses[0].plugin; + console.log('Checking against installed plugin URL:', pluginUrl); + + // If the installed plugin is a GitHub URL, extract its identifier + const installedPluginId = extractPluginIdentifier(pluginUrl); + console.log('Installed plugin identifier:', installedPluginId); + + // If both are GitHub URLs, compare the repo names + if (pluginUrl.includes('github') && pluginUrl.includes('github')) { + const isMatch = manifestPluginId === installedPluginId; + console.log('GitHub match?', isMatch); + return isMatch; + } + + // Otherwise check if the installed URL contains the repo name + const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); + console.log('URL match?', isMatch); + return isMatch; + }); loadListeners({ renderer, @@ -105,15 +143,6 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } resetToDefaultButton.hidden = !!(plugin || isInstalled); - const manifestCache = getManifestCache(); - const pluginUrls = Object.keys(manifestCache); - const pluginUrl = pluginUrls.find((url) => { - return manifestCache[url].name === pluginManifest?.name; - }); - - if (!pluginUrl) { - throw new Error("Plugin URL not found"); - } const readme = manifestCache[pluginUrl].readme; if (readme) { diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index a7ee070..02f1914 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -1,7 +1,7 @@ import { ManifestCache, ManifestPreDecode, Plugin } from "../../types/plugins"; import { createElement } from "../../utils/element-helpers"; import { getManifestCache } from "../../utils/storage"; -import { STRINGS } from "../../utils/strings"; +import { STRINGS, extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; import { renderConfigEditor } from "./config-editor"; import { controlButtons } from "./control-buttons"; @@ -30,6 +30,7 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (userConfig) { installedPlugins = renderer.configParser.parseConfig(userConfig).plugins; + console.log('All installed plugins:', installedPlugins); } const cleanManifestCache = Object.keys(manifestCache).reduce((acc, key) => { @@ -62,9 +63,34 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (!cleanManifestCache[url]?.name) { return; } - const normalizedName = normalizePluginName(cleanManifestCache[url].name); - const reg = new RegExp(normalizedName, "i"); - const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => plugin.uses[0].plugin.match(reg)); + + console.log('\nProcessing plugin:', cleanManifestCache[url].name); + console.log('Original URL:', url); + const manifestPluginId = extractPluginIdentifier(url); + console.log('Manifest plugin identifier:', manifestPluginId); + + // Check if plugin is installed by looking for any URL that matches + const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { + const pluginUrl = plugin.uses[0].plugin; + console.log('Checking against installed plugin URL:', pluginUrl); + + // If the installed plugin is a GitHub URL, extract its identifier + const installedPluginId = extractPluginIdentifier(pluginUrl); + console.log('Installed plugin identifier:', installedPluginId); + + // If both are GitHub URLs, compare the repo names + if (url.includes('github') && pluginUrl.includes('github')) { + const isMatch = manifestPluginId === installedPluginId; + console.log('GitHub match?', isMatch); + return isMatch; + } + + // Otherwise check if the installed URL contains the repo name + const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); + console.log('URL match?', isMatch); + return isMatch; + }); + const defaultForInstalled: ManifestPreDecode | null = cleanManifestCache[url]; const optionText = defaultForInstalled.name; const indicator = installedPlugin ? "🟢" : "🔴"; diff --git a/static/utils/strings.ts b/static/utils/strings.ts index bb65ebe..c54b169 100644 --- a/static/utils/strings.ts +++ b/static/utils/strings.ts @@ -1,8 +1,23 @@ export const STRINGS = { - TDV_CENTERED: "table-data-value centered", - SELECT_ITEMS: ".select-items", - SELECT_SELECTED: ".select-selected", + TDV_CENTERED: "tdv-centered", SELECT_HIDE: "select-hide", SELECT_ARROW_ACTIVE: "select-arrow-active", - PICKER_SELECT: "picker-select", }; + +/** + * For manifest URLs from GitHub, extracts just the repo name. + * For all other URLs (workers, actions, etc), returns the full URL. + * This allows for flexible matching without assuming URL formats. + */ +export function extractPluginIdentifier(url: string): string { + // For GitHub manifest URLs, extract just the repo name + if (url.includes('github.com/') || url.includes('githubusercontent.com/')) { + const parts = url.split('/'); + if (parts.length >= 5) { + return parts[4].split('@')[0].split('?')[0]; // Get repo name without branch or query params + } + } + + // For all other URLs (workers, actions, etc), use the full URL + return url; +} From da87849e0872540f98da0917f5f12b5565cc238d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:04:31 +0900 Subject: [PATCH 07/10] fix: accidentally removed selector --- static/utils/strings.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/static/utils/strings.ts b/static/utils/strings.ts index c54b169..27a05ab 100644 --- a/static/utils/strings.ts +++ b/static/utils/strings.ts @@ -1,7 +1,10 @@ export const STRINGS = { - TDV_CENTERED: "tdv-centered", + TDV_CENTERED: "table-data-value centered", + SELECT_ITEMS: ".select-items", + SELECT_SELECTED: ".select-selected", SELECT_HIDE: "select-hide", SELECT_ARROW_ACTIVE: "select-arrow-active", + PICKER_SELECT: "picker-select", }; /** @@ -11,10 +14,10 @@ export const STRINGS = { */ export function extractPluginIdentifier(url: string): string { // For GitHub manifest URLs, extract just the repo name - if (url.includes('github.com/') || url.includes('githubusercontent.com/')) { - const parts = url.split('/'); + if (url.includes("github.com/") || url.includes("githubusercontent.com/")) { + const parts = url.split("/"); if (parts.length >= 5) { - return parts[4].split('@')[0].split('?')[0]; // Get repo name without branch or query params + return parts[4].split("@")[0].split("?")[0]; // Get repo name without branch or query params } } From 8f54cf50b7d2754de2b13e31cd32e79dcbd8b5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:04:31 +0900 Subject: [PATCH 08/10] chore: remove verbose logging --- static/scripts/rendering/config-editor.ts | 20 ++++++-------------- static/scripts/rendering/plugin-select.ts | 12 ++---------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 754acfb..3151649 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -1,12 +1,12 @@ +import MarkdownIt from "markdown-it"; import { Manifest, Plugin } from "../../types/plugins"; -import { controlButtons } from "./control-buttons"; +import { getManifestCache } from "../../utils/storage"; +import { extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; +import { controlButtons } from "./control-buttons"; import { processProperties } from "./input-parsing"; -import { addTrackedEventListener, getTrackedEventListeners, normalizePluginName, removeTrackedEventListener, updateGuiTitle } from "./utils"; +import { addTrackedEventListener, getTrackedEventListeners, removeTrackedEventListener, updateGuiTitle } from "./utils"; import { handleResetToDefault, writeNewConfig } from "./write-add-remove"; -import MarkdownIt from "markdown-it"; -import { getManifestCache } from "../../utils/storage"; -import { extractPluginIdentifier } from "../../utils/strings"; const md = new MarkdownIt(); /** @@ -85,7 +85,6 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M } const parsedConfig = renderer.configParser.parseConfig(renderer.configParser.repoConfig || localStorage.getItem("config")); - console.log('All installed plugins:', parsedConfig.plugins); // Get the repository URL for the current plugin from the manifest cache const manifestCache = getManifestCache(); @@ -98,30 +97,23 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M throw new Error("Plugin URL not found"); } - console.log('\nProcessing plugin:', pluginManifest?.name); - console.log('Original URL:', pluginUrl); const manifestPluginId = extractPluginIdentifier(pluginUrl); - console.log('Manifest plugin identifier:', manifestPluginId); // Check if plugin is installed by looking for any URL that matches const isInstalled = parsedConfig.plugins?.find((p) => { const pluginUrl = p.uses[0].plugin; - console.log('Checking against installed plugin URL:', pluginUrl); // If the installed plugin is a GitHub URL, extract its identifier const installedPluginId = extractPluginIdentifier(pluginUrl); - console.log('Installed plugin identifier:', installedPluginId); // If both are GitHub URLs, compare the repo names - if (pluginUrl.includes('github') && pluginUrl.includes('github')) { + if (pluginUrl.includes("github") && pluginUrl.includes("github")) { const isMatch = manifestPluginId === installedPluginId; - console.log('GitHub match?', isMatch); return isMatch; } // Otherwise check if the installed URL contains the repo name const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - console.log('URL match?', isMatch); return isMatch; }); diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index 02f1914..ed4856c 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -5,7 +5,7 @@ import { STRINGS, extractPluginIdentifier } from "../../utils/strings"; import { ManifestRenderer } from "../render-manifest"; import { renderConfigEditor } from "./config-editor"; import { controlButtons } from "./control-buttons"; -import { closeAllSelect, normalizePluginName, updateGuiTitle } from "./utils"; +import { closeAllSelect, updateGuiTitle } from "./utils"; /** * Renders a dropdown of plugins taken from the marketplace with an installed indicator. @@ -30,7 +30,6 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { if (userConfig) { installedPlugins = renderer.configParser.parseConfig(userConfig).plugins; - console.log('All installed plugins:', installedPlugins); } const cleanManifestCache = Object.keys(manifestCache).reduce((acc, key) => { @@ -64,30 +63,23 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { return; } - console.log('\nProcessing plugin:', cleanManifestCache[url].name); - console.log('Original URL:', url); const manifestPluginId = extractPluginIdentifier(url); - console.log('Manifest plugin identifier:', manifestPluginId); // Check if plugin is installed by looking for any URL that matches const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { const pluginUrl = plugin.uses[0].plugin; - console.log('Checking against installed plugin URL:', pluginUrl); // If the installed plugin is a GitHub URL, extract its identifier const installedPluginId = extractPluginIdentifier(pluginUrl); - console.log('Installed plugin identifier:', installedPluginId); // If both are GitHub URLs, compare the repo names - if (url.includes('github') && pluginUrl.includes('github')) { + if (url.includes("github") && pluginUrl.includes("github")) { const isMatch = manifestPluginId === installedPluginId; - console.log('GitHub match?', isMatch); return isMatch; } // Otherwise check if the installed URL contains the repo name const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - console.log('URL match?', isMatch); return isMatch; }); From 6a0b6ad6016fb8561fa06756881fbb8dd6b19f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:04:31 +0900 Subject: [PATCH 09/10] fix: github url comparison --- static/scripts/rendering/config-editor.ts | 13 ++++++------- static/scripts/rendering/plugin-select.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/static/scripts/rendering/config-editor.ts b/static/scripts/rendering/config-editor.ts index 3151649..5f15d7b 100644 --- a/static/scripts/rendering/config-editor.ts +++ b/static/scripts/rendering/config-editor.ts @@ -101,20 +101,19 @@ export function renderConfigEditor(renderer: ManifestRenderer, pluginManifest: M // Check if plugin is installed by looking for any URL that matches const isInstalled = parsedConfig.plugins?.find((p) => { - const pluginUrl = p.uses[0].plugin; + const installedUrl = p.uses[0].plugin; // If the installed plugin is a GitHub URL, extract its identifier - const installedPluginId = extractPluginIdentifier(pluginUrl); + const installedPluginId = extractPluginIdentifier(installedUrl); // If both are GitHub URLs, compare the repo names - if (pluginUrl.includes("github") && pluginUrl.includes("github")) { - const isMatch = manifestPluginId === installedPluginId; - return isMatch; + const isBothGithubUrls = pluginUrl.includes("github") && installedUrl.includes("github"); + if (isBothGithubUrls) { + return manifestPluginId === installedPluginId; } // Otherwise check if the installed URL contains the repo name - const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - return isMatch; + return installedUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); }); loadListeners({ diff --git a/static/scripts/rendering/plugin-select.ts b/static/scripts/rendering/plugin-select.ts index ed4856c..5ba7de3 100644 --- a/static/scripts/rendering/plugin-select.ts +++ b/static/scripts/rendering/plugin-select.ts @@ -67,20 +67,19 @@ export function renderPluginSelector(renderer: ManifestRenderer): void { // Check if plugin is installed by looking for any URL that matches const installedPlugin: Plugin | undefined = installedPlugins.find((plugin) => { - const pluginUrl = plugin.uses[0].plugin; + const installedUrl = plugin.uses[0].plugin; // If the installed plugin is a GitHub URL, extract its identifier - const installedPluginId = extractPluginIdentifier(pluginUrl); + const installedPluginId = extractPluginIdentifier(installedUrl); // If both are GitHub URLs, compare the repo names - if (url.includes("github") && pluginUrl.includes("github")) { - const isMatch = manifestPluginId === installedPluginId; - return isMatch; + const isBothGithubUrls = url.includes("github") && installedUrl.includes("github"); + if (isBothGithubUrls) { + return manifestPluginId === installedPluginId; } // Otherwise check if the installed URL contains the repo name - const isMatch = pluginUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); - return isMatch; + return installedUrl.toLowerCase().includes(manifestPluginId.toLowerCase()); }); const defaultForInstalled: ManifestPreDecode | null = cleanManifestCache[url]; From 2e4e0791e7629275a9a11d08b0308bca05fba6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 11 Dec 2024 07:04:31 +0900 Subject: [PATCH 10/10] fix(eslint): config to ignore dist and js --- eslint.config.mjs | 259 ++++++++++++++++--------------- static/scripts/fetch-manifest.ts | 4 +- 2 files changed, 132 insertions(+), 131 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index c56fce8..75d1225 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,137 +1,138 @@ -// @ts-check -import tsEslint from "typescript-eslint"; import eslint from "@eslint/js"; -import sonarjs from "eslint-plugin-sonarjs"; import checkFile from "eslint-plugin-check-file"; +import sonarjs from "eslint-plugin-sonarjs"; +import tsEslint from "typescript-eslint"; -export default tsEslint.config({ - plugins: { - "@typescript-eslint": tsEslint.plugin, - "check-file": checkFile, +export default [ + { + ignores: ["dist/**/*", "**/*.js", ".github/*.ts", "cypress.config.ts"], }, - // static\dist\main.js - ignores: [".github/*.ts", "static/dist/*.js", "static/dist/*.ts", "static/dist/*.d.ts", "cypress.config.ts", "coverage/*"], - extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended], - languageOptions: { - parser: tsEslint.parser, - parserOptions: { - projectService: { - defaultProject: "tsconfig.json", - allowDefaultProject: ["*.mjs"], - }, - tsconfigRootDir: import.meta.dirname, + eslint.configs.recommended, + ...tsEslint.configs.recommended, + sonarjs.configs.recommended, + { + plugins: { + "@typescript-eslint": tsEslint.plugin, + "check-file": checkFile, }, - }, - rules: { - "check-file/filename-naming-convention": [ - "error", - { - "**/*.{js,ts}": "+([-._a-z0-9])", - }, - ], - "prefer-arrow-callback": [ - "warn", - { - allowNamedFunctions: true, - }, - ], - "func-style": [ - "warn", - "declaration", - { - allowArrowFunctions: false, - }, - ], - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/no-non-null-assertion": "error", - "constructor-super": "error", - "no-invalid-this": "off", - "@typescript-eslint/no-invalid-this": ["error"], - "no-restricted-syntax": ["error", "ForInStatement"], - "use-isnan": "error", - "no-unneeded-ternary": "error", - "no-nested-ternary": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { - args: "after-used", - ignoreRestSiblings: true, - vars: "all", - varsIgnorePattern: "^_", - argsIgnorePattern: "^_", + languageOptions: { + parser: tsEslint.parser, + parserOptions: { + project: "./tsconfig.json", + tsconfigRootDir: import.meta.dirname, }, - ], - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "sonarjs/no-all-duplicated-branches": "error", - "sonarjs/no-collection-size-mischeck": "error", - "sonarjs/no-duplicated-branches": "error", - "sonarjs/no-element-overwrite": "error", - "sonarjs/no-identical-conditions": "error", - "sonarjs/no-identical-expressions": "error", - "sonarjs/new-cap": "off", - "sonarjs/different-types-comparison": "off", - "sonarjs/sonar-prefer-regexp-exec": "off", - "sonarjs/function-return-type": "off", - "sonarjs/no-misleading-array-reverse": "off", - "sonarjs/slow-regex": "off", - "@typescript-eslint/naming-convention": [ - "error", - { - selector: "interface", - format: ["StrictPascalCase"], - custom: { - regex: "^I[A-Z]", - match: false, + }, + rules: { + "check-file/filename-naming-convention": [ + "error", + { + "**/*.{js,ts}": "+([-._a-z0-9])", }, - }, - { - selector: "memberLike", - modifiers: ["private"], - format: ["strictCamelCase"], - leadingUnderscore: "require", - }, - { - selector: "typeLike", - format: ["StrictPascalCase"], - }, - { - selector: "typeParameter", - format: ["StrictPascalCase"], - prefix: ["T"], - }, - { - selector: "variable", - format: ["strictCamelCase", "UPPER_CASE"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "variable", - format: ["strictCamelCase"], - leadingUnderscore: "allow", - trailingUnderscore: "allow", - }, - { - selector: "variable", - modifiers: ["destructured"], - format: null, - }, - { - selector: "variable", - types: ["boolean"], - format: ["StrictPascalCase"], - prefix: ["is", "should", "has", "can", "did", "will", "does"], - }, - { - selector: "variableLike", - format: ["strictCamelCase"], - }, - { - selector: ["function", "variable"], - format: ["strictCamelCase"], - }, - ], + ], + "prefer-arrow-callback": [ + "warn", + { + allowNamedFunctions: true, + }, + ], + "func-style": [ + "warn", + "declaration", + { + allowArrowFunctions: false, + }, + ], + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "constructor-super": "error", + "no-invalid-this": "off", + "@typescript-eslint/no-invalid-this": ["error"], + "no-restricted-syntax": ["error", "ForInStatement"], + "use-isnan": "error", + "no-unneeded-ternary": "error", + "no-nested-ternary": "error", + "@typescript-eslint/no-unused-vars": [ + "error", + { + args: "after-used", + ignoreRestSiblings: true, + vars: "all", + varsIgnorePattern: "^_", + argsIgnorePattern: "^_", + }, + ], + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/restrict-plus-operands": "error", + "sonarjs/no-all-duplicated-branches": "error", + "sonarjs/no-collection-size-mischeck": "error", + "sonarjs/no-duplicated-branches": "error", + "sonarjs/no-element-overwrite": "error", + "sonarjs/no-identical-conditions": "error", + "sonarjs/no-identical-expressions": "error", + "sonarjs/new-cap": "off", + "sonarjs/different-types-comparison": "off", + "sonarjs/sonar-prefer-regexp-exec": "off", + "sonarjs/function-return-type": "off", + "sonarjs/no-misleading-array-reverse": "off", + "sonarjs/slow-regex": "off", + "@typescript-eslint/naming-convention": [ + "error", + { + selector: "interface", + format: ["StrictPascalCase"], + custom: { + regex: "^I[A-Z]", + match: false, + }, + }, + { + selector: "memberLike", + modifiers: ["private"], + format: ["strictCamelCase"], + leadingUnderscore: "require", + }, + { + selector: "typeLike", + format: ["StrictPascalCase"], + }, + { + selector: "typeParameter", + format: ["StrictPascalCase"], + prefix: ["T"], + }, + { + selector: "variable", + format: ["strictCamelCase", "UPPER_CASE"], + leadingUnderscore: "allow", + trailingUnderscore: "allow", + }, + { + selector: "variable", + format: ["strictCamelCase"], + leadingUnderscore: "allow", + trailingUnderscore: "allow", + }, + { + selector: "variable", + modifiers: ["destructured"], + format: null, + }, + { + selector: "variable", + types: ["boolean"], + format: ["StrictPascalCase"], + prefix: ["is", "should", "has", "can", "did", "will", "does"], + }, + { + selector: "variableLike", + format: ["strictCamelCase"], + }, + { + selector: ["function", "variable"], + format: ["strictCamelCase"], + }, + ], + }, }, -}); +]; diff --git a/static/scripts/fetch-manifest.ts b/static/scripts/fetch-manifest.ts index 6ead971..a7d3a0e 100644 --- a/static/scripts/fetch-manifest.ts +++ b/static/scripts/fetch-manifest.ts @@ -37,7 +37,7 @@ export class ManifestFetcher { for (const repo of repos.data) { const manifestUrl = this.createGithubRawEndpoint(org, repo.name, "development", "manifest.json"); const manifest = await this.fetchPluginManifest(manifestUrl); - const decoded = this.decodeManifestFromFetch(manifest, repo.name); + const decoded = this.decodeManifestFromFetch(manifest); const readme = await this.fetchPluginReadme(this.createGithubRawEndpoint(org, repo.name, "development", "README.md")); if (decoded) { @@ -190,7 +190,7 @@ export class ManifestFetcher { } } - decodeManifestFromFetch(manifest: ManifestPreDecode, repoName: string) { + decodeManifestFromFetch(manifest: ManifestPreDecode) { if (manifest.error) { return null; }