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

chore: format all files with prettier #164

Merged
merged 1 commit into from
Apr 10, 2020
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
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
lib
parcel
node_modules
.gitignore
.prettierignore
.gitkeep
.npmignore
.editorconfig
*.template
yarn.lock
yarn-error.log
LICENSE
browserslist
*.ico
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
See https://github.com/single-spa/single-spa-angular/releases.
See https://github.com/single-spa/single-spa-angular/releases.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ npm link single-spa-angular
## Now try things out!
ng build
ng serve
```
```
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# single-spa-angular

Helpers for building [single-spa](https://github.com/single-spa/single-spa) applications which use Angular.

This lets you have multiple Angular microfrontends coexist within the same page.

[Join the #angular channel in single-spa's slack workspace](https://join.slack.com/t/single-spa/shared_invite/enQtMzIwMTcxNTU3ODQyLTM1Y2U1OWMzNTNjOWYyZDBlMDJhN2VkYzk3MDI2NzQ2Nzg0MzMzNjVhNWE2YjVhMTcxNjFkOWYzMjllMmUxMjk)

## Documentation
See [documentation on single-spa.js.org](https://single-spa.js.org/docs/ecosystem-angular.html).

See [documentation on single-spa.js.org](https://single-spa.js.org/docs/ecosystem-angular.html).
5 changes: 1 addition & 4 deletions cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"video": false,
"responseTimeout": 60000,
"pageLoadTimeout": 120000,
"ignoreTestFiles": [
"**/plugins/**.js",
"**/tsconfig.json"
]
"ignoreTestFiles": ["**/plugins/**.js", "**/tsconfig.json"]
}
17 changes: 3 additions & 14 deletions integration/portal/src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@ import { IS_PRODUCTION } from './config';
type Resolve = () => void;
type Reject = (error: ErrorEvent) => void;

function createScriptElement(
resolve: Resolve,
reject: Reject
): HTMLScriptElement {
function createScriptElement(resolve: Resolve, reject: Reject): HTMLScriptElement {
const script = document.createElement('script');
script.addEventListener('load', () => resolve());
script.addEventListener('error', error => reject(error));
return script;
}

function loadScriptUsingDefaultFileName(
url: string,
resolve: Resolve,
reject: Reject
): void {
function loadScriptUsingDefaultFileName(url: string, resolve: Resolve, reject: Reject): void {
const script = createScriptElement(resolve, reject);
script.src = `${url}/main.js`;
document.head.appendChild(script);
}

function loadAngularScriptsInProductionMode(
url: string,
resolve: Resolve,
reject: Reject
): void {
function loadAngularScriptsInProductionMode(url: string, resolve: Resolve, reject: Reject): void {
const moduleScript = createScriptElement(resolve, reject);
moduleScript.type = 'module';
moduleScript.src = `${url}/main-es2015.js`;
Expand Down
2 changes: 1 addition & 1 deletion integration/portal/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ registerApplication(
await loadAngularScript(SHOP_APP_URL);
return window.shop;
},
() => true
() => true,
);

start();
9 changes: 2 additions & 7 deletions integration/shop/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
]
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"]
},
"configurations": {
"production": {
Expand Down
2 changes: 1 addition & 1 deletion integration/shop/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const routes: Routes = [
path: 'transmission/:id',
loadChildren: () =>
import('./pages/transmission-details/transmission-details.module').then(
m => m.TransmissionDetailsModule
m => m.TransmissionDetailsModule,
),
},
];
Expand Down
2 changes: 1 addition & 1 deletion integration/shop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'shop-root',
templateUrl: './app.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
title = 'shop';
Expand Down
2 changes: 1 addition & 1 deletion integration/shop/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const environment = {
production: true
production: true,
};
2 changes: 1 addition & 1 deletion integration/shop/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
};

/*
Expand Down
22 changes: 11 additions & 11 deletions integration/shop/src/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AngularShop</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<shop-root></shop-root>
</body>
<head>
<meta charset="utf-8" />
<title>AngularShop</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<shop-root></shop-root>
</body>
</html>
3 changes: 2 additions & 1 deletion integration/shop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ if (environment.production) {
enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.error(err));
3 changes: 1 addition & 2 deletions integration/shop/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.

import 'zone.js/dist/zone'; // Included with Angular CLI.

/***************************************************************************************************
* APPLICATION IMPORTS
Expand Down
8 changes: 2 additions & 6 deletions integration/shop/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
"compilerOptions": {
"types": ["node"]
},
"files": [
"src/main.single-spa.ts"
],
"include": [
"src/**/*.d.ts"
]
"files": ["src/main.single-spa.ts"],
"include": ["src/**/*.d.ts"]
}
2 changes: 1 addition & 1 deletion integration/shop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"declaration": false,
"importHelpers": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"experimentalDecorators": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
Expand Down
5 changes: 1 addition & 4 deletions integration/shop/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import singleSpaAngularWebpack from '../../src/webpack';

export default (angularWebpackConfig, options) => {
const singleSpaWebpackConfig = singleSpaAngularWebpack(
angularWebpackConfig,
options
);
const singleSpaWebpackConfig = singleSpaAngularWebpack(angularWebpackConfig, options);

singleSpaWebpackConfig.output.library = 'shop';

Expand Down
5 changes: 1 addition & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: [
'/node_modules/',
'/lib/'
],
testPathIgnorePatterns: ['/node_modules/', '/lib/'],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"parcel": "ngc -p tsconfig.parcel.json",
"spa": "tsc -p tsconfig.spa.json",
"build:webpack": "tsc -p tsconfig.node.json",
"format": "prettier './**/*' --write",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the command I ran to format all these files

"// - INTEGRATION INSTALLS": "Install packages for integration apps",
"install:integration:shop": "yarn --cwd integration/shop install",
"install:integration:portal": "yarn --cwd integration/portal install",
Expand Down
8 changes: 4 additions & 4 deletions src/browser-lib/parcel-lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NgModule } from "@angular/core";
import { ParcelComponent } from "./parcel.component";
import { NgModule } from '@angular/core';
import { ParcelComponent } from './parcel.component';

@NgModule({
declarations: [ParcelComponent],
exports: [ParcelComponent],
entryComponents: [ParcelComponent]
entryComponents: [ParcelComponent],
})
export class ParcelModule { }
export class ParcelModule {}
60 changes: 33 additions & 27 deletions src/browser-lib/parcel-lib/parcel.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Component, OnInit, OnDestroy, Input, OnChanges, ViewChild, ElementRef } from '@angular/core';
import {
Component,
OnInit,
OnDestroy,
Input,
OnChanges,
ViewChild,
ElementRef,
} from '@angular/core';
import { Parcel, ParcelConfig } from 'single-spa';


@Component({
selector: 'parcel',
template: `
<div #parcelDiv></div>
`
template: ` <div #parcelDiv></div> `,
})
export class ParcelComponent implements OnInit, OnDestroy, OnChanges {
@ViewChild('parcelDiv') parcelDiv: ElementRef;
Expand All @@ -18,19 +23,19 @@ export class ParcelComponent implements OnInit, OnDestroy, OnChanges {
@Input() appendTo: any;
@Input() handleError = err => console.error(err);


createdDomElement: any;
hasError: boolean;
unmounted: any;
nextThingToDo: Promise<any>;
parcel: Parcel;

constructor() {
}
constructor() {}

ngOnInit() {
if (!this.config) {
throw new Error(`single-spa-angular's Parcel component requires the 'config' prop to either be a parcel config or a loading function that returns a promise. See https://github.com/CanopyTax/single-spa-angular`)
throw new Error(
`single-spa-angular's Parcel component requires the 'config' prop to either be a parcel config or a loading function that returns a promise. See https://github.com/CanopyTax/single-spa-angular`,
);
}

this.addThingToDo('mount', () => {
Expand Down Expand Up @@ -58,63 +63,64 @@ export class ParcelComponent implements OnInit, OnDestroy, OnChanges {
}
this.unmounted = false;
return this.parcel.mountPromise;
})
});
}

ngOnChanges() {
this.addThingToDo('update', () => {
if (this.parcel && this.parcel.update) {
return this.parcel.update(this.customProps)
return this.parcel.update(this.customProps);
}
})
});
}

ngOnDestroy() {
this.addThingToDo('unmount', () => {
if (this.parcel && this.parcel.getStatus() === "MOUNTED") {
return this.parcel.unmount()
if (this.parcel && this.parcel.getStatus() === 'MOUNTED') {
return this.parcel.unmount();
}
})
});

if (this.createdDomElement) {
this.createdDomElement.parentNode.removeChild(this.createdDomElement)
this.createdDomElement.parentNode.removeChild(this.createdDomElement);
}

this.unmounted = true
this.unmounted = true;
}

addThingToDo(action, thing) {
if (this.hasError && action !== 'unmount') {
// In an error state, we don't do anything anymore except for unmounting
return
return;
}

this.nextThingToDo = (this.nextThingToDo || Promise.resolve())
.then((...args) => {
if (this.unmounted && action !== 'unmount') {
// Never do anything once the angular component unmounts
return
return;
}

return thing(...args)
return thing(...args);
})
.catch(err => {
this.nextThingToDo = Promise.resolve() // reset so we don't .then() the bad promise again
this.nextThingToDo = Promise.resolve(); // reset so we don't .then() the bad promise again
this.hasError = true;

if (err && err.message) {
err.message = `During '${action}', parcel threw an error: ${err.message}`
err.message = `During '${action}', parcel threw an error: ${err.message}`;
}

if (this.handleError) {
this.handleError(err)
this.handleError(err);
} else {
setTimeout(() => { throw err })
setTimeout(() => {
throw err;
});
}

// No more things to do should be done -- the parcel is in an error state
throw err
})
throw err;
});
}

}