create-spark-html-app 0.3.2 → 0.3.3

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/bin/index.js CHANGED
@@ -63,6 +63,29 @@ function isEmptyDir(dir) {
63
63
  return entries.length === 0;
64
64
  }
65
65
 
66
+ // Resolve the newest published version of a package from the npm registry,
67
+ // so a freshly scaffolded app always starts on the latest spark-html.
68
+ // Returns a caret range (e.g. "^0.13.2"), or null if the lookup fails
69
+ // (offline, registry down) — callers fall back to the template default.
70
+ async function latestRange(pkgName) {
71
+ try {
72
+ const ctrl = new AbortController();
73
+ const timer = setTimeout(() => ctrl.abort(), 4000);
74
+ const registry = (process.env.npm_config_registry || 'https://registry.npmjs.org')
75
+ .replace(/\/+$/, '');
76
+ const res = await fetch(`${registry}/${pkgName}/latest`, {
77
+ signal: ctrl.signal,
78
+ headers: { accept: 'application/json' },
79
+ });
80
+ clearTimeout(timer);
81
+ if (!res.ok) return null;
82
+ const { version } = await res.json();
83
+ return version ? `^${version}` : null;
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+
66
89
  async function prompt(question, fallback) {
67
90
  const rl = createInterface({ input: stdin, output: stdout });
68
91
  try {
@@ -115,10 +138,17 @@ async function main() {
115
138
  if (existsSync(src)) renameSync(src, join(targetDir, to));
116
139
  }
117
140
 
118
- // 4 ─ stamp the project name into package.json ───────────────────────
141
+ // 4 ─ stamp the project name + pin the latest spark-html ─────────────
119
142
  const pkgPath = join(targetDir, 'package.json');
120
143
  const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
121
144
  pkg.name = projectName;
145
+ // Always start on the newest published spark-html. If the registry can't
146
+ // be reached, the template's "latest" default still resolves on install.
147
+ const range = await latestRange('spark-html');
148
+ if (range && pkg.dependencies && pkg.dependencies['spark-html']) {
149
+ pkg.dependencies['spark-html'] = range;
150
+ stdout.write(`${c.dim(` using spark-html ${range}`)}\n`);
151
+ }
122
152
  writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
123
153
 
124
154
  // 5 ─ celebrate + print next steps ───────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-spark-html-app",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Scaffold a Vite + spark-html app with a live reactive welcome screen.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "spark-html": "^0.12.0"
12
+ "spark-html": "latest"
13
13
  },
14
14
  "devDependencies": {
15
15
  "vite": "^5.0.0"