Skip to content

Commit

Permalink
fix syntax error in mjs
Browse files Browse the repository at this point in the history
Shipping hybrid modules is so full of gotchas. sigh.

Fix: #247
  • Loading branch information
isaacs committed Jan 13, 2023
1 parent bad1ecf commit bcc7691
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/default-tmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// it uses os.tmpdir() always.
import { tmpdir } from 'os'
import { parse, resolve } from 'path'
import { promises, statSync } from './fs'
import platform from './platform'
import { promises, statSync } from './fs.js'
import platform from './platform.js'
const { stat } = promises

const isDirSync = (path: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/fix-eperm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises, chmodSync, FsError } from './fs'
import { promises, chmodSync, FsError } from './fs.js'
const { chmod } = promises

export const fixEPERM =
Expand Down
2 changes: 1 addition & 1 deletion src/ignore-enoent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FsError } from './fs'
import { FsError } from './fs.js'

export const ignoreENOENT = async (p: Promise<any>) =>
p.catch(er => {
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import optArg from './opt-arg'
import pathArg from './path-arg'
import optArg from './opt-arg.js'
import pathArg from './path-arg.js'

export interface RimrafOptions {
preserveRoot?: boolean
Expand Down Expand Up @@ -35,12 +35,12 @@ export const assertRimrafOptions: (o: any) => void = (
}
/* c8 ignore stop */

import { rimrafManual, rimrafManualSync } from './rimraf-manual'
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove'
import { rimrafNative, rimrafNativeSync } from './rimraf-native'
import { rimrafPosix, rimrafPosixSync } from './rimraf-posix'
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows'
import { useNative, useNativeSync } from './use-native'
import { rimrafManual, rimrafManualSync } from './rimraf-manual.js'
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
import { rimrafNative, rimrafNativeSync } from './rimraf-native.js'
import { rimrafPosix, rimrafPosixSync } from './rimraf-posix.js'
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows.js'
import { useNative, useNativeSync } from './use-native.js'

const wrap =
(fn: (p: string, o: RimrafOptions) => Promise<void>) =>
Expand Down
2 changes: 1 addition & 1 deletion src/opt-arg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertRimrafOptions, RimrafOptions } from './index'
import { assertRimrafOptions, RimrafOptions } from './index.js'
export default (opt: RimrafOptions = {}) => {
assertRimrafOptions(opt)
return opt
Expand Down
4 changes: 2 additions & 2 deletions src/path-arg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform from './platform'
import platform from './platform.js'
import { resolve, parse } from 'path'
import { inspect } from 'util'
import { RimrafOptions } from './index'
import { RimrafOptions } from './index.js'

const pathArg = (path: string, opt: RimrafOptions = {}) => {
const type = typeof path
Expand Down
2 changes: 1 addition & 1 deletion src/readdir-or-error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// returns an array of entries if readdir() works,
// or the error that readdir() raised if not.
import { FsError, promises, readdirSync } from './fs'
import { FsError, promises, readdirSync } from './fs.js'
const { readdir } = promises
export const readdirOrError = (path: string) =>
readdir(path).catch(er => er as FsError)
Expand Down
2 changes: 1 addition & 1 deletion src/retry-busy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// note: max backoff is the maximum that any *single* backoff will do

import { RimrafOptions } from '.'
import { FsError } from './fs'
import { FsError } from './fs.js'

export const MAXBACKOFF = 200
export const RATE = 1.2
Expand Down
6 changes: 3 additions & 3 deletions src/rimraf-manual.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform from './platform'
import platform from './platform.js'

import { rimrafPosix, rimrafPosixSync } from './rimraf-posix'
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows'
import { rimrafPosix, rimrafPosixSync } from './rimraf-posix.js'
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows.js'

export const rimrafManual = platform === 'win32' ? rimrafWindows : rimrafPosix
export const rimrafManualSync =
Expand Down
6 changes: 3 additions & 3 deletions src/rimraf-move-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// However, it is HELLA SLOW, like 2-10x slower than a naive recursive rm.

import { basename, parse, resolve } from 'path'
import { defaultTmp, defaultTmpSync } from './default-tmp'
import { defaultTmp, defaultTmpSync } from './default-tmp.js'

import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent'
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'

import {
chmodSync,
Expand All @@ -27,7 +27,7 @@ import {
const { rename, unlink, rmdir, chmod } = fsPromises

import { RimrafOptions } from '.'
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error'
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'

// crypto.randomBytes is much slower, and Math.random() is enough here
const uniqueFilename = (path: string) => `.${basename(path)}.${Math.random()}`
Expand Down
2 changes: 1 addition & 1 deletion src/rimraf-native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RimrafOptions } from '.'
import { promises, rmSync } from './fs'
import { promises, rmSync } from './fs.js'
const { rm } = promises

export const rimrafNative = (path: string, opt: RimrafOptions) =>
Expand Down
6 changes: 3 additions & 3 deletions src/rimraf-posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// calls), because sunos will let root unlink a directory, and some
// SUPER weird breakage happens as a result.

import { promises, rmdirSync, unlinkSync } from './fs'
import { promises, rmdirSync, unlinkSync } from './fs.js'
const { rmdir, unlink } = promises

import { parse, resolve } from 'path'

import { readdirOrError, readdirOrErrorSync } from './readdir-or-error'
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'

import { RimrafOptions } from '.'
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent'
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'

export const rimrafPosix = async (path: string, opt: RimrafOptions) => {
const entries = await readdirOrError(path)
Expand Down
12 changes: 6 additions & 6 deletions src/rimraf-windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// Note: "move then remove" is 2-10 times slower, and just as unreliable.

import { parse, resolve } from 'path'
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent'
import { fixEPERM, fixEPERMSync } from './fix-eperm'
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error'
import { retryBusy, retryBusySync } from './retry-busy'
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove'
import { FsError, promises, rmdirSync, unlinkSync } from './fs'
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
import { fixEPERM, fixEPERMSync } from './fix-eperm.js'
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'
import { retryBusy, retryBusySync } from './retry-busy.js'
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
import { FsError, promises, rmdirSync, unlinkSync } from './fs.js'
import { RimrafOptions } from '.'
const { unlink, rmdir } = promises

Expand Down
2 changes: 1 addition & 1 deletion src/use-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const versArr = version.replace(/^v/, '').split('.')
const hasNative = +versArr[0] > 14 || (+versArr[0] === 14 && +versArr[1] >= 14)
// we do NOT use native by default on Windows, because Node's native
// rm implementation is less advanced. Change this code if that changes.
import platform from './platform'
import platform from './platform.js'
export const useNative =
!hasNative || platform === 'win32' ? () => false : () => true
export const useNativeSync =
Expand Down
4 changes: 2 additions & 2 deletions test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import t from 'tap'
// and that when the cb returns an error, the promised version fails,
// and when the cb returns data, the promisified version resolves to it.
import realFS from 'fs'
import * as fs from '../src/fs'
import * as fs from '../dist/cjs/src/fs.js'

const mockFSMethodPass =
(method: string) =>
Expand All @@ -20,7 +20,7 @@ const mockFSMethodFail =
process.nextTick(() => cb(new Error('oops'), method, 1, 2, 3))
}

import { useNative } from '../src/use-native'
import { useNative } from '../dist/cjs/src/use-native.js'
t.type(fs.promises, Object)
const mockFSPass: { [k: string]: (...a: any[]) => any } = {}
const mockFSFail: { [k: string]: (...a: any[]) => any } = {}
Expand Down

0 comments on commit bcc7691

Please sign in to comment.