poad 2.37.0 → 2.39.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/.github/workflows/release.yml +13 -1
- package/global/clean.js +2 -2
- package/global/cli.js +2 -1
- package/global/create.js +286 -0
- package/global/init.js +22 -7
- package/global/install.js +2 -2
- package/global/run.js +17 -10
- package/package.json +4 -2
- package/poad.js +26 -1
- package/project/cli.js +4 -4
- package/project/client/index.js +2 -2
- package/project/client/init.js +43 -59
- package/project/info.js +22 -2
- package/project/upgrade.js +10 -7
- package/test/create.e2e.test.js +73 -0
- package/test/create.test.js +95 -0
- package/test/help-stub.js +29 -0
- package/test/help.test.js +124 -0
- package/test/helpers.js +53 -0
- package/test/offline-stub.js +5 -0
- package/test/registry.test.js +95 -0
- package/test/secrets.test.js +94 -0
- package/test/starter.test.js +122 -0
- package/test/tar.test.js +101 -0
- package/utils/engine.js +16 -13
- package/utils/git.js +1 -1
- package/utils/help.js +80 -0
- package/utils/latest.js +80 -32
- package/utils/registry.js +145 -0
- package/utils/report.js +23 -12
- package/utils/services.js +2 -2
- package/utils/starter.js +214 -0
- package/utils/tar.js +180 -0
- package/utils/version.js +43 -0
package/utils/tar.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Lecture et extraction d'une archive .tgz (paquet npm) avec les seuls modules
|
|
2
|
+
// de Node (zlib + un lecteur tar minimal), sans dépendance ni commande tar.
|
|
3
|
+
//
|
|
4
|
+
// Sûreté : toute l'archive est lue et vérifiée AVANT la première écriture.
|
|
5
|
+
// Refusés : chemins absolus (/x, C:\x, \\serveur), segments « .. », barres
|
|
6
|
+
// obliques inverses, octet nul, liens symboliques et liens physiques (un
|
|
7
|
+
// paquet npm n'en contient jamais), fichiers spéciaux (périphériques, fifo),
|
|
8
|
+
// doublons, archive trop grosse ou trop de fichiers. Les fichiers sont créés
|
|
9
|
+
// en 0644 (0755 s'ils étaient exécutables), jamais setuid.
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const zlib = require('zlib');
|
|
13
|
+
|
|
14
|
+
const LIMITS = { maxBytes: 200 * 1024 * 1024, maxEntries: 20000 };
|
|
15
|
+
|
|
16
|
+
class TarError extends Error {}
|
|
17
|
+
|
|
18
|
+
const str = (buf, start, len) => {
|
|
19
|
+
const raw = buf.subarray(start, start + len);
|
|
20
|
+
const end = raw.indexOf(0);
|
|
21
|
+
return raw.subarray(0, end === -1 ? raw.length : end).toString('utf8');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Nombre octal, ou base 256 (bit de poids fort du premier octet) pour les grandes tailles
|
|
25
|
+
const num = (buf, start, len) => {
|
|
26
|
+
if (buf[start] & 0x80) {
|
|
27
|
+
let n = 0;
|
|
28
|
+
for (let i = start + 1; i < start + len; i++) n = n * 256 + buf[i];
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
const s = str(buf, start, len).trim();
|
|
32
|
+
return s ? parseInt(s, 8) : 0;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const checksumOk = (header) => {
|
|
36
|
+
const stored = num(header, 148, 8);
|
|
37
|
+
let sum = 0;
|
|
38
|
+
for (let i = 0; i < 512; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
|
|
39
|
+
return sum === stored;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// En-têtes pax (« x ») : enregistrements « longueur clé=valeur\n »
|
|
43
|
+
const parsePax = (data) => {
|
|
44
|
+
const out = {};
|
|
45
|
+
let i = 0;
|
|
46
|
+
while (i < data.length) {
|
|
47
|
+
const sp = data.indexOf(0x20, i);
|
|
48
|
+
if (sp === -1) break;
|
|
49
|
+
const len = parseInt(data.subarray(i, sp).toString('utf8'), 10);
|
|
50
|
+
if (!len || len < 0 || i + len > data.length) throw new TarError('corrupt pax header');
|
|
51
|
+
const rec = data.subarray(sp + 1, i + len - 1).toString('utf8');
|
|
52
|
+
const eq = rec.indexOf('=');
|
|
53
|
+
if (eq > 0) out[rec.slice(0, eq)] = rec.slice(eq + 1);
|
|
54
|
+
i += len;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Chemin relatif sûr d'une entrée, sans le premier segment (« package/ » dans
|
|
61
|
+
* un paquet npm, comme npm le fait), ou une erreur. '' pour la racine.
|
|
62
|
+
*/
|
|
63
|
+
function safeRelative(name, { strip = 1 } = {}) {
|
|
64
|
+
if (typeof name !== 'string' || !name) throw new TarError('entry without a name');
|
|
65
|
+
if (name.includes('\0')) throw new TarError(`refused entry ${JSON.stringify(name)}: NUL byte`);
|
|
66
|
+
if (name.includes('\\')) throw new TarError(`refused entry ${JSON.stringify(name)}: backslash`);
|
|
67
|
+
if (name.startsWith('/') || /^[A-Za-z]:/.test(name)) throw new TarError(`refused entry ${JSON.stringify(name)}: absolute path`);
|
|
68
|
+
const parts = name.split('/').filter((p) => p && p !== '.');
|
|
69
|
+
if (parts.some((p) => p === '..')) throw new TarError(`refused entry ${JSON.stringify(name)}: ".." in the path`);
|
|
70
|
+
return parts.slice(strip).join('/');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Entrées d'une archive tar (non compressée) : [{ path, type: 'file'|'dir', mode, data }].
|
|
75
|
+
* Lève TarError à la première entrée refusée.
|
|
76
|
+
*/
|
|
77
|
+
function readTar(buf, { strip = 1, maxEntries = LIMITS.maxEntries } = {}) {
|
|
78
|
+
const entries = [];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
let off = 0;
|
|
81
|
+
let pax = {};
|
|
82
|
+
let longName = null;
|
|
83
|
+
while (off + 512 <= buf.length) {
|
|
84
|
+
const header = buf.subarray(off, off + 512);
|
|
85
|
+
if (header.every((b) => b === 0)) break; // fin de l'archive
|
|
86
|
+
if (!checksumOk(header)) throw new TarError('corrupt tar header (checksum)');
|
|
87
|
+
const size = num(header, 124, 12);
|
|
88
|
+
const type = String.fromCharCode(header[156] || 0x30);
|
|
89
|
+
const dataStart = off + 512;
|
|
90
|
+
const dataEnd = dataStart + size;
|
|
91
|
+
if (dataEnd > buf.length) throw new TarError('truncated archive');
|
|
92
|
+
const data = buf.subarray(dataStart, dataEnd);
|
|
93
|
+
off = dataStart + Math.ceil(size / 512) * 512;
|
|
94
|
+
|
|
95
|
+
// En-têtes étendus : s'appliquent à l'entrée suivante
|
|
96
|
+
if (type === 'x') {
|
|
97
|
+
pax = parsePax(data);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (type === 'g') continue; // en-tête pax global : rien d'utile ici
|
|
101
|
+
if (type === 'L') {
|
|
102
|
+
longName = str(data, 0, data.length);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const prefix = str(header, 345, 155);
|
|
107
|
+
const magic = str(header, 257, 6);
|
|
108
|
+
let name = str(header, 0, 100);
|
|
109
|
+
if (magic.startsWith('ustar') && prefix) name = `${prefix}/${name}`;
|
|
110
|
+
if (longName !== null) name = longName;
|
|
111
|
+
if (pax.path) name = pax.path;
|
|
112
|
+
pax = {};
|
|
113
|
+
longName = null;
|
|
114
|
+
|
|
115
|
+
if (type === '1' || type === '2') {
|
|
116
|
+
throw new TarError(`refused entry ${JSON.stringify(name)}: ${type === '2' ? 'symbolic' : 'hard'} link (a template must not contain links)`);
|
|
117
|
+
}
|
|
118
|
+
if (!['0', '\0', '7', '5'].includes(type)) throw new TarError(`refused entry ${JSON.stringify(name)}: unsupported type "${type}"`);
|
|
119
|
+
|
|
120
|
+
const rel = safeRelative(name, { strip });
|
|
121
|
+
if (!rel) continue; // le dossier racine lui-même
|
|
122
|
+
if (seen.has(rel)) throw new TarError(`refused entry ${JSON.stringify(name)}: duplicate`);
|
|
123
|
+
seen.add(rel);
|
|
124
|
+
if (entries.length >= maxEntries) throw new TarError(`more than ${maxEntries} entries`);
|
|
125
|
+
const mode = num(header, 100, 8);
|
|
126
|
+
entries.push(type === '5' ? { path: rel, type: 'dir' } : { path: rel, type: 'file', mode: mode & 0o111 ? 0o755 : 0o644, data });
|
|
127
|
+
}
|
|
128
|
+
// Un fichier « a » puis un fichier « a/b » : refusé (pas de fichier pris pour un dossier)
|
|
129
|
+
const files = new Set(entries.filter((e) => e.type === 'file').map((e) => e.path));
|
|
130
|
+
for (const e of entries) {
|
|
131
|
+
const parts = e.path.split('/');
|
|
132
|
+
for (let i = 1; i < parts.length; i++) {
|
|
133
|
+
if (files.has(parts.slice(0, i).join('/'))) throw new TarError(`refused entry ${JSON.stringify(e.path)}: a parent is a file`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return entries;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Décompresse une archive .tgz, en bornant la taille décompressée */
|
|
140
|
+
function gunzip(tgz, { maxBytes = LIMITS.maxBytes } = {}) {
|
|
141
|
+
try {
|
|
142
|
+
return zlib.gunzipSync(tgz, { maxOutputLength: maxBytes });
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err && err.code === 'ERR_BUFFER_TOO_LARGE') throw new TarError(`archive larger than ${maxBytes} bytes once decompressed`);
|
|
145
|
+
throw new TarError(`not a gzip archive: ${err.message}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Écrit les entrées vérifiées dans target (qui doit exister) ; chaque chemin y reste */
|
|
150
|
+
function writeEntries(entries, target) {
|
|
151
|
+
const base = fs.realpathSync(target);
|
|
152
|
+
const inside = (rel) => {
|
|
153
|
+
const abs = path.resolve(base, ...rel.split('/'));
|
|
154
|
+
if (abs !== base && !abs.startsWith(base + path.sep)) throw new TarError(`refused entry ${JSON.stringify(rel)}: outside the target folder`);
|
|
155
|
+
return abs;
|
|
156
|
+
};
|
|
157
|
+
for (const e of entries) {
|
|
158
|
+
const abs = inside(e.path);
|
|
159
|
+
if (e.type === 'dir') {
|
|
160
|
+
fs.mkdirSync(abs, { recursive: true, mode: 0o755 });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true, mode: 0o755 });
|
|
164
|
+
// wx : jamais d'écriture sur un fichier (ou un lien) déjà là
|
|
165
|
+
fs.writeFileSync(abs, e.data, { flag: 'wx', mode: e.mode });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Extrait une archive .tgz dans target (créé s'il manque). Tout est vérifié
|
|
171
|
+
* avant d'écrire ; renvoie le nombre de fichiers écrits.
|
|
172
|
+
*/
|
|
173
|
+
function extractTgz(tgz, target, options = {}) {
|
|
174
|
+
const entries = readTar(gunzip(tgz, options), options);
|
|
175
|
+
fs.mkdirSync(target, { recursive: true });
|
|
176
|
+
writeEntries(entries, target);
|
|
177
|
+
return entries.filter((e) => e.type === 'file').length;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
module.exports = { extractTgz, readTar, gunzip, safeRelative, writeEntries, TarError, LIMITS };
|
package/utils/version.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Versions d'engine : x.y.z, ou x.y.z-beta.N (préversion, canal beta).
|
|
2
|
+
// Une préversion passe avant sa version finale : 0.29.0-beta.1 < 0.29.0-beta.2 < 0.29.0.
|
|
3
|
+
const VERSION_RE = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
4
|
+
|
|
5
|
+
const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);
|
|
6
|
+
const isRelease = (v) => typeof v === 'string' && /^\d+\.\d+\.\d+$/.test(v);
|
|
7
|
+
|
|
8
|
+
const parse = (v) => {
|
|
9
|
+
const m = VERSION_RE.exec(String(v || ''));
|
|
10
|
+
if (!m) {
|
|
11
|
+
const [a, b, c] = String(v || '').split('.').map((n) => parseInt(n, 10) || 0);
|
|
12
|
+
return { core: [a || 0, b || 0, c || 0], pre: null };
|
|
13
|
+
}
|
|
14
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split('.') : null };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Identifiants de préversion : numériques comparés en nombre, sinon en texte (semver)
|
|
18
|
+
const comparePre = (a, b) => {
|
|
19
|
+
if (!a && !b) return 0;
|
|
20
|
+
if (!a) return 1;
|
|
21
|
+
if (!b) return -1;
|
|
22
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
23
|
+
if (a[i] === undefined) return -1;
|
|
24
|
+
if (b[i] === undefined) return 1;
|
|
25
|
+
const na = /^\d+$/.test(a[i]);
|
|
26
|
+
const nb = /^\d+$/.test(b[i]);
|
|
27
|
+
if (na && nb && Number(a[i]) !== Number(b[i])) return Number(a[i]) - Number(b[i]);
|
|
28
|
+
if (na !== nb) return na ? -1 : 1;
|
|
29
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const compareVersions = (a, b) => {
|
|
35
|
+
const x = parse(a);
|
|
36
|
+
const y = parse(b);
|
|
37
|
+
for (let i = 0; i < 3; i++) if (x.core[i] !== y.core[i]) return x.core[i] - y.core[i];
|
|
38
|
+
return comparePre(x.pre, y.pre);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isNewer = (a, b) => compareVersions(a, b) > 0;
|
|
42
|
+
|
|
43
|
+
module.exports = { isVersion, isRelease, compareVersions, isNewer };
|