Skip to content
Merged

Pnpm #626

Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
link-workspace-packages=true
save-prefix=''
shamefully-hoist=true
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,15 @@ To build a project according to its derivation:
nix build .#DERIVATION_NAME
```

### Using NPM
### Using PNPM

The repository uses NPM Workspaces to manage collective dependencies across the JS/TS projects it is hosting.
The repository uses PNPM Workspaces to manage collective dependencies across the JS/TS projects it is hosting.

There can only be one top-level `package-lock.json` file that can be regenerated as follows:
There can only be one top-level `pnpm-lock` file.

```bash
npm run install:clean
```

Individual projects should not have separate `package-lock.json` files. If such files exist, it may lead to unintended behaviors.
Individual projects should not have separate `pnpm-lock` files. If such files exist, it may lead to unintended behaviors.

In addition, Nix validates the hashum of the `package-lock.json` file when building the project. Perform the following actions after running the `install:clean` script:
Perform the following actions after running the `pnpm install` script:

1. Open the `./nix/npmdeps.nix` file
2. Remove the current hashsum (located under the list of all `package.json` files)
Expand Down
6 changes: 3 additions & 3 deletions clijs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": "https://github.com/nil-blockchain/issues",
"dependencies": {
"@libp2p/peer-id": "^5.0.9",
"@nilfoundation/niljs": "0.25.0",
"@nilfoundation/niljs": "workspace:*",
"@oclif/core": "^4",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^5",
Expand Down Expand Up @@ -61,8 +61,8 @@
},
"repository": "nil-blockchain/clijs",
"scripts": {
"build": "rimraf dist && npx tsc -b",
"bundle": "rimraf dist && npx tsc -b && node ./bin/bundle.js",
"build": "rimraf dist && tsc -b",
"bundle": "rimraf dist && tsc -b && node ./bin/bundle.js",
"lint": "biome check .",
"lint:fix": "biome check --write .",
"postpack": "rimraf oclif.manifest.json",
Expand Down
2 changes: 1 addition & 1 deletion create-nil-hardhat-project/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ echo "Smart account addr: $SMART_ACCOUNT_ADDR"
cd $(dirname "$0")

set +e
if CI=true npx hardhat test --network nil test/*.ts; then
if CI=true pnpm exec hardhat test --network nil test/*.ts; then
exit 0
else
STATUS=$?
Expand Down
2 changes: 1 addition & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const config = {
},
themes: ["@docusaurus/theme-mermaid"],
plugins: [
"custom-loader",
[path.resolve(__dirname, "./plugins/custom-loader"), {}],
[path.resolve(__dirname, "./plugins/nil-playground-plugin"), {}],
[
"nil-docusaurus-plugin-typedoc",
Expand Down
11 changes: 5 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "npm run generate-cli-docs && docusaurus start",
"start": "pnpm run generate-cli-docs && docusaurus start",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"test": "vitest",
"generate-cli-docs": "npx tsx nil/scripts/cliRefGenerator.ts",
"build": "npm run generate-cli-docs && docusaurus build",
"generate-cli-docs": "tsx ./nil/scripts/cliRefGenerator.ts",
"build": "pnpm run generate-cli-docs && docusaurus build",
"lint": "biome check .",
"lint:fix": "biome check --write ."
},
Expand All @@ -34,14 +34,13 @@
"@docusaurus/types": "^3.7.0",
"@khannanov-nil/openrpc-docusaurus": "0.7.1",
"@mdx-js/react": "^3.0.0",
"@nilfoundation/niljs": "0.25.0",
"@nilfoundation/smart-contracts": "0.7.0",
"@nilfoundation/niljs": "workspace:*",
"@nilfoundation/smart-contracts": "workspace:*",
"@openzeppelin/contracts": "^5.0.2",
"@uiw/codemirror-themes": "4.21.0",
"@uiw/react-codemirror": "4.21.0",
"ai": "^4.0.11",
"clsx": "^2.0.0",
"custom-loader": "file:plugins/custom-loader",
"docusaurus": "^1.14.7",
"docusaurus-lunr-search": "^3.3.2",
"lottie-react": "^2.4.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nild run --http-port 8529 --collator-tick-ms=100 >nild.log 2>&1 &
NILD_PID=$!
sleep 2

if CI=true npm run test; then
if CI=true pnpm run test; then
exit 0
else
STATUS=$?
Expand Down
2 changes: 1 addition & 1 deletion docs_ai_backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@langchain/community": "^0.3.16",
"@libsql/client": "^0.14.0",
"@nilfoundation/smart-contracts": "0.7.0",
"@nilfoundation/smart-contracts": "workspace:*",
"ai": "^4.0.13",
"axios": "^1.7.9",
"bcryptjs": "^2.4.3",
Expand Down
5 changes: 2 additions & 3 deletions explorer_backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "ISC",
"dependencies": {
"@clickhouse/client": "^1.0.2",
"@nilfoundation/niljs": "0.25.0",
"@nilfoundation/niljs": "workspace:*",
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/auto-instrumentations-node": "^0.40.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.47.0",
Expand All @@ -29,11 +29,9 @@
"@tinyhttp/cors": "^2.0.0",
"@trpc/client": "10.38.5",
"@trpc/server": "10.38.5",
"@types/better-sqlite3": "^7.6.11",
"@types/jsonwebtoken": "^9.0.5",
"async-mutex": "^0.4.0",
"axios": "^1.6.7",
"better-sqlite3": "^11.1.2",
"dotenv": "^16.3.1",
"isomorphic-fetch": "^3.0.0",
"jsonwebtoken": "^9.0.2",
Expand All @@ -44,6 +42,7 @@
"nanoid": "^4.0.2",
"node-cache": "^5.1.2",
"node-fetch": "^3.3.1",
"node-sqlite3-wasm": "0.8.37",
"ts-node": "^10.9.2",
"tsx": "^4.10.5",
"viem": "^2.17.3",
Expand Down
2 changes: 1 addition & 1 deletion explorer_backend/routes/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const codeRouter = router({
}),
)
.mutation(async (opts) => {
const hash = setCode(opts.input);
const hash = await setCode(opts.input);
return {
hash,
};
Expand Down
17 changes: 9 additions & 8 deletions explorer_backend/services/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash } from "node:crypto";
import BetterSqlite3 from "better-sqlite3";
import sqlite3 from "node-sqlite3-wasm";

const db: BetterSqlite3.Database = new BetterSqlite3(process.env.EXPLORER_DB || "./database.db");
const db = new sqlite3.Database(process.env.EXPLORER_DB || "./database.db");

export { db };

Expand All @@ -13,21 +13,22 @@ CREATE TABLE IF NOT EXISTS code (
);
`);

const getStmt = db.prepare<string, { code: string }>("SELECT code FROM code WHERE hash = ?");
const getStmt = db.prepare("SELECT code FROM code WHERE hash = ?");

export const getCode = (hash: string): string | null => {
return getStmt.get(hash)?.code || null;
const result = getStmt.get(hash) as { code: string } | undefined;
return result?.code || null;
};

export const setCode = (code: string): string => {
export const setCode = async (code: string): Promise<string> => {
const hash = createHash("sha256").update(code).digest("hex");
const res = getStmt.get(hash);
const res = await getCode(hash);
if (res) {
return hash;
}
db.prepare("INSERT INTO code (hash, code, created_at) VALUES (?, ?, CURRENT_TIMESTAMP)").run(
db.prepare("INSERT INTO code (hash, code, created_at) VALUES (?, ?, CURRENT_TIMESTAMP)").run([
hash,
code,
);
]);
return hash;
};
4 changes: 2 additions & 2 deletions explorer_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@codemirror/state": "6.5.0",
"@codemirror/view": "^6.34.1",
"@loadable/component": "^5.15.3",
"@nilfoundation/niljs": "0.25.0",
"@nilfoundation/smart-contracts": "0.7.0",
"@nilfoundation/niljs": "workspace:*",
"@nilfoundation/smart-contracts": "workspace:*",
"@nilfoundation/ui-kit": "^2.5.28",
"@noble/curves": "^1.4.0",
"@replit/codemirror-lang-solidity": "^6.0.2",
Expand Down
7 changes: 4 additions & 3 deletions niljs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
"rollup-plugin-esbuild": "6.1.1",
"rollup-plugin-filesize": "^10.0.0",
"solc-typed-ast": "^18.2.3",
"tsx": "^4.17.0",
"tsx": "4.17.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.12.2"
"typescript-eslint": "^8.12.2",
"rimraf": "^6.0.1"
},
"publishConfig": {
"access": "public",
Expand All @@ -62,7 +63,7 @@
"dependencies": {
"@chainsafe/persistent-merkle-tree": "^0.7.2",
"@chainsafe/ssz": "^0.16.0",
"@nilfoundation/smart-contracts": "0.7.0",
"@nilfoundation/smart-contracts": "workspace:*",
"@noble/curves": "^1.4.0",
"@open-rpc/client-js": "^1.8.1",
"@rollup/plugin-json": "^6.1.0",
Expand Down
43 changes: 16 additions & 27 deletions nix/clijs.nix
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
{ pkgs
, lib
, stdenv
, biome
, callPackage
, npmHooks
, nil
, enableTesting ? false
}:
{ pkgs, lib, stdenv, biome, callPackage, pnpm_10, nil, enableTesting ? false }:

let
sigtool = callPackage ./sigtool.nix { };
nodejs_static = pkgs.pkgsStatic.nodejs_22;
pnpm_static = (pnpm_10.override { nodejs = nodejs_static; });
in
stdenv.mkDerivation rec {
name = "clijs";
pname = "clijs";
src = lib.sourceByRegex ./.. [
"package.json"
"package-lock.json"
"pnpm-workspace.yaml"
"pnpm-lock.yaml"
".npmrc"
"^clijs(/.*)?$"
"^niljs(/.*)?$"
"^smart-contracts(/.*)?$"
"biome.json"
];

npmDeps = (callPackage ./npmdeps.nix { });
pnpmDeps = (callPackage ./npmdeps.nix { });

NODE_PATH = "$npmDeps";

nativeBuildInputs = [
pkgs.pkgsStatic.nodejs_22
npmHooks.npmConfigHook
biome
]
++ lib.optionals stdenv.buildPlatform.isDarwin [ sigtool ]
++ (if enableTesting then [ nil ] else [ ]);

dontConfigure = true;
nativeBuildInputs = [ nodejs_static pnpm_static.configHook biome ]
++ lib.optionals stdenv.buildPlatform.isDarwin [ sigtool ]
++ (if enableTesting then [ nil ] else [ ]);

preUnpack = ''
echo "Setting UV_USE_IO_URING=0 to work around the io_uring kernel bug"
Expand All @@ -48,23 +38,23 @@ stdenv.mkDerivation rec {
'';

buildPhase = ''
PATH="${pkgs.pkgsStatic.nodejs_22}/bin/:$PATH"
PATH="${nodejs_static}/bin/:$PATH"

patchShebangs docs/node_modules
patchShebangs niljs/node_modules
(cd smart-contracts; npm run build)
(cd niljs; npm run build)
(cd smart-contracts; pnpm run build)
(cd niljs; pnpm run build)

cd clijs
npm run bundle
pnpm run bundle
'';

doCheck = enableTesting;

checkPhase = ''
export BIOME_BINARY=${biome}/bin/biome

npm run lint
pnpm run lint

./dist/clijs | grep -q "The CLI tool for interacting with the =nil; cluster" || {
echo "Error: Output does not contain the expected substring!" >&2
Expand All @@ -74,7 +64,7 @@ stdenv.mkDerivation rec {

nohup nild run --http-port 8529 --collator-tick-ms=100 > nild.log 2>&1 & echo $! > nild_pid &

npm run test:ci
pnpm run test:ci

kill `cat nild_pid` && rm nild_pid

Expand All @@ -86,4 +76,3 @@ stdenv.mkDerivation rec {
mv ./dist/clijs $out/${pname}
'';
}

13 changes: 8 additions & 5 deletions nix/docsaibackend.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, stdenv
, callPackage
, npmHooks
, pnpm_10
, nodejs
}:

Expand All @@ -10,18 +10,21 @@ stdenv.mkDerivation rec {
pname = "docsaibackend";
src = lib.sourceByRegex ./.. [
"package.json"
"package-lock.json"
"pnpm-lock.yaml"
"pnpm-workspace.yaml"
".npmrc"
"^docs_ai_backend(/.*)?$"
];

npmDeps = (callPackage ./npmdeps.nix { });
pnpmDeps = (callPackage ./npmdeps.nix { });

NODE_PATH = "$npmDeps";

nativeBuildInputs = [
nodejs
npmHooks.npmConfigHook
nodejs.python
pnpm_10
pnpm_10.configureHook
];

dontConfigure = true;
Expand All @@ -34,7 +37,7 @@ stdenv.mkDerivation rec {
buildPhase = ''
patchShebangs docs_ai_backend/node_modules

(cd docs_ai_backend; npm run build)
(cd docs_ai_backend; pnpm run build)
'';

checkPhase = ''
Expand Down
Loading