@steambrew/ttc 2.8.7 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,53 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
- import { readFile } from 'fs/promises';
4
- import { dirname } from 'path';
5
- import { Logger } from './logger';
6
-
7
- export const CheckForUpdates = async (): Promise<boolean> => {
8
- return new Promise<boolean>(async (resolve) => {
9
- const packageJsonPath = path.resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
10
- const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
11
-
12
- fetch('https://registry.npmjs.org/@steambrew/ttc')
13
- .then((response) => response.json())
14
- .then((json) => {
15
- if (json?.['dist-tags']?.latest != packageJson.version) {
16
- Logger.Tree('versionMon', `@steambrew/ttc@${packageJson.version} requires update to ${json?.['dist-tags']?.latest}`, {
17
- cmd: `run "npm install @steambrew/ttc@${json?.['dist-tags']?.latest}" to get latest updates!`,
18
- });
19
-
20
- resolve(true);
21
- } else {
22
- Logger.Info('versionMon', `@steambrew/ttc@${packageJson.version} is up-to-date!`);
23
- resolve(false);
24
- }
25
- })
26
- .catch((exception) => {
27
- Logger.Error('Failed to check for updates: ' + exception);
28
- resolve(false);
29
- });
30
- });
31
- };
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { readFile, access } from 'fs/promises';
4
+ import { dirname } from 'path';
5
+ import { Logger } from './logger';
6
+
7
+ async function fileExists(filePath: string): Promise<boolean> {
8
+ return access(filePath).then(() => true).catch(() => false);
9
+ }
10
+
11
+ async function detectPackageManager(): Promise<string> {
12
+ const userAgent = process.env.npm_config_user_agent ?? '';
13
+ if (userAgent.startsWith('bun')) return 'bun';
14
+ if (userAgent.startsWith('pnpm')) return 'pnpm';
15
+ if (userAgent.startsWith('yarn')) return 'yarn';
16
+
17
+ const cwd = process.cwd();
18
+ if (await fileExists(path.join(cwd, 'bun.lock')) || await fileExists(path.join(cwd, 'bun.lockb'))) return 'bun';
19
+ if (await fileExists(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
20
+ if (await fileExists(path.join(cwd, 'yarn.lock'))) return 'yarn';
21
+
22
+ return 'npm';
23
+ }
24
+
25
+ function installCommand(pm: string, pkg: string): string {
26
+ switch (pm) {
27
+ case 'bun': return `bun add -d ${pkg}`;
28
+ case 'pnpm': return `pnpm add -D ${pkg}`;
29
+ case 'yarn': return `yarn add -D ${pkg}`;
30
+ default: return `npm i -D ${pkg}`;
31
+ }
32
+ }
33
+
34
+ export const CheckForUpdates = async (): Promise<boolean> => {
35
+ try {
36
+ const packageJsonPath = path.resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
37
+ const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
38
+
39
+ const response = await fetch('https://registry.npmjs.org/@steambrew/ttc');
40
+ const json = await response.json();
41
+ const latest = json?.['dist-tags']?.latest;
42
+
43
+ if (latest && latest !== packageJson.version) {
44
+ const pm = await detectPackageManager();
45
+ Logger.update(packageJson.version, latest, installCommand(pm, `@steambrew/ttc@${latest}`));
46
+ return true;
47
+ }
48
+ } catch {
49
+ // network or parse failure — silently skip
50
+ }
51
+
52
+ return false;
53
+ };
package/tsconfig.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "module": "ESNext",
5
- "target": "ES2020",
6
- "jsx": "react",
7
- "jsxFactory": "window.SP_REACT.createElement",
8
- "declaration": false,
9
- "moduleResolution": "node",
10
- "noUnusedLocals": true,
11
- "noUnusedParameters": true,
12
- "esModuleInterop": true,
13
- "noImplicitReturns": true,
14
- "noImplicitThis": true,
15
- "noImplicitAny": true,
16
- "strict": true,
17
- "ignoreDeprecations": "5.0",
18
- "allowSyntheticDefaultImports": true,
19
- "skipLibCheck": true
20
- },
21
- "include": ["./src/**/*"],
22
- "exclude": ["node_modules"]
23
- }
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "module": "ESNext",
5
+ "target": "ES2020",
6
+ "jsx": "react",
7
+ "jsxFactory": "window.SP_REACT.createElement",
8
+ "declaration": false,
9
+ "moduleResolution": "node",
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
12
+ "esModuleInterop": true,
13
+ "noImplicitReturns": true,
14
+ "noImplicitThis": true,
15
+ "noImplicitAny": true,
16
+ "strict": true,
17
+ "ignoreDeprecations": "5.0",
18
+ "allowSyntheticDefaultImports": true,
19
+ "skipLibCheck": true
20
+ },
21
+ "include": ["./src/**/*"],
22
+ "exclude": ["node_modules"]
23
+ }
@@ -1,2 +0,0 @@
1
- onlyBuiltDependencies:
2
- - '@parcel/watcher'