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

Migrate lifecycles folder to typescript #1210

Merged
merged 7 commits into from
Apr 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-rings-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"single-spa": minor
---

Migrate lifecycles folder to typescript
5 changes: 5 additions & 0 deletions .changeset/tasty-mirrors-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"single-spa": patch
---

Update eslint config for typescript
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": ["important-stuff"],
"parser": "@babel/eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"env": {
"browser": true,
"node": true
Expand All @@ -11,8 +14,6 @@
},
"plugins": ["es5"],
"rules": {
"es5/no-es6-methods": "error",
"es5/no-es6-static-methods": "error",
"es5/no-binary-and-octal-literals": "error",
"es5/no-classes": "error",
"es5/no-for-of": "error",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"test:lockfile": "js-correct-lockfile pnpm",
"format": "prettier --write .",
"check-format": "prettier --check .",
"lint": "eslint src",
"lint": "eslint src --ext .ts",
"postinstall": "husky install",
"prepublishOnly": "pinst --disable && pnpm run build",
"postpublish": "pinst --enable"
Expand Down Expand Up @@ -79,7 +79,6 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/eslint-parser": "^7.23.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.23.3",
Expand All @@ -92,6 +91,7 @@
"@rollup/plugin-replace": "^2.3.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/jest": "^26.0.23",
"@typescript-eslint/parser": "^7.5.0",
"babel-jest": "^29.7.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"concurrently": "^6.2.0",
Expand Down
158 changes: 132 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions src/applications/app-errors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { AppOrParcel } from "../lifecycles/lifecycle.helpers";
import {
AppOrParcelStatus,
InternalApplication,
objectType,
toName,
} from "./app.helpers";
import { AppOrParcelStatus, objectType, toName } from "./app.helpers";

let errorHandlers: ErrorHandler[] = [];

Expand All @@ -16,7 +11,7 @@ type ErrorHandler = (err: SingleSpaError) => any;

export function handleAppError(
err: Error,
app: InternalApplication,
app: AppOrParcel,
newStatus: AppOrParcelStatus
) {
const transformedErr = transformErr(err, app, newStatus);
Expand Down
25 changes: 16 additions & 9 deletions src/applications/app.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
ActivityFn,
AppOrParcel,
Application,
CustomProps,
InternalParcel,
LoadApp,
ParcelMap,
} from "../lifecycles/lifecycle.helpers";
import { handleAppError } from "./app-errors";
Expand Down Expand Up @@ -53,8 +55,10 @@ export function toName(app) {
return app.name;
}

export function isParcel(appOrParcel) {
return Boolean(appOrParcel.unmountThisParcel);
export function isParcel(
appOrParcel: AppOrParcel
): appOrParcel is InternalParcel {
return Boolean((appOrParcel as InternalParcel).unmountThisParcel);
}

export function objectType(appOrParcel: AppOrParcel): "parcel" | "application" {
Expand All @@ -64,17 +68,20 @@ export function objectType(appOrParcel: AppOrParcel): "parcel" | "application" {
export interface InternalApplication {
name: string;
activeWhen: ActivityFn;
loadApp: Application;
loadApp: LoadApp;
status: AppOrParcelStatus;
loadErrorTime: number;
parcels: ParcelMap;
customProps?: CustomProps;
// The ensureValidAppTimeouts function gets called once the app is loaded
timeouts?: AppOrParcelTimeouts;
devtools: {
overlays: {
options: OverlayOptions;
selectors: string[];
};
devtools: AppDevtools;
}

export interface AppDevtools {
overlays: {
options: OverlayOptions;
selectors: string[];
};
}

Expand Down