Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add built-in FileSystem #430

Merged
merged 1 commit into from
Feb 17, 2023
Merged

feat: add built-in FileSystem #430

merged 1 commit into from
Feb 17, 2023

Conversation

nodece
Copy link
Member

@nodece nodece commented Feb 12, 2023

Motivation

The casbin can only use the Node.js FileSystem module, when users want to use the custom FileSystem, the casbin doesn't support that.

Modification

  • Define the FileSystem interface, and add default implement
  • Add FileSystem to Enforce, Model, Config, and FileAdapter

@casbin-bot
Copy link
Member

@Zxilly @Shivansh-yadav13 please review

@Zxilly
Copy link
Contributor

Zxilly commented Feb 13, 2023

To keep forward-compatibility, maybe legacy node fs can be used as an default implementation?
To avoid bundle error, use require.

if (typeof global === 'object') {
    const fs = __non_webpack_require__('fs');
    const defaultFileSystem = {
        readFileSync(path, encoding) {
            return fs.readFileSync(path, encoding);
        },
        writeFileSync(path, text, encoding) {
            return fs.writeFileSync(path, text, encoding);
        },
    };
    setDefaultFileSystem(defaultFileSystem);
}

This is a webpack specific implementation, for possible other bundlers we need more work.

Another possible solution is

const fs = eval('require("fs")')

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
@nodece nodece changed the title feat!: built-in FileSystem instead of Node.js FileSystem feat: add built-in FileSystem Feb 16, 2023
@nodece
Copy link
Member Author

nodece commented Feb 16, 2023

Ping @Zxilly

@nodece
Copy link
Member Author

nodece commented Feb 16, 2023

Right now, there are no breaking changes.

Copy link
Contributor

@Zxilly Zxilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nodece nodece merged commit 999c34c into casbin:master Feb 17, 2023
github-actions bot pushed a commit that referenced this pull request Feb 17, 2023
# [5.24.0](v5.23.2...v5.24.0) (2023-02-17)

### Features

* add built-in FileSystem ([#430](#430)) ([999c34c](999c34c))
@github-actions
Copy link

🎉 This PR is included in version 5.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants