Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add conditional "exports" support #68

Merged
merged 6 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ node_modules
.DS_Store
*.lock
*.log

/dist
/sync
/index.d.ts
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.2.8",
"description": "Tiny and extremely fast globbing",
"repository": "terkelg/tiny-glob",
"module": "dist/index.mjs",
"main": "dist/index.js",
"types": "index.d.ts",
"license": "MIT",
"author": {
Expand All @@ -11,21 +13,40 @@
"url": "https://terkel.com"
},
"files": [
"*.js",
"*.d.ts"
"*.d.ts",
"dist",
"sync"
],
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./sync": {
"import": "./sync/index.mjs",
"require": "./sync/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "bundt",
"bench": "node bench",
"pretest": "npm run build",
"test": "tape test/*.js | tap-spec"
},
"dependencies": {
"globalyzer": "0.1.0",
"globrex": "^0.1.2"
},
"devDependencies": {
"bundt": "1.1.2",
"tap-spec": "^5.0.0",
"tape": "^5.0.1"
},
"modes": {
"sync": "src/sync.js",
"default": "src/index.js"
},
"keywords": [
"glob",
"globbing",
Expand Down
File renamed without changes.
15 changes: 8 additions & 7 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs');
const globrex = require('globrex');
const { promisify } = require('util');
const globalyzer = require('globalyzer');
const { join, resolve, relative } = require('path');
import * as fs from 'fs';
import globrex from 'globrex';
import { promisify } from 'util';
import globalyzer from 'globalyzer';
import { join, resolve, relative } from 'path';

const isHidden = /(^|[\\\/])\.[^\\\/\.]/g;
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
Expand Down Expand Up @@ -50,7 +51,7 @@ async function walk(output, prefix, lexer, opts, dirname='', level=0) {
* @param {Boolean} [options.flush=false] Reset cache object
* @returns {Array} array containing matching files
*/
module.exports = async function (str, opts={}) {
export default async function (str, opts={}) {
if (!str) return [];

let glob = globalyzer(str);
Expand Down Expand Up @@ -80,4 +81,4 @@ module.exports = async function (str, opts={}) {
await walk(matches, glob.base, path, opts, '.', 0);

return opts.absolute ? matches.map(x => resolve(opts.cwd, x)) : matches;
};
}
File renamed without changes.
13 changes: 7 additions & 6 deletions sync.js → src/sync.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require('fs');
const globrex = require('globrex');
const globalyzer = require('globalyzer');
const { join, resolve, relative } = require('path');
import * as fs from 'fs';
import globrex from 'globrex';
import globalyzer from 'globalyzer';
import { join, resolve, relative } from 'path';

const isHidden = /(^|[\\\/])\.[^\\\/\.]/g;

let CACHE = {};
Expand Down Expand Up @@ -48,7 +49,7 @@ function walk(output, prefix, lexer, opts, dirname='', level=0) {
* @param {Boolean} [options.flush=false] Reset cache object
* @returns {Array} array containing matching files
*/
module.exports = function (str, opts={}) {
export default function (str, opts={}) {
if (!str) return [];

let glob = globalyzer(str);
Expand Down Expand Up @@ -78,4 +79,4 @@ module.exports = function (str, opts={}) {
walk(matches, glob.base, path, opts, '.', 0);

return opts.absolute ? matches.map(x => resolve(opts.cwd, x)) : matches;
};
}
2 changes: 1 addition & 1 deletion test/glob.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const test = require('tape');
const { join, resolve } = require('path');
const { order, unixify } = require('./helpers');
const glob = require('../');
const glob = require('../dist');

const cwd = join(__dirname, 'fixtures');

Expand Down