@fias/create-fias-plugin 1.1.4 → 1.2.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.
- package/index.js +88 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,9 +4,97 @@
|
|
|
4
4
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
|
+
var childProcess = require('child_process');
|
|
7
8
|
|
|
8
9
|
var TEMPLATE_DIR = path.resolve(__dirname, 'templates/default');
|
|
9
10
|
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Self-update on stale npx cache.
|
|
13
|
+
//
|
|
14
|
+
// Failure mode this guards against: a developer who has scaffolded a FIAS
|
|
15
|
+
// plugin once before has `@fias/create-fias-plugin` in their npx cache
|
|
16
|
+
// (`~/.npm/_npx/<hash>/`). Subsequent `npm create @fias/fias-plugin <name>`
|
|
17
|
+
// invocations reuse the cached binary WITHOUT checking the npm registry for
|
|
18
|
+
// a newer version. Result: the CLAUDE.md / AGENTS.md / templates dropped
|
|
19
|
+
// into their new project are months out of date, and an AI assistant
|
|
20
|
+
// reading those files designs against an obsolete SDK surface (we hit this
|
|
21
|
+
// concretely in May 2026 — a fresh scaffold's CLAUDE.md was missing the
|
|
22
|
+
// in-app-purchase hook, vault documents, asset library, and the
|
|
23
|
+
// `store:purchase` permission, even though all four had been live on npm
|
|
24
|
+
// for weeks).
|
|
25
|
+
//
|
|
26
|
+
// Fix: at startup, hit the registry for the latest published version. If
|
|
27
|
+
// our running version is older, transparently re-exec the latest via npx
|
|
28
|
+
// (which downloads it on the fly) with the same args, then exit. A
|
|
29
|
+
// `_FIAS_CREATE_REEXEC=1` env marker prevents infinite recursion when the
|
|
30
|
+
// freshly-installed copy starts and re-runs this same check.
|
|
31
|
+
//
|
|
32
|
+
// Any failure of the check (offline, npm slow, registry 503, ...) falls
|
|
33
|
+
// through silently to the cached version. Scaffolding a slightly-old
|
|
34
|
+
// plugin is strictly better than blocking the user on a network hiccup.
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
var SELF_NAME = '@fias/create-fias-plugin';
|
|
38
|
+
var REEXEC_GUARD = '_FIAS_CREATE_REEXEC';
|
|
39
|
+
|
|
40
|
+
function compareSemver(a, b) {
|
|
41
|
+
// Returns 1 if a > b, -1 if a < b, 0 if equal. Plain x.y.z; pre-release
|
|
42
|
+
// suffixes ignored (we never publish pre-releases of this scaffold).
|
|
43
|
+
var pa = a.split('.').map(function (s) {
|
|
44
|
+
return parseInt(s, 10) || 0;
|
|
45
|
+
});
|
|
46
|
+
var pb = b.split('.').map(function (s) {
|
|
47
|
+
return parseInt(s, 10) || 0;
|
|
48
|
+
});
|
|
49
|
+
for (var i = 0; i < 3; i++) {
|
|
50
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return 1;
|
|
51
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return -1;
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function maybeReexecLatest() {
|
|
57
|
+
if (process.env[REEXEC_GUARD] === '1') return;
|
|
58
|
+
|
|
59
|
+
var currentVersion = require('./package.json').version;
|
|
60
|
+
|
|
61
|
+
// 5s timeout so a slow/offline network doesn't make scaffolding hang.
|
|
62
|
+
var view = childProcess.spawnSync('npm', ['view', SELF_NAME, 'version'], {
|
|
63
|
+
encoding: 'utf-8',
|
|
64
|
+
timeout: 5000,
|
|
65
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
66
|
+
});
|
|
67
|
+
if (view.status !== 0 || !view.stdout) return;
|
|
68
|
+
|
|
69
|
+
var latest = view.stdout.trim();
|
|
70
|
+
if (!latest || compareSemver(latest, currentVersion) <= 0) return;
|
|
71
|
+
|
|
72
|
+
console.log(
|
|
73
|
+
'[create-fias-plugin] cached version ' +
|
|
74
|
+
currentVersion +
|
|
75
|
+
' is stale; using latest ' +
|
|
76
|
+
latest +
|
|
77
|
+
' from npm\n',
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
var env = Object.assign({}, process.env);
|
|
81
|
+
env[REEXEC_GUARD] = '1';
|
|
82
|
+
|
|
83
|
+
var rerun = childProcess.spawnSync(
|
|
84
|
+
'npx',
|
|
85
|
+
['--yes', SELF_NAME + '@' + latest].concat(process.argv.slice(2)),
|
|
86
|
+
{ stdio: 'inherit', env: env },
|
|
87
|
+
);
|
|
88
|
+
process.exit(rerun.status == null ? 1 : rerun.status);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
maybeReexecLatest();
|
|
93
|
+
} catch (_e) {
|
|
94
|
+
// Any unexpected error: fall through to the cached version. Don't block
|
|
95
|
+
// the user on a self-update-check failure.
|
|
96
|
+
}
|
|
97
|
+
|
|
10
98
|
function copyDir(src, dest, replacements, opts) {
|
|
11
99
|
fs.mkdirSync(dest, { recursive: true });
|
|
12
100
|
|