Skip to content

Commit

Permalink
Merge pull request #22 from StarLederer/develop
Browse files Browse the repository at this point in the history
Release v1.1.0
  • Loading branch information
StarLederer authored Nov 25, 2023
2 parents 7d8c0e4 + 90d3548 commit ff68a57
Show file tree
Hide file tree
Showing 14 changed files with 1,685 additions and 1,422 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2023-11-25

### Added

- Binary data support to `writeFile`.

### Fixed

- Incorrect handling of international characters in paths.
- Incorrect `readdir` return type when not `withFileTypes: true`.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
[libera-src]: https://img.shields.io/badge/libera-manifesto-lightgrey.svg
[libera-href]: https://liberamanifesto.com

[issue-tracker]: https://github.com/HermanLederer/vite-plugin-fs/issues
[show-n-tell]: https://github.com/HermanLederer/vite-plugin-fs/discussions/categories/show-and-tell
[github]: https://github.com/HermanLederer/vite-plugin-fs/tree/feature/beta-readme
[issue-tracker]: https://github.com/StarLederer/vite-plugin-fs/issues
[show-n-tell]: https://github.com/StarLederer/vite-plugin-fs/discussions/categories/show-and-tell
[github]: https://github.com/StarLederer/vite-plugin-fs
[changelog]: https://github.com/StarLederer/vite-plugin-fs/tree/master/CHANGELOG.md

# [vite-plugin-fs](https://npmjs.com/package/vite-plugin-fs)

Expand All @@ -20,7 +21,7 @@

Interact with fs from the browser in dev mode.

> **News:** v1.0.0 has been released after nearly 2 years of preview! The original release criteria were not met completely but the plugin has proven itself over this time in other ways, and it is about to receive new and exciting features that would fit a lot better in a version bump. Thank you for using vite-plugin-fs, and see you in v1.1.0!
> **News:** v1.1.0 is out and v2.0.0 is already in the works! See [changelog][changelog] for updates since v1.0.0 and keep and eye on the [issue tracker][issue-tracker] for future improvement plans.
## What's supported by the relay server

Expand Down
Empty file.
24 changes: 17 additions & 7 deletions __tests__/src/abstraction/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,37 @@ describe('abstraction', () => {
await abstraction.readdir('', true);
expect(lastFetch).toEqual({ url: `http://localhost:${testPort}/?cmd=readdir&withFileTypes=true` });
});

it('should build correct readFile queries', async () => {
await abstraction.readFile('');
expect(lastFetch).toEqual({ url: `http://localhost:${testPort}/?cmd=readFile` });
});

it('should build correct stat queries', async () => {
await abstraction.stat('');
expect(lastFetch).toEqual({ url: `http://localhost:${testPort}/?cmd=stat` });
});

it('should build correct writeFile queries', async () => {
await abstraction.writeFile('file', '');
expect(lastFetch).toEqual({
const expected = {
url: `http://localhost:${testPort}/file?cmd=writeFile`,
init: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: '{"data":""}',
headers: { 'Content-Type': 'text/plain' },
body: '',
},
});
};

await abstraction.writeFile('file', '');
expect(lastFetch).toEqual(expected);

await abstraction.writeFile('file', new Uint8Array());
expect(lastFetch).toEqual(expected);

await abstraction.writeFile('file', new DataView(new ArrayBuffer(0)));
expect(lastFetch).toEqual(expected);
});

it('should build correct rm queries', async () => {
await abstraction.rm('');
expect(lastFetch).toEqual({
Expand Down
88 changes: 75 additions & 13 deletions __tests__/src/server/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fetch from 'node-fetch';
import * as fs from 'fs/promises';
import { resolve } from 'path';

import { UserOptions } from 'src/plugin/Options';
import { SimpleStats } from 'src/common/ApiResponses';
import FsServer from '../../../src/plugin/server';
Expand Down Expand Up @@ -84,6 +83,11 @@ describe('readdir request', () => {
const response = await fetch(`${url}/file?cmd=readdir`);
expect(response.status).toEqual(400);
});

it('should support various UTF-8 characters in path', async () => {
const response = await fetch(`${url}/directory 目录 каталог/file 文件 файл?cmd=readFile`);
expect(response.status).toEqual(200);
});
});

// readFile
Expand Down Expand Up @@ -119,6 +123,11 @@ describe('readFile request', () => {
const response = await fetch(`${url}/directory?cmd=readFile`);
expect(response.status).toEqual(400);
});

it('should support various UTF-8 characters in path', async () => {
const response = await fetch(`${url}/directory 目录 каталог/file 文件 файл?cmd=readFile`);
expect(response.status).toEqual(200);
});
});

// stat
Expand All @@ -142,23 +151,67 @@ describe('stat request', () => {
const response = await fetch(`${url}/notfile?cmd=stat`);
expect(response.status).toEqual(404);
});

it('should support various UTF-8 characters in path', async () => {
const response = await fetch(`${url}/directory 目录 каталог/file 文件 файл?cmd=stat`);
expect(response.status).toEqual(200);
});
});

// writeFile

describe('writeFile request', () => {
it('should write files correctly', async () => {
const response = await fetch(`${url}/newdirectory/newfile?cmd=writeFile`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ data: 'new data' }),
});
const newdata = await fs.readFile(resolveWithRoot('newdirectory/newfile'), 'utf-8');
expect(response.status).toEqual(200);
expect(newdata).toEqual('new data');
const textDecoder = new TextDecoder();

it('should write strings to files correctly', async () => {
const testData = 'new data';
const testFilename = 'newfile-string';
const response = await fetch(`${url}/newdirectory/${testFilename}?cmd=writeFile`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: testData,
});
const newdata = await fs.readFile(resolveWithRoot(`newdirectory/${testFilename}`), 'utf-8');
expect(response.status).toEqual(200);
expect(newdata).toEqual(testData);
});

it('should write TypedArrays to files correctly', async () => {
const testData = new Uint8Array([84, 121, 112, 101, 100, 65, 114, 114, 97, 121]);
const testFilename = 'newfile-typedarray';
const response = await fetch(`${url}/newdirectory/${testFilename}?cmd=writeFile`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: textDecoder.decode(testData),
});
const newdata = await fs.readFile(resolveWithRoot(`newdirectory/${testFilename}`));
expect(response.status).toEqual(200);
expect(newdata.buffer).toEqual(testData.buffer);
});

it('should write DataViews to files correctly', async () => {
const testData = new Uint8Array([68, 97, 116, 97, 86, 105, 101, 119]).buffer;
const testFilename = 'newfile-dataview';
const response = await fetch(`${url}/newdirectory/${testFilename}?cmd=writeFile`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: new DataView(testData),
});
const newdata = await fs.readFile(resolveWithRoot(`newdirectory/${testFilename}`));
expect(response.status).toEqual(200);
expect(newdata.buffer).toEqual(testData);
});

it('should support various UTF-8 characters in path', async () => {
const testFilename = 'new file 文件 файл';
const response = await fetch(`${url}/newdirectory/${testFilename}?cmd=writeFile`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: '',
});
const statPromise = fs.stat(resolveWithRoot(`newdirectory/${testFilename}`));
expect(response.status).toEqual(200);
await expect(statPromise).resolves.toBeTruthy();
});
});

Expand Down Expand Up @@ -193,6 +246,15 @@ describe('rm request', () => {
expect(response.status).toEqual(200);
await expect(statPromise).rejects.toBeTruthy();
});

it('should support various UTF-8 characters in path', async () => {
const testFilename = 'auto file 文件 файл';
try { await fs.writeFile(resolve(resolveWithRoot(testFilename)), ''); } catch (err) { /**/ }
const response = await fetch(`${url}/${testFilename}?cmd=rm`, { method: 'DELETE' });
const statPromise = fs.stat(resolveWithRoot(testFilename));
expect(response.status).toEqual(200);
await expect(statPromise).rejects.toBeTruthy();
});
});

export default {};
32 changes: 25 additions & 7 deletions flake.lock

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

12 changes: 4 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{
description = "pnpm";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/22.11";
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
};

outputs = { self, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pnpm = pkgs.nodePackages.pnpm.override {
nodejs = pkgs.nodejs-18_x;
};
in {
devShell = pkgs.mkShell rec {
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
pnpm
bashInteractive
nodePackages.pnpm
];
};
}
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-fs",
"version": "1.0.0",
"version": "1.1.0",
"description": "Interact with fs from the browser in dev mode",
"author": "StarLederer",
"license": "MIT",
Expand Down Expand Up @@ -62,34 +62,34 @@
"lint": "eslint ."
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/cors": "^2.8.15",
"@types/express": "^4.17.20",
"@types/jest": "^27.5.2",
"@types/koa": "^2.13.5",
"@types/koa-bodyparser": "^4.3.10",
"@types/koa-router": "^7.4.4",
"@types/koa": "^2.13.10",
"@types/koa-bodyparser": "^4.3.11",
"@types/koa-router": "^7.4.6",
"@types/koa__cors": "^3.3.1",
"@types/node-fetch": "^2.6.2",
"@types/node-fetch": "^2.6.7",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^14.0.2",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "^2.29.0",
"jest": "^27.5.1",
"node-fetch": "^2.6.9",
"node-fetch": "^2.7.0",
"rimraf": "^3.0.2",
"rollup": "^3.19.1",
"rollup": "^3.29.4",
"ts-jest": "^27.1.5",
"tsup": "^5.12.9",
"typescript": "^4.9.5",
"vite": "^4.2.0"
"vite": "^4.5.0"
},
"dependencies": {
"@koa/cors": "^3.4.3",
"get-port": "^5.1.1",
"koa": "^2.14.1",
"koa-bodyparser": "^4.4.0",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.1",
"koa-router": "^10.1.1"
}
}
Loading

0 comments on commit ff68a57

Please sign in to comment.