Disable license check when offline (#198)

* Disable license check when offline. Fix issue with PNPM > 9 detection.
This commit is contained in:
Giancarlo Buomprisco
2025-03-01 16:28:25 +07:00
committed by GitHub
parent a5d3338950
commit 20f7fd2c22
2 changed files with 34 additions and 4 deletions

View File

@@ -1,13 +1,16 @@
import { execSync } from 'child_process';
const endpoint = 'https://makerkit.dev/api/license/check';
async function checkLicense() {
let gitUser, gitEmail;
try {
gitUser =
execSync('git config user.username').toString().trim();
gitUser = execSync('git config user.username').toString().trim();
if (!gitUser) {
gitUser = execSync('git config user.name').toString().trim();
@@ -50,7 +53,9 @@ async function checkLicense() {
return Promise.resolve();
} else {
return Promise.reject(
new Error(`License check failed. Please set the git user name with the command 'git config user.username <username>'. The username needs to match the GitHub username in your Makerkit organization.`),
new Error(
`License check failed. Please set the git user name with the command 'git config user.username <username>'. The username needs to match the GitHub username in your Makerkit organization.`,
),
);
}
}
@@ -107,8 +112,33 @@ function checkVisibility() {
});
}
async function isOnline() {
const { lookup } = await import('dns');
try {
return await new Promise((resolve, reject) => {
lookup('google.com', (err) => {
if (err && err.code === 'ENOTFOUND') {
reject(false);
} else {
resolve(true);
}
});
}).catch(() => false);
} catch (e) {
return false;
}
}
async function main() {
try {
const isUserOnline = await isOnline();
// disable the check if the user is offline
if (!isUserOnline) {
return process.exit(0);
}
await checkVisibility();
await checkLicense().catch((error) => {

View File

@@ -37,7 +37,7 @@ function checkPnpmVersion() {
}
// warn if the minor version is less than 12
if (minor < 12) {
if (major < 9 && minor < 12) {
console.warn(
`\x1b[33m%s\x1b[0m`,
`You are running pnpm ${currentPnpmVersion}. Makerkit recommends using pnpm 9.12.0 or higher.`,