Skip to content

Commit 8874830

Browse files
committed
Remove browser stubs
1 parent d3c76bd commit 8874830

File tree

8 files changed

+37
-49
lines changed

8 files changed

+37
-49
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {toVFile} from './lib/fs.js'
1+
export {toVFile} from './lib/index.js'

lib/core.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/fs.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/async.js renamed to lib/index.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import {toVFile} from './core.js'
3+
import buffer from 'is-buffer'
4+
import {VFile} from 'vfile'
5+
6+
// Create a virtual file from a description. If `options` is a string or a
7+
// buffer, it’s used as the path. In all other cases, the options are passed
8+
// through to `vfile()`.
9+
export function toVFile(options) {
10+
if (typeof options === 'string' || buffer(options)) {
11+
options = {path: String(options)}
12+
}
13+
14+
return options instanceof VFile ? options : new VFile(options)
15+
}
16+
17+
toVFile.read = read
18+
toVFile.readSync = readSync
19+
toVFile.write = write
20+
toVFile.writeSync = writeSync
21+
22+
// Create a virtual file and read it in, synchronously.
23+
function readSync(description, options) {
24+
var file = toVFile(description)
25+
file.value = fs.readFileSync(path.resolve(file.cwd, file.path), options)
26+
return file
27+
}
28+
29+
// Create a virtual file and write it out, synchronously.
30+
function writeSync(description, options) {
31+
var file = toVFile(description)
32+
fs.writeFileSync(path.resolve(file.cwd, file.path), file.value || '', options)
33+
return file
34+
}
435

536
// Create a virtual file and read it in, asynchronously.
6-
export function read(description, options, callback) {
37+
function read(description, options, callback) {
738
var file = toVFile(description)
839

940
if (!callback && typeof options === 'function') {
@@ -44,7 +75,7 @@ export function read(description, options, callback) {
4475
}
4576

4677
// Create a virtual file and write it out, asynchronously.
47-
export function write(description, options, callback) {
78+
function write(description, options, callback) {
4879
var file = toVFile(description)
4980

5081
// Weird, right? Otherwise `fs` doesn’t accept it.

lib/sync.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"sideEffects": false,
2929
"type": "module",
3030
"main": "index.js",
31-
"browser": "lib/core.js",
3231
"files": [
3332
"lib",
3433
"index.js"

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
2222
npm install to-vfile
2323
```
2424

25-
> **Note**: the file system stuff is not available in the browser.
26-
2725
## Use
2826

2927
```js

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test('toVFile.readSync', function (t) {
9191

9292
t.test('should honor file.cwd when file.path is relative', function (st) {
9393
var cwd = path.join(process.cwd(), 'lib')
94-
var file = toVFile.readSync({path: 'core.js', cwd}, 'utf8')
94+
var file = toVFile.readSync({path: 'index.js', cwd}, 'utf8')
9595

9696
st.equal(typeof file.value, 'string')
9797

@@ -101,7 +101,7 @@ test('toVFile.readSync', function (t) {
101101
t.test(
102102
'should honor file.cwd when file.path is relative, even with relative cwd',
103103
function (st) {
104-
var file = toVFile.readSync({path: 'core.js', cwd: 'lib'}, 'utf8')
104+
var file = toVFile.readSync({path: 'index.js', cwd: 'lib'}, 'utf8')
105105

106106
st.equal(typeof file.value, 'string')
107107

0 commit comments

Comments
 (0)