Skip to content

Commit

Permalink
refactor(packaging): remove peer dependencies where not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Nov 17, 2023
1 parent 1707dc6 commit 95b489d
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 126 deletions.
5 changes: 1 addition & 4 deletions demos/taco-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@nucypher/taco": "^0.1.0-rc.6",
"@nucypher/shared": "^0.1.0-rc.4",
"@usedapp/core": "^1.2.13",
"buffer": "^6.0.3",
"ethers": "^5.7.1",
Expand All @@ -22,10 +23,6 @@
"react-dom": "^18.2.0",
"react-spinners": "^0.13.6"
},
"peerDependencies": {
"@nucypher/taco": "workspace:*",
"@nucypher/shared": "workspace:*"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@types/react": "^18.2.33",
Expand Down
5 changes: 1 addition & 4 deletions demos/taco-nft-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@nucypher/taco": "^0.1.0-rc.6",
"@nucypher/shared": "^0.1.0-rc.4",
"@usedapp/core": "^1.2.13",
"buffer": "^6.0.3",
"ethers": "^5.7.1",
Expand All @@ -22,10 +23,6 @@
"react-dom": "^18.2.0",
"react-spinners": "^0.13.6"
},
"peerDependencies": {
"@nucypher/taco": "workspace:*",
"@nucypher/shared": "workspace:*"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@types/react": "^18.2.33",
Expand Down
7 changes: 1 addition & 6 deletions examples/pre/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
"ethers": "^5.7.2",
"next": "13.5.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2"
},
"peerDependencies": {
"ethers": "^5.7.2",
"typescript": "5.2.2"
"react-dom": "18.2.0"
}
}
4 changes: 1 addition & 3 deletions examples/pre/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
},
"dependencies": {
"@nucypher/pre": "workspace:*",
"dotenv": "^16.3.1"
},
"peerDependencies": {
"dotenv": "^16.3.1",
"ethers": "^5.7.2"
}
}
6 changes: 2 additions & 4 deletions examples/pre/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
"dependencies": {
"@nucypher/pre": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"ethers": "^5.7.2"
},
"devDependencies": {
"@types/node": "^16.18.50",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"react-scripts": "^5.0.1"
},
"peerDependencies": {
"ethers": "^5.7.2"
}
}
4 changes: 1 addition & 3 deletions examples/pre/webpack-5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
"esbuild-loader": "^2.11.0",
"webpack": "^5.4.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.7.4"
},
"peerDependencies": {
"webpack-dev-server": "^4.7.4",
"ethers": "^5.7.2"
}
}
2 changes: 1 addition & 1 deletion examples/pre/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SecretKey,
} from '@nucypher/pre';
import { ethers } from 'ethers';
import { hexlify } from "ethers/lib/utils";
import { hexlify } from 'ethers/lib/utils';

declare global {
interface Window {
Expand Down
4 changes: 0 additions & 4 deletions examples/taco/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2"
},
"peerDependencies": {
"ethers": "^5.7.2",
"typescript": "5.2.2"
}
}
4 changes: 1 addition & 3 deletions examples/taco/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
},
"dependencies": {
"@nucypher/taco": "workspace:*",
"dotenv": "^16.3.1"
},
"peerDependencies": {
"dotenv": "^16.3.1",
"ethers": "^5.7.2"
}
}
2 changes: 1 addition & 1 deletion examples/taco/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
toBytes,
} from '@nucypher/taco';
import { ethers } from 'ethers';
import { hexlify } from "ethers/lib/utils";
import { hexlify } from 'ethers/lib/utils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const window: any;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@changesets/cli": "^2.26.2",
"@nucypher/nucypher-core": "0.13.0-alpha.1"
"@nucypher/nucypher-core": "^0.13.0-alpha.1"
},
"devDependencies": {
"@skypack/package-check": "^0.2.2",
Expand Down
6 changes: 2 additions & 4 deletions packages/pre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@
},
"dependencies": {
"@nucypher/nucypher-core": "^0.13.0-alpha.1",
"@nucypher/shared": "workspace:*"
"@nucypher/shared": "workspace:*",
"ethers": "^5.7.2"
},
"devDependencies": {
"@nucypher/test-utils": "workspace:*"
},
"peerDependencies": {
"ethers": "^5.7.2"
},
"engines": {
"node": ">=18",
"pnpm": ">=8.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nucypher/nucypher-contracts": "^0.9.0",
"@nucypher/nucypher-core": "0.13.0-alpha.1",
"@nucypher/nucypher-core": "^0.13.0-alpha.1",
"axios": "^1.5.0",
"deep-equal": "^2.2.1",
"ethers": "^5.7.2",
Expand Down
1 change: 0 additions & 1 deletion packages/shared/scripts/typechain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import * as tmp from 'tmp';
import { glob, runTypeChain } from 'typechain';


const parseContractRegistry = (registry: ContractRegistry): Contract[] =>
Object.keys(registry)
.map((chainId) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/contracts/agents/coordinator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getContract } from '@nucypher/nucypher-contracts'
import { getContract } from '@nucypher/nucypher-contracts';
import {
DkgPublicKey,
SessionStaticKey,
Expand Down
6 changes: 3 additions & 3 deletions packages/taco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
"@nucypher/nucypher-core": "0.13.0-alpha.1",
"@nucypher/nucypher-core": "^0.13.0-alpha.1",
"@nucypher/shared": "^0.1.0-rc.4",
"ethers": "^5.7.2",
"semver": "^7.5.2",
"zod": "^3.22.4"
},
Expand All @@ -50,8 +51,7 @@
"@types/semver": "^7.5.4"
},
"peerDependencies": {
"@nucypher/shared": "workspace:*",
"ethers": "^5.7.2"
"@nucypher/shared": "workspace:*"
},
"engines": {
"node": ">=18",
Expand Down
9 changes: 4 additions & 5 deletions packages/taco/src/conditions/compound-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ export const compoundConditionSchema: z.ZodSchema = z
// We test positive cases exhaustively, so we return false here:
return false;
},
({ operands, operator }) => ({
message: `Invalid number of operands ${operands.length} for operator "${operator}"`,
path: ['operands'],
})
({ operands, operator }) => ({
message: `Invalid number of operands ${operands.length} for operator "${operator}"`,
path: ['operands'],
}),
);


export type CompoundConditionProps = z.infer<typeof compoundConditionSchema>;
87 changes: 49 additions & 38 deletions packages/taco/test/conditions/compound-condition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import {
} from '../test-utils';

describe('validation', () => {
it.each([{
operator: 'and',
operands: [testContractConditionObj, testTimeConditionObj]
}, {
operator: 'or',
operands: [testContractConditionObj, testTimeConditionObj]
}, {
operator: 'not',
operands: [testContractConditionObj]
}])('accepts "$operator" operator', ({operator, operands}) => {
it.each([
{
operator: 'and',
operands: [testContractConditionObj, testTimeConditionObj],
},
{
operator: 'or',
operands: [testContractConditionObj, testTimeConditionObj],
},
{
operator: 'not',
operands: [testContractConditionObj],
},
])('accepts "$operator" operator', ({ operator, operands }) => {
const conditionObj: CompoundConditionProps = {
conditionType: CompoundConditionType,
operator,
Expand Down Expand Up @@ -61,31 +65,38 @@ describe('validation', () => {
});
});

it.each([{
operator: 'and',
nrOfOperands: 1,
}, {
operator: 'or',
nrOfOperands: 1,
}, {
operator: 'not',
nrOfOperands: 2,
}])('rejects invalid number of operands $nrOfOperands for operator $operator', ({operator, nrOfOperands}) => {
const result = CompoundCondition.validate(compoundConditionSchema, {
operator,
operands: Array(nrOfOperands).fill(testRpcConditionObj)
});

expect(result.error).toBeDefined();
expect(result.data).toBeUndefined();
expect(result.error?.format()).toMatchObject({
operands: {
_errors: [
`Invalid number of operands ${nrOfOperands} for operator "${operator}"`,
],
},
});
});
it.each([
{
operator: 'and',
nrOfOperands: 1,
},
{
operator: 'or',
nrOfOperands: 1,
},
{
operator: 'not',
nrOfOperands: 2,
},
])(
'rejects invalid number of operands $nrOfOperands for operator $operator',
({ operator, nrOfOperands }) => {
const result = CompoundCondition.validate(compoundConditionSchema, {
operator,
operands: Array(nrOfOperands).fill(testRpcConditionObj),
});

expect(result.error).toBeDefined();
expect(result.data).toBeUndefined();
expect(result.error?.format()).toMatchObject({
operands: {
_errors: [
`Invalid number of operands ${nrOfOperands} for operator "${operator}"`,
],
},
});
},
);

it('accepts recursive compound conditions', () => {
const conditionObj = {
Expand Down Expand Up @@ -185,9 +196,9 @@ describe('validation', () => {
])('accepts shorthand for "%s" operator', (operator, operands, expected) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const compoundConditionShorthands: Record<string, any> = {
'and': CompoundCondition.and,
'or': CompoundCondition.or,
'not': CompoundCondition.not,
and: CompoundCondition.and,
or: CompoundCondition.or,
not: CompoundCondition.not,
};
const compoundCondition = compoundConditionShorthands[operator](operands);

Expand Down
48 changes: 27 additions & 21 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ describe('context', () => {
const context = conditionExpr.buildContext(provider, {}, signer);

describe('custom parameters', () => {
it("serializes bytes as hex strings", async () => {
it('serializes bytes as hex strings', async () => {
const customParamsWithBytes: Record<string, CustomContextParam> = {};
const customParam = toBytes('hello');
// Uint8Array is not a valid CustomContextParam, override the type:
customParamsWithBytes[customParamKey] = customParam as unknown as string;
customParamsWithBytes[customParamKey] =
customParam as unknown as string;

const asJson = await context.withCustomParams(customParamsWithBytes).toJson();
const asJson = await context
.withCustomParams(customParamsWithBytes)
.toJson();
const asObj = JSON.parse(asJson);
expect(asObj).toBeDefined();
expect(asObj[customParamKey]).toEqual(`0x${toHexString(customParam)}`);
Expand Down Expand Up @@ -216,24 +219,27 @@ describe('context', () => {
expect(asObj[USER_ADDRESS_PARAM]).toBeDefined();
});

it.each([0, ''])('accepts on a falsy parameter value: %s', async (falsyParam) => {
const customParamKey = ':customParam';
const customContractCondition = new ContractCondition({
...contractConditionObj,
parameters: [USER_ADDRESS_PARAM, customParamKey],
});
const customParameters: Record<string, CustomContextParam> = {};
customParameters[customParamKey] = falsyParam;
const conditionContext = new ConditionExpression(
customContractCondition,
).buildContext(provider, customParameters, signer);

const asObj = await conditionContext.toObj();
expect(asObj).toBeDefined();
expect(asObj[USER_ADDRESS_PARAM]).toBeDefined();
expect(asObj[customParamKey]).toBeDefined();
expect(asObj[customParamKey]).toEqual(falsyParam);
});
it.each([0, ''])(
'accepts on a falsy parameter value: %s',
async (falsyParam) => {
const customParamKey = ':customParam';
const customContractCondition = new ContractCondition({
...contractConditionObj,
parameters: [USER_ADDRESS_PARAM, customParamKey],
});
const customParameters: Record<string, CustomContextParam> = {};
customParameters[customParamKey] = falsyParam;
const conditionContext = new ConditionExpression(
customContractCondition,
).buildContext(provider, customParameters, signer);

const asObj = await conditionContext.toObj();
expect(asObj).toBeDefined();
expect(asObj[USER_ADDRESS_PARAM]).toBeDefined();
expect(asObj[customParamKey]).toBeDefined();
expect(asObj[customParamKey]).toEqual(falsyParam);
},
);
});
});
});
2 changes: 1 addition & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint:fix": "pnpm lint --fix"
},
"dependencies": {
"@nucypher/nucypher-core": "0.13.0-alpha.1",
"@nucypher/nucypher-core": "^0.13.0-alpha.1",
"@nucypher/shared": "workspace:*",
"axios": "^1.5.0",
"ethers": "^5.7.2",
Expand Down
Loading

0 comments on commit 95b489d

Please sign in to comment.