Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert easy entrypoints files to Typescript #30102

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './public-path';
import main from "mastodon/main";
import main from 'mastodon/main';

import { start } from '../mastodon/common';
import { loadLocale } from '../mastodon/locales';
Expand All @@ -10,6 +10,6 @@ start();
loadPolyfills()
.then(loadLocale)
.then(main)
.catch(e => {
.catch((e: unknown) => {
console.error(e);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import './public-path';
import ready from '../mastodon/ready';

ready(() => {
const image = document.querySelector('img');
const image = document.querySelector<HTMLImageElement>('img');

if (!image) return;

image.addEventListener('mouseenter', () => {
image.src = '/oops.gif';
Expand All @@ -11,4 +13,6 @@ ready(() => {
image.addEventListener('mouseleave', () => {
image.src = '/oops.png';
});
}).catch((e: unknown) => {
console.error(e);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// to share the same assets regardless of instance configuration.
// See https://webpack.js.org/guides/public-path/#on-the-fly

function removeOuterSlashes(string) {
function removeOuterSlashes(string: string) {
return string.replace(/^\/*/, '').replace(/\/*$/, '');
}

Expand All @@ -15,7 +15,9 @@ function formatPublicPath(host = '', path = '') {
return `${formattedHost}/${formattedPath}/`;
}

const cdnHost = document.querySelector('meta[name=cdn-host]');
const cdnHost = document.querySelector<HTMLMetaElement>('meta[name=cdn-host]');

// eslint-disable-next-line no-undef
__webpack_public_path__ = formatPublicPath(cdnHost ? cdnHost.content : '', process.env.PUBLIC_OUTPUT_PATH);
__webpack_public_path__ = formatPublicPath(
cdnHost ? cdnHost.content : '',
process.env.PUBLIC_OUTPUT_PATH,
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './public-path';
import { createRoot } from 'react-dom/client';

import { start } from '../mastodon/common';
import ComposeContainer from '../mastodon/containers/compose_container';
import ComposeContainer from '../mastodon/containers/compose_container';
import { loadPolyfills } from '../mastodon/polyfills';
import ready from '../mastodon/ready';

Expand All @@ -16,17 +16,21 @@ function loaded() {

if (!attr) return;

const props = JSON.parse(attr);
const props = JSON.parse(attr) as object;
const root = createRoot(mountNode);

root.render(<ComposeContainer {...props} />);
}
}

function main() {
ready(loaded);
ready(loaded).catch((error: unknown) => {
console.error(error);
});
}

loadPolyfills().then(main).catch(error => {
console.error(error);
});
loadPolyfills()
.then(main)
.catch((error: unknown) => {
console.error(error);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"@types/redux-immutable": "^4.0.3",
"@types/requestidlecallback": "^0.3.5",
"@types/webpack": "^4.41.33",
"@types/webpack-env": "^1.18.4",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"babel-jest": "^29.5.0",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,7 @@ __metadata:
"@types/redux-immutable": "npm:^4.0.3"
"@types/requestidlecallback": "npm:^0.3.5"
"@types/webpack": "npm:^4.41.33"
"@types/webpack-env": "npm:^1.18.4"
"@typescript-eslint/eslint-plugin": "npm:^7.0.0"
"@typescript-eslint/parser": "npm:^7.0.0"
arrow-key-navigation: "npm:^1.2.0"
Expand Down Expand Up @@ -3990,6 +3991,13 @@ __metadata:
languageName: node
linkType: hard

"@types/webpack-env@npm:^1.18.4":
version: 1.18.4
resolution: "@types/webpack-env@npm:1.18.4"
checksum: 10c0/3fa77dbff0ed71685404576b0a1cf74587567fe2ee1cfd11d56d6eefcab7a61e4c9ead0eced264e289d2cf0fc74296dbd55ed6c95774fe0fd6264d156c5a59f0
languageName: node
linkType: hard

"@types/webpack-sources@npm:*":
version: 3.2.2
resolution: "@types/webpack-sources@npm:3.2.2"
Expand Down
Loading