Skip to content
Open
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
18 changes: 9 additions & 9 deletions .github/workflows/codequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
steps:
- name: Checkout Project
uses: actions/checkout@v1
- name: Use Node.js 12
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- name: Restore CI Cache
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-12-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
run: yarn
- name: Run ESLint
Expand All @@ -38,15 +38,15 @@ jobs:
steps:
- name: Checkout Project
uses: actions/checkout@v1
- name: Use Node.js 12
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- name: Restore CI Cache
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-12-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
run: yarn
- name: Run TSC
Expand All @@ -62,15 +62,15 @@ jobs:
steps:
- name: Checkout Project
uses: actions/checkout@v1
- name: Use Node.js 12
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- name: Restore CI Cache
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-12-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
run: yarn
- name: Test Docs
Expand Down
23 changes: 4 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: [12, 14]
node_version: [14]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down Expand Up @@ -47,42 +47,27 @@ jobs:
steps:
- name: Checkout Project
uses: actions/checkout@v1
- name: Use Node.js 12
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- name: Restore CI Cache
uses: actions/cache@v1
with:
path: node_modules
key: Windows-12-${{ hashFiles('**\yarn.lock') }}
key: Windows-14-${{ hashFiles('**\yarn.lock') }}
- name: Install Dependencies
run: yarn
- uses: actions/download-artifact@v1
name: Download Windows-12 Coverage Data
with:
name: Windows-12
path: .nyc_output
- uses: actions/download-artifact@v1
name: Download Windows-14 Coverage Data
with:
name: Windows-14
path: .nyc_output
- uses: actions/download-artifact@v1
name: Download macOS-12 Coverage Data
with:
name: macOS-12
path: .nyc_output
- uses: actions/download-artifact@v1
name: Download macOS-14 Coverage Data
with:
name: macOS-14
path: .nyc_output
- uses: actions/download-artifact@v1
name: Download Linux-12 Coverage Data
with:
name: Linux-12
path: .nyc_output
- uses: actions/download-artifact@v1
name: Download Linux-14 Coverage Data
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"author": "BDISTIN",
"license": "MIT",
"engines": {
"node": ">=12.12.0"
"node": ">=14.0.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
Expand Down
22 changes: 12 additions & 10 deletions src/nextra/copy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { resolve, dirname, join, basename } from 'path';
import { promises as fsp, Stats } from 'fs';
import { access, mkdir, lstat, chmod, readdir, stat, symlink, readlink, copyFile } from 'fs/promises';

import type { Stats } from 'fs';

import { replaceEsc, isSrcKid } from '../utils/util';
import { mkdirs } from './mkdirs';
Expand Down Expand Up @@ -44,7 +46,7 @@ export async function copy(source: string, destination: string, options: CopyOpt

if (resolve(source) === resolve(destination)) {
if (copyOptions.errorOnExist) throw new Error('FS-NEXTRA: Source and destination must not be the same.');
await fsp.access(source);
await access(source);
} else {
await mkdirs(dirname(destination));
await startCopy(source, copyOptions);
Expand All @@ -66,7 +68,7 @@ function resolveCopyOptions(source: string, destination: string, options: CopyOp

async function isWritable(myPath: string): Promise<boolean> {
try {
await fsp.lstat(myPath);
await lstat(myPath);
return false;
} catch (err) {
return err.code === 'ENOENT';
Expand All @@ -75,7 +77,7 @@ async function isWritable(myPath: string): Promise<boolean> {

async function startCopy(mySource: string, options: CopyData): Promise<void> {
if (!options.filter(mySource, options.targetPath)) return;
const stats = await fsp.lstat(mySource);
const stats = await lstat(mySource);
const target = mySource.replace(options.currentPath, replaceEsc(options.targetPath));

if (stats.isDirectory()) await copyDirectory(mySource, stats, target, options);
Expand All @@ -85,16 +87,16 @@ async function startCopy(mySource: string, options: CopyData): Promise<void> {
async function copyDirectory(mySource: string, stats: Stats, target: string, options: CopyData): Promise<void> {
if (isSrcKid(mySource, target)) throw new Error('FS-NEXTRA: Copying a parent directory into a child will result in an infinite loop.');
if (await isWritable(target)) {
await fsp.mkdir(target, stats.mode);
await fsp.chmod(target, stats.mode);
await mkdir(target, stats.mode);
await chmod(target, stats.mode);
}
const items = await fsp.readdir(mySource);
const items = await readdir(mySource);
await Promise.all(items.map((item): Promise<void> => startCopy(join(mySource, item), options)));
}

async function copyOther(mySource: string, stats: Stats, target: string, options: CopyData): Promise<void> {
try {
const tstats = await fsp.stat(target);
const tstats = await stat(target);
if (tstats && tstats.isDirectory()) target = join(target, basename(mySource));
} catch (err) {
// noop
Expand All @@ -106,6 +108,6 @@ async function copyOther(mySource: string, stats: Stats, target: string, options
await remove(target);
}

if (stats.isSymbolicLink()) await fsp.symlink(await fsp.readlink(mySource), target);
else await fsp.copyFile(mySource, target);
if (stats.isSymbolicLink()) await symlink(await readlink(mySource), target);
else await copyFile(mySource, target);
}
4 changes: 2 additions & 2 deletions src/nextra/copyFileAtomic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs';
import { copyFile } from 'fs/promises';

import { tempFile } from '../utils/util';
import { move } from './move';
Expand All @@ -12,6 +12,6 @@ import { move } from './move';
*/
export async function copyFileAtomic(source: string, destination: string): Promise<void> {
const tempPath = tempFile();
await fsp.copyFile(source, tempPath);
await copyFile(source, tempPath);
await move(tempPath, destination, { overwrite: true });
}
4 changes: 2 additions & 2 deletions src/nextra/createFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname } from 'path';
import { promises as fsp } from 'fs';
import { writeFile } from 'fs/promises';

import { writeFileAtomic } from './writeFileAtomic';
import { mkdirs } from './mkdirs';
Expand All @@ -24,7 +24,7 @@ export async function createFile(file: string, atomic = false): Promise<void> {

await mkdirs(dirname(file));

const writeMethod = atomic ? writeFileAtomic : fsp.writeFile;
const writeMethod = atomic ? writeFileAtomic : writeFile;
await writeMethod(file, '');
}

Expand Down
7 changes: 3 additions & 4 deletions src/nextra/createFileCopy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { dirname, resolve } from 'path';

import { promises as fsp } from 'fs';
import { access, copyFile } from 'fs/promises';

import { copyFileAtomic } from './copyFileAtomic';
import { mkdirs } from './mkdirs';
Expand All @@ -23,11 +22,11 @@ import { mkdirs } from './mkdirs';
*/
export async function createFileCopy(source: string, destination: string, atomic = false): Promise<void> {
if (resolve(source) === resolve(destination)) {
await fsp.access(source);
await access(source);
} else {
await mkdirs(dirname(destination));

const copyMethod = atomic ? copyFileAtomic : fsp.copyFile;
const copyMethod = atomic ? copyFileAtomic : copyFile;
await copyMethod(source, destination);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/nextra/createLink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { dirname } from 'path';

import { promises as fsp } from 'fs';
import { lstat, link } from 'fs/promises';

import { linkAtomic } from './linkAtomic';
import { mkdirs } from './mkdirs';
Expand All @@ -24,11 +23,11 @@ import { pathExists } from './pathExists';
*/
export async function createLink(source: string, destination: string, atomic = false): Promise<void> {
if (await pathExists(destination)) return;
await fsp.lstat(source);
await lstat(source);

await mkdirs(dirname(destination));

const linkMethod = atomic ? linkAtomic : fsp.link;
const linkMethod = atomic ? linkAtomic : link;
await linkMethod(source, destination);
}

Expand Down
10 changes: 5 additions & 5 deletions src/nextra/createSymlink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname, join, isAbsolute, relative, resolve } from 'path';
import { promises as fsp } from 'fs';
import { symlink, lstat } from 'fs/promises';

import { pathExists } from './pathExists';
import { mkdirs } from './mkdirs';
Expand Down Expand Up @@ -48,25 +48,25 @@ export async function createSymlink(source: string, destination: string, type?:
await mkdirs(dirname(destination));
const relativePath = await symlinkPaths(source, destination);

const symlinkMethod = atomic ? symlinkAtomic : fsp.symlink;
const symlinkMethod = atomic ? symlinkAtomic : symlink;
await symlinkMethod(relativePath.toDst, resolve(destination), type as SymLinkType || await symlinkType(relativePath.toCwd));
}

async function symlinkPaths(srcpath: string, dstPath: string): Promise<SymLinkPaths> {
if (isAbsolute(srcpath)) {
await fsp.lstat(srcpath);
await lstat(srcpath);
return { toCwd: srcpath, toDst: srcpath };
}
const dstDir = dirname(dstPath);
const relativeToDst = join(dstDir, srcpath);
/* istanbul ignore next: Doesn't get tested on all OSs */
if (await pathExists(relativeToDst)) return { toCwd: relativeToDst, toDst: srcpath };
await fsp.lstat(srcpath);
await lstat(srcpath);
return { toCwd: srcpath, toDst: relative(dstDir, srcpath) };
}

async function symlinkType(srcpath: string): Promise<SymLinkType> {
const stats = await fsp.lstat(srcpath);
const stats = await lstat(srcpath);
return stats.isDirectory() ? 'dir' : 'file';
}

Expand Down
4 changes: 2 additions & 2 deletions src/nextra/emptyDir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { promises as fsp } from 'fs';
import { readdir } from 'fs/promises';

import { mkdirs } from './mkdirs';
import { remove } from './remove';
Expand All @@ -18,7 +18,7 @@ import { remove } from './remove';
*/
export async function emptyDir(dir: string): Promise<void> {
try {
const items = await fsp.readdir(dir);
const items = await readdir(dir);
await Promise.all(items.map((item): Promise<void> => remove(join(dir, item))));
} catch (err) {
await mkdirs(dir);
Expand Down
4 changes: 2 additions & 2 deletions src/nextra/linkAtomic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs';
import { link } from 'fs/promises';

import { tempFile } from '../utils/util';
import { move } from './move';
Expand All @@ -12,6 +12,6 @@ import { move } from './move';
*/
export async function linkAtomic(source: string, destination: string): Promise<void> {
const tempPath = tempFile();
await fsp.link(source, tempPath);
await link(source, tempPath);
await move(tempPath, destination, { overwrite: true });
}
6 changes: 3 additions & 3 deletions src/nextra/mkdirs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve, dirname } from 'path';
import { promises as fsp } from 'fs';
import { mkdir, stat } from 'fs/promises';

import { isWindows, invalidWin32Path, umask } from '../utils/util';

Expand Down Expand Up @@ -47,14 +47,14 @@ export async function mkdirs(path: string, options?: MkdirsOptions | number): Pr
path = resolve(path);

try {
await fsp.mkdir(path, dirOptions.mode);
await mkdir(path, dirOptions.mode);
} catch (err) {
if (err.code === 'ENOENT') {
await mkdirs(dirname(path), dirOptions);
await mkdirs(path, dirOptions);
return;
}
const myStat = await fsp.stat(path);
const myStat = await stat(path);
if (myStat.isDirectory()) return;
throw err;
}
Expand Down
8 changes: 4 additions & 4 deletions src/nextra/move.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve, dirname } from 'path';
import { promises as fsp } from 'fs';
import { access, lstat, rename } from 'fs/promises';

import { isSrcKid } from '../utils/util';
import { remove } from './remove';
Expand All @@ -25,9 +25,9 @@ export interface MoveOptions {
*/
export async function move(source: string, destination: string, options: MoveOptions = {}): Promise<void> {
const overwrite = options.overwrite || false;
if (resolve(source) === resolve(destination)) return fsp.access(source);
if (resolve(source) === resolve(destination)) return access(source);

const myStat = await fsp.lstat(source);
const myStat = await lstat(source);
if (myStat.isDirectory() && isSrcKid(source, destination)) {
throw new Error('FS-NEXTRA: Moving a parent directory into a child will result in an infinite loop.');
}
Expand All @@ -41,7 +41,7 @@ export async function move(source: string, destination: string, options: MoveOpt
}

try {
return await fsp.rename(source, destination);
return await rename(source, destination);
} catch (err) {
/* istanbul ignore next: Can't test via CI */
if (err.code === 'EXDEV') {
Expand Down
4 changes: 2 additions & 2 deletions src/nextra/outputFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname } from 'path';
import { promises as fsp } from 'fs';
import { writeFile } from 'fs/promises';

import { writeFileAtomic, WriteOptions, BaseEncodingOptions } from './writeFileAtomic';
import { mkdirs } from './mkdirs';
Expand All @@ -20,6 +20,6 @@ export async function outputFile(file: string, data: string | Buffer | Uint8Arra

await mkdirs(dirname(file));

const writeMethod = atomic ? writeFileAtomic : fsp.writeFile;
const writeMethod = atomic ? writeFileAtomic : writeFile;
await writeMethod(file, data, options);
}
Loading