Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codemod upgrade-legacy cause path errors #4094

Open
kyken opened this issue Mar 6, 2023 · 2 comments
Open

codemod upgrade-legacy cause path errors #4094

kyken opened this issue Mar 6, 2023 · 2 comments
Labels
kind/bug Something isn't working status/ready-to-work-on This issue is up for grabs

Comments

@kyken
Copy link

kyken commented Mar 6, 2023

What is the problem?

When I try to upgrade legacy-framework (v0.45.5) using codemod, I get some wrong path errors

Paste all your error logs here:

$ npx @blitzjs/codemod upgrade-legacy
✔ Successfully ran move the config from /Users/kyken/Documents/develop/tmp/legacy-framework/examples/auth/blitz.config.ts to next.config.js
✔ Successfully ran update .eslintrc.js configuration
✔ Successfully ran update dependencies in package.json
✔ Successfully ran update project's imports
✔ Successfully ran update NextJS' default imports
✔ Successfully ran change queryClient to getQueryClient()
✔ Successfully ran change BlitzApiRequest to NextApiRequest
✔ Successfully ran change BlitzApiResponse to NextApiResponse
✔ Successfully ran change BlitzApiHandler to NextApiHandler
✖ create blitz-server.ts and blitz-client.ts setup files
Error: ENOENT: no such file or directory, open '/Users/kyken/.npm/_npx/80c77bdc0015bdea/node_modules/@blitzjs/generator/dist/templates/app/app/blitz-server.ts'
This is an unexpected error. Please ask for help in the discord #general-help channel. https://discord.blitzjs.com

Paste all relevant code snippets here:

  steps.push({
    name: "create blitz-server.ts and blitz-client.ts setup files",
    action: async () => {
      let appDirExist = fs.existsSync(appDir)

      if (appDirExist) {
        const templatePath = path.join(
          require.resolve("@blitzjs/generator"),
          "..",
          "..",
          isInternalBlitzMonorepoDevelopment ? "templates" : "dist/templates",
        )
        const blitzServer = fs
          .readFileSync(path.join(templatePath, "app", "app", "blitz-server.ts"))
          .toString()
        const blitzClient = fs
          .readFileSync(path.join(templatePath, "app", "app", "blitz-client.ts"))
          .toString()

        const replaceTemplateValues = (input: string) => {
          let result = input
          const token = `__safeNameSlug__`
          if (result.includes(token)) {
            result = result.replace(new RegExp(token, "g"), "blitz")
          }
          return result
        }

        fs.writeFileSync(
          `${appDir}/blitz-server.${isTypescript ? "ts" : "js"}`,
          replaceTemplateValues(blitzServer),
        )

        fs.writeFileSync(
          `${appDir}/blitz-client.${isTypescript ? "ts" : "js"}`,
          replaceTemplateValues(blitzClient),
        )
      } else {
        throw new ExpectedError("App directory doesn't exit")
      }
    },
  })

What are detailed steps to reproduce this?

  1. clone legacy-framework)
  2. $ cd legacy-framework/examples/auth (maybe anything with examples).
  3. npx @blitzjs/codemod upgrade-legacy

Run blitz -v and paste the output here:

blitz -v
Blitz version: 2.0.0-beta.23 (local)
macOS Ventura | darwin-x64 | Node: v16.15.0


 Package manager: npm

  System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 292.80 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.volta/tools/image/node/16.15.0/bin/node
    Yarn: Not Found
    npm: 8.5.5 - ~/.volta/tools/image/node/16.15.0/bin/npm
  npmPackages:
    @blitzjs/auth: Not Found
    @blitzjs/next: Not Found
    @blitzjs/rpc: Not Found
    @prisma/client: Not Found
    blitz: Not Found
    next: Not Found
    prisma: Not Found
    react: Not Found
    react-dom: Not Found
    typescript: Not Found

Please include below any other applicable logs and screenshots that show your problem:

No response

@kyken kyken added kind/bug Something isn't working status/triage labels Mar 6, 2023
@siddhsuresh
Copy link
Member

Hey @kyken, thanks for the issue. The quickest workaround would be to use beta 15 of the codemod that still uses the app directory.

npx @blitzjs/[email protected] upgrade-legacy

The issue can be solved in the following way:

- const blitzServer = fs.readFileSync(path.join(templatePath, "app", "app", "blitz-server.ts")).toString()
+ const blitzServer = fs.readFileSync(path.join(templatePath, "app", "src", "blitz-server.ts")).toString()
- const blitzClient = fs.readFileSync(path.join(templatePath, "app", "app", "blitz-client.ts")).toString()
+ const blitzClient = fs.readFileSync(path.join(templatePath, "app", "src", "blitz-client.ts")).toString()

@siddhsuresh siddhsuresh added the status/ready-to-work-on This issue is up for grabs label Mar 6, 2023
@MadcowD
Copy link

MadcowD commented May 15, 2023

Man this is a bummer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/ready-to-work-on This issue is up for grabs
Projects
None yet
Development

No branches or pull requests

4 participants