From ec7b6d25e2f47bbd961ff62e7bbb747ee1e32b9f Mon Sep 17 00:00:00 2001 From: Peter van Gulik Date: Wed, 21 Aug 2024 17:58:56 +0200 Subject: [PATCH] fix: datapack filenames should not contain path seperators --- packages/vlocity-deploy/src/export/datapackExpander.ts | 10 +++++----- .../vlocity-deploy/src/export/exportDefinitionStore.ts | 4 ++-- .../vlocity-deploy/src/export/exportDefinitions.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vlocity-deploy/src/export/datapackExpander.ts b/packages/vlocity-deploy/src/export/datapackExpander.ts index c08db000..c2591f0f 100644 --- a/packages/vlocity-deploy/src/export/datapackExpander.ts +++ b/packages/vlocity-deploy/src/export/datapackExpander.ts @@ -76,13 +76,13 @@ export class DatapackExpander { scope: context?.scope }; - const baseSourceKey = substringAfter(datapack.VlocityRecordSourceKey, '/').replace(/\/+/g, '_'); + const baseSourceKey = substringAfter(datapack.VlocityRecordSourceKey, '/'); const fileNameFormat = this.definitions.getFileName(itemRef) ?? baseSourceKey; const baseName = this.evalPathFormat(fileNameFormat, { context: datapack }); const folderFormat = this.definitions.getFolder(itemRef) ?? baseSourceKey; const folder = path.join( - this.normalizePath(datapack.VlocityRecordSObjectType), + this.normalizeFileName(datapack.VlocityRecordSObjectType), this.evalPathFormat(folderFormat, { context: datapack }) ); @@ -163,13 +163,13 @@ export class DatapackExpander { const name = Array.isArray(format) ? format.map(f => f.startsWith('_') ? f.substring(1) : options?.context?.[f] ?? '').join('_') : (options?.context ? formatString(format, options?.context) : format); - return this.normalizePath(name, options?.defaultExt); + return this.normalizeFileName(name, options?.defaultExt); } - private normalizePath(path: string, extension?: string) { + private normalizeFileName(path: string, extension?: string) { const normalized = path.trim() + .replace(/[\s\\/]+/g, '-') .replace(/[^\s\w.\\/-]+/g, '') - .replace(/\s+/g, '-') .replace(/-+/g, '-'); if (extension) { return `${normalized}.${extension}`; diff --git a/packages/vlocity-deploy/src/export/exportDefinitionStore.ts b/packages/vlocity-deploy/src/export/exportDefinitionStore.ts index 9a362d2a..3ecd2184 100644 --- a/packages/vlocity-deploy/src/export/exportDefinitionStore.ts +++ b/packages/vlocity-deploy/src/export/exportDefinitionStore.ts @@ -1,5 +1,5 @@ import { injectable } from "@vlocode/core"; -import { merge, withDefaults } from "@vlocode/util"; +import { merge } from "@vlocode/util"; import { ObjectRef } from "./datapackExporter"; import { DatapackExportDefinition, ExportFieldDefinition, ObjectFilter, ObjectRelationship } from "./exportDefinitions"; @@ -189,7 +189,7 @@ export class DatapackExportDefinitionStore { } public getFolder(item: ObjectRef) { - return this.get(item, 'folder'); + return this.get(item, 'folderName'); } public isAutoGeneratedMatchingKey(item: ObjectRef) { diff --git a/packages/vlocity-deploy/src/export/exportDefinitions.ts b/packages/vlocity-deploy/src/export/exportDefinitions.ts index 6eed9f9e..6dc63716 100644 --- a/packages/vlocity-deploy/src/export/exportDefinitions.ts +++ b/packages/vlocity-deploy/src/export/exportDefinitions.ts @@ -20,7 +20,7 @@ export interface DatapackExportDefinition extends ExpandFileDefinition { * ``` * All exported fields are written to this file in JSON format and '.json' is appended to the file name if no extension is provided. */ - folder?: string | string[]; + folderName?: string | string[]; /** * Type of SObject to export */