From dd97a46a0318d6b2d0c04decfd579d6322bed510 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 18 Sep 2023 16:37:15 -0500 Subject: [PATCH] Update code to deal with new paths under src --- .eslintrc.cjs | 5 ++- .gitignore | 1 + package.json | 1 + src/components/site-logo.tsx | 4 +-- src/components/verification-badge.tsx | 2 +- src/custom.ts | 2 +- .../crypto-donate/components/crypto-icon.tsx | 4 +-- src/index.html | 2 +- src/main.tsx | 6 ++-- src/messages.ts | 2 +- src/normalizers/__tests__/account.test.ts | 4 +-- src/normalizers/account.ts | 4 +-- src/normalizers/group.ts | 4 +-- src/schemas/account.ts | 4 +-- src/schemas/group.ts | 4 +-- src/utils/accounts.ts | 4 +-- src/utils/code-compiletime.ts | 2 +- src/utils/sounds.ts | 8 ++--- tsconfig.json | 7 +++-- vite.config.ts | 9 +++--- yarn.lock | 31 +++++++++++++++++-- 21 files changed, 69 insertions(+), 41 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index efd966cb9..f600af38d 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -48,9 +48,8 @@ module.exports = { '\\.(css|scss|json)$', ], 'import/resolver': { - node: { - paths: ['src'], - }, + typescript: true, + node: true, }, polyfills: [ 'es:all', // core-js diff --git a/.gitignore b/.gitignore index 678f25775..176314352 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ yarn-error.log* /junit.xml *.timestamp-* +*.bundled_* /dist/ /static/ diff --git a/package.json b/package.json index 3d001c26a..9e5d33611 100644 --- a/package.json +++ b/package.json @@ -188,6 +188,7 @@ "cross-env": "^7.0.3", "danger": "^11.0.7", "eslint": "^8.49.0", + "eslint-import-resolver-typescript": "^3.6.0", "eslint-plugin-compat": "^4.2.0", "eslint-plugin-import": "^2.28.1", "eslint-plugin-jsdoc": "^46.8.1", diff --git a/src/components/site-logo.tsx b/src/components/site-logo.tsx index eb7f414b0..9d545a48d 100644 --- a/src/components/site-logo.tsx +++ b/src/components/site-logo.tsx @@ -20,8 +20,8 @@ const SiteLogo: React.FC = ({ className, theme, ...rest }) => { /** Soapbox logo. */ const soapboxLogo = darkMode - ? require('assets/images/soapbox-logo-white.svg') - : require('assets/images/soapbox-logo.svg'); + ? require('soapbox/assets/images/soapbox-logo-white.svg') + : require('soapbox/assets/images/soapbox-logo.svg'); // Use the right logo if provided, then use fallbacks. const getSrc = () => { diff --git a/src/components/verification-badge.tsx b/src/components/verification-badge.tsx index df10acc7b..0d0e67d7c 100644 --- a/src/components/verification-badge.tsx +++ b/src/components/verification-badge.tsx @@ -18,7 +18,7 @@ const VerificationBadge: React.FC = ({ className }) => { const soapboxConfig = useSoapboxConfig(); // Prefer a custom icon if found - const icon = soapboxConfig.verifiedIcon || require('assets/icons/verified.svg'); + const icon = soapboxConfig.verifiedIcon || require('soapbox/assets/icons/verified.svg'); // Render component based on file extension const Element = icon.endsWith('.svg') ? Icon : 'img'; diff --git a/src/custom.ts b/src/custom.ts index efebce1e2..dcbcba547 100644 --- a/src/custom.ts +++ b/src/custom.ts @@ -7,7 +7,7 @@ import * as BuildConfig from 'soapbox/build-config'; export const custom = (filename: string, fallback: any = {}): any => { if (BuildConfig.NODE_ENV === 'test') return fallback; - const modules = import.meta.glob('../../custom/*.json', { eager: true }); + const modules = import.meta.glob('../custom/*.json', { eager: true }); const key = `../../custom/${filename}.json`; return modules[key] ? modules[key] : fallback; diff --git a/src/features/crypto-donate/components/crypto-icon.tsx b/src/features/crypto-donate/components/crypto-icon.tsx index 07f0c9be6..26f51a464 100644 --- a/src/features/crypto-donate/components/crypto-icon.tsx +++ b/src/features/crypto-donate/components/crypto-icon.tsx @@ -3,8 +3,8 @@ import React from 'react'; /** Get crypto icon URL by ticker symbol, or fall back to generic icon */ const getIcon = (ticker: string): string => { - const modules: Record = import.meta.glob('../../../../../node_modules/cryptocurrency-icons/svg/color/*.svg', { eager: true }); - const key = `../../../../../node_modules/cryptocurrency-icons/svg/color/${ticker}.svg`; + const modules: Record = import.meta.glob('../../../../node_modules/cryptocurrency-icons/svg/color/*.svg', { eager: true }); + const key = `../../../../node_modules/cryptocurrency-icons/svg/color/${ticker}.svg`; return modules[key]?.default || genericIcon; }; diff --git a/src/index.html b/src/index.html index a56e5867e..6e4bf1c9b 100644 --- a/src/index.html +++ b/src/index.html @@ -7,7 +7,7 @@ - +
diff --git a/src/main.tsx b/src/main.tsx index 7045b0637..74d967b01 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -17,9 +17,9 @@ import '@fontsource/roboto-mono/400.css'; import 'line-awesome/dist/font-awesome-line-awesome/css/all.css'; import 'react-datepicker/dist/react-datepicker.css'; -import '../soapbox/iframe'; -import '../styles/application.scss'; -import '../styles/tailwind.css'; +import './iframe'; +import './styles/application.scss'; +import './styles/tailwind.css'; import './precheck'; import { default as Soapbox } from './containers/soapbox'; diff --git a/src/messages.ts b/src/messages.ts index c7aebb4d4..e180908ec 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -4,7 +4,7 @@ type MessageModule = { default: MessageJson }; /** Import custom messages */ const importCustom = async (locale: string): Promise => { try { - return await import(`../../custom/locales/${locale}.json`); + return await import(`../custom/locales/${locale}.json`); } catch { return ({ default: {} }); } diff --git a/src/normalizers/__tests__/account.test.ts b/src/normalizers/__tests__/account.test.ts index 6c2abc2b3..a51917866 100644 --- a/src/normalizers/__tests__/account.test.ts +++ b/src/normalizers/__tests__/account.test.ts @@ -2,8 +2,8 @@ import { Record as ImmutableRecord, fromJS } from 'immutable'; import { normalizeAccount } from '../account'; -const AVATAR_MISSING = require('assets/images/avatar-missing.png'); -const HEADER_MISSING = require('assets/images/header-missing.png'); +const AVATAR_MISSING = require('soapbox/assets/images/avatar-missing.png'); +const HEADER_MISSING = require('soapbox/assets/images/header-missing.png'); describe('normalizeAccount()', () => { it('adds base fields', () => { diff --git a/src/normalizers/account.ts b/src/normalizers/account.ts index 21c15dc68..74a84e46b 100644 --- a/src/normalizers/account.ts +++ b/src/normalizers/account.ts @@ -100,7 +100,7 @@ const normalizePleromaLegacyFields = (account: ImmutableMap) => { const normalizeAvatar = (account: ImmutableMap) => { const avatar = account.get('avatar'); const avatarStatic = account.get('avatar_static'); - const missing = require('assets/images/avatar-missing.png'); + const missing = require('soapbox/assets/images/avatar-missing.png'); return account.withMutations(account => { account.set('avatar', avatar || avatarStatic || missing); @@ -112,7 +112,7 @@ const normalizeAvatar = (account: ImmutableMap) => { const normalizeHeader = (account: ImmutableMap) => { const header = account.get('header'); const headerStatic = account.get('header_static'); - const missing = require('assets/images/header-missing.png'); + const missing = require('soapbox/assets/images/header-missing.png'); return account.withMutations(account => { account.set('header', header || headerStatic || missing); diff --git a/src/normalizers/group.ts b/src/normalizers/group.ts index c5f34aafb..ebe10ed89 100644 --- a/src/normalizers/group.ts +++ b/src/normalizers/group.ts @@ -53,7 +53,7 @@ export const GroupRecord = ImmutableRecord({ const normalizeAvatar = (group: ImmutableMap) => { const avatar = group.get('avatar'); const avatarStatic = group.get('avatar_static'); - const missing = require('assets/images/avatar-missing.png'); + const missing = require('soapbox/assets/images/avatar-missing.png'); return group.withMutations(group => { group.set('avatar', avatar || avatarStatic || missing); @@ -65,7 +65,7 @@ const normalizeAvatar = (group: ImmutableMap) => { const normalizeHeader = (group: ImmutableMap) => { const header = group.get('header'); const headerStatic = group.get('header_static'); - const missing = require('assets/images/header-missing.png'); + const missing = require('soapbox/assets/images/header-missing.png'); return group.withMutations(group => { group.set('header', header || headerStatic || missing); diff --git a/src/schemas/account.ts b/src/schemas/account.ts index a4881f4bc..88128c35e 100644 --- a/src/schemas/account.ts +++ b/src/schemas/account.ts @@ -10,8 +10,8 @@ import { contentSchema, filteredArray, makeCustomEmojiMap } from './utils'; import type { Resolve } from 'soapbox/utils/types'; -const avatarMissing = require('assets/images/avatar-missing.png'); -const headerMissing = require('assets/images/header-missing.png'); +const avatarMissing = require('soapbox/assets/images/avatar-missing.png'); +const headerMissing = require('soapbox/assets/images/header-missing.png'); const birthdaySchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/); diff --git a/src/schemas/group.ts b/src/schemas/group.ts index be9238308..9d97a4047 100644 --- a/src/schemas/group.ts +++ b/src/schemas/group.ts @@ -9,8 +9,8 @@ import { groupRelationshipSchema } from './group-relationship'; import { groupTagSchema } from './group-tag'; import { filteredArray, makeCustomEmojiMap } from './utils'; -const avatarMissing = require('assets/images/avatar-missing.png'); -const headerMissing = require('assets/images/header-missing.png'); +const avatarMissing = require('soapbox/assets/images/avatar-missing.png'); +const headerMissing = require('soapbox/assets/images/header-missing.png'); const groupSchema = z.object({ avatar: z.string().catch(avatarMissing), diff --git a/src/utils/accounts.ts b/src/utils/accounts.ts index a51ed9aad..51122dfc5 100644 --- a/src/utils/accounts.ts +++ b/src/utils/accounts.ts @@ -37,7 +37,7 @@ export const isRemote = (account: Pick): boolean => !isLocal(ac const DEFAULT_HEADERS: string[] = [ '/headers/original/missing.png', // Mastodon '/images/banner.png', // Pleroma - require('assets/images/header-missing.png'), // header not provided by backend + require('soapbox/assets/images/header-missing.png'), // header not provided by backend ]; /** Check if the avatar is a default avatar */ @@ -49,7 +49,7 @@ export const isDefaultHeader = (url: string) => { const DEFAULT_AVATARS = [ '/avatars/original/missing.png', // Mastodon '/images/avi.png', // Pleroma - require('assets/images/avatar-missing.png'), // avatar not provided by backend + require('soapbox/assets/images/avatar-missing.png'), // avatar not provided by backend ]; /** Check if the avatar is a default avatar */ diff --git a/src/utils/code-compiletime.ts b/src/utils/code-compiletime.ts index 7b19b7ec2..b43c1d86e 100644 --- a/src/utils/code-compiletime.ts +++ b/src/utils/code-compiletime.ts @@ -1,6 +1,6 @@ import { execSync } from 'node:child_process'; -import pkg from '../../../package.json'; +import pkg from '../../package.json'; const { CI_COMMIT_TAG, CI_COMMIT_REF_NAME, CI_COMMIT_SHA } = process.env; diff --git a/src/utils/sounds.ts b/src/utils/sounds.ts index ad4c58250..0beab3e75 100644 --- a/src/utils/sounds.ts +++ b/src/utils/sounds.ts @@ -35,21 +35,21 @@ const play = (audio: HTMLAudioElement): void => { const soundCache: Record = { boop: createAudio([ { - src: require('../../assets/sounds/boop.ogg'), + src: require('../assets/sounds/boop.ogg'), type: 'audio/ogg', }, { - src: require('../../assets/sounds/boop.mp3'), + src: require('../assets/sounds/boop.mp3'), type: 'audio/mpeg', }, ]), chat: createAudio([ { - src: require('../../assets/sounds/chat.oga'), + src: require('../assets/sounds/chat.oga'), type: 'audio/ogg', }, { - src: require('../../assets/sounds/chat.mp3'), + src: require('../assets/sounds/chat.mp3'), type: 'audio/mpeg', }, ]), diff --git a/tsconfig.json b/tsconfig.json index 33ea901d0..c43fe36e3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "baseUrl": "src/", - "outDir": "build/", + "baseUrl": "./", + "outDir": "dist", "sourceMap": true, "strict": true, "module": "ESNext", @@ -12,6 +12,9 @@ "moduleResolution": "node", "resolveJsonModule": true, "esModuleInterop": true, + "paths": { + "soapbox/*": ["src/*"], + }, "typeRoots": [ "./types", "./node_modules/@types", diff --git a/vite.config.ts b/vite.config.ts index 8a1dd7aad..c10c4ff74 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,5 @@ /// -import path from 'path'; +import { fileURLToPath, URL } from 'node:url'; import react from '@vitejs/plugin-react'; import { visualizer } from 'rollup-plugin-visualizer'; @@ -62,7 +62,7 @@ export default defineConfig({ short_name: 'Soapbox', description: 'A social media frontend with a focus on custom branding and ease of use.', }, - srcDir: 'soapbox/service-worker', + srcDir: 'service-worker', filename: 'sw.ts', }), viteStaticCopy({ @@ -79,8 +79,7 @@ export default defineConfig({ ], resolve: { alias: [ - { find: 'soapbox', replacement: path.resolve(__dirname, 'src', 'soapbox') }, - { find: 'assets', replacement: path.resolve(__dirname, 'src', 'assets') }, + { find: 'soapbox', replacement: fileURLToPath(new URL('./src', import.meta.url)) }, ], }, assetsInclude: ['**/*.oga'], @@ -90,6 +89,6 @@ export default defineConfig({ cache: { dir: '../node_modules/.vitest', }, - setupFiles: 'soapbox/jest/test-setup.ts', + setupFiles: 'jest/test-setup.ts', }, }); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 042e5e38d..5fa9df298 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ end-of-stream@^1.1.0, end-of-stream@^1.4.4: dependencies: once "^1.4.0" -enhanced-resolve@^5.15.0: +enhanced-resolve@^5.12.0, enhanced-resolve@^5.15.0: version "5.15.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== @@ -4546,7 +4546,20 @@ eslint-import-resolver-node@^0.3.7: is-core-module "^2.13.0" resolve "^1.22.4" -eslint-module-utils@^2.8.0: +eslint-import-resolver-typescript@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.0.tgz#36f93e1eb65a635e688e16cae4bead54552e3bbd" + integrity sha512-QTHR9ddNnn35RTxlaEnx2gCxqFlF2SEN0SE2d17SqwyM7YOSI2GHWRYp5BiRkObTUNYPupC/3Fq2a0PpT+EKpg== + dependencies: + debug "^4.3.4" + enhanced-resolve "^5.12.0" + eslint-module-utils "^2.7.4" + fast-glob "^3.3.1" + get-tsconfig "^4.5.0" + is-core-module "^2.11.0" + is-glob "^4.0.3" + +eslint-module-utils@^2.7.4, eslint-module-utils@^2.8.0: version "2.8.0" resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz#e439fee65fc33f6bba630ff621efc38ec0375c49" integrity sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw== @@ -5110,6 +5123,13 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" +get-tsconfig@^4.5.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.0.tgz#06ce112a1463e93196aa90320c35df5039147e34" + integrity sha512-pmjiZ7xtB8URYm74PlGJozDNyhvsVLUcpBa8DZBG3bWHwaHa9bPiRpiSfovw+fjhwONSCWKRyk+JQHEGZmMrzw== + dependencies: + resolve-pkg-maps "^1.0.0" + git-config-path@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/git-config-path/-/git-config-path-1.0.1.tgz#6d33f7ed63db0d0e118131503bab3aca47d54664" @@ -5688,7 +5708,7 @@ is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.7: resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055" integrity sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA== -is-core-module@^2.13.0, is-core-module@^2.5.0, is-core-module@^2.9.0: +is-core-module@^2.11.0, is-core-module@^2.13.0, is-core-module@^2.5.0, is-core-module@^2.9.0: version "2.13.0" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.0.tgz#bb52aa6e2cbd49a30c2ba68c42bf3435ba6072db" integrity sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ== @@ -8157,6 +8177,11 @@ resolve-pathname@^3.0.0: resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng== +resolve-pkg-maps@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" + integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== + resolve@^1.1.7, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.22.2, resolve@^1.22.4: version "1.22.6" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.6.tgz#dd209739eca3aef739c626fea1b4f3c506195362"