@@ -42,12 +42,7 @@ const {
4242 VITEST
4343} = constants
4444
45- export const EXTERNAL_PACKAGES = [
46- '@socketsecurity/registry' ,
47- 'blessed'
48- ]
49-
50- const SOCKET_INTEROP = '_socketInterop'
45+ export const EXTERNAL_PACKAGES = [ '@socketsecurity/registry' , 'blessed' ]
5146
5247const builtinAliases = builtinModules . reduce ( ( o , n ) => {
5348 o [ n ] = `node:${ n } `
@@ -60,20 +55,6 @@ const customResolver = nodeResolve({
6055 preferBuiltins : true
6156} )
6257
63- const requireAssignmentsRegExp =
64- / (?< = \s * = \s * ) r e q u i r e \( [ " ' ] (? ! n o d e : | @ s o c k e t (?: o v e r r i d e | r e g i s t r y | s e c u r i t y ) \/ | \. ) .+ ?[ " ' ] \) (? = ; ? \r ? \n ) / g
65-
66- const checkRequireAssignmentRegExp = new RegExp (
67- requireAssignmentsRegExp . source ,
68- ''
69- )
70-
71- const checkSocketInteropUseRegExp = new RegExp ( `\\b${ SOCKET_INTEROP } \\b` )
72-
73- const danglingRequiresRegExp = / ^ \s * r e q u i r e \( [ " ' ] .+ ?[ " ' ] \) ; ? \r ? \n / gm
74-
75- const firstUseStrictRegExp = / ' u s e s t r i c t ' ; ? /
76-
7758const requireTinyColorsRegExp = / r e q u i r e \( [ " ' ] t i n y - c o l o r s [ " ' ] \) / g
7859
7960// eslint-disable-next-line no-unused-vars
@@ -153,10 +134,8 @@ export default function baseConfig(extendConfig = {}) {
153134 )
154135 } ,
155136 onwarn ( warning , warn ) {
156- // Suppress FILE_NAME_CONFLICT, INVALID_ANNOTATION, and THIS_IS_UNDEFINED
157- // warnings.
137+ // Suppress INVALID_ANNOTATION and THIS_IS_UNDEFINED warnings.
158138 if (
159- warning . code === 'FILE_NAME_CONFLICT' ||
160139 warning . code === 'INVALID_ANNOTATION' ||
161140 warning . code === 'THIS_IS_UNDEFINED'
162141 ) {
@@ -305,44 +284,11 @@ export default function baseConfig(extendConfig = {}) {
305284 return requireUrlAssignmentRegExp . exec ( this . input ) ?. [ 0 ] ?? match
306285 }
307286 } ) ,
308- // Remove dangling require calls, e.g. require calls not associated with
309- // an import binding:
310- // require('node:util')
311- // require('graceful-fs')
312- socketModifyPlugin ( {
313- find : danglingRequiresRegExp ,
314- replace : ''
315- } ) ,
316287 // Replace require('blessed/lib/widgets/xyz') with require('../blessed/lib/widgets/xyz').
317288 // socketModifyPlugin({
318289 // find: blessedRequiresRegExp,
319- // replace: (id) => `.. /${id}`
290+ // replace: (id) => `./${id}`
320291 // }),
321- // Wrap require calls with SOCKET_INTEROP helper.
322- socketModifyPlugin ( {
323- find : requireAssignmentsRegExp ,
324- replace : match => `${ SOCKET_INTEROP } (${ match } )`
325- } ) ,
326- // Add CJS interop helper for "default" only exports.
327- socketModifyPlugin ( {
328- find : firstUseStrictRegExp ,
329- replace ( match ) {
330- return checkRequireAssignmentRegExp . test ( this . input ) ||
331- checkSocketInteropUseRegExp . test ( this . input )
332- ? `${ match } \n
333- function ${ SOCKET_INTEROP } (e) {
334- let c = 0
335- for (const k in e ?? {}) {
336- c = c === 0 && k === 'default' ? 1 : 0
337- if (!c && k !== '__esModule') {
338- break
339- }
340- }
341- return c ? e.default : e
342- }`
343- : match
344- }
345- } ) ,
346292 ...( extendConfig . plugins ?? [ ] )
347293 ]
348294 }
@@ -378,26 +324,6 @@ function ${SOCKET_INTEROP}(e) {
378324 return o
379325 } )
380326
381- // Replace hard-coded absolute paths in source with hard-coded relative paths.
382- const replaceAbsPathsOutputPlugin = ( ( ) => {
383- const { name, renderChunk } = replacePlugin ( {
384- delimiters : [ '(?<=["\'])' , '/' ] ,
385- preventAssignment : false ,
386- values : {
387- // Lazily access constants.rootPath.
388- [ constants . rootPath ] : '../../'
389- }
390- } )
391- return { name, renderChunk }
392- } ) ( )
393-
394- for ( const o of output ) {
395- o . plugins = [
396- ...( Array . isArray ( o . plugins ) ? o . plugins : [ ] ) ,
397- replaceAbsPathsOutputPlugin
398- ]
399- }
400-
401327 config . output = output
402328 return config
403329}
0 commit comments