Skip to content

Commit af94e15

Browse files
committed
feat(nf): support assets for dev server
1 parent 4b88da8 commit af94e15

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

libs/native-federation-core/src/lib/core/default-skip-list.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const DEFAULT_SKIP_LIST: SkipList = [
1515
'@angular/localize',
1616
'@angular/localize/init',
1717
'@angular/localize/tools',
18+
'@angular/platform-server',
19+
'@angular/platform-server/init',
20+
'@angular/ssr',
21+
'express',
1822
/\/schematics(\/|$)/,
1923
(pkg) => pkg.startsWith('@angular/') && !!pkg.match(/\/testing(\/|$)/),
2024
(pkg) => pkg.startsWith('@types/'),

libs/native-federation/src/builders/build/builder.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,14 @@ import {
3232
} from '../../utils/dev-server';
3333
import { RebuildHubs } from '../../utils/rebuild-events';
3434
import { updateIndexHtml } from '../../utils/updateIndexHtml';
35-
import { appendFileSync, existsSync, mkdirSync } from 'fs';
35+
import { existsSync, mkdirSync } from 'fs';
3636
import {
3737
EsBuildResult,
3838
MemResults,
3939
NgCliAssetResult,
4040
} from '../../utils/mem-resuts';
4141
import { JsonObject } from '@angular-devkit/core';
4242

43-
function log(...args) {
44-
const msg = args.join(' ');
45-
appendFileSync('c:/temp/log.txt', msg + '\n');
46-
console.log(args);
47-
}
48-
4943
export async function* runBuilder(
5044
nfOptions: NfBuilderSchema,
5145
context: BuilderContext
@@ -123,7 +117,6 @@ export async function* runBuilder(
123117
write,
124118
})) {
125119
lastResult = output;
126-
yield output;
127120

128121
if (!output.success) {
129122
setError('Compilation Error');
@@ -159,6 +152,10 @@ export async function* runBuilder(
159152
reloadBrowser();
160153
}
161154

155+
if (!runServer) {
156+
yield output;
157+
}
158+
162159
if (!first && watch) {
163160
setTimeout(async () => {
164161
logger.info('Rebuilding federation artefacts ...');

libs/native-federation/src/utils/angular-esbuild-adapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ function writeResult(
338338
writtenFiles.push(filePath);
339339
}
340340

341+
if (!memOnly) {
342+
// for (const asset of result.outputFiles)
343+
}
344+
341345
return writtenFiles;
342346
}
343347

libs/native-federation/src/utils/dev-server.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import * as browserSync from 'browser-sync';
22
import { NfBuilderSchema } from '../builders/build/schema';
33
import { BuildResult, MemResults } from './mem-resuts';
4-
import { appendFileSync } from 'fs';
5-
import { basename, extname } from 'path';
4+
import { extname } from 'path';
65
import { lookup } from 'mrmime';
76
import { updateScriptTags } from './updateIndexHtml';
87

98
let server: browserSync.BrowserSyncInstance;
109

11-
function log(...args) {
12-
const msg = args.join(' ');
13-
appendFileSync('c:/temp/log.txt', msg + '\n');
14-
console.log(args);
15-
}
16-
1710
export function startServer(
1811
options: NfBuilderSchema,
1912
path: string,
@@ -33,7 +26,7 @@ export function startServer(
3326
open: options.open,
3427
middleware: [
3528
function (req, res, next) {
36-
const key = basename(req.url || '');
29+
const key = req.url.startsWith('/') ? req.url.substring(1) : req.url;
3730
const result = memResults.get(key);
3831

3932
if (result) {

libs/native-federation/src/utils/mem-resuts.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export interface BuildResult {
88
}
99

1010
export class EsBuildResult implements BuildResult {
11-
public fileName: string;
12-
13-
constructor(private outputFile: OutputFile) {
14-
this.fileName = outputFile.path;
11+
get fileName() {
12+
return basename(this.outputFile.path);
1513
}
1614

15+
constructor(private outputFile: OutputFile) {}
16+
1717
get(): Uint8Array {
1818
return this.outputFile.contents;
1919
}
@@ -26,7 +26,7 @@ export interface NgCliAssetFile {
2626

2727
export class NgCliAssetResult implements BuildResult {
2828
public get fileName(): string {
29-
return this.file.source;
29+
return unify(this.file.destination);
3030
}
3131

3232
private file: NgCliAssetFile;
@@ -45,7 +45,7 @@ export class MemResults {
4545

4646
public add(result: BuildResult[]): void {
4747
for (const file of result) {
48-
this.map.set(basename(file.fileName), file);
48+
this.map.set(file.fileName, file);
4949
}
5050
}
5151

@@ -57,3 +57,7 @@ export class MemResults {
5757
return [...this.map.keys()];
5858
}
5959
}
60+
61+
function unify(path) {
62+
return path?.replace(/\\/g, '/');
63+
}

0 commit comments

Comments
 (0)