Skip to content

Commit ff91405

Browse files
authored
Bundle registry package (#466)
1 parent 7ba040b commit ff91405

File tree

6 files changed

+66
-60
lines changed

6 files changed

+66
-60
lines changed

.config/rollup.base.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const EXTERNAL_PACKAGES = [
4949
'blessed-contrib'
5050
]
5151

52+
export const BUNDLED_PACKAGES = EXTERNAL_PACKAGES.slice()
53+
5254
const builtinAliases = builtinModules.reduce((o, n) => {
5355
o[n] = `node:${n}`
5456
return o
@@ -309,7 +311,7 @@ export default function baseConfig(extendConfig = {}) {
309311
}),
310312
// Replace requires like require('blessed/lib/widgets/screen') with
311313
// require('../blessed/lib/widgets/screen').
312-
...[/*'@socketsecurity/registry',*/ 'blessed', 'blessed-contrib'].map(n => {
314+
...BUNDLED_PACKAGES.map(n => {
313315
const requiresRegExp = new RegExp(
314316
`(?<=require\\(["'])${escapeRegExp(n)}(?:=(?:\\/[^"']+)?["']\\))`,
315317
'g'

.config/rollup.dist.config.mjs

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@socketsecurity/registry/lib/packages'
1515
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
1616

17-
import baseConfig from './rollup.base.config.mjs'
17+
import baseConfig, { BUNDLED_PACKAGES } from './rollup.base.config.mjs'
1818
import constants from '../scripts/constants.js'
1919

2020
const {
@@ -55,19 +55,21 @@ async function copyPackage(pkgName) {
5555
// Add 'use strict' directive to js files.
5656
const jsFiles = await tinyGlob(['**/*.js'], {
5757
absolute: true,
58-
cwd: pkgDestPath
58+
cwd: pkgDestPath,
59+
ignore: ['node_modules/**']
5960
})
6061
await Promise.all(
6162
jsFiles.map(async p => {
6263
const content = await fs.readFile(p, 'utf8')
6364
// Start by trimming the hashbang.
64-
const hashbang = /^#!.*(?=\r?\n|$)/.exec(content)?.[0] ?? ''
65+
const hashbang = /^#!.*(?:\r?\n)*/.exec(content)?.[0] ?? ''
6566
let trimmed = content.slice(hashbang.length).trimStart()
6667
// Then, trim "use strict" directive.
67-
const useStrict = /^(['"])use strict\1/.exec(trimmed)?.[0] ?? ''
68+
const useStrict =
69+
/^(['"])use strict\1;?(?:\r?\n)*/.exec(trimmed)?.[0] ?? ''
6870
trimmed = trimmed.slice(useStrict.length).trimStart()
6971
// Add back hashbang and add "use strict" directive.
70-
const modded = `${hashbang}${os.EOL}${useStrict ?? "'use strict'"}${os.EOL}${trimmed}`
72+
const modded = `${hashbang.trim()}${hashbang ? os.EOL : ''}${useStrict.trim() || "'use strict'"}${os.EOL}${os.EOL}${trimmed}`
7173
await fs.writeFile(p, modded, 'utf8')
7274
})
7375
)
@@ -81,6 +83,38 @@ async function getSentryManifest() {
8183
return _sentryManifest
8284
}
8385

86+
async function removeDirs(srcPath, options) {
87+
const { exclude } = { __proto__: null, ...options }
88+
const ignore = Array.isArray(exclude) ? exclude : exclude ? [exclude] : []
89+
return Promise.all([
90+
(
91+
await tinyGlob(['**/*'], {
92+
absolute: true,
93+
onlyDirectories: true,
94+
cwd: srcPath,
95+
dot: true,
96+
ignore
97+
})
98+
).map(p => remove(p))
99+
])
100+
}
101+
102+
async function removeFiles(srcPath, options) {
103+
const { exclude } = { __proto__: null, ...options }
104+
const ignore = Array.isArray(exclude) ? exclude : exclude ? [exclude] : []
105+
return Promise.all([
106+
(
107+
await tinyGlob(['**/*'], {
108+
absolute: true,
109+
onlyFiles: true,
110+
cwd: srcPath,
111+
dot: true,
112+
ignore
113+
})
114+
).map(p => remove(p))
115+
])
116+
}
117+
84118
function resetBin(bin) {
85119
const tmpBin = {
86120
[SOCKET_CLI_BIN_NAME]:
@@ -216,10 +250,8 @@ export default () =>
216250
async writeBundle() {
217251
await Promise.all([
218252
copyInitGradle(),
219-
// copyPackage('@socketsecurity/registry'),
220-
copyPackage('blessed'),
221-
copyPackage('blessed-contrib'),
222-
updatePackageJson()
253+
updatePackageJson(),
254+
...BUNDLED_PACKAGES.map(n => copyPackage(n))
223255
])
224256

225257
const blessedDestPath = path.join(rootDistPath, 'blessed')
@@ -235,55 +267,29 @@ export default () =>
235267
rootDistPath,
236268
'blessed-contrib'
237269
)
238-
const blessedContribIgnore = ['lib/**', 'node_modules/**', 'LICENSE*']
270+
const blessedContribIgnore = [
271+
'lib/**',
272+
'node_modules/**',
273+
'index.d.ts',
274+
'LICENSE*'
275+
]
239276

240277
// Remove directories.
241278
await Promise.all([
242-
// Remove directories from 'blessed'.
243-
...(
244-
await tinyGlob(['**/*'], {
245-
absolute: true,
246-
onlyDirectories: true,
247-
cwd: blessedDestPath,
248-
dot: true,
249-
ignore: blessedIgnore
250-
})
251-
).map(p => remove(p)),
252-
// Remove directories from 'contrib'.
253-
...(
254-
await tinyGlob(['**/*'], {
255-
absolute: true,
256-
onlyDirectories: true,
257-
cwd: blessedContribDestPath,
258-
dot: true,
259-
ignore: blessedContribIgnore
260-
})
261-
).map(p => remove(p))
279+
removeDirs(blessedDestPath, { exclude: blessedIgnore }),
280+
removeDirs(blessedContribDestPath, {
281+
exclude: blessedContribIgnore
282+
})
262283
])
263284

264285
// Remove files.
265286
await Promise.all([
266-
// Remove files from 'blessed'.
267-
...(
268-
await tinyGlob(['**/*'], {
269-
absolute: true,
270-
cwd: blessedDestPath,
271-
dot: true,
272-
ignore: blessedIgnore
273-
})
274-
).map(p => remove(p)),
275-
// Remove files from 'blessed-contrib'.
276-
...(
277-
await tinyGlob(['**/*'], {
278-
absolute: true,
279-
cwd: blessedContribDestPath,
280-
dot: true,
281-
ignore: blessedContribIgnore
282-
})
283-
).map(p => remove(p))
287+
removeFiles(blessedDestPath, { exclude: blessedIgnore }),
288+
removeFiles(blessedContribDestPath, {
289+
exclude: blessedContribIgnore
290+
})
284291
])
285292

286-
await Promise.all([])
287293
// Rewire 'blessed' inside 'blessed-contrib'.
288294
await Promise.all([
289295
...(

.oxlintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"no-unused-vars": "off",
2424
"no-var": "error",
2525
"unicorn/no-empty-file": "off",
26-
"unicorn/no-new-array": "off"
26+
"unicorn/no-new-array": "off",
27+
"unicorn/prefer-string-starts-ends-with": "off"
2728
}
2829
}

bin/cli.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
const process = require('node:process')
55

6-
const { spawn } = require('@socketsecurity/registry/lib/spawn')
7-
6+
const { spawn } = require('../dist/@socketsecurity/registry/lib/spawn')
87
const constants = require('../dist/constants')
98

109
const { INLINED_SOCKET_CLI_SENTRY_BUILD } = constants

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767
"update": "run-p --aggregate-output update:**",
6868
"update:deps": "npx --yes npm-check-updates"
6969
},
70-
"dependencies": {
71-
"@socketsecurity/registry": "1.0.153"
72-
},
7370
"devDependencies": {
7471
"@babel/core": "7.26.10",
7572
"@babel/plugin-proposal-export-default-from": "7.25.9",
@@ -102,6 +99,7 @@
10299
"@socketregistry/is-interactive": "1.0.5",
103100
"@socketregistry/packageurl-js": "1.0.6",
104101
"@socketsecurity/config": "2.1.3",
102+
"@socketsecurity/registry": "1.0.153",
105103
"@socketsecurity/sdk": "1.4.28",
106104
"@types/blessed": "0.1.25",
107105
"@types/cmd-shim": "5.0.2",

0 commit comments

Comments
 (0)