Skip to content

Commit 9d2cdca

Browse files
feat: render warning when using a tagged or outdated version (t3-oss#727)
1 parent 1722613 commit 9d2cdca

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.changeset/warm-sheep-suffer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-t3-app": minor
3+
---
4+
5+
feat: add warning message when not using latest

cli/src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { buildPkgInstallerMap } from "~/installers/index.js";
1010
import { logger } from "~/utils/logger.js";
1111
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
1212
import { renderTitle } from "~/utils/renderTitle.js";
13+
import {
14+
getNpmVersion,
15+
renderVersionWarning,
16+
} from "./utils/renderVersionWarning.js";
1317
import { installDependencies } from "./helpers/installDependencies.js";
1418
import { getVersion } from "./utils/getT3Version.js";
1519

@@ -20,7 +24,9 @@ type CT3APackageJSON = PackageJson & {
2024
};
2125

2226
const main = async () => {
27+
const npmVersion = await getNpmVersion();
2328
renderTitle();
29+
npmVersion && renderVersionWarning(npmVersion);
2430

2531
const {
2632
appName,

cli/src/utils/renderVersionWarning.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { execSync } from "child_process";
2+
import { getVersion } from "./getT3Version.js";
3+
import { logger } from "./logger.js";
4+
5+
export const renderVersionWarning = (npmVersion: string) => {
6+
const currentVersion = getVersion();
7+
8+
// console.log("current", currentVersion);
9+
// console.log("npm", npmVersion);
10+
11+
if (currentVersion.includes("beta")) {
12+
logger.warn(" You are using a beta version of create-t3-app.");
13+
logger.warn(" Please report any bugs you encounter.");
14+
} else if (currentVersion.includes("next")) {
15+
logger.warn(
16+
" You are running create-t3-app with the @next tag which is no longer maintained.",
17+
);
18+
logger.warn(" Please run the CLI with @latest instead.");
19+
} else if (currentVersion !== npmVersion) {
20+
logger.warn(" You are using an outdated version of create-t3-app.");
21+
logger.warn(
22+
" Your version:",
23+
currentVersion + ".",
24+
"Latest version in the npm registry:",
25+
npmVersion,
26+
);
27+
logger.warn(" Please run the CLI with @latest to get the latest updates.");
28+
}
29+
console.log("");
30+
};
31+
32+
/**
33+
* Copyright (c) 2015-present, Facebook, Inc.
34+
*
35+
* This source code is licensed under the MIT license found in the
36+
* LICENSE file in the root directory of this source tree.
37+
* https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE
38+
*/
39+
import https from "https";
40+
function checkForLatestVersion(): Promise<string> {
41+
return new Promise((resolve, reject) => {
42+
https
43+
.get(
44+
"https://registry.npmjs.org/-/package/create-t3-app/dist-tags",
45+
(res) => {
46+
if (res.statusCode === 200) {
47+
let body = "";
48+
res.on("data", (data) => (body += data));
49+
res.on("end", () => {
50+
resolve(JSON.parse(body).latest);
51+
});
52+
} else {
53+
reject();
54+
}
55+
},
56+
)
57+
.on("error", () => {
58+
// logger.error("Unable to check for latest version.");
59+
reject();
60+
});
61+
});
62+
}
63+
64+
export const getNpmVersion = () =>
65+
// `fetch` to the registry is faster than `npm view` so we try that first
66+
checkForLatestVersion().catch(() => {
67+
try {
68+
return execSync("npm view create-t3-app version").toString().trim();
69+
} catch {
70+
return null;
71+
}
72+
});

0 commit comments

Comments
 (0)