Skip to content

Commit 367814a

Browse files
committed
resolve package conflicts
2 parents f478124 + 4f2907e commit 367814a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2651
-2265
lines changed

.config/rollup.base.config.mjs

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

31+
const require = createRequire(import.meta.url)
32+
3133
const {
3234
BABEL_RUNTIME,
35+
CONSTANTS,
3336
LATEST,
3437
ROLLUP_ENTRY_SUFFIX,
3538
ROLLUP_EXTERNAL_SUFFIX,
3639
SLASH_NODE_MODULES_SLASH,
40+
VENDOR,
3741
babelConfigPath,
3842
rootPackageJsonPath,
3943
rootPath,
4044
rootSrcPath,
4145
tsconfigPath
4246
} = constants
4347

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

46-
const tsPlugin = require('rollup-plugin-ts')
50+
const constantsSrcPath = path.join(rootSrcPath, `${CONSTANTS}.ts`)
4751

52+
const babelConfig = require(babelConfigPath)
53+
const tsPlugin = require('rollup-plugin-ts')
4854
const rootPackageJson = require(rootPackageJsonPath)
55+
4956
const {
5057
dependencies: pkgDeps,
5158
devDependencies: pkgDevDeps,
5259
overrides: pkgOverrides
5360
} = rootPackageJson
5461

55-
const SOCKET_INTEROP = '_socketInterop'
56-
57-
const constantsSrcPath = path.join(rootSrcPath, 'constants.ts')
58-
5962
const builtinAliases = builtinModules.reduce((o, n) => {
6063
o[n] = `node:${n}`
6164
return o
6265
}, {})
6366

64-
const babelConfig = require(babelConfigPath)
65-
6667
const customResolver = nodeResolve({
6768
exportConditions: ['node'],
6869
preferBuiltins: true
6970
})
7071

7172
const requireAssignmentsRegExp =
7273
/(?<=\s*=\s*)require\(["'](?!node:|@socket(?:registry|security)\/|\.).+?["']\)(?=;?\r?\n)/g
74+
7375
const checkRequireAssignmentRegExp = new RegExp(
7476
requireAssignmentsRegExp.source,
7577
''
7678
)
7779
const checkSocketInteropUseRegExp = new RegExp(`\\b${SOCKET_INTEROP}\\b`)
80+
7881
const danglingRequiresRegExp = /^\s*require\(["'].+?["']\);?\r?\n/gm
82+
7983
const firstUseStrictRegExp = /'use strict';?/
84+
8085
const oraSpinnersAssignmentsRegExp = /(?<=ora[^.]+\.spinners\s*=\s*)[$\w]+/g
86+
8187
const requireTinyColorsRegExp = /require\(["']tiny-colors["']\)/g
88+
8289
const requireUrlAssignmentRegExp =
8390
/(?<=var +)[$\w]+(?= *= *require\('node:url'\))/
91+
8492
const splitUrlRequiresRegExp = /require\(["']u["']\s*\+\s*["']rl["']\)/g
8593

8694
function isAncestorsExternal(id, depStats) {
@@ -314,10 +322,10 @@ function ${SOCKET_INTEROP}(e) {
314322
manualChunks: id_ => {
315323
const id = normalizeId(id_)
316324
if (id === constantsSrcPath) {
317-
return 'constants'
325+
return CONSTANTS
318326
}
319327
if (id.includes(SLASH_NODE_MODULES_SLASH)) {
320-
return 'vendor'
328+
return VENDOR
321329
}
322330
return null
323331
}

.config/rollup.dist.config.mjs

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
1+
import {
2+
copyFileSync,
3+
existsSync,
4+
mkdirSync,
5+
rmSync,
6+
writeFileSync
7+
} from 'node:fs'
28
import path from 'node:path'
39

410
import { globSync as tinyGlobSync } from 'tinyglobby'
@@ -12,6 +18,7 @@ import { isRelative } from '@socketsecurity/registry/lib/path'
1218

1319
import baseConfig from './rollup.base.config.mjs'
1420
import constants from '../scripts/constants.js'
21+
import socketModifyPlugin from '../scripts/rollup/socket-modify-plugin.js'
1522
import { readJsonSync } from '../scripts/utils/fs.js'
1623
import { formatObject } from '../scripts/utils/objects.js'
1724
import {
@@ -22,26 +29,48 @@ import {
2229

2330
const {
2431
BABEL_RUNTIME,
32+
CONSTANTS,
33+
MODULE_SYNC,
34+
REQUIRE,
2535
ROLLUP_EXTERNAL_SUFFIX,
36+
VENDOR,
2637
depStatsPath,
2738
rootDistPath,
2839
rootPath,
2940
rootSrcPath
3041
} = constants
3142

32-
const CONSTANTS_JS = 'constants.js'
33-
const CONSTANTS_STUB_CODE = `'use strict'\n\nmodule.exports = require('../${CONSTANTS_JS}')\n`
43+
const CONSTANTS_JS = `${CONSTANTS}.js`
44+
const CONSTANTS_STUB_CODE = createStubCode(`../${CONSTANTS_JS}`)
45+
const VENDOR_JS = `${VENDOR}.js`
3446

3547
const distConstantsPath = path.join(rootDistPath, CONSTANTS_JS)
36-
const distModuleSyncPath = path.join(rootDistPath, 'module-sync')
37-
const distRequirePath = path.join(rootDistPath, 'require')
48+
const distModuleSyncPath = path.join(rootDistPath, MODULE_SYNC)
49+
const distRequirePath = path.join(rootDistPath, REQUIRE)
3850

3951
const editablePkgJson = readPackageJsonSync(rootPath, { editable: true })
4052

41-
function removeDtsFilesSync(distPath) {
42-
for (const filepath of tinyGlobSync(['**/*.d.ts'], {
53+
const processEnvTapRegExp =
54+
/\bprocess\.env(?:\.TAP|\[['"]TAP['"]\])(\s*\?[^:]+:\s*)?/g
55+
56+
function createStubCode(relFilepath) {
57+
return `'use strict'\n\nmodule.exports = require('${relFilepath}')\n`
58+
}
59+
60+
function moveDtsFilesSync(namePattern, srcPath, destPath) {
61+
for (const filepath of tinyGlobSync([`**/${namePattern}.d.ts{.map,}`], {
62+
absolute: true,
63+
cwd: srcPath
64+
})) {
65+
copyFileSync(filepath, path.join(destPath, path.basename(filepath)))
66+
rmSync(filepath)
67+
}
68+
}
69+
70+
function removeDtsFilesSync(namePattern, srcPath) {
71+
for (const filepath of tinyGlobSync([`**/${namePattern}.d.ts{.map,}`], {
4372
absolute: true,
44-
cwd: distPath
73+
cwd: srcPath
4574
})) {
4675
rmSync(filepath)
4776
}
@@ -127,12 +156,13 @@ export default () => {
127156
plugins: [
128157
{
129158
generateBundle(_options, bundle) {
130-
const constantsBundle = bundle[CONSTANTS_JS]
131-
if (constantsBundle) {
132-
mkdirSync(rootDistPath, { recursive: true })
133-
writeFileSync(distConstantsPath, constantsBundle.code, 'utf8')
134-
bundle[CONSTANTS_JS].code = CONSTANTS_STUB_CODE
159+
const data = bundle[CONSTANTS_JS]
160+
if (data?.type === 'chunk') {
161+
data.code = CONSTANTS_STUB_CODE
135162
}
163+
},
164+
writeBundle() {
165+
removeDtsFilesSync(CONSTANTS, distModuleSyncPath)
136166
}
137167
}
138168
]
@@ -156,14 +186,33 @@ export default () => {
156186
}
157187
],
158188
plugins: [
189+
// When process.env['TAP'] is found either remove it, if part of a ternary
190+
// operation, or replace it with `false`.
191+
socketModifyPlugin({
192+
find: processEnvTapRegExp,
193+
replace: (_match, ternary) => (ternary ? '' : 'false')
194+
}),
159195
{
160196
generateBundle(_options, bundle) {
161-
if (bundle[CONSTANTS_JS]) {
162-
bundle[CONSTANTS_JS].code = CONSTANTS_STUB_CODE
197+
for (const basename of Object.keys(bundle)) {
198+
const data = bundle[basename]
199+
if (data.type === 'chunk') {
200+
if (basename === CONSTANTS_JS) {
201+
mkdirSync(rootDistPath, { recursive: true })
202+
writeFileSync(distConstantsPath, data.code, 'utf8')
203+
data.code = CONSTANTS_STUB_CODE
204+
} else if (
205+
basename !== VENDOR_JS &&
206+
!data.code.includes(`'./${VENDOR_JS}'`)
207+
) {
208+
data.code = createStubCode(`../${MODULE_SYNC}/${basename}`)
209+
}
210+
}
163211
}
164212
},
165213
writeBundle() {
166-
removeDtsFilesSync(distRequirePath)
214+
moveDtsFilesSync(CONSTANTS, distRequirePath, rootDistPath)
215+
removeDtsFilesSync('*', distRequirePath)
167216
updateDepStatsSync(requireConfig.meta.depStats)
168217
}
169218
}

.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', 'errors', 'path-resolve'].reduce((o, k) => {
22+
o[k.replaceAll('/', '-')] = `${rootSrcPath}/utils/${k}.ts`
23+
return o
24+
}, {}),
2525
output: [
2626
{
2727
dir: 'test/dist',

.ncurc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"loglevel": "minimal",
3+
"reject": ["has-flag", "terminal-link", "typescript"],
4+
"upgrade": true
5+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ use of the `projectIgnorePaths` to excludes files when creating a report.
117117

118118
## Environment variables
119119

120-
- `SOCKET_SECURITY_API_KEY` - if set, this will be used as the API-key
120+
- `SOCKET_SECURITY_API_TOKEN` - if set, this will be used as the API-key
121121

122122
## Contributing
123123

bin/cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22
'use strict'
33

4+
const process = require('node:process')
5+
46
const constants = require('../dist/constants')
57

68
const { DIST_TYPE } = constants

eslint.config.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function getImportXFlatConfigs(isEsm) {
100100
// TypeScript compilation already ensures that named imports exist in
101101
// the referenced module.
102102
'import-x/named': 'off',
103-
'import-x/no-named-as-default-member': 'off'
103+
'import-x/no-named-as-default-member': 'off',
104+
'import-x/no-unresolved': 'off'
104105
}
105106
}
106107
}
@@ -121,17 +122,9 @@ module.exports = [
121122
...importFlatConfigsForModule.recommended
122123
},
123124
{
124-
files: ['src/**/*.ts'],
125+
files: ['src/**/*.ts', 'test/**/*.ts'],
125126
...importFlatConfigsForModule.typescript
126127
},
127-
{
128-
files: ['test/**/*.ts'],
129-
...importFlatConfigsForModule.typescript,
130-
rules: {
131-
...importFlatConfigsForModule.typescript.rules,
132-
'import-x/no-unresolved': 'off'
133-
}
134-
},
135128
{
136129
files: ['src/**/*.ts', 'test/**/*.ts'],
137130
languageOptions: {

scripts/constants.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ const {
99
[kInternalsSymbol]: { createConstantsObject }
1010
} = registryConstants
1111

12+
const CONSTANTS = 'constants'
13+
const MODULE_SYNC = 'module-sync'
14+
const REQUIRE = 'require'
1215
const ROLLUP_ENTRY_SUFFIX = '?commonjs-entry'
1316
const ROLLUP_EXTERNAL_SUFFIX = '?commonjs-external'
1417
const SLASH_NODE_MODULES_SLASH = '/node_modules/'
18+
const VENDOR = 'vendor'
1519

1620
const lazyBabelConfigPath = () =>
1721
// Lazily access constants.rootConfigPath.
@@ -45,9 +49,13 @@ const lazyTsconfigPath = () =>
4549

4650
const constants = createConstantsObject(
4751
{
52+
CONSTANTS,
53+
MODULE_SYNC,
54+
REQUIRE,
4855
ROLLUP_ENTRY_SUFFIX,
4956
ROLLUP_EXTERNAL_SUFFIX,
5057
SLASH_NODE_MODULES_SLASH,
58+
VENDOR,
5159
babelConfigPath: undefined,
5260
depStatsPath: undefined,
5361
rootConfigPath: undefined,

src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import process from 'node:process'
34
import { pathToFileURL } from 'node:url'
45

56
import { messageWithCauses, stackWithCauses } from 'pony-cause'
@@ -8,8 +9,8 @@ import colors from 'yoctocolors-cjs'
89

910
import * as cliCommands from './commands'
1011
import constants from './constants'
11-
import { logSymbols } from './utils/color-or-markdown'
1212
import { AuthError, InputError } from './utils/errors'
13+
import { logSymbols } from './utils/logging'
1314
import { meowWithSubcommands } from './utils/meow-with-subcommands'
1415

1516
const { rootPkgJsonPath } = constants

src/commands/analytics.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ import colors from 'yoctocolors-cjs'
1414
import { Spinner } from '@socketsecurity/registry/lib/spinner'
1515

1616
import { commonFlags, outputFlags } from '../flags'
17-
import {
18-
handleApiCall,
19-
handleUnsuccessfulApiResponse
20-
} from '../utils/api-helpers'
17+
import { handleApiCall, handleUnsuccessfulApiResponse } from '../utils/api'
2118
import { AuthError, InputError } from '../utils/errors'
22-
import { printFlagList } from '../utils/formatting'
23-
import { getDefaultKey, setupSdk } from '../utils/sdk'
19+
import { getFlagListOutput } from '../utils/output-formatting'
20+
import { getDefaultToken, setupSdk } from '../utils/sdk'
2421

2522
import type { CliSubcommand } from '../utils/meow-with-subcommands'
2623

@@ -32,7 +29,7 @@ export const analytics: CliSubcommand = {
3229

3330
const input = setupCommand(name, analytics.description, argv, importMeta)
3431
if (input) {
35-
const apiKey = getDefaultKey()
32+
const apiKey = getDefaultToken()
3633
if (!apiKey) {
3734
throw new AuthError(
3835
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
@@ -117,7 +114,7 @@ function setupCommand(
117114
$ ${name} --scope=<scope> --time=<time filter>
118115
119116
Options
120-
${printFlagList(flags, 6)}
117+
${getFlagListOutput(flags, 6)}
121118
122119
Examples
123120
$ ${name} --scope=org --time=7

0 commit comments

Comments
 (0)