@rhinestone/shared-configs 1.4.12 → 1.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,10 +6,13 @@
6
6
 
7
7
  ### Installation
8
8
 
9
- ```bash
10
- npm install viem @rhinestone/shared-configs
11
- ```
12
-
13
9
  ```bash
14
10
  bun install viem @rhinestone/shared-configs
15
11
  ```
12
+
13
+ ## Making changes
14
+
15
+ 1. Update [`chains.ts`](./src/chains.ts) or [`providers.ts`](./src/providers.ts)
16
+ 2. This will will regenerate the configs and trigger a new release
17
+ 3. Merge the release PR
18
+ 4. Update the `@rhinestone/shared-configs` package in SDK and Orchestrator
@@ -38,7 +38,7 @@
38
38
  ]
39
39
  },
40
40
  "10": {
41
- "name": "Optimism",
41
+ "name": "OP Mainnet",
42
42
  "settlementLayers": [
43
43
  "ACROSS",
44
44
  "ECO",
@@ -123,7 +123,7 @@
123
123
  ]
124
124
  },
125
125
  "1868": {
126
- "name": "Soneium",
126
+ "name": "Soneium Mainnet",
127
127
  "settlementLayers": [
128
128
  "ACROSS",
129
129
  "ECO",
@@ -192,7 +192,7 @@
192
192
  ]
193
193
  },
194
194
  "42161": {
195
- "name": "Arbitrum",
195
+ "name": "Arbitrum One",
196
196
  "settlementLayers": [
197
197
  "ACROSS",
198
198
  "ECO",
@@ -230,7 +230,7 @@
230
230
  ]
231
231
  },
232
232
  "84532": {
233
- "name": "Base-sepolia",
233
+ "name": "Base Sepolia",
234
234
  "settlementLayers": [
235
235
  "ACROSS",
236
236
  "ECO",
@@ -323,7 +323,7 @@
323
323
  ]
324
324
  },
325
325
  "11155420": {
326
- "name": "Optimism Sepolia",
326
+ "name": "OP Sepolia",
327
327
  "settlementLayers": [
328
328
  "ACROSS",
329
329
  "ECO",
@@ -6,10 +6,9 @@
6
6
  "10": "optimism",
7
7
  "137": "polygon",
8
8
  "146": "sonic",
9
- "324": "zksync",
9
+ "1868": "soneium",
10
10
  "8453": "base",
11
11
  "42161": "arbitrum",
12
- "1868": "soneium",
13
12
  "84532": "base-sepolia",
14
13
  "421614": "arbitrum-sepolia",
15
14
  "11155111": "sepolia",
@@ -21,26 +20,25 @@
21
20
  "chain_mapping": {
22
21
  "1": "eth-mainnet",
23
22
  "10": "opt-mainnet",
24
- "1868": "soneium-mainnet",
25
- "11155111": "eth-sepolia",
26
- "11155420": "opt-sepolia",
27
- "84532": "base-sepolia",
28
- "421614": "arb-sepolia",
29
23
  "137": "polygon-mainnet",
30
24
  "146": "sonic-mainnet",
31
- "324": "zksync-mainnet",
25
+ "1868": "soneium-mainnet",
32
26
  "8453": "base-mainnet",
33
- "42161": "arb-mainnet"
27
+ "42161": "arb-mainnet",
28
+ "84532": "base-sepolia",
29
+ "421614": "arb-sepolia",
30
+ "11155111": "eth-sepolia",
31
+ "11155420": "opt-sepolia"
34
32
  }
35
33
  },
36
34
  "local-rpc": {
37
35
  "url_template": "http://localhost:{{chain_param}}",
38
36
  "chain_mapping": {
39
37
  "1": "30001",
40
- "42161": "30002",
41
- "8453": "30003",
42
38
  "137": "30004",
43
- "146": "30005"
39
+ "146": "30005",
40
+ "8453": "30003",
41
+ "42161": "30002"
44
42
  }
45
43
  }
46
44
  }
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_fs_1 = require("node:fs");
7
6
  const promises_1 = require("node:fs/promises");
8
7
  const node_path_1 = __importDefault(require("node:path"));
9
8
  const viem_1 = require("viem");
10
9
  const chains_1 = require("../src/chains");
10
+ const providers_1 = require("../src/providers");
11
11
  const types_1 = require("../src/types");
12
12
  function isZeroAddress(addr) {
13
13
  return addr.toLowerCase() === '0x0000000000000000000000000000000000000000';
@@ -17,12 +17,6 @@ function enumNumberValues(e) {
17
17
  }
18
18
  const MAINNET_IDS = new Set(enumNumberValues(types_1.MainnetNetwork).map(String));
19
19
  const TESTNET_IDS = new Set(enumNumberValues(types_1.TestnetNetwork).map(String));
20
- async function readJsonIfExists(filePath) {
21
- if (!(0, node_fs_1.existsSync)(filePath))
22
- return null;
23
- const buf = await (0, promises_1.readFile)(filePath, 'utf8');
24
- return JSON.parse(buf);
25
- }
26
20
  async function fetchErc20Metadata(client, token) {
27
21
  try {
28
22
  const [symbol, decimals] = await Promise.all([
@@ -43,81 +37,54 @@ async function fetchErc20Metadata(client, token) {
43
37
  return { symbol: null, decimals: null };
44
38
  }
45
39
  }
46
- async function generate() {
47
- const baseDir = node_path_1.default.resolve(process.cwd());
48
- const configsDir = node_path_1.default.join(baseDir, 'configs');
40
+ async function generateChains(configsDir) {
41
+ console.log('Generating chains configuration...');
49
42
  const chainsJsonPath = node_path_1.default.join(configsDir, 'chains.json');
50
43
  const mainnetsJsonPath = node_path_1.default.join(configsDir, 'mainnets.json');
51
44
  const testnetsJsonPath = node_path_1.default.join(configsDir, 'testnets.json');
52
- const cachedRegistry = (await readJsonIfExists(chainsJsonPath)) || {};
53
45
  const outRegistry = {};
54
46
  const outMainnets = {};
55
47
  const outTestnets = {};
56
48
  for (const [chainId, chainCfg] of Object.entries(chains_1.chains)) {
57
- console.log(`Processing chain ${chainId}`);
58
49
  const chain = types_1.chains.find((c) => c.id === parseInt(chainId));
59
50
  if (!chain) {
60
- console.error(`Chain ${chainId} not found in viem chains`);
51
+ console.error(` Chain ${chainId} not found in viem chains`);
61
52
  continue;
62
53
  }
63
54
  const client = (0, viem_1.createPublicClient)({
64
55
  chain,
65
56
  transport: (0, viem_1.http)(),
66
57
  });
67
- const cachedChain = cachedRegistry[chainId];
68
58
  const tokens = [];
69
59
  for (const t of chainCfg.tokens) {
70
60
  const addr = t.address;
71
- const cachedToken = cachedChain?.tokens?.find((x) => x.address.toLowerCase() === addr.toLowerCase());
72
61
  if (isZeroAddress(addr)) {
73
- const symbol = t.symbol ?? cachedToken?.symbol ?? 'ETH';
74
62
  tokens.push({
75
- symbol,
63
+ symbol: t.symbol ?? chain.nativeCurrency.symbol,
76
64
  address: addr,
77
- decimals: 18,
65
+ decimals: chain.nativeCurrency.decimals,
78
66
  balanceSlot: null,
79
67
  approvalSlot: null,
80
68
  });
81
69
  continue;
82
70
  }
83
- if (cachedToken) {
84
- tokens.push({
85
- symbol: t.symbol ?? cachedToken.symbol,
86
- address: addr,
87
- decimals: cachedToken.decimals,
88
- balanceSlot: cachedToken.balanceSlot,
89
- approvalSlot: cachedToken.approvalSlot,
90
- });
91
- continue;
92
- }
93
71
  let symbol = t.symbol ?? 'UNKNOWN';
94
72
  let decimals = 18;
95
- if (client) {
96
- const meta = await fetchErc20Metadata(client, addr);
97
- if (meta.symbol)
98
- symbol = t.symbol ?? meta.symbol;
99
- if (meta.decimals != null)
100
- decimals = meta.decimals;
101
- }
102
- const balanceSlot = t.balanceSlot;
103
- const approvalSlot = t.approvalSlot;
104
- console.log('token', {
105
- symbol,
106
- address: addr,
107
- decimals,
108
- balanceSlot,
109
- approvalSlot,
110
- });
73
+ const meta = await fetchErc20Metadata(client, addr);
74
+ if (meta.symbol)
75
+ symbol = t.symbol ?? meta.symbol;
76
+ if (meta.decimals != null)
77
+ decimals = meta.decimals;
111
78
  tokens.push({
112
79
  symbol,
113
80
  address: addr,
114
81
  decimals,
115
- balanceSlot,
116
- approvalSlot,
82
+ balanceSlot: t.balanceSlot,
83
+ approvalSlot: t.approvalSlot,
117
84
  });
118
85
  }
119
86
  outRegistry[chainId] = {
120
- name: chainCfg.name,
87
+ name: chain.name,
121
88
  settlementLayers: chainCfg.settlementLayers,
122
89
  tokens,
123
90
  };
@@ -127,9 +94,34 @@ async function generate() {
127
94
  else if (TESTNET_IDS.has(chainId))
128
95
  outTestnets[chainId] = chainItem;
129
96
  }
130
- await (0, promises_1.writeFile)(chainsJsonPath, JSON.stringify(outRegistry, null, 2) + '\n');
131
- await (0, promises_1.writeFile)(mainnetsJsonPath, JSON.stringify(outMainnets, null, 2) + '\n');
132
- await (0, promises_1.writeFile)(testnetsJsonPath, JSON.stringify(outTestnets, null, 2) + '\n');
97
+ await (0, promises_1.writeFile)(chainsJsonPath, `${JSON.stringify(outRegistry, null, 2)}\n`);
98
+ await (0, promises_1.writeFile)(mainnetsJsonPath, `${JSON.stringify(outMainnets, null, 2)}\n`);
99
+ await (0, promises_1.writeFile)(testnetsJsonPath, `${JSON.stringify(outTestnets, null, 2)}\n`);
100
+ console.log('Chains configuration generated successfully!');
101
+ }
102
+ async function generateProviders(configsDir) {
103
+ console.log('Generating providers configuration...');
104
+ const providersJsonPath = node_path_1.default.join(configsDir, 'providers.json');
105
+ // Convert the provider data to JSON-compatible format
106
+ const outProviders = {};
107
+ for (const [providerName, providerCfg] of Object.entries(providers_1.providers)) {
108
+ // Convert chain_mapping keys from numbers to strings for JSON output
109
+ const chainMapping = {};
110
+ for (const [chainId, chainParam] of Object.entries(providerCfg.chain_mapping)) {
111
+ chainMapping[chainId.toString()] = chainParam;
112
+ }
113
+ outProviders[providerName] = {
114
+ url_template: providerCfg.url_template,
115
+ chain_mapping: chainMapping,
116
+ };
117
+ }
118
+ await (0, promises_1.writeFile)(providersJsonPath, `${JSON.stringify(outProviders, null, 2)}\n`);
119
+ }
120
+ async function generate() {
121
+ const baseDir = node_path_1.default.resolve(process.cwd());
122
+ const configsDir = node_path_1.default.join(baseDir, 'configs');
123
+ await generateChains(configsDir);
124
+ await generateProviders(configsDir);
133
125
  }
134
126
  generate().catch((err) => {
135
127
  console.error(err);
@@ -7,7 +7,6 @@ interface Token {
7
7
  approvalSlot: number | null;
8
8
  }
9
9
  interface Chain {
10
- name: string;
11
10
  settlementLayers: SettlementLayer[];
12
11
  providers: ProviderName[];
13
12
  tokens: Token[];
@@ -1 +1 @@
1
- {"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE5E,UAAU,KAAK;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,eAAe,EAAE,CAAA;IACnC,SAAS,EAAE,YAAY,EAAE,CAAA;IACzB,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB;AAED,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,KAAK,CA0QzC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE5E,UAAU,KAAK;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,UAAU,KAAK;IACb,gBAAgB,EAAE,eAAe,EAAE,CAAA;IACnC,SAAS,EAAE,YAAY,EAAE,CAAA;IACzB,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB;AAED,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,KAAK,CAsPzC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA"}
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chains = void 0;
4
4
  const chains = {
5
5
  '1': {
6
- name: 'Ethereum',
7
6
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
8
7
  providers: ['DRPC', 'Alchemy'],
9
8
  tokens: [
10
9
  {
11
- symbol: 'ETH',
12
10
  address: '0x0000000000000000000000000000000000000000',
13
11
  balanceSlot: null,
14
12
  approvalSlot: null,
@@ -31,12 +29,10 @@ const chains = {
31
29
  ],
32
30
  },
33
31
  '10': {
34
- name: 'Optimism',
35
32
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
36
33
  providers: ['DRPC', 'Alchemy'],
37
34
  tokens: [
38
35
  {
39
- symbol: 'ETH',
40
36
  address: '0x0000000000000000000000000000000000000000',
41
37
  balanceSlot: null,
42
38
  approvalSlot: null,
@@ -59,12 +55,10 @@ const chains = {
59
55
  ],
60
56
  },
61
57
  '8453': {
62
- name: 'Base',
63
58
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
64
59
  providers: ['DRPC', 'Alchemy'],
65
60
  tokens: [
66
61
  {
67
- symbol: 'ETH',
68
62
  address: '0x0000000000000000000000000000000000000000',
69
63
  balanceSlot: null,
70
64
  approvalSlot: null,
@@ -88,12 +82,10 @@ const chains = {
88
82
  ],
89
83
  },
90
84
  '42161': {
91
- name: 'Arbitrum',
92
85
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
93
86
  providers: ['DRPC', 'Alchemy'],
94
87
  tokens: [
95
88
  {
96
- symbol: 'ETH',
97
89
  address: '0x0000000000000000000000000000000000000000',
98
90
  balanceSlot: null,
99
91
  approvalSlot: null,
@@ -117,7 +109,6 @@ const chains = {
117
109
  ],
118
110
  },
119
111
  '137': {
120
- name: 'Polygon',
121
112
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
122
113
  providers: ['DRPC', 'Alchemy'],
123
114
  tokens: [
@@ -140,7 +131,6 @@ const chains = {
140
131
  ],
141
132
  },
142
133
  '146': {
143
- name: 'Sonic',
144
134
  settlementLayers: ['ECO', 'RELAY'],
145
135
  providers: ['DRPC', 'Alchemy'],
146
136
  tokens: [
@@ -152,12 +142,10 @@ const chains = {
152
142
  ],
153
143
  },
154
144
  '1868': {
155
- name: 'Soneium',
156
145
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
157
146
  providers: ['DRPC', 'Alchemy'],
158
147
  tokens: [
159
148
  {
160
- symbol: 'ETH',
161
149
  address: '0x0000000000000000000000000000000000000000',
162
150
  balanceSlot: null,
163
151
  approvalSlot: null,
@@ -176,12 +164,10 @@ const chains = {
176
164
  ],
177
165
  },
178
166
  '84532': {
179
- name: 'Base-sepolia',
180
167
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
181
168
  providers: ['DRPC'],
182
169
  tokens: [
183
170
  {
184
- symbol: 'ETH',
185
171
  address: '0x0000000000000000000000000000000000000000',
186
172
  balanceSlot: null,
187
173
  approvalSlot: null,
@@ -199,12 +185,10 @@ const chains = {
199
185
  ],
200
186
  },
201
187
  '421614': {
202
- name: 'Arbitrum Sepolia',
203
188
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
204
189
  providers: ['DRPC'],
205
190
  tokens: [
206
191
  {
207
- symbol: 'ETH',
208
192
  address: '0x0000000000000000000000000000000000000000',
209
193
  balanceSlot: null,
210
194
  approvalSlot: null,
@@ -222,12 +206,10 @@ const chains = {
222
206
  ],
223
207
  },
224
208
  '11155111': {
225
- name: 'Sepolia',
226
209
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
227
210
  providers: ['DRPC'],
228
211
  tokens: [
229
212
  {
230
- symbol: 'ETH',
231
213
  address: '0x0000000000000000000000000000000000000000',
232
214
  balanceSlot: null,
233
215
  approvalSlot: null,
@@ -245,12 +227,10 @@ const chains = {
245
227
  ],
246
228
  },
247
229
  '11155420': {
248
- name: 'Optimism Sepolia',
249
230
  settlementLayers: ['ACROSS', 'ECO', 'RELAY'],
250
231
  providers: ['DRPC'],
251
232
  tokens: [
252
233
  {
253
- symbol: 'ETH',
254
234
  address: '0x0000000000000000000000000000000000000000',
255
235
  balanceSlot: null,
256
236
  approvalSlot: null,
@@ -0,0 +1,4 @@
1
+ import type { ProviderRegistry } from './types';
2
+ declare const providers: ProviderRegistry;
3
+ export { providers };
4
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,QAAA,MAAM,SAAS,EAAE,gBA8ChB,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.providers = void 0;
4
+ const providers = {
5
+ DRPC: {
6
+ url_template: 'https://lb.drpc.org/ogrpc?network={{chain_param}}&dkey=$' +
7
+ '{DRPC_API_KEY}',
8
+ chain_mapping: {
9
+ 1: 'ethereum',
10
+ 10: 'optimism',
11
+ 137: 'polygon',
12
+ 146: 'sonic',
13
+ 8453: 'base',
14
+ 42161: 'arbitrum',
15
+ 1868: 'soneium',
16
+ 84532: 'base-sepolia',
17
+ 421614: 'arbitrum-sepolia',
18
+ 11155111: 'sepolia',
19
+ 11155420: 'optimism-sepolia',
20
+ },
21
+ },
22
+ Alchemy: {
23
+ url_template: 'https://{{chain_param}}.g.alchemy.com/v2/$' + '{ALCHEMY_API_KEY}',
24
+ chain_mapping: {
25
+ 1: 'eth-mainnet',
26
+ 10: 'opt-mainnet',
27
+ 1868: 'soneium-mainnet',
28
+ 11155111: 'eth-sepolia',
29
+ 11155420: 'opt-sepolia',
30
+ 84532: 'base-sepolia',
31
+ 421614: 'arb-sepolia',
32
+ 137: 'polygon-mainnet',
33
+ 146: 'sonic-mainnet',
34
+ 8453: 'base-mainnet',
35
+ 42161: 'arb-mainnet',
36
+ },
37
+ },
38
+ 'local-rpc': {
39
+ url_template: 'http://localhost:{{chain_param}}',
40
+ chain_mapping: {
41
+ 1: '30001',
42
+ 42161: '30002',
43
+ 8453: '30003',
44
+ 137: '30004',
45
+ 146: '30005',
46
+ },
47
+ },
48
+ };
49
+ exports.providers = providers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/shared-configs",
3
- "version": "1.4.12",
3
+ "version": "1.4.16",
4
4
  "description": "Reusable configuration files for Rhinestone services",
5
5
  "author": {
6
6
  "name": "Rhinestone",
@@ -18,6 +18,9 @@
18
18
  "prepublishOnly": "bun run build",
19
19
  "clean": "rimraf dist",
20
20
  "generate": "bun run scripts/generate.ts",
21
+ "changeset": "changeset",
22
+ "changeset:release": "bun run build && changeset publish",
23
+ "changeset:version": "changeset version",
21
24
  "build": "bun run clean && tsc"
22
25
  },
23
26
  "devDependencies": {
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=update-sdk-dependency.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-sdk-dependency.d.ts","sourceRoot":"","sources":["../../scripts/update-sdk-dependency.ts"],"names":[],"mappings":""}
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_fs_1 = require("node:fs");
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const targetName = process.env.TARGET_NAME;
9
- const targetVersionInput = process.env.TARGET_VERSION;
10
- if (!targetName || !targetVersionInput) {
11
- throw new Error('TARGET_NAME and TARGET_VERSION env vars are required');
12
- }
13
- const targetVersion = `^${targetVersionInput}`;
14
- function readJson(jsonPath) {
15
- return JSON.parse((0, node_fs_1.readFileSync)(jsonPath, 'utf8'));
16
- }
17
- function writeJson(jsonPath, obj) {
18
- (0, node_fs_1.writeFileSync)(jsonPath, JSON.stringify(obj, null, 2) + '\n');
19
- }
20
- function tryUpdatePackageJson(pkg) {
21
- let changed = false;
22
- for (const key of ['dependencies', 'devDependencies', 'peerDependencies']) {
23
- const deps = pkg[key];
24
- if (deps && targetName in deps) {
25
- if (deps[targetName] !== targetVersion) {
26
- deps[targetName] = targetVersion;
27
- changed = true;
28
- }
29
- }
30
- }
31
- return changed;
32
- }
33
- function walkAndUpdate(startDir) {
34
- const stack = [startDir];
35
- while (stack.length) {
36
- const dir = stack.pop();
37
- const entries = (0, node_fs_1.readdirSync)(dir, { withFileTypes: true });
38
- for (const entry of entries) {
39
- if (entry.name === 'node_modules' || entry.name === '.git')
40
- continue;
41
- const fullPath = node_path_1.default.join(dir, entry.name);
42
- if (entry.isDirectory()) {
43
- stack.push(fullPath);
44
- }
45
- else if (entry.isFile() && entry.name === 'package.json') {
46
- try {
47
- const pkg = readJson(fullPath);
48
- if (tryUpdatePackageJson(pkg)) {
49
- writeJson(fullPath, pkg);
50
- console.log('updated', fullPath);
51
- }
52
- }
53
- catch {
54
- // ignore invalid json files
55
- }
56
- }
57
- }
58
- }
59
- }
60
- walkAndUpdate(process.cwd());