@sap-ux/fiori-migration-writer 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ export declare class BulkProjectMigrator {
8
8
  * @param vscode
9
9
  * @param internalToggle
10
10
  */
11
- migrate(projects: MigrationUIProjectInfo[], ui5SnapshotUrl: string, vscode?: any, internalToggle?: boolean): Promise<MigrationUIProjectInfo[]>;
11
+ migrate(projects: MigrationUIProjectInfo[], ui5SnapshotUrl?: string, vscode?: any, internalToggle?: boolean): Promise<MigrationUIProjectInfo[]>;
12
12
  /**
13
13
  * Migrate a single project
14
14
  *
@@ -2,6 +2,7 @@ import { ProjectMigrator } from './ProjectMigrator.js';
2
2
  import { URI } from 'vscode-uri';
3
3
  import { i18nText } from './i18n.js';
4
4
  import { createMemFsEditor } from './utils/fs-adapter.js';
5
+ import { commitFileSystemChanges } from './files/file-system.js';
5
6
  // Telemetry stub - @sap-ux/telemetry is an optional dependency for performance measurement
6
7
  // This provides a no-op implementation for open-source usage
7
8
  const uxTelemetryPerf = {
@@ -64,16 +65,7 @@ export class BulkProjectMigrator {
64
65
  // Commit changes to disk for this project
65
66
  if (result) {
66
67
  try {
67
- await new Promise((resolve, reject) => {
68
- fs.commit((err) => {
69
- if (err) {
70
- reject(err);
71
- }
72
- else {
73
- resolve();
74
- }
75
- });
76
- });
68
+ await commitFileSystemChanges(fs);
77
69
  }
78
70
  catch (error) {
79
71
  // Handle both callback errors and synchronous throws from fs.commit
@@ -9,7 +9,7 @@ export interface MigrateOptions {
9
9
  /** Base URI for backend services */
10
10
  baseUri: string;
11
11
  /** URL for UI5 snapshot version */
12
- ui5SnapshotUrl: string;
12
+ ui5SnapshotUrl?: string;
13
13
  /** Optional partial project information */
14
14
  importProjectInfo?: Partial<ImportProjectInfo>;
15
15
  /** Optional VS Code context */
@@ -5,11 +5,11 @@ import { ui5VersionRequestInfo } from '@sap-ux/ui5-info';
5
5
  import { getAppProgrammingLanguage } from '@sap-ux/project-access';
6
6
  import { enableTypescript, ui5TSSupport } from '@sap-ux/ui5-application-writer';
7
7
  import { UI5Config } from '@sap-ux/ui5-config';
8
- import { join } from 'node:path';
8
+ import { join, resolve } from 'node:path';
9
9
  // Migration-specific functions
10
10
  import { determineSourceTemplateType, checkForErrors, createMigrationErrorMessage, prepareConfigurationData, setupProjectStructure, generateAppSettings, applyAllTemplates, postProcessMigration } from './migration-process/index.js';
11
11
  // File operations
12
- import { copyAdaptationFiles, copyLibraryFiles } from './files/index.js';
12
+ import { copyAdaptationFiles, copyLibraryFiles, commitFileSystemChanges } from './files/index.js';
13
13
  // Template functions
14
14
  import { assembleTemplateData } from './template/index.js';
15
15
  // Project functions
@@ -27,7 +27,9 @@ export class ProjectMigrator {
27
27
  * @returns Promise with fs editor, migration result, and messages
28
28
  */
29
29
  static async migrate(options) {
30
- const { projectRoot, baseUri: baseUriOpt, ui5SnapshotUrl: ui5SnapshotUrlOpt, importProjectInfo: importProjectInfoOpt, vscode: vscodeOpt, internalToggle: internalToggleOpt = false, fs: fsOpt, strict: strictOpt = false } = options;
30
+ const { projectRoot: projectRootInput, baseUri: baseUriOpt, ui5SnapshotUrl: ui5SnapshotUrlOpt, importProjectInfo: importProjectInfoOpt, vscode: vscodeOpt, internalToggle: internalToggleOpt = false, fs: fsOpt, strict: strictOpt = false } = options;
31
+ // Resolve relative paths to absolute to avoid issues with path traversal
32
+ const projectRoot = resolve(projectRootInput);
31
33
  // Create a new isolated editor instance for this migration if not provided
32
34
  // This enables concurrent migrations without shared state corruption
33
35
  const ownsEditor = !fsOpt;
@@ -42,6 +44,9 @@ export class ProjectMigrator {
42
44
  // Load or fetch project information
43
45
  const { projectInfo, messages: projectInfoMessages } = await loadOrFetchProjectInfo(projectRoot, importProjectInfoOpt, editor);
44
46
  messages = messages.concat(projectInfoMessages);
47
+ // Ensure projectInfo.rootPath uses the resolved absolute path
48
+ // This is critical when importProjectInfo is provided with a relative rootPath
49
+ projectInfo.rootPath = projectRoot;
45
50
  projectInfo.baseUri = baseUriOpt;
46
51
  // Resolve UI5 versions for migration
47
52
  const ui5Versions = await resolveUI5VersionsForMigration(projectInfo, ui5SnapshotUrlOpt);
@@ -70,7 +75,7 @@ export class ProjectMigrator {
70
75
  // Commit only when we own the editor; otherwise the caller commits (matches other writers).
71
76
  if (ownsEditor && migrationResult.result) {
72
77
  try {
73
- await new Promise((resolve, reject) => migrationResult.fs.commit((error) => (error ? reject(error) : resolve())));
78
+ await commitFileSystemChanges(migrationResult.fs);
74
79
  }
75
80
  catch (error) {
76
81
  migrationResult.result = false;
@@ -6,5 +6,5 @@ import type { ImportProjectInfo } from '../types.js';
6
6
  * @param ui5SnapshotUrl - Optional snapshot URL to use for UI5 version resolution
7
7
  * @returns Resolved UI5 versions object
8
8
  */
9
- export declare function resolveUI5VersionsForMigration(projectInfo: ImportProjectInfo, ui5SnapshotUrl: string): Promise<any>;
9
+ export declare function resolveUI5VersionsForMigration(projectInfo: ImportProjectInfo, ui5SnapshotUrl?: string): Promise<any>;
10
10
  //# sourceMappingURL=ui5-version.d.ts.map
@@ -12,7 +12,7 @@ import type { ImportProjectInfo, Message } from '../types.js';
12
12
  * @param snapshotUrl - URL for UI5 snapshot version
13
13
  * @returns Result object with fs editor, success status and messages
14
14
  */
15
- export declare function copyAdaptationFiles(fs: Editor, projectInfo: ImportProjectInfo, snapshotUrl: string): Promise<{
15
+ export declare function copyAdaptationFiles(fs: Editor, projectInfo: ImportProjectInfo, snapshotUrl?: string): Promise<{
16
16
  fs: Editor;
17
17
  result: boolean;
18
18
  messages: Message[];
@@ -388,7 +388,7 @@ export interface UI5ConfigOptions {
388
388
  localUI5Version?: string;
389
389
  ui5Version?: string;
390
390
  ui5Theme: string;
391
- ui5SnapshotUrl: string;
391
+ ui5SnapshotUrl?: string;
392
392
  ui5VersionRequestInfo: any;
393
393
  }
394
394
  /**
@@ -58,7 +58,7 @@ export interface AddV4MockMiddlewareConfig {
58
58
  projectInfo: ImportProjectInfo;
59
59
  projectData: Partial<ProjectMigrate>;
60
60
  ui5Version: string | undefined;
61
- ui5SnapshotUrl: string;
61
+ ui5SnapshotUrl?: string;
62
62
  ui5VersionRequestInfo: any;
63
63
  ui5Yaml: Ui5Yaml;
64
64
  }
@@ -18,11 +18,13 @@ export declare class MigrationError extends Error {
18
18
  private setMessage;
19
19
  }
20
20
  /**
21
- * Determine error message based on error type
21
+ * Determine error message based on error type.
22
+ * Always returns a non-empty string with fallback to error.message.
22
23
  *
23
- * @param error
24
- * @param filename
25
- * @param useMessage
24
+ * @param error - The error object
25
+ * @param filename - Optional filename context for file-specific errors
26
+ * @param useMessage - Whether to use the raw error message
27
+ * @returns A user-friendly error message, or the original error message as fallback
26
28
  */
27
29
  export declare function determineMessage(error: Error, filename?: string, useMessage?: boolean): string;
28
30
  /**
@@ -42,11 +42,13 @@ export class MigrationError extends Error {
42
42
  }
43
43
  }
44
44
  /**
45
- * Determine error message based on error type
45
+ * Determine error message based on error type.
46
+ * Always returns a non-empty string with fallback to error.message.
46
47
  *
47
- * @param error
48
- * @param filename
49
- * @param useMessage
48
+ * @param error - The error object
49
+ * @param filename - Optional filename context for file-specific errors
50
+ * @param useMessage - Whether to use the raw error message
51
+ * @returns A user-friendly error message, or the original error message as fallback
50
52
  */
51
53
  export function determineMessage(error, filename, useMessage) {
52
54
  let errorMessage = '';
@@ -62,7 +64,8 @@ export function determineMessage(error, filename, useMessage) {
62
64
  else if (error.message.includes('EPERM')) {
63
65
  errorMessage = i18nText(filename ? 'ERROR_PERMISSION_FILE' : 'ERROR_PERMISSION', { filename });
64
66
  }
65
- return errorMessage;
67
+ // Fallback to original error message if no specific message was determined
68
+ return errorMessage || error.message || error.toString();
66
69
  }
67
70
  /**
68
71
  * Generate template file using EJS and template utilities
@@ -5,6 +5,7 @@
5
5
  import { join } from 'node:path';
6
6
  import { readFile, fileExists, readJSON, deleteFile } from '../file-access.js';
7
7
  import { createMemFsEditor } from '../fs-adapter.js';
8
+ import { commitFileSystemChanges } from '../../files/file-system.js';
8
9
  import mergeWith from 'lodash/mergeWith.js';
9
10
  import { MigrationTypes } from '../constants.js';
10
11
  /**
@@ -107,7 +108,7 @@ export async function handlePackageJsonFile(projectRoot, targetFile, templateCon
107
108
  // When we created the editor ourselves, persist staged side effects (e.g. Gruntfile.js deletion).
108
109
  // When the caller passed an editor, they own the commit (migration flow commits once at the end).
109
110
  if (ownsEditor) {
110
- await new Promise((resolve, reject) => fs.commit((err) => (err ? reject(err) : resolve())));
111
+ await commitFileSystemChanges(fs);
111
112
  }
112
113
  return JSON.stringify(mergedContent, null, 2);
113
114
  }
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "bugs": {
11
11
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Afiori-migration-writer"
12
12
  },
13
- "version": "0.0.15",
13
+ "version": "0.0.16",
14
14
  "license": "Apache-2.0",
15
15
  "main": "dist/index.js",
16
16
  "files": [