Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active October 21, 2023 22:35
Show Gist options
  • Save wtnabe/bedac43ed85b5ad6f71e6d3b78edb6ad to your computer and use it in GitHub Desktop.
Save wtnabe/bedac43ed85b5ad6f71e6d3b78edb6ad to your computer and use it in GitHub Desktop.
globby negate behavior
import { globby } from 'globby'
const IGNORE = [
'!node_modules/**/*.*',
'!bower_components/**/*.*',
'!**/*.test.{js,ts}',
'!**/*.suite.{js,ts}',
'!**/*.config.{js,ts}',
'!**/*.d.ts',
];
async function putsGlobResult (message, pattern) {
console.log(`--- ${message} ---`)
console.log('-- pattern')
console.log(pattern)
console.log('-- result')
console.log(await globby(pattern))
}
;(async () => {
await putsGlobResult(
'appending IGNORE to last position, returns no node_modules files',
[
'**/*.js',
'node_modules/globby',
...IGNORE
]
)
await putsGlobResult(
'appending additional package name in a specific pattern, returns expected file list',
[
'**/*.js',
...IGNORE,
'node_modules/globby/**/*.js',
'!node_modules/globby/node_modules'
]
)
})()
--- appending IGNORE to last position, returns no node_modules files ---
-- pattern
[
'**/*.js',
'node_modules/globby',
'!node_modules/**/*.*',
'!bower_components/**/*.*',
'!**/*.test.{js,ts}',
'!**/*.suite.{js,ts}',
'!**/*.config.{js,ts}',
'!**/*.d.ts'
]
-- result
[
'glob.js',
'node_modules/globby/license',
'node_modules/globby/node_modules/slash/license'
]
--- appending additional package name in a specific pattern, returns expected file list ---
-- pattern
[
'**/*.js',
'!node_modules/**/*.*',
'!bower_components/**/*.*',
'!**/*.test.{js,ts}',
'!**/*.suite.{js,ts}',
'!**/*.config.{js,ts}',
'!**/*.d.ts',
'node_modules/globby/**/*.js',
'!node_modules/globby/node_modules'
]
-- result
[
'glob.js',
'node_modules/globby/ignore.js',
'node_modules/globby/index.js',
'node_modules/globby/utilities.js'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment