Skip to content

Commit c7d6815

Browse files
fix: introduce window modules
1 parent 3e3e295 commit c7d6815

File tree

6 files changed

+79
-10
lines changed

6 files changed

+79
-10
lines changed

fuse.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FuseBox, QuantumPlugin, JSONPlugin, RawPlugin } from 'fuse-box'
22
import { src, task } from 'fuse-box/sparky'
33
import { resolve } from 'path'
44
import { argv } from 'yargs'
5-
import { spawn } from 'child_process'
5+
import { execSync } from 'child_process'
66
import shabang from './tools/scripts/fuse-shebang'
77
// import { unlinkSync } from 'fs'
88

@@ -61,10 +61,9 @@ task('bundle', ['cp.jest', 'ng.modules'], () => {
6161

6262
task('ng.modules', () => {
6363
return new Promise((res, rej) => {
64-
const tsc = spawn(resolve('node_modules/.bin/ngc'), [
65-
'--p',
66-
resolve('src/modules/tsconfig.aot.json')
67-
])
68-
tsc.on('close', res)
64+
const tsc = execSync(
65+
resolve('node_modules/.bin/ngc --p src/modules/tsconfig.aot.json')
66+
).toString()
67+
return tsc ? rej() : res()
6968
})
7069
})

src/modules/http-cache-tag/http-cache-tag-interceptor.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
HttpHandler,
44
HttpInterceptor,
55
HttpRequest,
6-
HttpResponse
6+
HttpResponse,
7+
HttpEvent
78
} from '@angular/common/http'
89
import {
910
CACHE_TAG_CONFIG,
@@ -12,6 +13,7 @@ import {
1213
CacheTagConfig
1314
} from './http-cache-tag.server.module'
1415
import { map } from 'rxjs/operators'
16+
import { Observable } from 'rxjs'
1517

1618
// tslint:disable:no-class
1719
// tslint:disable:no-this
@@ -36,7 +38,10 @@ export class HttpCacheTagInterceptor implements HttpInterceptor {
3638
return this.config.cacheableUrls.test(url)
3739
}
3840

39-
intercept(req: HttpRequest<any>, next: HttpHandler) {
41+
intercept(
42+
req: HttpRequest<any>,
43+
next: HttpHandler
44+
): Observable<HttpEvent<any>> {
4045
return next.handle(req).pipe(
4146
map(event => {
4247
if (

src/modules/util/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { WINDOW } from './tokens'
22

3-
export { IWindowService, WindowService } from './window.service'
3+
export { IWindowService, WindowService } from './window/window.service'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
ModuleWithProviders,
3+
NgModule,
4+
Optional,
5+
SkipSelf
6+
} from '@angular/core'
7+
import { WINDOW } from '../tokens'
8+
import { WindowService } from './window.service'
9+
10+
// tslint:disable-next-line:no-class
11+
@NgModule()
12+
export class WindowBrowserModule {
13+
static forRoot(): ModuleWithProviders {
14+
return {
15+
ngModule: WindowBrowserModule,
16+
providers: [{ provide: WINDOW, useValue: window }, WindowService]
17+
}
18+
}
19+
20+
constructor(
21+
@Optional()
22+
@SkipSelf()
23+
parentModule: WindowBrowserModule
24+
) {
25+
// tslint:disable-next-line:no-if-statement
26+
if (parentModule)
27+
throw new Error(
28+
'WindowBrowserModule already loaded. Import in root module only.'
29+
)
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
ModuleWithProviders,
3+
NgModule,
4+
Optional,
5+
SkipSelf
6+
} from '@angular/core'
7+
import { WINDOW } from '../tokens'
8+
import { WindowService } from './window.service'
9+
10+
// tslint:disable-next-line:no-class
11+
@NgModule()
12+
export class WindowServerModule {
13+
static forRoot(windowObject: any): ModuleWithProviders {
14+
return {
15+
ngModule: WindowServerModule,
16+
providers: [
17+
{ provide: WINDOW, useValue: windowObject || {} },
18+
WindowService
19+
]
20+
}
21+
}
22+
23+
constructor(
24+
@Optional()
25+
@SkipSelf()
26+
parentModule: WindowServerModule
27+
) {
28+
// tslint:disable-next-line:no-if-statement
29+
if (parentModule)
30+
throw new Error(
31+
'WindowServerModule already loaded. Import in root module only.'
32+
)
33+
}
34+
}

src/modules/util/window.service.ts renamed to src/modules/util/window/window.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Injectable } from '@angular/core'
2-
import { WINDOW } from './tokens'
2+
import { WINDOW } from '../tokens'
33

44
export interface IWindowService {
55
readonly window: <T>() => Window & T

0 commit comments

Comments
 (0)