@@ -14,7 +14,7 @@ import {
1414} from '@socketsecurity/registry/lib/packages'
1515import { 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'
1818import constants from '../scripts/constants.js'
1919
2020const {
@@ -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 = / ^ ( [ ' " ] ) u s e s t r i c t \1/ . exec ( trimmed ) ?. [ 0 ] ?? ''
68+ const useStrict =
69+ / ^ ( [ ' " ] ) u s e s t r i c t \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+
84118function 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 ...(
0 commit comments