Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BSekula committed Aug 7, 2024
1 parent 05c279f commit 7271064
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
55 changes: 14 additions & 41 deletions lib/core/schematics/migrations/7_0_0/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,11 +62,7 @@ const alfrescoApiFactoryMigration: MigrationData = {
}
};

const migrations: MigrationData[] = [
alfrescoApiServiceMigration,
alfrescoApiMockMigration,
alfrescoApiFactoryMigration
];
const migrations: MigrationData[] = [alfrescoApiServiceMigration, alfrescoApiMockMigration, alfrescoApiFactoryMigration];

/**
* @returns Schematic rule for updating imports
Expand All @@ -76,7 +72,6 @@ export function updateAlfrescoApiImports(): Rule {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return (tree: Tree, _context: SchematicContext) => {

tree.visit((filePath: string) => visitor(filePath, tree, project));

return tree;
Expand All @@ -98,12 +93,7 @@ export const visitor = (filePath: string, tree: Pick<Tree, 'read' | 'overwrite'>
}

migrations.forEach((migrationData) => {
const fileWithUpdatedImport = moveImport(
filePath,
bufferFileContent,
project,
migrationData
);
const fileWithUpdatedImport = moveImport(filePath, bufferFileContent, project, migrationData);

if (fileWithUpdatedImport) {
tree.overwrite(filePath, fileWithUpdatedImport);
Expand All @@ -112,30 +102,17 @@ export const visitor = (filePath: string, tree: Pick<Tree, 'read' | 'overwrite'>
}
};

const moveImport = (
filePath: string,
bufferFileContent: Buffer,
project: Project,
migrationData: MigrationData
): string | undefined => {
const moveImport = (filePath: string, bufferFileContent: Buffer, project: Project, migrationData: MigrationData): string | undefined => {
const fileContent = bufferFileContent.toString();
const predictImport = fileContent.includes(migrationData.change.importedValue);

if (predictImport) {
const sourceFile =
project.getSourceFile(`migration-${filePath}`) ??
project.createSourceFile(
`migration-${filePath}`,
fileContent
);

const alfrescoApiImportResult = getImportedValueFromSource(
sourceFile,
{
importedIdentifier: migrationData.change.importedValue,
from: migrationData.change.importSource
}
);
const sourceFile = project.getSourceFile(`migration-${filePath}`) ?? project.createSourceFile(`migration-${filePath}`, fileContent);

const alfrescoApiImportResult = getImportedValueFromSource(sourceFile, {
importedIdentifier: migrationData.change.importedValue,
from: migrationData.change.importSource
});

if (alfrescoApiImportResult?.importedValue) {
if (alfrescoApiImportResult.allImportedValuesCount === 1) {
Expand All @@ -146,10 +123,7 @@ const moveImport = (
alfrescoApiImportResult.importedValue?.remove();
}

const alfrescoContentServiceImport = getSourceImport(
sourceFile,
migrationData.to.importSource
);
const alfrescoContentServiceImport = getSourceImport(sourceFile, migrationData.to.importSource);

if (alfrescoContentServiceImport) {
alfrescoContentServiceImport.addNamedImport(migrationData.to.importedValue);
Expand Down Expand Up @@ -203,14 +177,13 @@ const getImportedValueFromSource = (
const namedImports = importedValues?.getNamedBindings() as NamedImports;
const namedImportsElements = namedImports?.getElements() ?? [];

const importedValue =
namedImportsElements.find(
(binding) => binding.getName() === searchedImport.importedIdentifier
);
const importedValue = namedImportsElements.find((binding) => binding.getName() === searchedImport.importedIdentifier);

return {
importedValue,
importSource,
allImportedValuesCount: namedImportsElements.length
};
};

export default updateAlfrescoApiImports;
1 change: 0 additions & 1 deletion lib/core/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
Expand Down

0 comments on commit 7271064

Please sign in to comment.