Skip to content
5 changes: 5 additions & 0 deletions .changeset/khaki-mice-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/preview-middleware': patch
---

fix loading i18n bundle for CAP projects
37 changes: 11 additions & 26 deletions packages/preview-middleware/src/base/flp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export class FlpSandbox {
resources: Record<string, string> = {},
adp?: AdpPreview
): Promise<void> {
this.projectType = await getProjectType(await findProjectRoot(process.cwd(), true, true));
const appRoot = await findProjectRoot(process.cwd(), false, true);
this.projectType = await getProjectType(appRoot);
this.createFlexHandler();
this.flpConfig.libs ??= await this.hasLocateReuseLibsScript();
const id = manifest['sap.app']?.id ?? '';
Expand All @@ -169,7 +170,7 @@ export class FlpSandbox {
{
componentId,
target: resources[componentId ?? id] ?? this.templateConfig.basePath,
local: '.',
local: appRoot,
intent: this.flpConfig.intent
},
this.logger
Expand Down Expand Up @@ -221,21 +222,21 @@ export class FlpSandbox {
return new Map([
// Run application in design time mode
// Adds bindingString to BindingInfo objects. Required to create and read PropertyBinding changes
['xx-designMode', 'true'],
['data-sap-ui-xx-designMode', 'true'],
// In design mode, the controller code will not be executed by default, which is not desired in our case, so we suppress the deactivation
['xx-suppressDeactivationOfControllerCode', 'true'],
['data-sap-ui-xx-suppressDeactivationOfControllerCode', 'true'],
// Make sure that XML preprocessing results are correctly invalidated
['xx-viewCache', 'false']
['data-sap-ui-xx-viewCache', 'false']
]);
} else {
return new Map([
// Run application in design time mode
// Adds bindingString to BindingInfo objects. Required to create and read PropertyBinding changes
['xx-design-mode', 'true'],
['data-sap-ui-xx-design-mode', 'true'],
// In design mode, the controller code will not be executed by default, which is not desired in our case, so we suppress the deactivation
['xx-suppress-deactivation-of-controller-code', 'true'],
['data-sap-ui-xx-suppress-deactivation-of-controller-code', 'true'],
// Make sure that XML preprocessing results are correctly invalidated
['xx-view-cache', 'false']
['data-sap-ui-xx-view-cache', 'false']
]);
}
}
Expand Down Expand Up @@ -1127,29 +1128,13 @@ export class FlpSandbox {
}

/**
* Creates an attribute string that can be added to an HTML element.
*
* @param attributes map with attributes and their values
* @param indent indentation that's inserted before each attribute
* @param prefix value that should be added at the start of to all attribute names
* @returns attribute string
*/
function serializeDataAttributes(attributes: Map<string, string>, indent = '', prefix = 'data'): string {
return [...attributes.entries()]
.map(([name, value]) => {
return `${indent}${prefix}-${name}="${value}"`;
})
.join('\n');
}

/**
* Creates an attribute string that can be added to bootstrap script in a HTML file.
* Creates an attribute string that can be added to the UI5 bootstrap script of an HTML file.
*
* @param config ui5 configuration options
* @returns attribute string
*/
function serializeUi5Configuration(config: Map<string, string>): string {
return '\n' + serializeDataAttributes(config, ' ', 'data-sap-ui');
return '\n' + [...config.entries()].map(([name, value]) => ` ${name}="${value}"`).join('\n');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/preview-middleware/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export interface Intent {
*/
export interface App {
target: string;
/**
* Either a local path to a folder containing the application or the componentId of a remote app
*/
local?: string;
/**
* Optional component id if it differs from the manifest (e.g. for adaptation projects)
Expand Down
2 changes: 1 addition & 1 deletion packages/preview-middleware/test/unit/base/flp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createPropertiesI18nEntries } from '@sap-ux/i18n';
//@ts-expect-error: this import is not relevant for the 'erasableSyntaxOnly' check
import connect = require('connect');

jest.spyOn(projectAccess, 'findProjectRoot').mockImplementation(() => Promise.resolve(''));
jest.spyOn(projectAccess, 'findProjectRoot').mockImplementation(() => Promise.resolve(process.cwd()));
jest.spyOn(projectAccess, 'getProjectType').mockImplementation(() => Promise.resolve('EDMXBackend'));

jest.mock('@sap-ux/adp-tooling', () => {
Expand Down
Loading