Skip to content

Commit

Permalink
Merge pull request #1029 from streamich/bump-build-target
Browse files Browse the repository at this point in the history
Bump build target
  • Loading branch information
streamich authored Apr 29, 2024
2 parents 030c682 + 9d9bd01 commit af53c0a
Show file tree
Hide file tree
Showing 65 changed files with 868 additions and 3,698 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ jobs:
- name: Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: GitHub Pages

on:
push:
branches: [master]

jobs:
gh-pages:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn typedoc
- run: yarn coverage
- run: yarn build:pages
- name: Publish to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gh-pages
22 changes: 22 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Mirror

on:
push:
branches: [master]

jobs:
mirror:
name: Push To Gitlab
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push To Gitlab
env:
token: ${{ secrets.GITLAB_TOKEN }}
run: |
git config user.name "streamich"
git config user.email "[email protected]"
git remote add mirror "https://oauth2:${token}@gitlab.com/streamich/memfs.git"
git push mirror master
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
node_modules
/.idea
.nyc_output
coverage
/coverage/
package-lock.json
/lib/
/gh-pages
/gh-pages/
/dist
/fs-test/
/typedocs/
55 changes: 53 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
## [4.7.5-next.1](https://github.com/streamich/memfs/compare/v4.7.4...v4.7.5-next.1) (2024-02-17)
## [4.9.1](https://github.com/streamich/memfs/compare/v4.9.0...v4.9.1) (2024-04-27)


### Bug Fixes

* inline `thingies` ([#1001](https://github.com/streamich/memfs/issues/1001)) ([ed265f0](https://github.com/streamich/memfs/commit/ed265f0212b09f04ffbef9430f4f863f0cfc7674))
* 🐛 use latest json-pack implementation ([de54ab5](https://github.com/streamich/memfs/commit/de54ab53a5df3b857975094ce4c59d760240a6d6))

# [4.9.0](https://github.com/streamich/memfs/compare/v4.8.2...v4.9.0) (2024-04-27)


### Features

* 🎸 define .scan() CRUD method ([921e05d](https://github.com/streamich/memfs/commit/921e05d26092f6dbf5a4a302c4ac251944d5d008))
* 🎸 implement .scan() in Node.js CRUD ([3d973b7](https://github.com/streamich/memfs/commit/3d973b7dd4475c6a59443171795ef5449d11805b))
* 🎸 implement .scan() method for FSA CRUD ([a148fb8](https://github.com/streamich/memfs/commit/a148fb89d0373442f5773c6656e433abdafdb2a0))

## [4.8.2](https://github.com/streamich/memfs/compare/v4.8.1...v4.8.2) (2024-04-14)


### Bug Fixes

* don't include filename in `path` when calling `readdir` with `withFileTypes: true` ([#1024](https://github.com/streamich/memfs/issues/1024)) ([711c4bd](https://github.com/streamich/memfs/commit/711c4bd24667c88a45551f1bed7a5069d7170dc2))

## [4.8.1](https://github.com/streamich/memfs/compare/v4.8.0...v4.8.1) (2024-03-31)


### Bug Fixes

* fix handle paths in FSA entries iterator ([#1019](https://github.com/streamich/memfs/issues/1019)) ([b8905eb](https://github.com/streamich/memfs/commit/b8905eb0661d926f45e9a6012658210794e86d31))

# [4.8.0](https://github.com/streamich/memfs/compare/v4.7.7...v4.8.0) (2024-03-19)


### Features

* 🎸 allow to customize CAS storage hash and location mappin ([e32a57d](https://github.com/streamich/memfs/commit/e32a57d07dc05c8275180e59cff59cd76cbd4841))

## [4.7.7](https://github.com/streamich/memfs/compare/v4.7.6...v4.7.7) (2024-02-21)


### Bug Fixes

* accept file names beginning with a period ([#1005](https://github.com/streamich/memfs/issues/1005)) ([3c18dae](https://github.com/streamich/memfs/commit/3c18daeb7ee78813ae66df484070f51f3a16777e))

## [4.7.6](https://github.com/streamich/memfs/compare/v4.7.5...v4.7.6) (2024-02-17)


### Bug Fixes

* remove tests from published package ([#1003](https://github.com/streamich/memfs/issues/1003)) ([d3b62dc](https://github.com/streamich/memfs/commit/d3b62dc3785a50776369aa47bc2244c896ff2bdc))

## [4.7.5](https://github.com/streamich/memfs/compare/v4.7.4...v4.7.5) (2024-02-17)


### Bug Fixes

* inline `thingies` dependency ([#1004](https://github.com/streamich/memfs/issues/1004)) ([6fc340d](https://github.com/streamich/memfs/commit/6fc340d83544d04c35f62bc0fa7aadf77266af12))

## [4.7.4](https://github.com/streamich/memfs/compare/v4.7.3...v4.7.4) (2024-02-17)

Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ JavaScript file system utilities for Node.js and browser.
npm i memfs
```

## Docs

- [In-memory Node.js `fs` API](./docs/node/index.md)
- `experimental` [`fs` to File System Access API adapter](./docs/fsa/fs-to-fsa.md)
- `experimental` [File System Access API to `fs` adapter](./docs/fsa/fsa-to-fs.md)
- `experimental` [`crudfs` a CRUD-like file system abstraction](./docs/crudfs/index.md)
- `experimental` [`casfs` Content Addressable Storage file system abstraction](./docs/casfs/index.md)
- [Directory `snapshot` utility](./docs/snapshot/index.md)
- [`print` directory tree to terminal](./docs/print/index.md)
## Resources

- Documentation
- [In-memory Node.js `fs` API](./docs/node/index.md)
- `experimental` [`fs` to File System Access API adapter](./docs/fsa/fs-to-fsa.md)
- `experimental` [File System Access API to `fs` adapter](./docs/fsa/fsa-to-fs.md)
- `experimental` [`crudfs` a CRUD-like file system abstraction](./docs/crudfs/index.md)
- `experimental` [`casfs` Content Addressable Storage file system abstraction](./docs/casfs/index.md)
- [Directory `snapshot` utility](./docs/snapshot/index.md)
- [`print` directory tree to terminal](./docs/print/index.md)
- [Code reference](https://streamich.github.io/memfs/)
- [Test coverage](https://streamich.github.io/memfs/coverage/lcov-report/)

## Demos

Expand Down
10 changes: 10 additions & 0 deletions docs/node/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ vol.writeFileSync('/foo', 'bar');
expect(vol.toJSON()).toEqual({ '/foo': 'bar' });
```

Construct new `memfs` volumes:

```js
import { memfs } from 'memfs';

const { fs, vol } = memfs({ '/foo': 'bar' });

fs.readFileSync('/foo', 'utf8'); // bar
```

Create as many filesystem volumes as you need:

```js
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"demo/runkit.js"
],
"scripts": {
"build": "tsc -p .",
"build": "tsc -p . && rimraf --glob lib/__tests__ 'lib/**/__tests__'",
"build:webfs": "NODE_ENV=production webpack --config ./src/webfs/webpack.config.js",
"clean": "rimraf lib types",
"clean": "rimraf lib types typedocs gh-pages coverage",
"demo:crud-and-cas": "webpack serve --config ./demo/crud-and-cas/webpack.config.js",
"demo:fsa-to-node-sync-tests": "webpack serve --config ./demo/fsa-to-node-sync-tests/webpack.config.js",
"demo:fsa-to-node-zipfile": "webpack serve --config ./demo/fsa-to-node-zipfile/webpack.config.js",
Expand All @@ -66,7 +66,10 @@
"test:watch": "jest --watch",
"tslint": "tslint \"src/**/*.ts\" -t verbose",
"typecheck": "tsc -p .",
"watch": "watch \"npm run build\" ./src"
"watch": "watch \"npm run build\" ./src",
"coverage": "yarn test --collectCoverage",
"typedoc": "npx [email protected] --tsconfig tsconfig.json",
"build:pages": "npx [email protected] gh-pages && mkdir -p gh-pages && cp -r typedocs/* gh-pages && cp -r coverage gh-pages/coverage"
},
"commitlint": {
"extends": [
Expand Down Expand Up @@ -121,13 +124,17 @@
}
},
"dependencies": {
"@jsonjoy.com/json-pack": "^1.0.2",
"@jsonjoy.com/util": "^1.1.0",
"sonic-forest": "^1.0.0",
"tslib": "^2.0.0"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",
"@types/jest": "^29.0.0",
"@types/mime": "^3.0.0",
"@types/node": "^10.17.60",
"app-root-path": "^3.1.0",
"assert": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Dirent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Dirent implements IDirent {

dirent.name = strToEncoding(link.getName(), encoding);
dirent.mode = mode;
dirent.path = link.getPath();
dirent.path = link.getParentPath();

return dirent;
}
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/volume/readdirSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ describe('readdirSync()', () => {
return { ...dirent };
});
expect(mapped).toEqual([
{ mode: 33206, name: 'af', path: '/x/af' },
{ mode: 16895, name: 'b', path: '/x/b' },
{ mode: 16895, name: 'c', path: '/x/c' },
{ mode: 33206, name: 'af', path: '/x' },
{ mode: 16895, name: 'b', path: '/x' },
{ mode: 16895, name: 'c', path: '/x' },
]);
});

Expand Down Expand Up @@ -105,16 +105,16 @@ describe('readdirSync()', () => {
})
.sort((a, b) => a.path.localeCompare(b.path));
expect(mapped).toEqual([
{ mode: 33206, name: 'af1', path: '/z/af1' },
{ mode: 33206, name: 'af2', path: '/z/af2' },
{ mode: 16895, name: 'b', path: '/z/b' },
{ mode: 33206, name: 'bf1', path: '/z/b/bf1' },
{ mode: 33206, name: 'bf2', path: '/z/b/bf2' },
{ mode: 33206, name: 'af1', path: '/z' },
{ mode: 33206, name: 'af2', path: '/z' },
{ mode: 16895, name: 'b', path: '/z' },
{ mode: 16895, name: 'c', path: '/z' },
{ mode: 33206, name: 'bf1', path: '/z/b' },
{ mode: 33206, name: 'bf2', path: '/z/b' },
{ mode: 16895, name: 'c', path: '/z/c' },
{ mode: 16895, name: 'c', path: '/z/c/c' },
{ mode: 33206, name: '.cf0', path: '/z/c/c/.cf0' },
{ mode: 33206, name: 'cf1', path: '/z/c/c/cf1' },
{ mode: 33206, name: 'cf2', path: '/z/c/c/cf2' },
{ mode: 33206, name: '.cf0', path: '/z/c/c' },
{ mode: 33206, name: 'cf1', path: '/z/c/c' },
{ mode: 33206, name: 'cf2', path: '/z/c/c' },
]);
});
});
10 changes: 5 additions & 5 deletions src/cas/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CrudResourceInfo } from '../crud/types';

export interface CasApi {
put(blob: Uint8Array): Promise<string>;
get(hash: string, options?: CasGetOptions): Promise<Uint8Array>;
del(hash: string, silent?: boolean): Promise<void>;
info(hash: string): Promise<CrudResourceInfo>;
export interface CasApi<Hash> {
put(blob: Uint8Array): Promise<Hash>;
get(hash: Hash, options?: CasGetOptions): Promise<Uint8Array>;
del(hash: Hash, silent?: boolean): Promise<void>;
info(hash: Hash): Promise<CrudResourceInfo>;
}

export interface CasGetOptions {
Expand Down
58 changes: 7 additions & 51 deletions src/crud-to-cas/CrudCas.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,18 @@
import { hashToLocation } from './util';
import type { CasApi, CasGetOptions } from '../cas/types';
import type { CrudApi, CrudResourceInfo } from '../crud/types';
import { CrudCasBase } from './CrudCasBase';
import type { CrudApi } from '../crud/types';

export interface CrudCasOptions {
hash: (blob: Uint8Array) => Promise<string>;
}

const normalizeErrors = async <T>(code: () => Promise<T>): Promise<T> => {
try {
return await code();
} catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'ResourceNotFound':
case 'CollectionNotFound':
throw new DOMException(error.message, 'BlobNotFound');
}
}
throw error;
}
};
const hashEqual = (h1: string, h2: string) => h1 === h2;

export class CrudCas implements CasApi {
export class CrudCas extends CrudCasBase<string> {
constructor(
protected readonly crud: CrudApi,
protected readonly options: CrudCasOptions,
) {}

public readonly put = async (blob: Uint8Array): Promise<string> => {
const digest = await this.options.hash(blob);
const [collection, resource] = hashToLocation(digest);
await this.crud.put(collection, resource, blob);
return digest;
};

public readonly get = async (hash: string, options?: CasGetOptions): Promise<Uint8Array> => {
const [collection, resource] = hashToLocation(hash);
return await normalizeErrors(async () => {
const blob = await this.crud.get(collection, resource);
if (!options?.skipVerification) {
const digest = await this.options.hash(blob);
if (hash !== digest) throw new DOMException('Blob contents does not match hash', 'Integrity');
}
return blob;
});
};

public readonly del = async (hash: string, silent?: boolean): Promise<void> => {
const [collection, resource] = hashToLocation(hash);
await normalizeErrors(async () => {
return await this.crud.del(collection, resource, silent);
});
};

public readonly info = async (hash: string): Promise<CrudResourceInfo> => {
const [collection, resource] = hashToLocation(hash);
return await normalizeErrors(async () => {
return await this.crud.info(collection, resource);
});
};
) {
super(crud, options.hash, hashToLocation, hashEqual);
}
}
Loading

0 comments on commit af53c0a

Please sign in to comment.