@lwrjs/app-service
Advanced tools
Comparing version 0.0.2-alpha17 to 0.0.2-alpha18
@@ -11,3 +11,3 @@ "use strict"; | ||
function validateSpecifier(specifier) { | ||
return specifier.startsWith(shared_utils_1.BOOTSTRAP_NAMESPACE) || specifier.startsWith(shared_utils_1.VIEW_NAMESPACE); | ||
return specifier.startsWith(shared_utils_1.BOOTSTRAP_NAMESPACE); | ||
} | ||
@@ -26,9 +26,6 @@ class AppService { | ||
async getModuleEntry({ specifier }) { | ||
const appName = specifier.replace(`${shared_utils_1.BOOTSTRAP_NAMESPACE}/`, ''); | ||
const { appName } = shared_utils_1.parseSyntheticSpecifier(specifier); | ||
// Validate the root app module specifier | ||
// expected formats: | ||
// - @lwrjs/view/path | ||
// - @lwrjs/bootstrap/app/name | ||
if (specifier.startsWith(shared_utils_1.VIEW_NAMESPACE) || | ||
(specifier.startsWith(shared_utils_1.BOOTSTRAP_NAMESPACE) && appName === this.appContext.name)) { | ||
// expected format: @lwrjs/bootstrap/app/name[/path/{requestPath}] | ||
if (validateSpecifier(specifier) && appName === this.appContext.name) { | ||
const normalizedSpecifier = specifier.endsWith('/') ? `${specifier}index` : specifier; | ||
@@ -52,17 +49,18 @@ return { | ||
} | ||
// Generate the ABS module | ||
const { root } = this.appContext; | ||
const rootModules = []; | ||
// Get the array of root components in the view | ||
if (specifier.startsWith(shared_utils_1.VIEW_NAMESPACE)) { | ||
const requestPath = specifier.replace(shared_utils_1.VIEW_NAMESPACE, ''); | ||
const { metadata } = await this.viewRegistry.getRenderedView({ | ||
path: requestPath, | ||
requestPath, | ||
}, runtimeContext); | ||
rootModules.push(...metadata.customElements.map(shared_utils_1.kebabcaseToCamelcase)); | ||
// Get the array of root components in the view by request path | ||
// The ABS specifier is in form: "@lwrjs/bootstrap/{appName}[/path/{requestPath}]" | ||
const { requestPath = '/' } = shared_utils_1.parseSyntheticSpecifier(specifier); | ||
// TODO240: If missing, pull the path from config (by appName) | ||
const { metadata } = await this.viewRegistry.getRenderedView({ | ||
path: requestPath, | ||
requestPath, | ||
}, runtimeContext); | ||
const rootModules = metadata.customElements.map(shared_utils_1.kebabcaseToCamelcase); | ||
if (!rootModules.includes(this.appContext.root)) { | ||
// If the root application module is not included in the root module array, add it | ||
// This happens when the 'lwr-root' HTML property is used for root insertion (see init.ts) | ||
// TODO240: Pull "root" component (if it exists) from config (by appName) | ||
rootModules.unshift(this.appContext.root); | ||
} | ||
else { | ||
rootModules.push(root); | ||
} | ||
// Generate ABS module | ||
const originalSource = await utils_1.createVirtualSource(rootModules, this.appContext, runtimeContext.format, this.moduleRegistry); | ||
@@ -69,0 +67,0 @@ return { |
@@ -24,16 +24,17 @@ "use strict"; | ||
const { mode, format } = context; | ||
const { name: appName, root: appRoot, workers, loaderServices, autoBoot = true } = this.appContext; | ||
const { name: configuredAppName, root: appRoot, workers, loaderServices, autoBoot = true, } = this.appContext; | ||
const { type, appName } = shared_utils_1.parseSyntheticSpecifier(specifier); | ||
// Reject the request if the app name (from config) or version (from package.json) do not match | ||
if (appName !== configuredAppName || version !== this.version) { | ||
return; | ||
} | ||
// Check if the resource is JSON for an app | ||
// expected format: @lwrjs/json/my/app | ||
const jsonSpecifier = specifier.replace(`${shared_utils_1.JSON_NAMESPACE}/`, ''); | ||
if (specifier.startsWith(shared_utils_1.JSON_NAMESPACE) && jsonSpecifier === appName && version === this.version) { | ||
return await utils_1.createJsonSource({ appName, appRoot, workers, version: this.version }, this.moduleRegistry, this.resourceRegistry, context); | ||
// expected format: @lwrjs/json/{appName}[/path/{requestPath}] | ||
if (type === shared_utils_1.JSON_NAMESPACE) { | ||
return await utils_1.createJsonSource({ specifier, appRoot, workers, version: this.version }, context, this.moduleRegistry, this.resourceRegistry); | ||
} | ||
// Check if the resource is a Client Bootstrap Config | ||
// expected format: @lwrjs/config/my/app | ||
const configSpecifier = specifier.replace(`${shared_utils_1.CONFIG_NAMESPACE}/`, ''); | ||
if (specifier.startsWith(shared_utils_1.CONFIG_NAMESPACE) && | ||
configSpecifier === appName && | ||
version === this.version) { | ||
return await utils_1.createBootstrapConfig({ appName, appRoot, mode, format, loaderServices, autoBoot, version: this.version }, context, this.moduleRegistry); | ||
// expected format: @lwrjs/config/{appName}[/path/{requestPath}] | ||
if (type === shared_utils_1.CONFIG_NAMESPACE) { | ||
return await utils_1.createBootstrapConfig({ specifier, mode, format, loaderServices, autoBoot }, context, this.moduleRegistry); | ||
} | ||
@@ -40,0 +41,0 @@ } |
import { BootstrapRuntimeContext, PublicModuleRegistry, PublicResourceRegistry, ResourceDefinition, RuntimeContext } from '@lwrjs/types'; | ||
interface ConfigContext { | ||
appName: string; | ||
appRoot: string; | ||
specifier: string; | ||
mode: string; | ||
format: string; | ||
version: string; | ||
autoBoot: boolean; | ||
@@ -19,3 +17,3 @@ loaderServices: string[]; | ||
interface JsonContext { | ||
appName: string; | ||
specifier: string; | ||
appRoot: string; | ||
@@ -35,4 +33,4 @@ workers: { | ||
*/ | ||
export declare function createJsonSource({ appName, appRoot, workers: workerSpecifiers, version }: JsonContext, moduleRegistry: PublicModuleRegistry, resourceRegistry: PublicResourceRegistry, context: RuntimeContext): Promise<ResourceDefinition>; | ||
export declare function createJsonSource({ specifier, appRoot, workers: workerSpecifiers, version }: JsonContext, context: RuntimeContext, moduleRegistry: PublicModuleRegistry, resourceRegistry: PublicResourceRegistry): Promise<ResourceDefinition>; | ||
export {}; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -21,7 +21,7 @@ "use strict"; | ||
async function createBootstrapConfig(context, runtimeContext, moduleRegistry) { | ||
const { appName, mode, format, autoBoot, loaderServices } = context; | ||
const { specifier, mode, format, autoBoot, loaderServices } = context; | ||
let loaderConfigStr = ''; | ||
if (format === 'amd') { | ||
// Build specifiers for the ABS module and Root App Component | ||
const bootstrapSpecifier = await shared_utils_1.getVersionedSpecifier(`${shared_utils_1.BOOTSTRAP_NAMESPACE}/${appName}`, moduleRegistry); | ||
const bootstrapSpecifier = await shared_utils_1.getVersionedSpecifier(specifier.replace(shared_utils_1.CONFIG_NAMESPACE, shared_utils_1.BOOTSTRAP_NAMESPACE), moduleRegistry); | ||
// If loader services/hooks are used, add all ABS module dependencies to requiredModules[] | ||
@@ -48,3 +48,3 @@ let requiredModules = []; | ||
return { | ||
specifier: `${shared_utils_1.CONFIG_NAMESPACE}/${appName}`, | ||
specifier, | ||
type: 'application/javascript', | ||
@@ -91,3 +91,3 @@ defer: true, | ||
*/ | ||
async function createJsonSource({ appName, appRoot, workers: workerSpecifiers, version }, moduleRegistry, resourceRegistry, context) { | ||
async function createJsonSource({ specifier, appRoot, workers: workerSpecifiers, version }, context, moduleRegistry, resourceRegistry) { | ||
// Build the workers object | ||
@@ -100,3 +100,3 @@ const workers = {}; | ||
const [bootstrapModule, rootComponent] = await Promise.all([ | ||
createJsonModule(`${shared_utils_1.BOOTSTRAP_NAMESPACE}/${appName}`, moduleRegistry, context), | ||
createJsonModule(specifier.replace(shared_utils_1.JSON_NAMESPACE, shared_utils_1.BOOTSTRAP_NAMESPACE), moduleRegistry, context), | ||
createJsonModule(appRoot, moduleRegistry, context), | ||
@@ -107,3 +107,3 @@ ]); | ||
// Client Bootstrap Config resource | ||
createJsonResource(`${shared_utils_1.CONFIG_NAMESPACE}/${appName}`, version, 'application/javascript', resourceRegistry, context), | ||
createJsonResource(specifier.replace(shared_utils_1.JSON_NAMESPACE, shared_utils_1.CONFIG_NAMESPACE), version, 'application/javascript', resourceRegistry, context), | ||
], | ||
@@ -121,3 +121,3 @@ // Application bootstrap module and root application component | ||
// Import Metadata resource | ||
createJsonResource(`${shared_utils_1.MAPPING_NAMESPACE}/${appName}`, version, 'application/javascript', resourceRegistry, context)); | ||
createJsonResource(specifier.replace(shared_utils_1.JSON_NAMESPACE, shared_utils_1.MAPPING_NAMESPACE), version, 'application/javascript', resourceRegistry, context)); | ||
} | ||
@@ -128,3 +128,3 @@ // Hash the JSON content | ||
return { | ||
specifier: `${shared_utils_1.JSON_NAMESPACE}/${appName}`, | ||
specifier, | ||
type: 'application/json', | ||
@@ -131,0 +131,0 @@ content: JSON.stringify(json), |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.2-alpha17", | ||
"version": "0.0.2-alpha18", | ||
"homepage": "https://lwr.dev/", | ||
@@ -27,5 +27,5 @@ "repository": { | ||
"dependencies": { | ||
"@lwrjs/shared-utils": "0.0.2-alpha17" | ||
"@lwrjs/shared-utils": "0.0.2-alpha18" | ||
}, | ||
"gitHead": "462556b16ca6b92f24becb361e510aa1a805e28b" | ||
"gitHead": "9cf922f2e624d3255ab89d39a019be4e88793c61" | ||
} |
20495
396
+ Added@lwrjs/shared-utils@0.0.2-alpha18(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
- Removed@lwrjs/shared-utils@0.0.2-alpha17(transitive)