From a3b5fdd03e6e040ec18614fcca4e7ffc0cc387d1 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 17 Aug 2022 20:14:52 +0530 Subject: [PATCH] Fix #3745 Change ES6 import to require syntax (#3746) * Fix #3745 Change ES6 import to require syntax * fix error in syntax of callExpression --- .changeset/forty-timers-rhyme.md | 5 +++++ packages/codemod/src/upgrade-legacy.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/forty-timers-rhyme.md diff --git a/.changeset/forty-timers-rhyme.md b/.changeset/forty-timers-rhyme.md new file mode 100644 index 0000000000..ff178a9f7b --- /dev/null +++ b/.changeset/forty-timers-rhyme.md @@ -0,0 +1,5 @@ +--- +"@blitzjs/codemod": patch +--- + +Change ES6 import for `withBlitz` during the codemod to the require syntax. diff --git a/packages/codemod/src/upgrade-legacy.ts b/packages/codemod/src/upgrade-legacy.ts index 64c6b2af33..d94f26d96d 100644 --- a/packages/codemod/src/upgrade-legacy.ts +++ b/packages/codemod/src/upgrade-legacy.ts @@ -90,8 +90,14 @@ const upgradeLegacy = async () => { }, }) let createdConfig = config.get().value.right - - addNamedImport(program, "withBlitz", "@blitzjs/next") + let importWithBlitz = j.expressionStatement( + j.assignmentExpression( + "=", + j.identifier("const { withBlitz }"), + j.callExpression(j.identifier("require"), [j.identifier(`"@blitzjs/next"`)]), + ) + ) + parsedProgram.value.program.body.unshift(importWithBlitz) config.remove() let moduleExportStatement = j.expressionStatement(