(ctx: Context)
| 626 | } |
| 627 | |
| 628 | async function updatePackageJSON(ctx: Context) { |
| 629 | let packageJSONPath = path.join(ctx.cwd, "package.json"); |
| 630 | if (!existsSync(packageJSONPath)) { |
| 631 | let relativePath = path.relative(process.cwd(), ctx.cwd); |
| 632 | error( |
| 633 | "Oh no!", |
| 634 | "The provided template must be a React Router project with a `package.json` " + |
| 635 | `file, but that file does not exist in ${color.bold(relativePath)}.`, |
| 636 | ); |
| 637 | throw new Error(`package.json does not exist in ${ctx.cwd}`); |
| 638 | } |
| 639 | |
| 640 | let contents = await readFile(packageJSONPath, "utf-8"); |
| 641 | let packageJSON: any; |
| 642 | try { |
| 643 | packageJSON = JSON.parse(contents); |
| 644 | if (!isValidJsonObject(packageJSON)) { |
| 645 | throw Error(); |
| 646 | } |
| 647 | } catch (err) { |
| 648 | error( |
| 649 | "Oh no!", |
| 650 | "The provided template must be a React Router project with a `package.json` " + |
| 651 | `file, but that file is invalid.`, |
| 652 | ); |
| 653 | throw err; |
| 654 | } |
| 655 | |
| 656 | for (let pkgKey of ["dependencies", "devDependencies"] as const) { |
| 657 | let dependencies = packageJSON[pkgKey]; |
| 658 | if (!dependencies) continue; |
| 659 | |
| 660 | if (!isValidJsonObject(dependencies)) { |
| 661 | error( |
| 662 | "Oh no!", |
| 663 | "The provided template must be a React Router project with a `package.json` " + |
| 664 | `file, but its ${pkgKey} value is invalid.`, |
| 665 | ); |
| 666 | throw new Error(`package.json ${pkgKey} are invalid`); |
| 667 | } |
| 668 | |
| 669 | for (let dependency in dependencies) { |
| 670 | let version = dependencies[dependency]; |
| 671 | if ( |
| 672 | (dependency.startsWith("@react-router/") || |
| 673 | dependency === "react-router") && |
| 674 | version === "*" |
| 675 | ) { |
| 676 | dependencies[dependency] = semver.prerelease(ctx.reactRouterVersion) |
| 677 | ? // Templates created from prereleases should pin to a specific version |
| 678 | ctx.reactRouterVersion |
| 679 | : "^" + ctx.reactRouterVersion; |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | packageJSON.name = ctx.projectName; |
| 685 |
no test coverage detected
searching dependent graphs…