Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump agent-js versions (alternate approach) #986

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
114 changes: 114 additions & 0 deletions .github/scripts/update-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Update agent-js dependencies across all example projects.

import { $ } from "execa";
import { readdir, readFile, stat, writeFile } from "fs/promises";
import latestVersion from "latest-version";
import { join, resolve } from "path";

// Skip updating these projects.
const ignoreProjects = ["motoko/ic-pos"];

// Skip updating these packages.
const ignorePackages = [
"@dfinity/internet-identity-vite-plugins",
"@dfinity/internet-identity-vc-api",
];

const projectDirectories = [];
const versionPromiseMap = new Map();

// Find and cache the latest version of a package.
async function findLatestVersion(pkg) {
if (versionPromiseMap.has(pkg)) {
return versionPromiseMap.get(pkg);
}
const version = latestVersion(pkg);
versionPromiseMap.set(pkg, version);
return version;
}

// Update all `package.json` files in the repository.
async function updatePackageJson(filePath) {
let content = await readFile(filePath, "utf8");
let updated = false;

const updateMap = {};
const packageRegex = /"(@dfinity\/[^"]+)":\s*"([^"]+)"/g;
for (const match of content.matchAll(packageRegex)) {
const pkg = match[1];
const version = match[2];
try {
if (ignorePackages.includes(pkg)) {
continue;
}
const newVersion = `^${await findLatestVersion(pkg)}`;
if (version !== newVersion) {
const regex = new RegExp(`("${pkg}"\\s*:\\s*")([^"]+)`, "g");
if (!regex.test(content)) {
throw new Error(
"Bug: missing regex pattern to replace package version"
);
}
content = content.replace(regex, `$1${newVersion}`);
updated = true;
updateMap[pkg] = newVersion;
}
} catch (error) {
console.error(`Error while updating ${pkg}:`);
throw error;
}
}

if (updated) {
await writeFile(filePath, content);
console.log(`Updated ${filePath}:`, updateMap);
}
}

// Update the `package-lock.json` file in the given directory.
async function updatePackageLock(directory) {
const packageJsonPath = join(directory, "package.json");
try {
await $({
stderr: "inherit",
cwd: directory,
})`npm install --package-lock-only`;
console.log(`Updated lockfile for ${packageJsonPath}`);
} catch (err) {
console.error(err);
throw new Error(`Error while updating lockfile for ${packageJsonPath}`);
}
}

// Search for and update directories with a `package.json` file.
// Returns a list of directories containing npm projects.
async function searchAndUpdate(directory) {
const files = await readdir(directory);
await Promise.all(
files.map(async (filename) => {
const filePath = join(directory, filename);
if ((await stat(filePath)).isDirectory()) {
if (filename === "node_modules") {
return;
}
await searchAndUpdate(filePath);
} else if (filename === "package.json") {
if (
ignoreProjects.some((path) => resolve(directory) === resolve(path))
) {
return;
}
projectDirectories.push(directory);
await updatePackageJson(filePath);
}
})
);
}

(async () => {
await searchAndUpdate(process.cwd());
for (const directory of projectDirectories) {
await updatePackageLock(directory);
}
console.log("Completed");
})();
10 changes: 5 additions & 5 deletions hosting/photo-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@dfinity/agent": "^0.15.0",
"@dfinity/assets": "^0.15.0",
"@dfinity/candid": "^0.15.0",
"@dfinity/identity": "^0.15.0",
"@dfinity/principal": "^0.15.0",
"@dfinity/agent": "^2.1.1",
"@dfinity/assets": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-masonry-css": "^1.0.16",
Expand Down
10 changes: 5 additions & 5 deletions motoko/auth_client_demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"last 2 edge version"
],
"dependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/auth-client": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/identity": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"lit-html": "^2.4.0",
"pinia": "^2.0.36",
"react": "^18.2.0",
Expand Down
6 changes: 3 additions & 3 deletions motoko/cert-var/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"generate": "dfx generate cert_var"
},
"devDependencies": {
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"css-loader": "^6.0.0",
Expand Down
12 changes: 6 additions & 6 deletions motoko/defi/src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"svelte": "^3.49.0"
},
"dependencies": {
"@dfinity/agent": "^0.10.4",
"@dfinity/auth-client": "^0.10.4",
"@dfinity/authentication": "^0.10.4",
"@dfinity/candid": "^0.10.4",
"@dfinity/identity": "^0.10.4",
"@dfinity/principal": "0.10.4",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/authentication": "^0.14.2",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"crc": "^4.1.0",
Expand Down
10 changes: 5 additions & 5 deletions motoko/encrypted-notes-dapp-vetkd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
"typescript": "^4.0.0"
},
"dependencies": {
"@dfinity/agent": "^0.15.1",
"@dfinity/auth-client": "^0.15.1",
"@dfinity/candid": "^0.15.1",
"@dfinity/identity": "^0.15.1",
"@dfinity/principal": "^0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"sirv-cli": "^1.0.0",
"svelte-icons": "^2.1.0",
"svelte-router-spa": "^6.0.3",
Expand Down
10 changes: 5 additions & 5 deletions motoko/encrypted-notes-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"typescript": "^4.0.0"
},
"dependencies": {
"@dfinity/agent": "^0.15.1",
"@dfinity/auth-client": "^0.15.1",
"@dfinity/candid": "^0.15.1",
"@dfinity/identity": "^0.15.1",
"@dfinity/principal": "^0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"crypto-js": "^4.2.0",
"idb": "^7.0.0",
"sirv-cli": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions motoko/hello/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"generate": "dfx generate hello"
},
"devDependencies": {
"@dfinity/agent": "^0.15.1",
"@dfinity/candid": "^0.15.1",
"@dfinity/principal": "^0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"events": "3.3.0",
Expand Down
14 changes: 7 additions & 7 deletions motoko/ic-pos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"dfx:generate": "dfx generate"
},
"dependencies": {
"@dfinity/agent": "^0.19.2",
"@dfinity/candid": "^0.19.2",
"@dfinity/ledger": "^0.0.15",
"@dfinity/principal": "^0.19.2",
"@dfinity/utils": "^0.0.22",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/ledger": "^1.0.0",
"@dfinity/principal": "^2.1.1",
"@dfinity/utils": "^2.5.0",
"@hookform/resolvers": "^3.1.1",
"@internet-identity-labs/react-ic-ii-auth": "^0.0.19",
"@radix-ui/react-icons": "^1.3.0",
Expand All @@ -64,8 +64,8 @@
"zod": "^3.22.3"
},
"devDependencies": {
"@dfinity/auth-client": "^0.19.2",
"@dfinity/identity": "^0.19.2",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"@types/node": "^20.6.0",
Expand Down
8 changes: 4 additions & 4 deletions motoko/icrc2-swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"fmt": "prettier --write ."
},
"dependencies": {
"@dfinity/agent": "^0.19.2",
"@dfinity/candid": "^0.19.2",
"@dfinity/identity": "^0.19.3",
"@dfinity/principal": "^0.19.2"
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1"
},
"devDependencies": {
"@babel/core": "^7.22.20",
Expand Down
10 changes: 5 additions & 5 deletions motoko/internet_identity_integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"generate": "dfx generate greet_backend"
},
"devDependencies": {
"@dfinity/agent": "0.15.3",
"@dfinity/auth-client": "^0.15.3",
"@dfinity/candid": "0.15.3",
"@dfinity/identity": "^0.15.3",
"@dfinity/principal": "0.15.3",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"copy-webpack-plugin": "^11.0.0",
Expand Down
12 changes: 6 additions & 6 deletions motoko/ios-notifications/dapp-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
"last 2 edge version"
],
"dependencies": {
"@dfinity/agent": "0.14.0",
"@dfinity/auth-client": "^0.14.0",
"@dfinity/authentication": "^0.14.0",
"@dfinity/candid": "0.14.0",
"@dfinity/identity": "^0.14.0",
"@dfinity/principal": "0.14.0",
"@dfinity/agent": "^2.1.1",
"@dfinity/auth-client": "^2.1.1",
"@dfinity/authentication": "^0.14.2",
"@dfinity/candid": "^2.1.1",
"@dfinity/identity": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"lit-html": "^2.4.0",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4"
Expand Down
6 changes: 3 additions & 3 deletions motoko/life/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"generate": "dfx generate life"
},
"devDependencies": {
"@dfinity/agent": "^0.15.1",
"@dfinity/candid": "^0.15.1",
"@dfinity/principal": "^0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"css-loader": "^6.0.0",
Expand Down
6 changes: 3 additions & 3 deletions motoko/minimal-counter-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"generate": "dfx generate minimal_dapp"
},
"devDependencies": {
"@dfinity/agent": "0.15.1",
"@dfinity/candid": "0.15.1",
"@dfinity/principal": "0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"events": "3.3.0",
Expand Down
6 changes: 3 additions & 3 deletions motoko/phone-book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"generate": "dfx generate phone_book"
},
"devDependencies": {
"@dfinity/agent": "^0.15.1",
"@dfinity/candid": "^0.15.1",
"@dfinity/principal": "^0.15.1",
"@dfinity/agent": "^2.1.1",
"@dfinity/candid": "^2.1.1",
"@dfinity/principal": "^2.1.1",
"assert": "2.0.0",
"buffer": "6.0.3",
"css-loader": "^6.0.0",
Expand Down
Loading