@theoptimalpartner/npm-security-kit 2.0.0-beta.1 → 2.0.0-beta.2
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/CHANGELOG.md +3 -1
- package/package.json +1 -1
- package/src/init.js +24 -4
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,9 @@ Cambios del paquete `@theoptimalpartner/npm-security-kit`. Formato basado en
|
|
|
8
8
|
Reescritura completa. La v2 es una CLI de Node sin dependencias que corre en el pipeline **antes de `npm ci`**.
|
|
9
9
|
Sale primero como beta (`2.0.0-beta.N`), con el dist-tag `beta`. Desde la `2.0.0-beta.1`, el step del pipeline y
|
|
10
10
|
`init` usan `npx --yes --min-release-age=0`: `npx` no aplica `min-release-age-exclude` y, sin el flag, una versión
|
|
11
|
-
nueva del kit no se puede usar hasta cumplir 7 días.
|
|
11
|
+
nueva del kit no se puede usar hasta cumplir 7 días. Desde la `2.0.0-beta.2`, `init` propone el Node que ya usa el
|
|
12
|
+
repo si es una LTS con soporte (la imagen del step de ejemplo y, si falta, `engines.node`), en vez de la LTS más
|
|
13
|
+
nueva: un `engines.node` más alto que el Node del repo rompe su `npm ci` con `engine-strict`.
|
|
12
14
|
|
|
13
15
|
### BREAKING
|
|
14
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoptimalpartner/npm-security-kit",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Revisa el lockfile antes de npm ci: malware, vulnerabilidades, versión de Node, .npmrc, install scripts y Dockerfiles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/init.js
CHANGED
|
@@ -77,6 +77,27 @@ export function mergePackageJson(text, policy, nodeMajor) {
|
|
|
77
77
|
return { text: finalNewline ? `${out}${eol}` : out, changes };
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
// El Node que init propone (engines.node y la imagen del step de ejemplo): el que ya usa el repo si es
|
|
81
|
+
// de una LTS con soporte, para que adoptar el kit no obligue a cambiar de Node. engines.node toma la
|
|
82
|
+
// línea más baja en uso (con engine-strict, un ">=" más alto rompe el npm ci de esa línea), y la imagen,
|
|
83
|
+
// la versión exacta del pipeline. Sin eso, la release LTS recomendada.
|
|
84
|
+
export function repoNode(ctx, cal) {
|
|
85
|
+
const recommended = cal.recommended ?? null;
|
|
86
|
+
let major = null;
|
|
87
|
+
let image = null;
|
|
88
|
+
for (const pin of nodeVersionCheck.findPins(ctx)) {
|
|
89
|
+
const r = nodeVersionCheck.resolvePin(pin, cal);
|
|
90
|
+
if (r.major === undefined || r.major === null || r.latest) continue;
|
|
91
|
+
if (!['active', 'maintenance'].includes(cal.phaseOf(r.major))) continue;
|
|
92
|
+
if (major === null || r.major < major) major = r.major;
|
|
93
|
+
if (!image && pin.file === 'bitbucket-pipelines.yml' && pin.kind === 'docker' && r.exact) image = r.exact;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
major: major ?? (recommended ? parseVersion(recommended)[0] : null),
|
|
97
|
+
image: image ?? recommended,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
80
101
|
export function pipelineStep(kitVersion, nodeVersion) {
|
|
81
102
|
return `- step: &test
|
|
82
103
|
name: Test (supply chain + build)
|
|
@@ -147,15 +168,14 @@ export async function runInit(ctx, { dryRun = false, stdout = process.stdout, co
|
|
|
147
168
|
} catch (error) {
|
|
148
169
|
cal = { error };
|
|
149
170
|
}
|
|
150
|
-
const
|
|
151
|
-
const nodeMajor = nodeVersion ? parseVersion(nodeVersion)[0] : null;
|
|
171
|
+
const node = cal.error ? { major: null, image: null } : repoNode(ctx, cal);
|
|
152
172
|
|
|
153
173
|
say(paint(2, `npm-security-kit ${ctx.kitVersion} · init${dryRun ? ' --dry-run' : ''} · ${ctx.dir}`));
|
|
154
174
|
|
|
155
175
|
// 1. .npmrc y package.json
|
|
156
176
|
const npmrcBefore = ctx.readFile('.npmrc');
|
|
157
177
|
const npmrc = mergeNpmrc(npmrcBefore, ctx.policy);
|
|
158
|
-
const pkg = mergePackageJson(pkgText, ctx.policy,
|
|
178
|
+
const pkg = mergePackageJson(pkgText, ctx.policy, node.major);
|
|
159
179
|
if (npmrc.changes.length) files['.npmrc'] = npmrc.text;
|
|
160
180
|
if (pkg.changes.length) files['package.json'] = pkg.text;
|
|
161
181
|
|
|
@@ -207,7 +227,7 @@ export async function runInit(ctx, { dryRun = false, stdout = process.stdout, co
|
|
|
207
227
|
} else {
|
|
208
228
|
say(` ${pipeline === null ? 'No hay bitbucket-pipelines.yml. ' : ''}Agregar el kit en el step de test, ANTES de npm ci, y correrlo solo en los PR a ramas que despliegan:`);
|
|
209
229
|
say();
|
|
210
|
-
for (const line of pipelineStep(ctx.kitVersion,
|
|
230
|
+
for (const line of pipelineStep(ctx.kitVersion, node.image ?? '<versión LTS>').split('\n')) say(` ${line}`);
|
|
211
231
|
}
|
|
212
232
|
|
|
213
233
|
// 4. Dockerfiles (no se editan)
|