-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated package names, added additional migrations
- Loading branch information
1 parent
954f94c
commit c84e7b1
Showing
6 changed files
with
144 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Project, ts } from 'ts-morph'; | ||
import { visitNotIgnoredFiles } from './tools/visit-not-ignored-files'; | ||
import { log } from '@clack/prompts'; | ||
|
||
export function replaceImportInFiles( | ||
changes: [oldImport: string, newImport: string][], | ||
library: string | ||
) { | ||
const project = new Project(); | ||
|
||
visitNotIgnoredFiles('.', (path) => { | ||
if (!path.endsWith('.ts') && !path.endsWith('.tsx')) { | ||
return; | ||
} | ||
project.addSourceFileAtPath(path); | ||
}); | ||
|
||
project.getSourceFiles().forEach((sourceFile) => { | ||
let hasChanges = false; | ||
|
||
sourceFile.getImportDeclarations().forEach((importDeclaration) => { | ||
// startsWith is used in order to handle nested imports | ||
if (importDeclaration.getModuleSpecifierValue().startsWith(library)) { | ||
for (const [oldImport, newImport] of changes) { | ||
importDeclaration.getNamedImports().forEach((namedImport) => { | ||
if (namedImport.getName() === oldImport) { | ||
namedImport.setName(newImport); | ||
hasChanges = true; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
sourceFile.getDescendantsOfKind(ts.SyntaxKind.Identifier).forEach((identifier) => { | ||
for (const [oldImport, newImport] of changes) { | ||
if (identifier.getText() === oldImport) { | ||
identifier.replaceWithText(newImport); | ||
hasChanges = true; | ||
} | ||
} | ||
}); | ||
|
||
if (hasChanges) { | ||
sourceFile.saveSync(); | ||
log.info(`Updated imports in ${sourceFile.getFilePath()}`); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const versions = { | ||
'@qwik.dev/qwik': '2.0.0', | ||
'@qwik.dev/city': '2.0.0', | ||
'@qwik.dev/core': '2.0.0', | ||
'@qwik.dev/router': '2.0.0', | ||
'@qwik.dev/react': '2.0.0', | ||
'eslint-plugin-qwik': '2.0.0', | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.