create-deka-app 0.0.3 → 0.0.4

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": "create-deka-app",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Scaffold a new deka app",
5
5
  "bin": {
6
6
  "create-deka-app": "./index.js"
package/src/cli.js CHANGED
@@ -17,11 +17,17 @@ export function run({
17
17
  cwd = process.cwd(),
18
18
  log = console.log,
19
19
  error = console.error,
20
+ // create-deka-app's own version. Not currently used by createApp -- the
21
+ // runtime version it pins in the generated package.json is resolved
22
+ // separately, from the npm registry, since create-deka-app's own 0.0.x
23
+ // line and @dekaruntime/deka's release line are not in lockstep. Kept
24
+ // here as the CLI's own version for whatever legitimately needs it
25
+ // (e.g. a future `--version` flag).
20
26
  ownVersion = ownPackageJson.version,
21
27
  } = {}) {
22
28
  const targetArg = argv[0]
23
29
  try {
24
- return createApp({ targetArg, cwd, env, ownVersion, log })
30
+ return createApp({ targetArg, cwd, env, log })
25
31
  } catch (err) {
26
32
  if (err instanceof ScaffoldError) {
27
33
  error(err.message)
package/src/scaffold.js CHANGED
@@ -29,10 +29,19 @@ function dekaBinPath(targetDir, platform) {
29
29
  return path.join(targetDir, 'node_modules', '.bin', platform === 'win32' ? 'deka.cmd' : 'deka')
30
30
  }
31
31
 
32
+ export const RUNTIME_PACKAGE = '@dekaruntime/deka'
33
+
32
34
  // Builds the package.json this package writes into every scaffolded
33
35
  // project. Exported so the test suite can assert on it directly without
34
36
  // re-deriving the shape.
35
- export function buildPackageJson(dirName, ownVersion) {
37
+ //
38
+ // `runtimeVersion` must be the @dekaruntime/deka version resolved at
39
+ // scaffold time (see resolveRuntimeVersion below) -- never this package's
40
+ // own version. create-deka-app has its own 0.0.x release line and
41
+ // @dekaruntime/deka tracks deka's releases; the two are not in lockstep
42
+ // and never will be, so passing this package's own version here pins a
43
+ // version of the runtime that may not exist (see deka#1076-era bug).
44
+ export function buildPackageJson(dirName, runtimeVersion) {
36
45
  return {
37
46
  name: sanitizePackageName(dirName),
38
47
  private: true,
@@ -43,11 +52,41 @@ export function buildPackageJson(dirName, ownVersion) {
43
52
  start: 'deka start',
44
53
  },
45
54
  devDependencies: {
46
- '@dekaruntime/deka': ownVersion,
55
+ [RUNTIME_PACKAGE]: runtimeVersion,
47
56
  },
48
57
  }
49
58
  }
50
59
 
60
+ // Looks up the latest published @dekaruntime/deka version from the npm
61
+ // registry so the generated package.json pins something that actually
62
+ // exists, rather than assuming it matches create-deka-app's own version.
63
+ //
64
+ // Always shells out to `npm` for this lookup (not the detected package
65
+ // manager) -- npm ships with every Node.js install, so it is available
66
+ // regardless of whether the user ran this via npx, pnpm create, yarn
67
+ // create or bun create, and `npm view` is a read-only registry query with
68
+ // no project-local side effects.
69
+ //
70
+ // Falls back to the "latest" dist-tag -- never to a version we already
71
+ // know is wrong -- if the registry can't be reached (offline, registry
72
+ // outage, etc), and says so via `log` so the fallback is visible.
73
+ export function resolveRuntimeVersion({ spawn = spawnSync, cwd = process.cwd(), log = console.log } = {}) {
74
+ const result = spawn('npm', ['view', RUNTIME_PACKAGE, 'version'], { cwd, encoding: 'utf8' })
75
+
76
+ const version =
77
+ result && !result.error && result.status === 0 ? String(result.stdout || '').trim() : ''
78
+
79
+ if (!version) {
80
+ log(
81
+ `> Could not resolve the latest ${RUNTIME_PACKAGE} version from the npm registry ` +
82
+ '(offline, or the registry is unreachable); pinning "latest" instead.'
83
+ )
84
+ return 'latest'
85
+ }
86
+
87
+ return version
88
+ }
89
+
51
90
  /**
52
91
  * Orchestrates the scaffold. Everything the real `deka init` binary is
53
92
  * responsible for (writing app/, public/, deka.json, deka.lock, printing
@@ -61,7 +100,6 @@ export function createApp({
61
100
  targetArg,
62
101
  cwd = process.cwd(),
63
102
  env = process.env,
64
- ownVersion,
65
103
  platform = process.platform,
66
104
  arch = process.arch,
67
105
  spawn = spawnSync,
@@ -96,7 +134,9 @@ export function createApp({
96
134
  mkdirSync(targetDir, { recursive: true })
97
135
  }
98
136
 
99
- const pkg = buildPackageJson(path.basename(targetDir), ownVersion)
137
+ const runtimeVersion = resolveRuntimeVersion({ spawn, cwd: targetDir, log })
138
+
139
+ const pkg = buildPackageJson(path.basename(targetDir), runtimeVersion)
100
140
  writeFileSync(path.join(targetDir, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`)
101
141
 
102
142
  const pm = detectPackageManager(env)