Skip to content

Commit fada95d

Browse files
committed
Use more @__PURE__ annotations
1 parent 7d2c94e commit fada95d

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

src/commands/analytics/output-analytics.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ ${mdTableStringNumber('Name', 'Counts', data['top_five_alert_types'])}
202202
}
203203

204204
function displayAnalyticsScreen(data: FormattedData): void {
205-
const ScreenWidget = require('blessed/lib/widgets/screen.js')
205+
const ScreenWidget = /*@__PURE__*/ require('blessed/lib/widgets/screen.js')
206206
// Lazily access constants.blessedOptions.
207207
const screen: Widgets.Screen = new ScreenWidget({
208208
...constants.blessedOptions,
209209
})
210-
const GridLayout = require('blessed-contrib/lib/layout/grid.js')
210+
const GridLayout = /*@__PURE__*/ require('blessed-contrib/lib/layout/grid.js')
211211
const grid = new GridLayout({ rows: 5, cols: 4, screen })
212212

213213
renderLineCharts(
@@ -267,7 +267,7 @@ function displayAnalyticsScreen(data: FormattedData): void {
267267
data['total_low_prevented'],
268268
)
269269

270-
const BarChart = require('blessed-contrib/lib/widget/charts/bar.js')
270+
const BarChart = /*@__PURE__*/ require('blessed-contrib/lib/widget/charts/bar.js')
271271
const bar = grid.set(4, 0, 1, 2, BarChart, {
272272
label: 'Top 5 alert types',
273273
barWidth: 10,
@@ -389,7 +389,7 @@ function renderLineCharts(
389389
coords: number[],
390390
data: Record<string, number>,
391391
): void {
392-
const LineChart = require('blessed-contrib/lib/widget/charts/line.js')
392+
const LineChart = /*@__PURE__*/ require('blessed-contrib/lib/widget/charts/line.js')
393393
const line = grid.set(...coords, LineChart, {
394394
style: { line: 'cyan', text: 'cyan', baseline: 'black' },
395395
xLabelPadding: 0,

src/commands/audit-log/output-audit-log.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async function outputWithBlessed(
211211
]
212212

213213
// Note: this temporarily takes over the terminal (just like `man` does).
214-
const ScreenWidget = require('blessed/lib/widgets/screen.js')
214+
const ScreenWidget = /*@__PURE__*/ require('blessed/lib/widgets/screen.js')
215215
// Lazily access constants.blessedOptions.
216216
const screen: Widgets.Screen = new ScreenWidget({
217217
...constants.blessedOptions,
@@ -222,7 +222,7 @@ async function outputWithBlessed(
222222
// eslint-disable-next-line n/no-process-exit
223223
screen.key(['escape', 'q', 'C-c'], () => process.exit(0))
224224

225-
const TableWidget = require('blessed-contrib/lib/widget/table.js')
225+
const TableWidget = /*@__PURE__*/ require('blessed-contrib/lib/widget/table.js')
226226
const tipsBoxHeight = 1 // 1 row for tips box
227227
const detailsBoxHeight = 20 // bottom N rows for details box. 20 gives 4 lines for condensed payload before it scrolls out of view
228228

@@ -253,7 +253,7 @@ async function outputWithBlessed(
253253
truncate: '_',
254254
})
255255

256-
const BoxWidget = require('blessed/lib/widgets/box.js')
256+
const BoxWidget = /*@__PURE__*/ require('blessed/lib/widgets/box.js')
257257
const tipsBox: Widgets.BoxElement = new BoxWidget({
258258
bottom: detailsBoxHeight, // sits just above the details box
259259
height: tipsBoxHeight,

src/commands/npm/cmd-npm.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ async function run(
6262
}
6363

6464
// Lazily access constants.shadowNpmBinPath.
65-
const shadowBin = require(constants.shadowNpmBinPath)
65+
const shadowBin = /*@__PURE__*/ require(constants.shadowNpmBinPath)
6666
await shadowBin('npm', argv)
6767
}

src/commands/npx/cmd-npx.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ async function run(
6262
}
6363

6464
// Lazily access constants.shadowNpmBinPath.
65-
const shadowBin = require(constants.shadowNpmBinPath)
65+
const shadowBin = /*@__PURE__*/ require(constants.shadowNpmBinPath)
6666
await shadowBin('npx', argv)
6767
}

src/commands/threat-feed/output-threat-feed.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function outputThreatFeed(
3939
const descriptions = result.data.results.map(d => d.description)
4040

4141
// Note: this temporarily takes over the terminal (just like `man` does).
42-
const ScreenWidget = require('blessed/lib/widgets/screen.js')
42+
const ScreenWidget = /*@__PURE__*/ require('blessed/lib/widgets/screen.js')
4343
// Lazily access constants.blessedOptions.
4444
const screen: Widgets.Screen = new ScreenWidget({
4545
...constants.blessedOptions,
@@ -50,7 +50,7 @@ export async function outputThreatFeed(
5050
// eslint-disable-next-line n/no-process-exit
5151
screen.key(['escape', 'q', 'C-c'], () => process.exit(0))
5252

53-
const TableWidget = require('blessed-contrib/lib/widget/table.js')
53+
const TableWidget = /*@__PURE__*/ require('blessed-contrib/lib/widget/table.js')
5454
const detailsBoxHeight = 20 // bottom N rows for details box
5555
const tipsBoxHeight = 1 // 1 row for tips box
5656

@@ -75,7 +75,7 @@ export async function outputThreatFeed(
7575
truncate: '_',
7676
})
7777

78-
const BoxWidget = require('blessed/lib/widgets/box.js')
78+
const BoxWidget = /*@__PURE__*/ require('blessed/lib/widgets/box.js')
7979
const tipsBox: Widgets.BoxElement = new BoxWidget({
8080
bottom: detailsBoxHeight, // sits just above the details box
8181
height: tipsBoxHeight,

src/instrument-with-sentry.mts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { createRequire } from 'node:module'
55

66
import { logger } from '@socketsecurity/registry/lib/logger'
77

8-
const require = createRequire(import.meta.url)
9-
10-
// Require constants with require(relConstantsPath) instead of require('./constants')
11-
// so Rollup doesn't generate a constants2.js chunk.
12-
const relConstantsPath = './constants'
13-
const constants = require(relConstantsPath)
8+
import constants from './constants.mts'
149

1510
// Lazily access constants.ENV.INLINED_SOCKET_CLI_SENTRY_BUILD.
1611
if (constants.ENV.INLINED_SOCKET_CLI_SENTRY_BUILD) {
17-
const Sentry = require('@sentry/node')
12+
const require = createRequire(import.meta.url)
13+
const Sentry = /*@__PURE__*/ require('@sentry/node')
1814
Sentry.init({
1915
onFatalError(error: Error) {
2016
// Defer module loads until after Sentry.init is called.

src/utils/translations.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let _translations: typeof import('../../translations.json') | undefined
99

1010
export function getTranslations() {
1111
if (_translations === undefined) {
12-
_translations = require(
12+
_translations = /*@__PURE__*/ require(
1313
// Lazily access constants.rootPath.
1414
path.join(constants.rootPath, 'translations.json'),
1515
)

0 commit comments

Comments
 (0)