@xk2800/nextjs-template 0.7.2-beta.8 → 0.7.2-beta.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xk2800/nextjs-template",
3
- "version": "0.7.2-beta.8",
3
+ "version": "0.7.2-beta.9",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,10 +63,12 @@
63
63
  "hooks/use-mobile.ts",
64
64
  "types/auth",
65
65
  "styles/theme.css",
66
- "README.md"
66
+ "README.md",
67
+ "scripts/check-deps.mjs"
67
68
  ],
68
69
  "exports": {
69
70
  "./package.json": "./package.json",
71
+ "./check-deps": "./scripts/check-deps.mjs",
70
72
  "./auth": {
71
73
  "types": "./dist/auth/index.d.ts",
72
74
  "import": "./dist/auth/index.mjs",
@@ -0,0 +1,67 @@
1
+ // Ships in @xk2800/nextjs-template and runs from the app's postinstall: lists packages
2
+ // where the app is older than what this template release declares. Warns only, never
3
+ // fails an install, and changes nothing. Runs on import and reads the app from cwd.
4
+ import { readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+
7
+ const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
8
+
9
+ // [major, minor, patch, prerelease] of a plain version
10
+ const parse = (v) => {
11
+ const m = v.match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([\w.-]+))?(?:\+[\w.-]+)?$/);
12
+ return m && [+m[1], +(m[2] ?? 0), +(m[3] ?? 0), m[4] ?? ''];
13
+ };
14
+ const compare = (a, b) => {
15
+ const [x, y] = [parse(a), parse(b)];
16
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] - y[i];
17
+ if (x[3] === y[3]) return 0;
18
+ if (!x[3] || !y[3]) return x[3] ? -1 : 1; // a prerelease is older than its release
19
+ return x[3].localeCompare(y[3], 'en', { numeric: true });
20
+ };
21
+
22
+ // Lowest version a range allows. Only exact, ^, ~, >= and || of those; null for
23
+ // anything else (file:, workspace:, "latest", "*"), which is then not compared.
24
+ const floor = (range) => {
25
+ const versions = range.split('||').map((r) => r.trim().replace(/^(\^|~|>=)\s*/, ''));
26
+ return versions.every(parse) ? versions.sort(compare)[0] : null;
27
+ };
28
+
29
+ try {
30
+ const template = readJson(new URL('../package.json', import.meta.url));
31
+ const app = readJson(join(process.cwd(), 'package.json'));
32
+ const outdated = [];
33
+ for (const [section, dev] of [['dependencies', false], ['devDependencies', true]]) {
34
+ for (const [name, spec] of Object.entries(app[section] ?? {})) {
35
+ if (name === template.name) continue;
36
+ // A package can be a peer (loose) and a devDependency (what the template is built with): take the newest.
37
+ const wanted = ['dependencies', 'peerDependencies', 'devDependencies']
38
+ .map((s) => floor(template[s]?.[name] ?? '')).filter(Boolean).sort(compare).at(-1);
39
+ if (!wanted) continue;
40
+ let installed;
41
+ try { installed = readJson(join(process.cwd(), 'node_modules', name, 'package.json')).version; } catch { continue; }
42
+ if (!parse(installed ?? '') || compare(installed, wanted) >= 0) continue;
43
+ // keep the app's range style: ^ and ~ stay, an exact pin stays exact
44
+ const prefix = /^\d/.test(spec) ? '' : spec.startsWith('~') ? '~' : '^';
45
+ outdated.push({ name, installed, wanted, dev, prefix });
46
+ }
47
+ }
48
+ if (outdated.length) {
49
+ const width = Math.max(...outdated.map((o) => o.name.length));
50
+ const commands = new Map();
51
+ for (const o of outdated) {
52
+ const command = `bun add${o.dev ? ' -d' : ''}${o.prefix ? '' : ' --exact'}`;
53
+ commands.set(command, [...(commands.get(command) ?? []), `"${o.name}@${o.prefix}${o.wanted}"`]);
54
+ }
55
+ console.log([
56
+ '',
57
+ `${template.name} ${template.version} uses newer versions than your app:`,
58
+ ...outdated.map((o) => ` ${o.name.padEnd(width)} ${o.installed} → ${o.wanted}`),
59
+ '',
60
+ 'Optional. To update:',
61
+ ...[...commands].map(([command, specs]) => ` ${command} ${specs.join(' ')}`),
62
+ '',
63
+ ].join('\n'));
64
+ }
65
+ } catch (err) {
66
+ console.warn(`Skipped the template dependency check: ${err.message}`);
67
+ }