Skip to content

Commit 707275f

Browse files
authored
refactor: Migrate to Vite (#31)
* chore: Initial vite migration * lint: Fix vite eslint * chore: Migrate HtmlWebpackPlugin * chore: Migrate CopyPlugin * chore: Replace webpack script with vite * ci: Trigger for refactor/ branches * fix: Snippets * chore: Rename index.ejs -> index.html * ci: `static/` -> `dist/` * chore: Migrate ServiceWorker to Vite * chore: Import locales at compile time * chore: Exported locales should contain `data` property * chore: Register SW * ci: Keep it `static/` * refactor: Set output dir from vite config * chore: Add `require(...)` support back * feat: Resolve and stuff * fix: Move index.html * fix: Resolve ambigous import * fix: Browserify path * chore: Remove crypto related stuff I don't do crypto * fix: Use `@akryum/flexsearch-es` REF: nextapps-de/flexsearch#341 * fix: webpack -> vite-ignore * fix: Vite env * chore: Ignore some vite temp files * revert: Vite env * revert: Vite env * chore: More vite env stuff * fix: CSP Imported CSS still doesn't work * fix: Entrypoint shouldn't be a relative path * fix: Adjust initial nonce * chore: TS Checker * fix: Adjust eslintignore * lint: Adjust eslintignore * fix: Adjust lint command * chore: Disable eslint checker for now For some reason it keep ignoring eslintignore (ironic) * chore: It's actually ts checker that keep checking node_modules * fix: lint command * chore: Disable stylelint * fix: Yarn can't be used for lint command * chore: Temporarily disable eslint * fix: CSP in dev mode * chore: CSP adjustment CSP may or may not be fine on prod... we'll see... * fix: Slight adjustment * fix: CSP forr vite-plugin-checker * fix: Resolve warnings * fix: More warning fixing * fix: Yet another warning fixes * fix: SW typing * fix: It's webworker not dom * chore: Remove webpack * chore: Disable eslint and stylelint * fix: Hopefully one last error fix * chore: Update immer to v10 * fix: Regex * chore: Update more deps * chore: Downgrade toast to v2.4.0 * chore: Remove dangerfile * fix: Dynamic locale import * fix: Try use __webpack_nonce__ just in case * fix: vite-plugin-require * revert: Revert "fix: vite-plugin-require" This reverts commit 7c4e15f. * chore: Remove keymap temporarily * fix: Goober * fix: nonce * chore: Temporarily disable hotkey * fix: Properly null check textarea * fix: NODE_ENV
1 parent 49e5dee commit 707275f

File tree

100 files changed

+2815
-3105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2815
-3105
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NODE_ENV=development
1+
# NODE_ENV=development
22
# BACKEND_URL="https://example.com"
33
# PROXY_HTTPS_INSECURE=false

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ module.exports = {
260260
alphabetize: { order: 'asc' },
261261
},
262262
],
263-
'@typescript-eslint/no-duplicate-imports': 'error',
264263
'@typescript-eslint/member-delimiter-style': [
265264
'error',
266265
{
@@ -285,6 +284,7 @@ module.exports = {
285284
},
286285
],
287286
'tailwindcss/migration-from-tailwind-2': 'error',
287+
'tailwindcss/no-custom-classname': 'warn',
288288
},
289289
overrides: [
290290
{

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- develop
77
- feat/**
88
- fix/**
9+
- refactor/**
910
release:
1011
types: [ published ]
1112

@@ -27,7 +28,7 @@ jobs:
2728
yarn install --ignore-scripts
2829
yarn patch-package
2930
env NODE_ENV=production yarn build
30-
zip -r static.zip static
31+
zip -r static.zip static/
3132
# -- For artifact
3233
mkdir __build/
3334
cp -r static/ __build/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/.vs/
1010
yarn-error.log*
1111
/junit.xml
12+
*.timestamp-*
13+
*.bundled_*
1214

1315
/static/
1416
/static-test/

app/soapbox/actions/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createSelector } from 'reselect';
44
import { v4 as uuid } from 'uuid';
55

66
import { patchMe } from 'soapbox/actions/me';
7-
import messages from 'soapbox/locales/messages';
7+
import messages from 'soapbox/messages';
88
import toast from 'soapbox/toast';
99
import { isLoggedIn } from 'soapbox/utils/auth';
1010

app/soapbox/actions/streaming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getLocale, getSettings } from 'soapbox/actions/settings';
22
import { importEntities } from 'soapbox/entity-store/actions';
33
import { Entities } from 'soapbox/entity-store/entities';
44
import { selectEntity } from 'soapbox/entity-store/selectors';
5-
import messages from 'soapbox/locales/messages';
5+
import messages from 'soapbox/messages';
66
import { ChatKeys, IChat, isLastMessage } from 'soapbox/queries/chats';
77
import { queryClient } from 'soapbox/queries/client';
88
import { getUnreadChatsCount, updateChatListItem, updateChatMessage } from 'soapbox/utils/chats';
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,41 @@
44
* @module soapbox/build-config
55
*/
66

7-
const trim = require('lodash/trim');
8-
const trimEnd = require('lodash/trimEnd');
7+
// eslint-disable-next-line import/extensions
8+
import trim from 'lodash/trim.js';
9+
// eslint-disable-next-line import/extensions
10+
import trimEnd from 'lodash/trimEnd.js';
911

1012
const {
1113
NODE_ENV,
1214
BACKEND_URL,
1315
FE_SUBDIRECTORY,
14-
FE_BUILD_DIR,
1516
FE_INSTANCE_SOURCE_DIR,
1617
SENTRY_DSN,
17-
} = process.env;
18+
} = process.env || {};
1819

19-
const sanitizeURL = url => {
20+
const sanitizeURL = (url: string | undefined = '') => {
2021
try {
2122
return trimEnd(new URL(url).toString(), '/');
2223
} catch {
2324
return '';
2425
}
2526
};
2627

27-
const sanitizeBasename = path => {
28+
const sanitizeBasename = (path: string | undefined = '') => {
2829
return `/${trim(path, '/')}`;
2930
};
3031

31-
const sanitizePath = path => {
32-
return trim(path, '/');
33-
};
34-
35-
// JSON.parse/stringify is to emulate what @preval is doing and avoid any
36-
// inconsistent behavior in dev mode
37-
const sanitize = obj => JSON.parse(JSON.stringify(obj));
38-
39-
module.exports = sanitize({
32+
const env = {
4033
NODE_ENV: NODE_ENV || 'development',
4134
BACKEND_URL: sanitizeURL(BACKEND_URL),
4235
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
43-
FE_BUILD_DIR: sanitizePath(FE_BUILD_DIR) || 'static',
4436
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
4537
SENTRY_DSN,
38+
};
39+
40+
export type BuildConfig = typeof env;
41+
42+
export default () => ({
43+
data: env,
4644
});

app/soapbox/build-config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { BuildConfig } from './build-config-compiletime';
2+
3+
export const {
4+
NODE_ENV,
5+
BACKEND_URL,
6+
FE_SUBDIRECTORY,
7+
FE_INSTANCE_SOURCE_DIR,
8+
SENTRY_DSN,
9+
} = import.meta.compileTime<BuildConfig>('./build-config-compiletime.ts');

app/soapbox/components/autosuggest-textarea.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { install, uninstall } from '@github/hotkey';
12
import clsx from 'clsx';
23
import React from 'react';
34
import ImmutablePureComponent from 'react-immutable-pure-component';
@@ -30,12 +31,14 @@ interface IAutosuggesteTextarea {
3031
onFocus: () => void
3132
onBlur?: () => void
3233
condensed?: boolean
34+
keymap?: string
3335
children: React.ReactNode
3436
}
3537

3638
class AutosuggestTextarea extends ImmutablePureComponent<IAutosuggesteTextarea> {
3739

3840
textarea: HTMLTextAreaElement | null = null;
41+
keymap?: string = undefined;
3942

4043
static defaultProps = {
4144
autoFocus: true,
@@ -171,8 +174,13 @@ class AutosuggestTextarea extends ImmutablePureComponent<IAutosuggesteTextarea>
171174

172175
setTextarea: React.Ref<HTMLTextAreaElement> = (c) => {
173176
this.textarea = c;
177+
if (this.textarea && this.keymap) install(this.textarea, this.keymap);
174178
};
175179

180+
componentWillUnmount(): void {
181+
if (this.textarea && this.keymap) uninstall(this.textarea);
182+
}
183+
176184
onPaste: React.ClipboardEventHandler<HTMLTextAreaElement> = (e) => {
177185
if (e.clipboardData && e.clipboardData.files.length === 1) {
178186
this.props.onPaste(e.clipboardData.files);
@@ -227,7 +235,8 @@ class AutosuggestTextarea extends ImmutablePureComponent<IAutosuggesteTextarea>
227235
}
228236

229237
render() {
230-
const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus, children, condensed, id } = this.props;
238+
const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus, children, condensed, id, keymap } = this.props;
239+
if (keymap) this.keymap = keymap;
231240
const { suggestionsHidden } = this.state;
232241
const style = { direction: 'ltr', minRows: 10 };
233242

0 commit comments

Comments
 (0)