import { relative , sep } from 'path' ; const esmRegex = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?(?!type)([^"'\(\)\n; ]+)\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/ , moduleGlob = [ '**/*' , '!node_modules' , '!test' , '!**/*.d.ts' ] ; export function isScript ( code ) { return ! Boolean ( code . match ( esmRegex ) ) ; } export function hasModuleGlobs ( file ) { return nodeModuleGlobs ( file ) !== moduleGlob ; } export function extraGlobs ( file ) { const globs = [ ] ; return globs . concat ( ... [ file . package ?. pkg ?. scripts || [ ] ] ) . concat ( ... [ file . package ?. pkg ?. assets || [ ] ] ) ; } export function nodeModuleGlobs ( file , useDefault = true ) { const normalGlobs = [ ] . concat ( ... ( file . package ?. files || [ ] ) ) ; if ( useDefault && ! normalGlobs . length ) { return moduleGlob ; } return normalGlobs ; } export type JsLoaderOptions = { loadContent : boolean ; isEntry : boolean ; type : 'module' | 'commonjs' ; context ? : { moduleRoot : string ; package : any ; expanded ? : boolean ; globs ? : string [ ] ; } ; expand : 'all' | 'variable' | 'none' ; } ; export type FileMap = { [ key ] : File | null ; } ; export type Files = { [ key ] : File ; } ; export interface File { deps : FileMap ; belongsTo ? : File ; realSize ? : number ; realPath ? : string ; size : number ; absPath : string ; moduleType : 'module' | 'commonjs' ; contents : string | null ; contextExpanded ? : boolean ; variableImports ? : boolean ; moduleRoot ? : string ; package ? : any ; } const notNodeModule = /^\.|^\// ; export function isNodeModule ( request ) { return ! notNodeModule . test ( request ) ; } export function ensureDottedRelative ( from , to ) { let rel = relative ( from , to ) ; if ( ! rel . startsWith ( '.' + sep ) ) { rel = './' + rel ; } return rel . split ( sep ) . join ( '/' ) ; } export function createFile ( absPath ) { return { size : 0 , deps : { } , absPath , moduleType : 'commonjs' , contents : null , variableImports : false , } ; }