Skip to content

Commit

Permalink
refactor(example): replaces ESM with CommonJS in helloworld
Browse files Browse the repository at this point in the history
To understand why check stalniy/casl#331. Also adds note that it's possible to use any package manager to run an example
  • Loading branch information
stalniy committed May 27, 2020
1 parent 898c515 commit 2b4eeb8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CASL Examples

This repository is a monorepo of [CASL](https://github.com/stalniy/casl) examples. Examples illustrate integrations with major frameworks. This repository uses [pnpm](https://pnpm.js.org/) as a package manager.
This repository is a monorepo of [CASL](https://github.com/stalniy/casl) examples. Examples illustrate integrations with major frameworks. This repository uses [pnpm](https://pnpm.js.org/) to manage all examples as a monorepo but you are not restricted to use pnpm. If you are interested in particular example, just navigate to its folder and use whatever package manager you like.

You can find examples in [packages](./packages) folder. See `README.md` of the specific example for details.

Expand Down
10 changes: 4 additions & 6 deletions packages/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# CASL hello world

This is a basic example that illustrates the easiest CASL configuration.
This is a basic example that allows to play around with [CASL](https://stalniy.github.io/casl/v4).

## Requirements

Node version that support experimental modules. Tested on node v12.13
**Note**: this example uses CommonJS as `@casl/ability` currently doesn't support new `exports` field in package.json and codesandbox doesn't allow to change the version of nodejs (10.x only at the time of writing).

## Run

```sh
pnpm install
pnpm start
npm install
npm start
```
2 changes: 1 addition & 1 deletion packages/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "CASL helloworld example",
"main": "index.js",
"scripts": {
"start": "node --experimental-modules src/index.mjs"
"start": "node src/index.js"
},
"keywords": [
"casl",
Expand Down
6 changes: 6 additions & 0 deletions packages/hello-world/src/defineAbility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { defineAbility } = require('@casl/ability');

module.exports = defineAbility((can, cannot) => {
can('manage', 'all');
cannot('delete', 'User');
});
6 changes: 0 additions & 6 deletions packages/hello-world/src/defineAbility.mjs

This file was deleted.

7 changes: 7 additions & 0 deletions packages/hello-world/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const ability = require('./defineAbility');

console.log('can read Post', ability.can('read', 'Post')) // true
console.log('can read User', ability.can('read', 'User')) // true
console.log('can update User', ability.can('update', 'User')) // true
console.log('can delete User', ability.can('delete', 'User')) // false
console.log('cannot delete User', ability.cannot('delete', 'User')) // true
7 changes: 0 additions & 7 deletions packages/hello-world/src/index.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-todo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This example shows how to integrate [CASL authorization](https://stalniy.github.

``` bash
# install dependencies
pnpm install
npm install

# serve with hot reload at localhost:3000
npm start
Expand Down

0 comments on commit 2b4eeb8

Please sign in to comment.