Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@
"license": "MIT",
"author": "self team",
"type": "module",
"exports": {
".": {
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
},
"./circuits/*": "./circuits/*"
},
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"files": [
"dist/**/*",
"circuits/**/*"
],
"scripts": {
"build": "tsc",
"build": "tsup && yarn build:types && yarn postbuild",
"build-all": "bash scripts/build/build_register_circuits.sh && bash scripts/build/build_register_circuits_id.sh && bash scripts/build/build_dsc_circuits.sh && bash scripts/build/build_disclose_circuits.sh",
"build-disclose": "bash scripts/build/build_disclose_circuits.sh",
"build-dsc": "bash scripts/build/build_dsc_circuits.sh",
Expand All @@ -18,6 +33,9 @@
"install-circuits": "yarn workspaces focus @selfxyz/circuits",
"lint": "prettier --check .",
"nice": "prettier --write .",
"postbuild": "node ./scripts/postBuild.mjs",
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
"build:watch": "tsup --watch",
"test": "yarn test-base 'tests/**/*.test.ts' --exit",
"test-base": "yarn ts-mocha -n import=tsx --max-old-space-size=8192 --paths -p tsconfig.spec.json",
"test-custom-hasher": "yarn test-base 'tests/other_circuits/custom_hasher.test.ts' --exit",
Expand Down Expand Up @@ -81,6 +99,7 @@
"prettier": "^3.3.3",
"ts-mocha": "^10.0.0",
"tsconfig-paths": "^4.2.0",
"tsup": "^8.5.0",
"tsx": "^4.20.3"
},
"engines": {
Expand Down
44 changes: 44 additions & 0 deletions circuits/scripts/postBuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { writeFileSync, mkdirSync, readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { shimConfigs } from './shimConfigs.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DIST = path.resolve(__dirname, '..', 'dist');

// Read package version
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));

writeFileSync(path.join(DIST, 'esm', 'package.json'), JSON.stringify({ type: 'module' }, null, 4));
writeFileSync(
path.join(DIST, 'cjs', 'package.json'),
JSON.stringify({ type: 'commonjs' }, null, 4)
);

// Create dist package.json for Metro
const distPackageJson = {
name: '@selfxyz/circuits',
version: packageJson.version,
type: 'module',
exports: {
'.': './esm/index.js',
},
};
writeFileSync(path.join(DIST, 'package.json'), JSON.stringify(distPackageJson, null, 4));

function createShim(shimPath, targetPath) {
const shimDir = path.join(DIST, shimPath);
mkdirSync(shimDir, { recursive: true });
const cjsTargetPath = targetPath.replace('/esm/', '/cjs/').replace('.js', '.cjs');
writeFileSync(
path.join(shimDir, 'index.js'),
`// Shim file for @selfxyz/circuits/${shimPath}\nmodule.exports = require('${cjsTargetPath}');`
);
writeFileSync(
path.join(shimDir, 'index.d.ts'),
`// Shim file for @selfxyz/circuits/${shimPath} types\nexport * from '${targetPath.replace('.js', '')}';`
);
}

shimConfigs.forEach((config) => createShim(config.shimPath, config.targetPath));
2 changes: 2 additions & 0 deletions circuits/scripts/shimConfigs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Shim configurations for @selfxyz/circuits
export const shimConfigs = [];
1 change: 1 addition & 0 deletions circuits/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
10 changes: 10 additions & 0 deletions circuits/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./dist/cjs",
"declarationDir": "./dist/cjs",
"esModuleInterop": true
}
}
9 changes: 6 additions & 3 deletions circuits/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
"module": "NodeNext",
"allowJs": true,
"checkJs": false,
"outDir": "./dist",
"baseUrl": "."
"outDir": "./dist/esm",
"declaration": true,
"declarationDir": "./dist/esm",
"baseUrl": ".",
"composite": true
},
"include": ["tests/**/*", "src/**/*"],
"include": ["tests/**/*", "tests/**/*.json", "src/**/*"],
"exclude": ["node_modules"],
"references": [
{
Expand Down
35 changes: 35 additions & 0 deletions circuits/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'path';
import { defineConfig } from 'tsup';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const entry = {
index: 'src/index.ts',
};

export default defineConfig([
{
tsconfig: './tsconfig.json',
entry,
format: ['esm'],
outDir: path.resolve(__dirname, 'dist/esm'),
dts: false,
splitting: false,
clean: true,
sourcemap: true,
target: 'es2020',
},
{
tsconfig: './tsconfig.cjs.json',
entry,
format: ['cjs'],
outDir: path.resolve(__dirname, 'dist/cjs'),
dts: false,
splitting: false,
clean: false,
sourcemap: true,
target: 'es2020',
},
]);
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,7 @@ __metadata:
snarkjs: "npm:^0.7.1"
ts-mocha: "npm:^10.0.0"
tsconfig-paths: "npm:^4.2.0"
tsup: "npm:^8.5.0"
tsx: "npm:^4.20.3"
typescript: "npm:^5.3.3"
languageName: unknown
Expand Down
Loading