Skip to content

Commit 5b0341b

Browse files
committed
Fix alert-rules.test
1 parent 75cd55b commit 5b0341b

5 files changed

Lines changed: 31 additions & 14 deletions

File tree

.config/rollup.base.config.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
resolveId
2929
} from '../scripts/utils/packages.js'
3030

31+
const require = createRequire(import.meta.url)
32+
3133
const {
3234
BABEL_RUNTIME,
3335
LATEST,
@@ -41,46 +43,50 @@ const {
4143
tsconfigPath
4244
} = constants
4345

44-
const require = createRequire(import.meta.url)
46+
const SOCKET_INTEROP = '_socketInterop'
4547

46-
const tsPlugin = require('rollup-plugin-ts')
48+
const constantsSrcPath = path.join(rootSrcPath, 'constants.ts')
4749

50+
const babelConfig = require(babelConfigPath)
51+
const tsPlugin = require('rollup-plugin-ts')
4852
const rootPackageJson = require(rootPackageJsonPath)
53+
4954
const {
5055
dependencies: pkgDeps,
5156
devDependencies: pkgDevDeps,
5257
overrides: pkgOverrides
5358
} = rootPackageJson
5459

55-
const SOCKET_INTEROP = '_socketInterop'
56-
57-
const constantsSrcPath = path.join(rootSrcPath, 'constants.ts')
58-
5960
const builtinAliases = builtinModules.reduce((o, n) => {
6061
o[n] = `node:${n}`
6162
return o
6263
}, {})
6364

64-
const babelConfig = require(babelConfigPath)
65-
6665
const customResolver = nodeResolve({
6766
exportConditions: ['node'],
6867
preferBuiltins: true
6968
})
7069

7170
const requireAssignmentsRegExp =
7271
/(?<=\s*=\s*)require\(["'](?!node:|@socket(?:registry|security)\/|\.).+?["']\)(?=;?\r?\n)/g
72+
7373
const checkRequireAssignmentRegExp = new RegExp(
7474
requireAssignmentsRegExp.source,
7575
''
7676
)
7777
const checkSocketInteropUseRegExp = new RegExp(`\\b${SOCKET_INTEROP}\\b`)
78+
7879
const danglingRequiresRegExp = /^\s*require\(["'].+?["']\);?\r?\n/gm
80+
7981
const firstUseStrictRegExp = /'use strict';?/
82+
8083
const oraSpinnersAssignmentsRegExp = /(?<=ora[^.]+\.spinners\s*=\s*)[$\w]+/g
84+
8185
const requireTinyColorsRegExp = /require\(["']tiny-colors["']\)/g
86+
8287
const requireUrlAssignmentRegExp =
8388
/(?<=var +)[$\w]+(?= *= *require\('node:url'\))/
89+
8490
const splitUrlRequiresRegExp = /require\(["']u["']\s*\+\s*["']rl["']\)/g
8591

8692
function isAncestorsExternal(id, depStats) {

.config/rollup.dist.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { isRelative } from '@socketsecurity/registry/lib/path'
1212

1313
import baseConfig from './rollup.base.config.mjs'
1414
import constants from '../scripts/constants.js'
15+
import socketModifyPlugin from '../scripts/rollup/socket-modify-plugin.js'
1516
import { readJsonSync } from '../scripts/utils/fs.js'
1617
import { formatObject } from '../scripts/utils/objects.js'
1718
import {
@@ -38,6 +39,8 @@ const distRequirePath = path.join(rootDistPath, 'require')
3839

3940
const editablePkgJson = readPackageJsonSync(rootPath, { editable: true })
4041

42+
const processEnvTapRegExp = /\bprocess\.env(?:\.TAP|\[['"]TAP['"]\])(\s*\?[^:]+:\s*)?/g
43+
4144
function removeDtsFilesSync(distPath) {
4245
for (const filepath of tinyGlobSync(['**/*.d.ts'], {
4346
absolute: true,
@@ -125,6 +128,12 @@ export default () => {
125128
return true
126129
},
127130
plugins: [
131+
// When process.env['TAP'] is found either remove it, if part of a ternary
132+
// operation, or replace it with `false`.
133+
socketModifyPlugin({
134+
find: processEnvTapRegExp,
135+
replace: (match, ternary) => ternary ? '' : 'false'
136+
}),
128137
{
129138
generateBundle(_options, bundle) {
130139
const constantsBundle = bundle[CONSTANTS_JS]

.config/rollup.test.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const {
1818

1919
export default () =>
2020
baseConfig({
21-
input: {
22-
misc: `${rootSrcPath}/utils/misc.ts`,
23-
'path-resolve': `${rootSrcPath}/utils/path-resolve.ts`
24-
},
21+
input: ['alert-rules', 'misc', 'path-resolve'].reduce((o, k) => {
22+
o[k] = `${rootSrcPath}/utils/${k}.ts`
23+
return o
24+
}, {}),
2525
output: [
2626
{
2727
dir: 'test/dist',

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const lazyRootDistPath = () =>
105105
// Lazily access constants.rootPath.
106106
path.join(constants.rootPath, 'dist')
107107

108-
const lazyRootPath = () => path.resolve(realpathSync(__dirname), '..')
108+
// The '@rollup/plugin-replace' will replace 'process.env.TAP' with `false` and
109+
// it will be dead code eliminated by Rollup.
110+
const lazyRootPath = () => path.resolve(realpathSync(__dirname), process.env['TAP'] ? '../..' : '..')
109111

110112
const lazyRootPkgJsonPath = () =>
111113
// Lazily access constants.rootPath.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert/strict'
22
import { describe, it } from 'node:test'
33

4-
import { createAlertUXLookup } from '../src/utils/alert-rules'
4+
import { createAlertUXLookup } from './dist/alert-rules'
55

66
describe('Alert Rule UX', () => {
77
it('should properly defer', () => {

0 commit comments

Comments
 (0)