Skip to content

Commit

Permalink
check for double quotes in import path
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp committed Nov 26, 2024
1 parent a13afbf commit 145a1ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primer-react-migrate",
"version": "0.5.0",
"version": "0.5.1",
"description": "One time migrations for primer/react",
"main": "index.js",
"bin": "index.js",
Expand Down
29 changes: 23 additions & 6 deletions src/utils/change-import-to-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ const updateImportDeclaration = (
}

// import ... from '@primer/react/lib-esm/*'
if (moduleSpecifier.includes('lib-esm/' + fileName) || moduleSpecifier.includes('lib/' + fileName)) {
if (
moduleSpecifier.includes('lib-esm/' + fileName) ||
moduleSpecifier.includes('lib/' + fileName)
) {
declaration.setModuleSpecifier(getUpdatedModuleSpecifier(moduleSpecifier));
return declaration;
} else if (moduleSpecifier.includes('lib-esm/') || moduleSpecifier.includes('lib/' + fileName)) {
} else if (
moduleSpecifier.includes('lib-esm/') ||
moduleSpecifier.includes('lib/' + fileName)
) {
return declaration; // skip different component from lib-esm
}

Expand Down Expand Up @@ -59,13 +65,17 @@ const updateImportDeclaration = (

// only deprecated component in this import
if (elements.length === componentElements.length) {
declaration.setModuleSpecifier(getUpdatedModuleSpecifier(moduleSpecifier));
declaration.setModuleSpecifier(
getUpdatedModuleSpecifier(moduleSpecifier)
);
return declaration;
}

// mixed imports: import {Button, TextInput} from '@primer/react'
// we need to split the import statement
const componentElementNames = componentElements.map((element) => element.getName());
const componentElementNames = componentElements.map((element) =>
element.getName()
);
const otherElementNames = elements
.filter((element) => !componentImportNames.includes(element.getName()))
.map((element) => element.getFullText().trim());
Expand All @@ -92,8 +102,15 @@ module.exports = updateImportDeclaration;
const getUpdatedModuleSpecifier = (currentModuleSpecifier) => {
let newModuleSpecifier;

if (currentModuleSpecifier === `'@primer/react'`) newModuleSpecifier = '@primer/react/deprecated';
else if (currentModuleSpecifier.includes('lib-esm/') || currentModuleSpecifier.includes('lib/')) {
if (
currentModuleSpecifier === `'@primer/react'` ||
currentModuleSpecifier === `"@primer/react"`
) {
newModuleSpecifier = '@primer/react/deprecated';
} else if (
currentModuleSpecifier.includes('lib-esm/') ||
currentModuleSpecifier.includes('lib/')
) {
newModuleSpecifier = currentModuleSpecifier
.replace('lib-esm/', 'lib-esm/deprecated/')
.replace('lib/', 'lib/deprecated/');
Expand Down

0 comments on commit 145a1ed

Please sign in to comment.