diff --git a/.eslintrc.json b/.eslintrc.json index ba84ad66..e84daa0d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,8 @@ }, "parserOptions": { - "ecmaVersion": 2018 + "ecmaVersion": 2018, + "sourceType": "module" }, "rules": { diff --git a/bench/first-match-picomatch.js b/bench/first-match-picomatch.js index b8039272..7869bcb0 100644 --- a/bench/first-match-picomatch.js +++ b/bench/first-match-picomatch.js @@ -1,6 +1,6 @@ 'use strict'; -const pm = require('..'); +const { default: pm } = require('..'); console.time('picomatch'); console.log(pm.makeRe('**/*').test('foo/bar/baz/qux.js')); diff --git a/bench/glob-parent.js b/bench/glob-parent.js index 2790415a..31815027 100644 --- a/bench/glob-parent.js +++ b/bench/glob-parent.js @@ -4,7 +4,7 @@ const { Suite } = require('benchmark'); const { red } = require('ansi-colors'); const argv = require('minimist')(process.argv.slice(2)); const parent = require('glob-parent'); -const scan = require('../lib/scan'); +const { default: scan } = require('../lib/scan'); /** * Setup diff --git a/bench/index.js b/bench/index.js index 7d6a86a8..5a3a98b0 100644 --- a/bench/index.js +++ b/bench/index.js @@ -4,7 +4,7 @@ const { Suite } = require('benchmark'); const { red } = require('ansi-colors'); const minimist = require('minimist'); const mm = require('minimatch'); -const pm = require('..'); +const { default: pm } = require('..'); const argv = minimist(process.argv.slice(2)); diff --git a/bench/load-time.js b/bench/load-time.js index b5e5c3a1..1060d0af 100644 --- a/bench/load-time.js +++ b/bench/load-time.js @@ -2,7 +2,7 @@ console.log('# Load time'); console.time('picomatch'); -exports.pm = require('..'); +exports.pm = require('..').default; console.timeEnd('picomatch'); console.time('minimatch'); exports.mm = require('minimatch'); diff --git a/index.js b/index.js index a753b1d9..a85359fe 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,14 @@ -'use strict'; +import pico from './lib/picomatch.js'; +import { isWindows } from './lib/utils.js'; -const pico = require('./lib/picomatch'); -const utils = require('./lib/utils'); - -function picomatch(glob, options, returnState = false) { +export default function picomatch(glob, options, returnState = false) { // default to os.platform() if (options && (options.windows === null || options.windows === undefined)) { // don't mutate the original options object - options = { ...options, windows: utils.isWindows() }; + options = { ...options, windows: isWindows() }; } return pico(glob, options, returnState); } Object.assign(picomatch, pico); -module.exports = picomatch; diff --git a/lib/constants.js b/lib/constants.js index 3f7ef7e5..f4ef6177 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,5 +1,3 @@ -'use strict'; - const WIN_SLASH = '\\\\/'; const WIN_NO_SLASH = `[^${WIN_SLASH}]`; @@ -85,7 +83,7 @@ const POSIX_REGEX_SOURCE = { xdigit: 'A-Fa-f0-9' }; -module.exports = { +export default { MAX_LENGTH: 1024 * 64, POSIX_REGEX_SOURCE, diff --git a/lib/parse.js b/lib/parse.js index 8fd8ff49..cd42204c 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,7 +1,5 @@ -'use strict'; - -const constants = require('./constants'); -const utils = require('./utils'); +import constants from './constants.js'; +import { escapeRegex, removePrefix, wrapOutput, hasRegexChars, escapeLast } from './utils.js'; /** * Constants @@ -31,7 +29,7 @@ const expandRange = (args, options) => { /* eslint-disable-next-line no-new */ new RegExp(value); } catch (ex) { - return args.map(v => utils.escapeRegex(v)).join('..'); + return args.map(v => escapeRegex(v)).join('..'); } return value; @@ -52,7 +50,7 @@ const syntaxError = (type, char) => { * @return {Object} */ -const parse = (input, options) => { +export default function parse(input, options) { if (typeof input !== 'string') { throw new TypeError('Expected a string'); } @@ -126,7 +124,7 @@ const parse = (input, options) => { tokens }; - input = utils.removePrefix(input, state); + input = removePrefix(input, state); len = input.length; const extglobs = []; @@ -319,7 +317,7 @@ const parse = (input, options) => { return state; } - state.output = utils.wrapOutput(output, state, options); + state.output = wrapOutput(output, state, options); return state; } @@ -432,7 +430,7 @@ const parse = (input, options) => { */ if (state.quotes === 1 && value !== '"') { - value = utils.escapeRegex(value); + value = escapeRegex(value); prev.value += value; append({ value }); continue; @@ -522,11 +520,11 @@ const parse = (input, options) => { // when literal brackets are explicitly disabled // assume we should match with a regex character class - if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) { + if (opts.literalBrackets === false || hasRegexChars(prevValue)) { continue; } - const escaped = utils.escapeRegex(prev.value); + const escaped = escapeRegex(prev.value); state.output = state.output.slice(0, -prev.value.length); // when literal brackets are explicitly enabled @@ -954,19 +952,19 @@ const parse = (input, options) => { while (state.brackets > 0) { if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']')); - state.output = utils.escapeLast(state.output, '['); + state.output = escapeLast(state.output, '['); decrement('brackets'); } while (state.parens > 0) { if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')')); - state.output = utils.escapeLast(state.output, '('); + state.output = escapeLast(state.output, '('); decrement('parens'); } while (state.braces > 0) { if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}')); - state.output = utils.escapeLast(state.output, '{'); + state.output = escapeLast(state.output, '{'); decrement('braces'); } @@ -988,7 +986,7 @@ const parse = (input, options) => { } return state; -}; +} /** * Fast paths for creating regular expressions for common glob patterns. @@ -1072,7 +1070,7 @@ parse.fastpaths = (input, options) => { } }; - const output = utils.removePrefix(input, state); + const output = removePrefix(input, state); let source = create(output); if (source && opts.strictSlashes !== true) { @@ -1081,5 +1079,3 @@ parse.fastpaths = (input, options) => { return source; }; - -module.exports = parse; diff --git a/lib/picomatch.js b/lib/picomatch.js index d0ebd9f1..68695872 100644 --- a/lib/picomatch.js +++ b/lib/picomatch.js @@ -1,9 +1,7 @@ -'use strict'; - -const scan = require('./scan'); -const parse = require('./parse'); -const utils = require('./utils'); -const constants = require('./constants'); +import scan from './scan.js'; +import parse from './parse.js'; +import { toPosixSlashes, basename } from './utils.js'; +import constants from './constants.js'; const isObject = val => val && typeof val === 'object' && !Array.isArray(val); /** @@ -14,7 +12,7 @@ const isObject = val => val && typeof val === 'object' && !Array.isArray(val); * returns an object with additional information. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch(glob[, options]); * * const isMatch = picomatch('*.!(*a)'); @@ -28,7 +26,7 @@ const isObject = val => val && typeof val === 'object' && !Array.isArray(val); * @api public */ -const picomatch = (glob, options, returnState = false) => { +export default function picomatch(glob, options, returnState = false) { if (Array.isArray(glob)) { const fns = glob.map(input => picomatch(input, options, returnState)); const arrayMatcher = str => { @@ -94,14 +92,14 @@ const picomatch = (glob, options, returnState = false) => { } return matcher; -}; +} /** * Test `input` with the given `regex`. This is used by the main * `picomatch()` function to test the input string. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch.test(input, regex[, options]); * * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/)); @@ -123,7 +121,7 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => { } const opts = options || {}; - const format = opts.format || (posix ? utils.toPosixSlashes : null); + const format = opts.format || (posix ? toPosixSlashes : null); let match = input === glob; let output = (match && format) ? format(input) : input; @@ -147,7 +145,7 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => { * Match the basename of a filepath. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch.matchBase(input, glob[, options]); * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true * ``` @@ -159,14 +157,14 @@ picomatch.test = (input, regex, options, { glob, posix } = {}) => { picomatch.matchBase = (input, glob, options) => { const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options); - return regex.test(utils.basename(input)); + return regex.test(basename(input)); }; /** * Returns true if **any** of the given glob `patterns` match the specified `string`. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch.isMatch(string, patterns[, options]); * * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true @@ -186,7 +184,7 @@ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str * expression. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * const result = picomatch.parse(pattern[, options]); * ``` * @param {String} `pattern` @@ -204,7 +202,7 @@ picomatch.parse = (pattern, options) => { * Scan a glob pattern to separate the pattern into segments. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch.scan(input[, options]); * * const result = picomatch.scan('!./foo/*.js'); @@ -267,7 +265,7 @@ picomatch.compileRe = (state, options, returnOutput = false, returnState = false * Create a regular expression from a parsed glob pattern. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * const state = picomatch.parse('*.js'); * // picomatch.compileRe(state[, options]); * @@ -304,7 +302,7 @@ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = fal * Create a regular expression from the given regex source string. * * ```js - * const picomatch = require('picomatch'); + * import picomatch from 'picomatch'; * // picomatch.toRegex(source[, options]); * * const { output } = picomatch.parse('*.js'); @@ -333,9 +331,3 @@ picomatch.toRegex = (source, options) => { */ picomatch.constants = constants; - -/** - * Expose "picomatch" - */ - -module.exports = picomatch; diff --git a/lib/scan.js b/lib/scan.js index e59cd7a1..5eb02e71 100644 --- a/lib/scan.js +++ b/lib/scan.js @@ -1,6 +1,5 @@ -'use strict'; - -const utils = require('./utils'); +import { removeBackslashes } from './utils.js'; +import constants from './constants.js'; const { CHAR_ASTERISK, /* * */ CHAR_AT, /* @ */ @@ -17,7 +16,7 @@ const { CHAR_RIGHT_CURLY_BRACE, /* } */ CHAR_RIGHT_PARENTHESES, /* ) */ CHAR_RIGHT_SQUARE_BRACKET /* ] */ -} = require('./constants'); +} = constants; const isPathSeparator = code => { return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; @@ -36,7 +35,7 @@ const depth = token => { * with `!(`) and `negatedExtglob` (true if the path starts with `!(`). * * ```js - * const pm = require('picomatch'); + * import pm from 'picomatch'; * console.log(pm.scan('foo/bar/*.js')); * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' } * ``` @@ -46,7 +45,7 @@ const depth = token => { * @api public */ -const scan = (input, options) => { +export default function scan(input, options) { const opts = options || {}; const length = input.length - 1; @@ -317,10 +316,10 @@ const scan = (input, options) => { } if (opts.unescape === true) { - if (glob) glob = utils.removeBackslashes(glob); + if (glob) glob = removeBackslashes(glob); if (base && backslashes === true) { - base = utils.removeBackslashes(base); + base = removeBackslashes(base); } } @@ -386,6 +385,4 @@ const scan = (input, options) => { } return state; -}; - -module.exports = scan; +} diff --git a/lib/utils.js b/lib/utils.js index 9c97cae2..9393a70f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,20 +1,20 @@ /*global navigator*/ -'use strict'; +import constants from './constants.js'; const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL -} = require('./constants'); +} = constants; -exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val); -exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str); -exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str); -exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1'); -exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/'); +export const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val); +export const hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str); +export const isRegexChar = str => str.length === 1 && hasRegexChars(str); +export const escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1'); +export const toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/'); -exports.isWindows = () => { +export const isWindows = () => { if (typeof navigator !== 'undefined' && navigator.platform) { const platform = navigator.platform.toLowerCase(); return platform === 'win32' || platform === 'windows'; @@ -27,20 +27,20 @@ exports.isWindows = () => { return false; }; -exports.removeBackslashes = str => { +export const removeBackslashes = str => { return str.replace(REGEX_REMOVE_BACKSLASH, match => { return match === '\\' ? '' : match; }); }; -exports.escapeLast = (input, char, lastIdx) => { +export const escapeLast = (input, char, lastIdx) => { const idx = input.lastIndexOf(char, lastIdx); if (idx === -1) return input; - if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1); + if (input[idx - 1] === '\\') return escapeLast(input, char, idx - 1); return `${input.slice(0, idx)}\\${input.slice(idx)}`; }; -exports.removePrefix = (input, state = {}) => { +export const removePrefix = (input, state = {}) => { let output = input; if (output.startsWith('./')) { output = output.slice(2); @@ -49,7 +49,7 @@ exports.removePrefix = (input, state = {}) => { return output; }; -exports.wrapOutput = (input, state = {}, options = {}) => { +export const wrapOutput = (input, state = {}, options = {}) => { const prepend = options.contains ? '' : '^'; const append = options.contains ? '' : '$'; @@ -60,7 +60,7 @@ exports.wrapOutput = (input, state = {}, options = {}) => { return output; }; -exports.basename = (path, { windows } = {}) => { +export const basename = (path, { windows } = {}) => { const segs = path.split(windows ? /[\\/]/ : '/'); const last = segs[segs.length - 1]; diff --git a/package.json b/package.json index 372e27e0..308e5f34 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "funding": "https://github.com/sponsors/jonschlinkert", "repository": "micromatch/picomatch", + "type": "module", "bugs": { "url": "https://github.com/micromatch/picomatch/issues" }, diff --git a/posix.js b/posix.js index d2f2bc59..1121d5b8 100644 --- a/posix.js +++ b/posix.js @@ -1,3 +1 @@ -'use strict'; - -module.exports = require('./lib/picomatch'); +export { default } from './lib/picomatch.js'; diff --git a/test/api.picomatch.js b/test/api.picomatch.js index 2fe67cff..579e90be 100644 --- a/test/api.picomatch.js +++ b/test/api.picomatch.js @@ -1,7 +1,5 @@ -'use strict'; - -const assert = require('assert'); -const picomatch = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; const { isMatch } = picomatch; const assertTokens = (actual, expected) => { diff --git a/test/api.posix.js b/test/api.posix.js index 6ccf38b2..debec1b1 100644 --- a/test/api.posix.js +++ b/test/api.posix.js @@ -1,7 +1,5 @@ -'use strict'; - -const assert = require('assert'); -const picomatch = require('../posix'); +import assert from 'assert'; +import picomatch from '../posix.js'; describe('picomatch/posix', () => { it('should use posix paths only by default', () => { diff --git a/test/api.scan.js b/test/api.scan.js index b1e63db1..c3d6a0f7 100644 --- a/test/api.scan.js +++ b/test/api.scan.js @@ -1,7 +1,5 @@ -'use strict'; - -const assert = require('assert'); -const scan = require('../lib/scan'); +import assert from 'assert'; +import scan from '../lib/scan.js'; const base = (...args) => scan(...args).base; const both = (...args) => { const { base, glob } = scan(...args); diff --git a/test/bash.js b/test/bash.js index 2ef4bb1a..5531612f 100644 --- a/test/bash.js +++ b/test/bash.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; // $echo a/{1..3}/b describe('from the Bash 4.3 spec/unit tests', () => { diff --git a/test/bash.spec.js b/test/bash.spec.js index 7cd276b9..d62b13a9 100644 --- a/test/bash.spec.js +++ b/test/bash.spec.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('bash.spec', () => { describe('dotglob', () => { diff --git a/test/braces.js b/test/braces.js index a343c316..369d9ec4 100644 --- a/test/braces.js +++ b/test/braces.js @@ -1,9 +1,9 @@ -'use strict'; +import assert from 'assert'; +import picomatch from '../index.js'; +import fill from 'fill-range'; +import match from './support/match.js'; -const assert = require('assert'); -const fill = require('fill-range'); -const match = require('./support/match'); -const { isMatch } = require('..'); +const { isMatch } = picomatch; describe('braces', () => { it('should not match with brace patterns when disabled', () => { diff --git a/test/brackets.js b/test/brackets.js index c5106254..f537a99f 100644 --- a/test/brackets.js +++ b/test/brackets.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('brackets', () => { describe('trailing stars', () => { diff --git a/test/dotfiles.js b/test/dotfiles.js index f90abb88..cf4d7399 100644 --- a/test/dotfiles.js +++ b/test/dotfiles.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +import match from './support/match.js'; +const { isMatch } = picomatch; describe('dotfiles', () => { describe('normal', () => { diff --git a/test/dots-invalid.js b/test/dots-invalid.js index ff730a89..66c7864b 100644 --- a/test/dots-invalid.js +++ b/test/dots-invalid.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('invalid (exclusive) dots', () => { describe('double dots', () => { diff --git a/test/extglobs-bash.js b/test/extglobs-bash.js index bea8d179..4f34b3ef 100644 --- a/test/extglobs-bash.js +++ b/test/extglobs-bash.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; /** * Some of tests were converted from bash 4.3, 4.4, and minimatch unit tests. diff --git a/test/extglobs-minimatch.js b/test/extglobs-minimatch.js index 4d480803..71b1a134 100644 --- a/test/extglobs-minimatch.js +++ b/test/extglobs-minimatch.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; /** * Some of tests were converted from bash 4.3, 4.4, and minimatch unit tests. diff --git a/test/extglobs-temp.js b/test/extglobs-temp.js index b62948f2..10da1732 100644 --- a/test/extglobs-temp.js +++ b/test/extglobs-temp.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; /** * Some of tests were converted from bash 4.3, 4.4, and minimatch unit tests. diff --git a/test/extglobs.js b/test/extglobs.js index ea436d1f..8ea6ee7a 100644 --- a/test/extglobs.js +++ b/test/extglobs.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch, makeRe } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +import match from './support/match.js'; +const { isMatch, makeRe } = picomatch; /** * Ported from Bash 4.3 and 4.4 unit tests diff --git a/test/globstars.js b/test/globstars.js index 9d101344..d2872b67 100644 --- a/test/globstars.js +++ b/test/globstars.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +import match from './support/match.js'; +const { isMatch } = picomatch; describe('stars', () => { describe('issue related', () => { diff --git a/test/issue-related.js b/test/issue-related.js index f85b3e62..6c53f1c5 100644 --- a/test/issue-related.js +++ b/test/issue-related.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('issue-related tests', () => { it('should match with braces (see picomatch/issues#8)', () => { diff --git a/test/malicious.js b/test/malicious.js index 82a7d2c9..ec27b427 100644 --- a/test/malicious.js +++ b/test/malicious.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; const repeat = n => '\\'.repeat(n); /** diff --git a/test/minimatch.js b/test/minimatch.js index 853e120a..00fd3e5d 100644 --- a/test/minimatch.js +++ b/test/minimatch.js @@ -1,8 +1,8 @@ -'use strict'; +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch, makeRe } = picomatch; -const assert = require('assert'); const format = str => str.replace(/^\.\//, ''); -const { isMatch, makeRe } = require('..'); describe('minimatch parity:', () => { describe('minimatch issues (as of 12/7/2016)', () => { diff --git a/test/negation.js b/test/negation.js index a3a6a832..d369037c 100644 --- a/test/negation.js +++ b/test/negation.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('negation patterns - "!"', () => { it('should patterns with a leading "!" as negated/inverted globs', () => { diff --git a/test/non-globs.js b/test/non-globs.js index 030da05c..b27385d0 100644 --- a/test/non-globs.js +++ b/test/non-globs.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('non-globs', () => { it('should match non-globs', () => { diff --git a/test/options.expandRange.js b/test/options.expandRange.js index 0eb05fc3..9c0169d0 100644 --- a/test/options.expandRange.js +++ b/test/options.expandRange.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const fill = require('fill-range'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; +import fill from 'fill-range'; describe('options.expandRange', () => { it('should support a custom function for expanding ranges in brace patterns', () => { diff --git a/test/options.format.js b/test/options.format.js index b4f3444d..c988f560 100644 --- a/test/options.format.js +++ b/test/options.format.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +import match from './support/match.js'; +const { isMatch } = picomatch; const equal = (actual, expected, msg) => { assert.deepStrictEqual([].concat(actual).sort(), [].concat(expected).sort(), msg); diff --git a/test/options.ignore.js b/test/options.ignore.js index e8cc6285..8ab4017c 100644 --- a/test/options.ignore.js +++ b/test/options.ignore.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; +import match from './support/match.js'; describe('options.ignore', () => { it('should not match ignored patterns', () => { diff --git a/test/options.js b/test/options.js index 8993d181..fbe202fd 100644 --- a/test/options.js +++ b/test/options.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; +import match from './support/match.js'; describe('options', () => { describe('options.matchBase', () => { diff --git a/test/options.noextglob.js b/test/options.noextglob.js index 3ff6bfa2..d97c6a31 100644 --- a/test/options.noextglob.js +++ b/test/options.noextglob.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('options.noextglob', () => { it('should disable extglob support when options.noextglob is true', () => { diff --git a/test/options.noglobstar.js b/test/options.noglobstar.js index 9f8757e0..4e680d02 100644 --- a/test/options.noglobstar.js +++ b/test/options.noglobstar.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('options.noglobstar', () => { it('should disable extglob support when options.noglobstar is true', () => { diff --git a/test/options.onMatch.js b/test/options.onMatch.js index caf23355..9b9d4c3e 100644 --- a/test/options.onMatch.js +++ b/test/options.onMatch.js @@ -1,9 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const picomatch = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; const { isMatch } = picomatch; +import match from './support/match.js'; const equal = (actual, expected, msg) => { assert.deepStrictEqual([].concat(actual).sort(), [].concat(expected).sort(), msg); diff --git a/test/parens.js b/test/parens.js index d73bf63d..ab035ed2 100644 --- a/test/parens.js +++ b/test/parens.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('parens (non-extglobs)', () => { it('should support stars following parens', () => { diff --git a/test/posix-classes.js b/test/posix-classes.js index f3eed940..e3b56720 100644 --- a/test/posix-classes.js +++ b/test/posix-classes.js @@ -1,7 +1,5 @@ -'use strict'; - -const assert = require('assert'); -const pm = require('..'); +import assert from 'assert'; +import pm from '../index.js'; const { makeRe, parse } = pm; const opts = { strictSlashes: true, posix: true, regex: true }; diff --git a/test/qmarks.js b/test/qmarks.js index 1a2dadf3..f4b7d8c9 100644 --- a/test/qmarks.js +++ b/test/qmarks.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const match = require('./support/match'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; +import match from './support/match.js'; describe('qmarks and stars', () => { it('should match question marks with question marks', () => { diff --git a/test/regex-features.js b/test/regex-features.js index bc84189b..f2edd9c2 100644 --- a/test/regex-features.js +++ b/test/regex-features.js @@ -1,8 +1,7 @@ -'use strict'; - -const assert = require('assert'); -const utils = require('../lib/utils'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; +import { basename } from '../lib/utils.js'; describe('regex features', () => { describe('word boundaries', () => { @@ -304,12 +303,12 @@ describe('regex features', () => { }); it('should basename paths', () => { - assert.equal(utils.basename('/a/b/c'), 'c'); - assert.equal(utils.basename('/a/b/c/'), 'c'); - assert.equal(utils.basename('/a\\b/c', { windows: true }), 'c'); - assert.equal(utils.basename('/a\\b/c\\', { windows: true }), 'c'); - assert.equal(utils.basename('\\a/b\\c', { windows: true }), 'c'); - assert.equal(utils.basename('\\a/b\\c/', { windows: true }), 'c'); + assert.equal(basename('/a/b/c'), 'c'); + assert.equal(basename('/a/b/c/'), 'c'); + assert.equal(basename('/a\\b/c', { windows: true }), 'c'); + assert.equal(basename('/a\\b/c\\', { windows: true }), 'c'); + assert.equal(basename('\\a/b\\c', { windows: true }), 'c'); + assert.equal(basename('\\a/b\\c/', { windows: true }), 'c'); }); }); }); diff --git a/test/slashes-posix.js b/test/slashes-posix.js index cd4d0b9f..a6c2949a 100644 --- a/test/slashes-posix.js +++ b/test/slashes-posix.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('slash handling - posix', () => { it('should match a literal string', () => { diff --git a/test/slashes-windows.js b/test/slashes-windows.js index 1e109948..d043565b 100644 --- a/test/slashes-windows.js +++ b/test/slashes-windows.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch, makeRe } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch, makeRe } = picomatch; describe('slash handling - windows', () => { it('should match absolute windows paths with regex from makeRe', () => { diff --git a/test/special-characters.js b/test/special-characters.js index c6958a51..120c06bf 100644 --- a/test/special-characters.js +++ b/test/special-characters.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch, makeRe } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch, makeRe } = picomatch; describe('special characters', () => { describe('numbers', () => { diff --git a/test/stars.js b/test/stars.js index 910b9f24..a1226eb5 100644 --- a/test/stars.js +++ b/test/stars.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('stars', () => { describe('issue related', () => { diff --git a/test/support/match.js b/test/support/match.js index f932cbd1..3968f28b 100644 --- a/test/support/match.js +++ b/test/support/match.js @@ -1,8 +1,6 @@ -'use strict'; +import picomatch from '../../index.js'; -const picomatch = require('../..'); - -module.exports = (list, pattern, options = {}) => { +export default (list, pattern, options = {}) => { const isMatch = picomatch(pattern, options, true); const matches = options.matches || new Set(); diff --git a/test/wildmat.js b/test/wildmat.js index c61195e5..b8ce3cd6 100644 --- a/test/wildmat.js +++ b/test/wildmat.js @@ -1,7 +1,6 @@ -'use strict'; - -const assert = require('assert'); -const { isMatch } = require('..'); +import assert from 'assert'; +import picomatch from '../index.js'; +const { isMatch } = picomatch; describe('Wildmat (git) tests', () => { it('Basic wildmat features', () => {