Skip to content

Commit 4912c0d

Browse files
authored
Merge pull request #762 from rikhoffbauer/761-pnpm-build-fails-with-exit-code-1
make this package an ES module Closes: #761
2 parents ede5c6b + cd28c4e commit 4912c0d

File tree

7 files changed

+47
-20
lines changed

7 files changed

+47
-20
lines changed
File renamed without changes.

.github/workflows/release.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@ on: [push, pull_request]
55
jobs:
66
release:
77
name: Release
8-
runs-on: ubuntu-18.04
8+
runs-on: ubuntu-latest
99
if: "!contains(github.event.head_commit.message, '[skip ci]')"
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v3
13-
- name: Setup pnpm
14-
uses: pnpm/[email protected]
13+
- name: Install pnpm
14+
uses: pnpm/action-setup@v2
15+
id: pnpm-install
1516
with:
16-
version: "6.11.0-0"
17-
- uses: actions/setup-node@v3
17+
version: "7.29.1"
18+
run_install: false
19+
- name: Setup nodejs
20+
uses: actions/setup-node@v3
1821
with:
19-
node-version: "14"
20-
cache: "pnpm"
22+
node-version: "19"
23+
#- name: Setup pnpm cache
24+
#uses: actions/cache@v3
25+
#with:
26+
#path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
27+
#key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
28+
#restore-keys: |
29+
#${{ runner.os }}-pnpm-store-
2130
- name: Install dependencies
2231
run: pnpm install
2332
- name: Build
@@ -29,3 +38,4 @@ jobs:
2938
env:
3039
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3140
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
41+

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
syncher 0.0.44
2-
nodejs 16.18.0
3-
pnpm 6.11.0-0
2+
nodejs 19.7.0
3+
pnpm 7.29.1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"main": "dist/index.js",
2121
"module": "dist/index.es.js",
2222
"jsnext:main": "dist/index.es.js",
23+
"type": "module",
2324
"types": "dist/index.d.ts",
2425
"typings": "./dist/index.d.ts",
2526
"files": [

rollup.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { terser } from "rollup-plugin-terser";
66
import typescript from "rollup-plugin-typescript2";
77
import url from "rollup-plugin-url";
88

9-
import pkg from "./package.json";
9+
import pkg from "./package.json" assert { type: "json" };
1010

1111
export default {
1212
input: "src/index.ts",
@@ -30,7 +30,6 @@ export default {
3030
resolve(),
3131
typescript({
3232
clean: true,
33-
rollupCommonJSResolveHack: true,
3433
exclude: ["*.d.ts", "**/*.d.ts"],
3534
}),
3635
commonjs(),

src/create.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,27 @@ const create = <Role extends string, Permission extends string, User>() => {
101101
};
102102

103103
const NotAllowedTo = ({
104-
yes,
105-
no,
106-
...props
107-
}: AllowedToProps<Permission>) => (
108-
<AllowedTo no={yes} yes={no} {...props} />
109-
);
104+
perform = [],
105+
children,
106+
yes: Yes,
107+
no: No,
108+
data,
109+
}: AllowedToProps<Permission>) => {
110+
const ctx = useAbac();
111+
112+
if (ctx === AbacContextDefaults) {
113+
console.error(
114+
`Can't render <AllowedTo />, wrap your app with an <AbacProvider />.`,
115+
);
116+
return null;
117+
}
118+
119+
if (!ctx.userHasPermissions(ensureArray(perform), data)) {
120+
return Yes ? <Yes /> : <React.Fragment>{children}</React.Fragment>;
121+
}
122+
123+
return No ? <No /> : null;
124+
};
110125

111126
const secured =
112127
<Props, Data>({

test/testEnvironment.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const Environment = require("jest-environment-jsdom-global")
1+
import Environment from "jest-environment-jsdom-global";
2+
import { TextEncoder } from "util";
23

34
/**
45
* A custom environment to set the TextEncoder
56
*/
6-
module.exports = class CustomTestEnvironment extends Environment {
7+
class CustomTestEnvironment extends Environment {
78
constructor({ globalConfig, projectConfig }, context) {
89
super({ globalConfig, projectConfig }, context);
910

1011
if (typeof this.global.TextEncoder === 'undefined') {
11-
const { TextEncoder } = require('util');
1212
this.global.TextEncoder = TextEncoder;
1313
}
1414
}
1515
};
1616

17+
export default CustomTestEnvironment;
18+

0 commit comments

Comments
 (0)