@svgrid/create-studio 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/index.mjs +25 -0
  2. package/package.json +2 -2
package/index.mjs CHANGED
@@ -17,6 +17,7 @@ import { existsSync } from 'node:fs'
17
17
  import { dirname, join, basename, resolve, isAbsolute } from 'node:path'
18
18
  import { fileURLToPath } from 'node:url'
19
19
  import { createInterface } from 'node:readline/promises'
20
+ import { createRequire } from 'node:module'
20
21
  import { stdin, stdout } from 'node:process'
21
22
 
22
23
  const __dirname = dirname(fileURLToPath(import.meta.url))
@@ -268,12 +269,36 @@ async function renameBack(dir) {
268
269
  }
269
270
  }
270
271
 
272
+ /**
273
+ * The @svgrid/enterprise version this scaffolder was published alongside, read
274
+ * from the copy npm actually installed next to it.
275
+ */
276
+ async function svgridVersion() {
277
+ try {
278
+ const require = createRequire(import.meta.url)
279
+ const pkg = JSON.parse(await readFile(require.resolve('@svgrid/enterprise/package.json'), 'utf8'))
280
+ return typeof pkg.version === 'string' && /^\d+\.\d+\.\d+/.test(pkg.version) ? pkg.version : null
281
+ } catch {
282
+ return null
283
+ }
284
+ }
285
+
271
286
  async function setProjectName(destDir, name) {
272
287
  const pkgPath = join(destDir, 'package.json')
273
288
  if (!existsSync(pkgPath)) return
274
289
  try {
275
290
  const pkg = JSON.parse(await readFile(pkgPath, 'utf8'))
276
291
  pkg.name = name
292
+ // The template ships "latest" so it stays honest in the repo, but a
293
+ // scaffolded app pins to the version this scaffolder was built against.
294
+ // Left as "latest", `npm install` resolves it fresh on every machine and
295
+ // every day, so an unrelated publish can break an app nobody touched.
296
+ const version = await svgridVersion()
297
+ if (version && pkg.dependencies) {
298
+ for (const dep of ['@svgrid/grid', '@svgrid/enterprise']) {
299
+ if (pkg.dependencies[dep] === 'latest') pkg.dependencies[dep] = `^${version}`
300
+ }
301
+ }
277
302
  await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
278
303
  } catch {
279
304
  // leave the template's name if it isn't valid JSON for some reason
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "commercial",
5
5
  "url": "https://svgrid.com/pricing"
6
6
  },
7
- "version": "0.4.0",
7
+ "version": "0.5.0",
8
8
  "description": "Scaffold a runnable SvGrid Studio data app in one command: npm create @svgrid/studio@latest",
9
9
  "type": "module",
10
10
  "license": "MIT",
@@ -41,6 +41,6 @@
41
41
  "node": ">=18"
42
42
  },
43
43
  "dependencies": {
44
- "@svgrid/enterprise": "^2.4.0"
44
+ "@svgrid/enterprise": "^2.5.0"
45
45
  }
46
46
  }