Skip to content

Commit 5808635

Browse files
committed
Add resource path provider
1 parent 07aa1e4 commit 5808635

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

bootstrap.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
import { createPlatformFactory, COMPILER_OPTIONS } from 'https://jspm.dev/@angular/core@10.0.1';
1+
import { createPlatformFactory, Injector, COMPILER_OPTIONS, InjectionToken } from 'https://jspm.dev/@angular/core@10.0.1';
22
import { ɵplatformCoreDynamic } from 'https://jspm.dev/@angular/platform-browser-dynamic@10.0.1';
33
import { ResourceLoader } from 'https://jspm.dev/@angular/compiler@10.0.1';
44
import { INITIAL_CONFIG, ɵINTERNAL_SERVER_PLATFORM_PROVIDERS as INTERNAL_SERVER_PLATFORM_PROVIDERS } from './platform-server.mjs';
55
import { DenoFileSystemResourceLoader } from './resource-loader.ts';
66

7-
const platformDenoDynamicServer = createPlatformFactory(ɵplatformCoreDynamic, "serverDenoDynamic",
7+
export const RESOURCE_PATH = new InjectionToken('RESOURCE_PATH');
8+
9+
const platformDenoDynamicServer = (resourcePath: string) => createPlatformFactory(ɵplatformCoreDynamic, "serverDenoDynamic",
810
[...INTERNAL_SERVER_PLATFORM_PROVIDERS,
911
{
1012
provide: COMPILER_OPTIONS,
1113
useValue: {
1214
providers: [
15+
{
16+
provide: RESOURCE_PATH,
17+
useValue: resourcePath
18+
},
1319
{
1420
provide: ResourceLoader,
1521
useClass: DenoFileSystemResourceLoader,
22+
deps: [Injector]
1623
}
1724
]
1825
},
1926
multi: true
2027
}
2128
]);
2229

23-
export async function bootstrap(module: any, document: string, resourcePath?: string) {
24-
return Promise.resolve(platformDenoDynamicServer({
30+
export async function bootstrap(module: any, document: string, resourcePath: string = "") {
31+
return Promise.resolve(platformDenoDynamicServer(resourcePath)([
32+
{
2533
provide: INITIAL_CONFIG,
2634
useValue: {
2735
document,
28-
url: '/',
29-
resourcePath
36+
url: '/'
3037
}
31-
}).bootstrapModule(module, { ngZone: 'noop' }).then((ref: any) => {
32-
38+
}]).bootstrapModule(module, { ngZone: 'noop' }).then((ref: any) => {
3339
return Promise.resolve(ref)
3440
}));
3541
}

mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { CommonEngine } from './engine.ts';
22

3-
export { bootstrap } from './bootstrap.ts';
3+
export { bootstrap, RESOURCE_PATH } from './bootstrap.ts';
44

55
export { ServerModule } from './platform-server.mjs';

resource-loader.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { ResourceLoader, Optional } from 'https://jspm.dev/@angular/compiler@10.0.1';
1+
import { ResourceLoader } from 'https://jspm.dev/@angular/compiler@10.0.1';
2+
import { Injector } from 'https://jspm.dev/@angular/core@10.0.1';
23
import { join } from "https://deno.land/std@0.58.0/path/posix.ts";
3-
import { INITIAL_CONFIG } from './platform-server.mjs';
4+
import { RESOURCE_PATH } from './bootstrap.ts';
45

56
const { readFile } = Deno;
67
const decoder = new TextDecoder();
78

89
export class DenoFileSystemResourceLoader extends ResourceLoader {
910
private readonly filesCache: Map<string, string> = new Map<string, string>()
11+
private readonly resourcePath: string;
1012

11-
constructor(@Optional() private readonly config: INITIAL_CONFIG) {
13+
constructor(private readonly injector: Injector) {
1214
super();
15+
16+
this.resourcePath = this.injector.get(RESOURCE_PATH);
1317
}
1418

1519
resolve(url: string, baseUrl: string): string {
@@ -23,7 +27,9 @@ export class DenoFileSystemResourceLoader extends ResourceLoader {
2327
}
2428

2529
get(url: string, aa?: any): Promise<string> {
26-
const appDir = (this.config && this.config.resourcePath) || '';
30+
console.log(11,this.resourcePath);
31+
32+
const appDir = this.resourcePath || '';
2733
const filePath = this.resolve(url, appDir);
2834

2935
if (this.filesCache.has(filePath)) {

0 commit comments

Comments
 (0)