Skip to content

Commit

Permalink
Improved blazor dependency loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Aug 22, 2023
1 parent 030a18f commit 11a570f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed issue with `loader-utils` version
- Updated `importmap` with `exclude` key allowing exclusions
- Added support for `dependencySymbols` in `piral-blazor`

## 1.1.0 (July 25, 2023)

Expand Down
13 changes: 9 additions & 4 deletions src/converters/piral-blazor/src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import type { BlazorDependencyLoader, BlazorRootConfig } from './types';
const loadedDependencies = (window.$blazorDependencies ??= []);
const depsWithPrios = (window.$blazorDependencyPrios ??= []);

function toPdb(url: string) {
const front = url.substring(0, url.length - 4);
return `${front}.pdb`;
}

export function createDependencyLoader(convert: ReturnType<typeof createConverter>) {
const definedBlazorReferences: Array<string> = [];
const loadedBlazorPilets: Array<string> = [];
Expand Down Expand Up @@ -41,9 +46,8 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte

const dependencies = references.filter((m) => m.endsWith('.dll'));
const dllUrl = dependencies.pop();
const piletName = dllUrl.substring(0, dllUrl.length - 4);
const piletPdb = `${piletName}.pdb`;
const pdbUrl = references.find((m) => m === piletPdb);
const pdbUrl = toPdb(dllUrl);
const dependencySymbols = dependencies.map(toPdb).filter(dep => references.includes(dep));
const id = Math.random().toString(26).substring(2);

await loadBlazorPilet(id, {
Expand All @@ -52,9 +56,10 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte
config: JSON.stringify(meta.config || {}),
baseUrl: meta.basePath || dllUrl.substring(0, dllUrl.lastIndexOf('/')).replace('/_framework/', '/'),
dependencies,
dependencySymbols: capabilities.includes('dependency-symbols') ? dependencySymbols : undefined,
satellites,
dllUrl,
pdbUrl,
pdbUrl: references.includes(pdbUrl) ? pdbUrl : undefined,
});

loadedBlazorPilets.push(id);
Expand Down
1 change: 1 addition & 0 deletions src/converters/piral-blazor/src/interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export interface PiletData {
baseUrl: string;
satellites?: Record<string, Array<string>>;
dependencies: Array<string>;
dependencySymbols?: Array<string>;
}

export function loadBlazorPilet(id: string, data: PiletData) {
Expand Down

0 comments on commit 11a570f

Please sign in to comment.