Skip to content

Commit

Permalink
convert to esm, require node 14
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Sep 16, 2022
1 parent 6f2c851 commit 1c22130
Show file tree
Hide file tree
Showing 13 changed files with 8,219 additions and 4,710 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ insert_final_newline = true

[Makefile]
indent_style = tab
indent_size = 2
File renamed without changes.
13 changes: 5 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-16.04, macOS-latest, windows-latest]
node: ['10', '12', '14']
node: ['14', '16', '18']

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: make deps
node-version: ${{matrix.node}}
- run: make test

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.vscode
/node_modules
/npm-debug.log*
/package-lock.json
/yarn-error.log
/yarn.lock
5 changes: 5 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
audit=false
fund=false
package-lock=true
save-exact=true
update-notifier=false
1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

50 changes: 26 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
node_modules: yarn.lock
@yarn -s --pure-lockfile
node_modules: package-lock.json
npm install --no-save
@touch node_modules

.PHONY: deps
deps: node_modules

test: node_modules
yarn -s run eslint --color .
yarn -s run jest --color

unittest: node_modules
yarn -s run jest --color --watchAll=true
.PHONY: lint
lint: node_modules
npx eslint --color .

coverage: node_modules
yarn -s run jest --collectCoverage --coverageReporters text
.PHONY: test
test: node_modules
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color

.PHONY: publish
publish: node_modules
git push -u --tags origin master
npm publish

.PHONY: update
update: node_modules
yarn -s run updates -cu
@rm yarn.lock
@yarn -s
npx updates -cu
rm package-lock.json
npm install
@touch node_modules

patch: node_modules test
yarn -s run versions -C patch
$(MAKE) --no-print-directory publish

minor: node_modules test
yarn -s run versions -C minor
$(MAKE) --no-print-directory publish
.PHONY: path
patch: node_modules lint test
npx versions -C patch
@$(MAKE) --no-print-directory publish

major: node_modules test
yarn -s run versions -C major
$(MAKE) --no-print-directory publish
.PHONY: minor
minor: node_modules lint test
npx versions -C minor
@$(MAKE) --no-print-directory publish

.PHONY: deps test unittest coverage publish update patch minor major
.PHONY: major
major: node_modules lint test
npx versions -C major
@$(MAKE) --no-print-directory publish
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@
npm i rrdir
```
```js
const rrdir = require("rrdir");
import {rrdir, rrdirAsync, rrdirSync} from "rrdir";

for await (const entry of rrdir("dir")) {
// => {path: 'dir/file', directory: false, symlink: false}
}

const entries = await rrdir.async("dir");
const entries = await rrdirAsync("dir");
// => [{path: 'dir/file', directory: false, symlink: false}]

const entries = rrdir.sync("dir");
const entries = rrdirSync("dir");
// => [{path: 'dir/file', directory: false, symlink: false}]

```

## API
### `rrdir(dir, [options])`
### `rrdir.async(dir, [options])`
### `rrdir.sync(dir, [options])`
### `rrdirAsync(dir, [options])`
### `rrdirSync(dir, [options])`

`rrdir` is an async iterator which yields `entry`. `rrdir.async` and `rrdir.sync` return an Array of `entry`.
`rrdir` is an async iterator which yields `entry`. `rrdirAsync` and `rrdirSync` return an Array of `entry`.

#### `dir` *String* | *Buffer*

Expand Down
26 changes: 12 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"use strict";

const {readdir, stat, lstat} = require("fs").promises;
const {readdirSync, statSync, lstatSync} = require("fs");
const {sep} = require("path");
const picomatch = require("picomatch");
import {readdir, stat, lstat} from "fs/promises";
import {readdirSync, statSync, lstatSync} from "fs";
import {sep} from "path";
import picomatch from "picomatch";

const sepBuffer = Buffer.from(sep);

Expand Down Expand Up @@ -42,7 +40,7 @@ function makeMatchers({include, exclude, match}) {
};
}

const rrdir = module.exports = async function* (dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
if (includeMatcher === undefined) {
opts = Object.assign({}, defaults, opts);
({includeMatcher, excludeMatcher} = makeMatchers(opts));
Expand Down Expand Up @@ -94,9 +92,9 @@ const rrdir = module.exports = async function* (dir, opts = {}, {includeMatcher,

if (recurse) yield* await rrdir(path, opts, {includeMatcher, excludeMatcher, encoding});
}
};
}

module.exports.async = async (dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) => {
export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
if (includeMatcher === undefined) {
opts = Object.assign({}, defaults, opts);
({includeMatcher, excludeMatcher} = makeMatchers(opts));
Expand Down Expand Up @@ -147,13 +145,13 @@ module.exports.async = async (dir, opts = {}, {includeMatcher, excludeMatcher, e
recurse = true;
}

if (recurse) results.push(...await module.exports.async(path, opts, {includeMatcher, excludeMatcher, encoding}));
if (recurse) results.push(...await rrdirAsync(path, opts, {includeMatcher, excludeMatcher, encoding}));
}));

return results;
};
}

module.exports.sync = (dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) => {
export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
if (includeMatcher === undefined) {
opts = Object.assign({}, defaults, opts);
({includeMatcher, excludeMatcher} = makeMatchers(opts));
Expand Down Expand Up @@ -203,8 +201,8 @@ module.exports.sync = (dir, opts = {}, {includeMatcher, excludeMatcher, encoding
recurse = true;
}

if (recurse) results.push(...module.exports.sync(path, opts, {includeMatcher, excludeMatcher, encoding}));
if (recurse) results.push(...rrdirSync(path, opts, {includeMatcher, excludeMatcher, encoding}));
}

return results;
};
}
Loading

0 comments on commit 1c22130

Please sign in to comment.