diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f8623c4..e09bae3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -8,6 +8,7 @@ module.exports = { "eslint:recommended", 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended', + "prettier", ], ignorePatterns: ['dist', '.eslintrc.cjs'], globals: { diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6f00ef7 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "all", + "semi": true, + "printWidth": 120 +} diff --git a/package.json b/package.json index 8213ab0..3ea2c55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kor-address-extension", - "version": "1.1.2", + "version": "1.2.0", "main": "dist/index.js", "type": "module", "repository": "git@github.com:Jaewoook/kor-address-extension.git", @@ -23,17 +23,18 @@ "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@types/styled-components": "^5.1.34", - "@types/webextension-polyfill": "^0.10.7", "@typescript-eslint/eslint-plugin": "^7.13.0", "@typescript-eslint/parser": "^7.13.0", "@vitejs/plugin-react": "^4.3.1", "archiver": "^5.3.1", "chalk": "^4.1.0", "eslint": "^8", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.7", "fs-extra": "^10.1.0", + "prettier": "3.3.2", "typescript": "^5.4.5", "vite": "^5.3.1" }, @@ -46,7 +47,6 @@ "react-dom": "^18.3.1", "react-icons": "^5.2.1", "recoil": "^0.7.7", - "styled-components": "^6.1.11", - "webextension-polyfill": "^0.12.0" + "styled-components": "^6.1.11" } } diff --git a/src/shared/storage.ts b/src/shared/storage.ts index 8d7fc64..b9e3302 100644 --- a/src/shared/storage.ts +++ b/src/shared/storage.ts @@ -1,13 +1,5 @@ -import type { Browser } from "webextension-polyfill"; import type { AddressData, SearchKey } from "./models/address"; -import { isExtension } from "./utils"; - -let browser: Browser | null = null; -if (isExtension()) { - import("webextension-polyfill").then((module) => { - browser = module.default; - }); -} +import { isExtension, getExtensionAPI } from "./utils"; type SearchResultOptions = { showEng: boolean; @@ -37,12 +29,14 @@ export const DEFAULT_SETTINGS: Settings = { }; const get = (key?: string) => { - if (isExtension() && browser) { - return browser.storage.local.get(key); + const extAPI = getExtensionAPI(); + if (isExtension() && extAPI) { + return extAPI.storage.local.get(key); } if (key) { - return { key: localStorage.getItem(key) }; + const raw = localStorage.getItem(key); + return { [key]: raw ? JSON.parse(raw) : null }; } return Array.from({ length: localStorage.length }) @@ -56,8 +50,9 @@ const get = (key?: string) => { }; const set = (items: Record) => { - if (isExtension() && browser) { - return browser.storage.local.set(items); + const extAPI = getExtensionAPI(); + if (isExtension() && extAPI) { + return extAPI.storage.local.set(items); } return Object.entries(items).forEach(([key, value]) => { @@ -77,6 +72,7 @@ export const getSearchResultOptions = async (): Promise => { const recentAddressList = await get("addressData"); + console.log("recent address list", recentAddressList); return recentAddressList?.addressData ?? null; }; @@ -88,7 +84,10 @@ export const setRecentAddressList = async (addressList: AddressData[]) => { set({ addressData: addressList }); }; -export const validateSettingsData = (settingsData: unknown, expected: Record = DEFAULT_SETTINGS): boolean => { +export const validateSettingsData = ( + settingsData: unknown, + expected: Record = DEFAULT_SETTINGS, +): boolean => { if (typeof settingsData !== "object" || settingsData === null) { return false; } diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 7c33608..a00adae 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -39,3 +39,16 @@ export const getRuntime = (): Runtime => { }; export const isExtension = () => getRuntime() === "extension"; + +export const getExtensionAPI = () => { + if (!isExtension()) { + return null; + } + if (typeof chrome === "object") { + return chrome; + } + if (typeof browser === "object") { + return browser; + } + return null; +}; diff --git a/yarn.lock b/yarn.lock index 0e500d0..ea122fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -935,11 +935,6 @@ resolved "https://registry.yarnpkg.com/@types/stylis/-/stylis-4.2.5.tgz#1daa6456f40959d06157698a653a9ab0a70281df" integrity sha512-1Xve+NMN7FWjY14vLoY5tL3BVEQ/n42YLwaqJIPYhotZ9uBHt87VceMwWQpzmdEt2TNXIorIFG+YeCUUW7RInw== -"@types/webextension-polyfill@^0.10.7": - version "0.10.7" - resolved "https://registry.yarnpkg.com/@types/webextension-polyfill/-/webextension-polyfill-0.10.7.tgz#de059250599733a60ed26c8a0c81e21e11183b90" - integrity sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw== - "@typescript-eslint/eslint-plugin@^7.13.0": version "7.13.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.0.tgz#3cdeb5d44d051b21a9567535dd90702b2a42c6ff" @@ -1790,6 +1785,11 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-config-prettier@^9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" + integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== + eslint-import-resolver-node@^0.3.9: version "0.3.9" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" @@ -2884,6 +2884,11 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prettier@3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.2.tgz#03ff86dc7c835f2d2559ee76876a3914cec4a90a" + integrity sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA== + printj@~1.1.0: version "1.1.2" resolved "https://registry.yarnpkg.com/printj/-/printj-1.1.2.tgz#d90deb2975a8b9f600fb3a1c94e3f4c53c78a222" @@ -3874,11 +3879,6 @@ vite@^5.3.1: optionalDependencies: fsevents "~2.3.3" -webextension-polyfill@^0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.12.0.tgz#f62c57d2cd42524e9fbdcee494c034cae34a3d69" - integrity sha512-97TBmpoWJEE+3nFBQ4VocyCdLKfw54rFaJ6EVQYLBCXqCIpLSZkwGgASpv4oPt9gdKCJ80RJlcmNzNn008Ag6Q== - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"