@openreachtech/mentsu-npm-audit-gate 0.0.0-stage → 0.1.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.
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Write texts to the standard output and the standard error of the process.
3
+ */
4
+ export default class ProcessLogger {
5
+ /**
6
+ * @param {{
7
+ * processClient: typeof process
8
+ * }} params - Parameters of this constructor.
9
+ */
10
+ constructor ({
11
+ processClient,
12
+ }) {
13
+ this.processClient = processClient
14
+ }
15
+
16
+ /**
17
+ * Factory method.
18
+ *
19
+ * @template {X extends typeof ProcessLogger ? X : never} T, X
20
+ * @param {{
21
+ * processClient?: typeof process
22
+ * }} [params] - Parameters for the factory method.
23
+ * @returns {InstanceType<T>} Instance of this class.
24
+ * @this {T}
25
+ * @public
26
+ */
27
+ static create ({
28
+ processClient = this.processClient,
29
+ } = {}) {
30
+ return /** @type {InstanceType<T>} */ (
31
+ new this({
32
+ processClient,
33
+ })
34
+ )
35
+ }
36
+
37
+ /**
38
+ * get: Current process.
39
+ *
40
+ * @returns {typeof process} Current process.
41
+ */
42
+ static get processClient () {
43
+ return process
44
+ }
45
+
46
+ /**
47
+ * get: Standard output stream.
48
+ *
49
+ * @returns {typeof process.stdout} Standard output stream.
50
+ */
51
+ get stdout () {
52
+ return this.processClient.stdout
53
+ }
54
+
55
+ /**
56
+ * get: Standard error stream.
57
+ *
58
+ * @returns {typeof process.stderr} Standard error stream.
59
+ */
60
+ get stderr () {
61
+ return this.processClient.stderr
62
+ }
63
+
64
+ /**
65
+ * Write a text to the standard output stream.
66
+ *
67
+ * @param {{
68
+ * text: string
69
+ * }} params - Parameters.
70
+ * @returns {BooleanLike} Whether the stream accepted the text.
71
+ * @public
72
+ */
73
+ logMessage ({
74
+ text,
75
+ }) {
76
+ return this.stdout.write(text)
77
+ }
78
+
79
+ /**
80
+ * Write a text to the standard error stream.
81
+ *
82
+ * @param {{
83
+ * text: string
84
+ * }} params - Parameters.
85
+ * @returns {BooleanLike} Whether the stream accepted the text.
86
+ * @public
87
+ */
88
+ logError ({
89
+ text,
90
+ }) {
91
+ return this.stderr.write(text)
92
+ }
93
+ }
94
+
95
+ /**
96
+ * @typedef {*} BooleanLike
97
+ */
@@ -0,0 +1,7 @@
1
+ import {
2
+ RootPath,
3
+ } from '@openreachtech/mentsu-rootpath'
4
+
5
+ const rootPath = RootPath.create()
6
+
7
+ export default rootPath
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { default as AuditFetcher } from './AuditFetcher.js'
2
+ export { default as AuditReportResponse } from './AuditReportResponse.js'
3
+ export { default as IgnoredAdvisoriesLoader } from './IgnoredAdvisoriesLoader.js'
4
+ export { default as NpmAuditGate } from './NpmAuditGate.js'
5
+ export { default as ProcessArgumentsResolver } from './ProcessArgumentsResolver.js'
6
+ export { default as ProcessLogger } from './ProcessLogger.js'
7
+
8
+ export { default as EXIT_CODE } from './EXIT_CODE.js'
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@openreachtech/mentsu-npm-audit-gate",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Gate that checks the result of npm audit",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "files": [
8
+ "lib/",
9
+ "scripts/",
10
+ "!scripts/stopgap-audit/IGNORED_ADVISORIES.js",
11
+ "types/",
12
+ "!types/env/**"
13
+ ],
14
+ "types": "./types/index.d.ts",
15
+ "scripts": {
16
+ "audit:npm": "node scripts/npm-audit-gate.js scripts/stopgap-audit/IGNORED_ADVISORIES.js",
17
+ "l": "npm run lint",
18
+ "lint": "eslint .",
19
+ "test": "export NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\"; export NODE_ENV=development; jest"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/openreachtech/mentsu-npm-audit-gate.git"
24
+ },
25
+ "author": "Open Reach Tech Inc.",
26
+ "license": "Apache-2.0",
27
+ "bugs": {
28
+ "url": "https://github.com/openreachtech/mentsu-npm-audit-gate/issues"
29
+ },
30
+ "homepage": "https://github.com/openreachtech/mentsu-npm-audit-gate#readme",
31
+ "engines": {
32
+ "node": ">=24.19.0",
33
+ "npm": ">=11.17.0"
34
+ },
35
+ "dependencies": {
36
+ "@openreachtech/mentsu-rootpath": "^1.1.3"
37
+ },
38
+ "devDependencies": {
39
+ "@openreachtech/eslint-config": "^4.5.0",
40
+ "@openreachtech/jest-constructor-spy": "^1.1.2",
41
+ "@openreachtech/jest-deep-containing": "^1.0.2",
42
+ "@openreachtech/jest-expect-each": "^1.0.3",
43
+ "@openreachtech/renchan-env": "^1.1.0",
44
+ "@types/jest": "^30.0.0",
45
+ "eslint": "^9.39.5",
46
+ "jest": "^30.5.2"
47
+ },
48
+ "overrides": {
49
+ "brace-expansion@5": "^5.0.12",
50
+ "glob": "^14.0.2",
51
+ "minimatch": "^11.0.4"
52
+ },
53
+ "allowScripts": {
54
+ "@parcel/watcher": false,
55
+ "unrs-resolver": false
56
+ }
57
+ }
@@ -0,0 +1,31 @@
1
+ import rootPath from '../lib/globals/root-path.js'
2
+
3
+ import IgnoredAdvisoriesLoader from '../lib/IgnoredAdvisoriesLoader.js'
4
+ import NpmAuditGate from '../lib/NpmAuditGate.js'
5
+ import ProcessArgumentsResolver from '../lib/ProcessArgumentsResolver.js'
6
+
7
+ const argumentsResolver = ProcessArgumentsResolver.create({
8
+ rawArguments: process.argv,
9
+ })
10
+
11
+ const ignoredAdvisoriesPath = argumentsResolver.extractIgnoredAdvisoriesFilePathArgument()
12
+
13
+ if (ignoredAdvisoriesPath === null) {
14
+ throw new Error('An argument that specifies the ignored advisories is required')
15
+ }
16
+
17
+ const loader = IgnoredAdvisoriesLoader.create({
18
+ ignoredAdvisoriesFilePath: rootPath.to(ignoredAdvisoriesPath),
19
+ })
20
+
21
+ const ignoredAdvisories = await loader.loadAdvisories()
22
+
23
+ if (ignoredAdvisories === null) {
24
+ throw new Error(`Failed to load the ignored advisories: ${ignoredAdvisoriesPath}`)
25
+ }
26
+
27
+ const gate = NpmAuditGate.create({
28
+ ignoredAdvisories,
29
+ })
30
+
31
+ process.exitCode = gate.auditAdvisories()
@@ -0,0 +1,49 @@
1
+ import type AuditFetcherActual from '../lib/AuditFetcher.js'
2
+ import type AuditReportResponseActual from '../lib/AuditReportResponse.js'
3
+ import type IgnoredAdvisoriesLoaderActual from '../lib/IgnoredAdvisoriesLoader.js'
4
+ import type NpmAuditGateActual from '../lib/NpmAuditGate.js'
5
+ import type ProcessArgumentsResolverActual from '../lib/ProcessArgumentsResolver.js'
6
+ import type ProcessLoggerActual from '../lib/ProcessLogger.js'
7
+
8
+ import type EXIT_CODE_ACTUAL from '../lib/EXIT_CODE.js'
9
+
10
+ export { default as AuditFetcher } from '../lib/AuditFetcher.js'
11
+ export { default as AuditReportResponse } from '../lib/AuditReportResponse.js'
12
+ export { default as IgnoredAdvisoriesLoader } from '../lib/IgnoredAdvisoriesLoader.js'
13
+ export { default as NpmAuditGate } from '../lib/NpmAuditGate.js'
14
+ export { default as ProcessArgumentsResolver } from '../lib/ProcessArgumentsResolver.js'
15
+ export { default as ProcessLogger } from '../lib/ProcessLogger.js'
16
+
17
+ export { default as EXIT_CODE } from '../lib/EXIT_CODE.js'
18
+
19
+ declare global {
20
+ namespace NpmAuditType {
21
+ type AuditFetcher = AuditFetcherActual
22
+ type AuditFetcherCtor = typeof AuditFetcherActual
23
+
24
+ type AuditReportResponse = AuditReportResponseActual
25
+ type AuditReportResponseCtor = typeof AuditReportResponseActual
26
+
27
+ type IgnoredAdvisoriesLoader = IgnoredAdvisoriesLoaderActual
28
+ type IgnoredAdvisoriesLoaderCtor = typeof IgnoredAdvisoriesLoaderActual
29
+
30
+ type NpmAuditGate = NpmAuditGateActual
31
+ type NpmAuditGateCtor = typeof NpmAuditGateActual
32
+
33
+ type ProcessArgumentsResolver = ProcessArgumentsResolverActual
34
+ type ProcessArgumentsResolverCtor = typeof ProcessArgumentsResolverActual
35
+
36
+ type ProcessLogger = ProcessLoggerActual
37
+ type ProcessLoggerCtor = typeof ProcessLoggerActual
38
+
39
+ type EXIT_CODE = typeof EXIT_CODE_ACTUAL
40
+
41
+ type IgnoredAdvisory = {
42
+ id: string
43
+ package: string
44
+ path: string
45
+ reason: string
46
+ removeWhen: string
47
+ }
48
+ }
49
+ }