@@ -5,7 +5,6 @@ import { globby } from 'globby'
55import ignore from 'ignore'
66// @ts -ignore This package provides no types
77import { directories } from 'ignore-by-default'
8- import micromatch from 'micromatch'
98import { ErrorWithCause } from 'pony-cause'
109
1110import { InputError } from './errors.js'
@@ -94,85 +93,65 @@ export async function mapGlobResultToFiles (entries, supportedFiles) {
9493 * @throws {InputError }
9594 */
9695export async function mapGlobEntryToFiles ( entry , supportedFiles ) {
97- /** @type {string|undefined } */
98- let pkgJSFile
99- /** @type {string[] } */
100- let jsLockFiles = [ ]
101- /** @type {string[] } */
102- let pyFiles = [ ]
103- /** @type {string|undefined } */
104- let pkgGoFile
105- /** @type {string[] } */
106- let goExtraFiles = [ ]
107-
10896 const jsSupported = supportedFiles [ 'npm' ] || { }
109- const jsLockFilePatterns = Object . keys ( jsSupported )
110- . filter ( key => key !== 'packagejson' )
111- . map ( key => / ** @type {{ pattern: string } } */ ( jsSupported [ key ] ) . pattern )
97+ const jsLockFilePatterns = Object . values ( jsSupported )
98+ // .filter(key => key !== 'packagejson')
99+ . map ( p => `**/ ${ / ** @type {{ pattern: string } } */ ( p ) . pattern } ` )
112100
113101 const pyFilePatterns = Object . values ( supportedFiles [ 'pypi' ] || { } )
114- . map ( p => / ** @type {{ pattern: string } } */ ( p ) . pattern )
102+ . map ( p => `**/ ${ / ** @type {{ pattern: string } } */ ( p ) . pattern } ` )
115103
116104 const goSupported = supportedFiles [ 'go' ] || { }
117- const goSupplementalPatterns = Object . keys ( goSupported )
118- . filter ( key => key !== 'gomod' )
119- . map ( key => /** @type {{ pattern: string } } */ ( goSupported [ key ] ) . pattern )
120-
121- if ( entry . endsWith ( '/' ) ) {
122- // If the match is a folder and that folder contains a package.json file, then include it
123- const jsPkg = path . resolve ( entry , 'package.json' )
124- if ( await fileExists ( jsPkg ) ) pkgJSFile = jsPkg
125-
126- const goPkg = path . resolve ( entry , 'go.mod' )
127- if ( await fileExists ( goPkg ) ) pkgGoFile = goPkg
128-
129- pyFiles = await globby ( pyFilePatterns , {
130- ...BASE_GLOBBY_OPTS ,
131- cwd : entry
132- } )
133- } else {
134- const entryFile = path . basename ( entry )
135-
136- if ( entryFile === 'package.json' ) {
137- // If the match is a package.json file, then include it
138- pkgJSFile = entry
139- } else if ( micromatch . isMatch ( entryFile , jsLockFilePatterns ) ) {
140- jsLockFiles = [ entry ]
141- pkgJSFile = path . resolve ( path . dirname ( entry ) , 'package.json' )
142- if ( ! ( await fileExists ( pkgJSFile ) ) ) return [ ]
143- } else if ( entryFile === 'go.mod' ) {
144- pkgGoFile = entry
145- } else if ( micromatch . isMatch ( entryFile , goSupplementalPatterns ) ) {
146- goExtraFiles = [ entry ]
147- pkgGoFile = path . resolve ( path . dirname ( entry ) , 'go.mod' )
148- } else if ( micromatch . isMatch ( entryFile , pyFilePatterns ) ) {
149- pyFiles = [ entry ]
150- }
151- }
152-
153- // If we will include a package.json file but don't already have a corresponding lockfile, then look for one
154- if ( ! jsLockFiles . length && pkgJSFile ) {
155- const pkgDir = path . dirname ( pkgJSFile )
156-
157- jsLockFiles = await globby ( jsLockFilePatterns , {
158- ...BASE_GLOBBY_OPTS ,
159- cwd : pkgDir
160- } )
161- }
162-
163- if ( ! goExtraFiles . length && pkgGoFile ) {
164- // get go.sum whenever possible
165- const pkgDir = path . dirname ( pkgGoFile )
166-
167- goExtraFiles = await globby ( goSupplementalPatterns , {
168- ...BASE_GLOBBY_OPTS ,
169- cwd : pkgDir
170- } )
171- }
172-
173- return [ ...jsLockFiles , ...pyFiles , ...goExtraFiles ]
174- . concat ( pkgJSFile ? [ pkgJSFile ] : [ ] )
175- . concat ( pkgGoFile ? [ pkgGoFile ] : [ ] )
105+ const goSupplementalPatterns = Object . values ( goSupported )
106+ // .filter(key => key !== 'gomod')
107+ . map ( p => `**/${ /** @type {{ pattern: string } } */ ( p ) . pattern } ` )
108+
109+ const files = await globby ( [
110+ ...jsLockFilePatterns ,
111+ ...pyFilePatterns ,
112+ ...goSupplementalPatterns
113+ ] , {
114+ ...BASE_GLOBBY_OPTS ,
115+ onlyFiles : true ,
116+ cwd : path . resolve ( ( await stat ( entry ) ) . isDirectory ( ) ? entry : path . dirname ( entry ) )
117+ } )
118+ return files
119+
120+ // if (entry.endsWith('/')) {
121+ // // If the match is a folder and that folder contains a package.json file, then include it
122+ // const jsPkg = path.resolve(entry, 'package.json')
123+ // if (await fileExists(jsPkg)) pkgJSFile = jsPkg
124+
125+ // const goPkg = path.resolve(entry, 'go.mod')
126+ // if (await fileExists(goPkg)) pkgGoFile = goPkg
127+
128+ // pyFiles = await globby(pyFilePatterns, {
129+ // ...BASE_GLOBBY_OPTS,
130+ // cwd: entry
131+ // })
132+ // } else {
133+ // const entryFile = path.basename(entry)
134+
135+ // if (entryFile === 'package.json') {
136+ // // If the match is a package.json file, then include it
137+ // pkgJSFile = entry
138+ // } else if (micromatch.isMatch(entryFile, jsLockFilePatterns)) {
139+ // jsLockFiles = [entry]
140+ // pkgJSFile = path.resolve(path.dirname(entry), 'package.json')
141+ // if (!(await fileExists(pkgJSFile))) return []
142+ // } else if (entryFile === 'go.mod') {
143+ // pkgGoFile = entry
144+ // } else if (micromatch.isMatch(entryFile, goSupplementalPatterns)) {
145+ // goExtraFiles = [entry]
146+ // pkgGoFile = path.resolve(path.dirname(entry), 'go.mod')
147+ // } else if (micromatch.isMatch(entryFile, pyFilePatterns)) {
148+ // pyFiles = [entry]
149+ // }
150+ // }
151+
152+ // return [...jsLockFiles, ...pyFiles, ...goExtraFiles]
153+ // .concat(pkgJSFile ? [pkgJSFile] : [])
154+ // .concat(pkgGoFile ? [pkgGoFile] : [])
176155}
177156
178157/**
0 commit comments