@pezkuwi/dev 0.84.2

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.
Files changed (37) hide show
  1. package/.skip-deno +0 -0
  2. package/README.md +547 -0
  3. package/config/eslint.js +160 -0
  4. package/config/eslint.rules.js +214 -0
  5. package/config/prettier.cjs +22 -0
  6. package/config/rollup.js +113 -0
  7. package/config/tsconfig.json +32 -0
  8. package/config/typedoc.cjs +18 -0
  9. package/package.json +107 -0
  10. package/scripts/polkadot-ci-ghact-build.mjs +540 -0
  11. package/scripts/polkadot-ci-ghact-docs.mjs +14 -0
  12. package/scripts/polkadot-ci-ghpages-force.mjs +43 -0
  13. package/scripts/polkadot-dev-build-docs.mjs +19 -0
  14. package/scripts/polkadot-dev-build-ts.mjs +1518 -0
  15. package/scripts/polkadot-dev-circular.mjs +29 -0
  16. package/scripts/polkadot-dev-clean-build.mjs +61 -0
  17. package/scripts/polkadot-dev-contrib.mjs +74 -0
  18. package/scripts/polkadot-dev-copy-dir.mjs +44 -0
  19. package/scripts/polkadot-dev-copy-to.mjs +53 -0
  20. package/scripts/polkadot-dev-deno-map.mjs +35 -0
  21. package/scripts/polkadot-dev-run-lint.mjs +40 -0
  22. package/scripts/polkadot-dev-run-node-ts.mjs +9 -0
  23. package/scripts/polkadot-dev-run-test.mjs +163 -0
  24. package/scripts/polkadot-dev-version.mjs +143 -0
  25. package/scripts/polkadot-dev-yarn-only.mjs +11 -0
  26. package/scripts/polkadot-exec-eslint.mjs +7 -0
  27. package/scripts/polkadot-exec-ghpages.mjs +11 -0
  28. package/scripts/polkadot-exec-ghrelease.mjs +7 -0
  29. package/scripts/polkadot-exec-node-test.mjs +368 -0
  30. package/scripts/polkadot-exec-rollup.mjs +7 -0
  31. package/scripts/polkadot-exec-tsc.mjs +7 -0
  32. package/scripts/polkadot-exec-webpack.mjs +7 -0
  33. package/scripts/util.mjs +540 -0
  34. package/tsconfig.build.json +18 -0
  35. package/tsconfig.config.json +14 -0
  36. package/tsconfig.scripts.json +14 -0
  37. package/tsconfig.spec.json +18 -0
@@ -0,0 +1,540 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2017-2025 @polkadot/dev authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import process from 'node:process';
9
+ import yargs from 'yargs';
10
+
11
+ import { copyDirSync, copyFileSync, denoCreateDir, execGit, execPm, execSync, exitFatal, GITHUB_REPO, GITHUB_TOKEN_URL, gitSetup, logBin, mkdirpSync, rimrafSync, topoSort } from './util.mjs';
12
+
13
+ /** @typedef {Record<string, any>} ChangelogMap */
14
+
15
+ logBin('polkadot-ci-ghact-build');
16
+
17
+ const DENO_REPO = 'polkadot-js/build-deno.land';
18
+ const BUND_REPO = 'polkadot-js/build-bundle';
19
+
20
+ const repo = `${GITHUB_TOKEN_URL}/${GITHUB_REPO}.git`;
21
+ const denoRepo = `${GITHUB_TOKEN_URL}/${DENO_REPO}.git`;
22
+ const bundRepo = `${GITHUB_TOKEN_URL}/${BUND_REPO}.git`;
23
+ const bundClone = 'build-bundle-clone';
24
+ const denoClone = 'build-deno-clone';
25
+
26
+ let withDeno = false;
27
+ let withBund = false;
28
+ let withNpm = false;
29
+
30
+ /** @type {string[]} */
31
+ const shouldDeno = [];
32
+ /** @type {string[]} */
33
+ const shouldBund = [];
34
+
35
+ const argv = await yargs(process.argv.slice(2))
36
+ .options({
37
+ 'skip-beta': {
38
+ description: 'Do not increment as beta',
39
+ type: 'boolean'
40
+ }
41
+ })
42
+ .strict()
43
+ .argv;
44
+
45
+ /**
46
+ * Removes a specific file, returning true if found, false otherwise
47
+ *
48
+ * @param {string} file
49
+ * @returns {boolean}
50
+ */
51
+ function rmFile (file) {
52
+ if (fs.existsSync(file)) {
53
+ rimrafSync(file);
54
+
55
+ return true;
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ /**
62
+ * Retrieves the path of the root package.json
63
+ *
64
+ * @returns {string}
65
+ */
66
+ function npmGetJsonPath () {
67
+ return path.resolve(process.cwd(), 'package.json');
68
+ }
69
+
70
+ /**
71
+ * Retrieves the contents of the root package.json
72
+ *
73
+ * @returns {{ name: string; version: string; versions?: { npm?: string; git?: string } }}
74
+ */
75
+ function npmGetJson () {
76
+ return JSON.parse(
77
+ fs.readFileSync(npmGetJsonPath(), 'utf8')
78
+ );
79
+ }
80
+
81
+ /**
82
+ * Writes the contents of the root package.json
83
+ *
84
+ * @param {any} json
85
+ */
86
+ function npmSetJson (json) {
87
+ fs.writeFileSync(npmGetJsonPath(), `${JSON.stringify(json, null, 2)}\n`);
88
+ }
89
+
90
+ /**
91
+ * Retrieved the current version included in package.json
92
+ *
93
+ * @returns {string}
94
+ */
95
+ function npmGetVersion () {
96
+ return npmGetJson().version;
97
+ }
98
+
99
+ /**
100
+ * Sets the current to have an -x version specifier (aka beta)
101
+ */
102
+ function npmAddVersionX () {
103
+ const json = npmGetJson();
104
+
105
+ if (!json.version.endsWith('-x')) {
106
+ json.version = json.version + '-x';
107
+ npmSetJson(json);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Removes the current -x version specifier (aka beta)
113
+ */
114
+ function npmDelVersionX () {
115
+ const json = npmGetJson();
116
+
117
+ if (json.version.endsWith('-x')) {
118
+ json.version = json.version.replace('-x', '');
119
+ npmSetJson(json);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Sets the {versions: { npm, git } } fields in package.json
125
+ */
126
+ function npmSetVersionFields () {
127
+ const json = npmGetJson();
128
+
129
+ if (!json.versions) {
130
+ json.versions = {};
131
+ }
132
+
133
+ json.versions.git = json.version;
134
+
135
+ if (!json.version.endsWith('-x')) {
136
+ json.versions.npm = json.version;
137
+ }
138
+
139
+ npmSetJson(json);
140
+ rmFile('.123current');
141
+ }
142
+
143
+ /**
144
+ * Sets the npm token in the home directory
145
+ */
146
+ function npmSetup () {
147
+ const registry = 'registry.npmjs.org';
148
+
149
+ fs.writeFileSync(path.join(os.homedir(), '.npmrc'), `//${registry}/:_authToken=${process.env['NPM_TOKEN']}`);
150
+ }
151
+
152
+ /**
153
+ * Publishes the current package
154
+ *
155
+ * @returns {void}
156
+ */
157
+ function npmPublish () {
158
+ if (fs.existsSync('.skip-npm') || !withNpm) {
159
+ return;
160
+ }
161
+
162
+ ['LICENSE', 'package.json']
163
+ .filter((file) => !fs.existsSync(path.join(process.cwd(), 'build', file)))
164
+ .forEach((file) => copyFileSync(file, 'build'));
165
+
166
+ process.chdir('build');
167
+
168
+ const tag = npmGetVersion().includes('-') ? '--tag beta' : '';
169
+ let count = 1;
170
+
171
+ while (true) {
172
+ try {
173
+ execSync(`npm publish --quiet --access public ${tag}`);
174
+
175
+ break;
176
+ } catch {
177
+ if (count < 5) {
178
+ const end = Date.now() + 15000;
179
+
180
+ console.error(`Publish failed on attempt ${count}/5. Retrying in 15s`);
181
+ count++;
182
+
183
+ while (Date.now() < end) {
184
+ // just spin our wheels
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ process.chdir('..');
191
+ }
192
+
193
+ /**
194
+ * Creates a map of changelog entries
195
+ *
196
+ * @param {string[][]} parts
197
+ * @param {ChangelogMap} result
198
+ * @returns {ChangelogMap}
199
+ */
200
+ function createChangelogMap (parts, result = {}) {
201
+ for (let i = 0, count = parts.length; i < count; i++) {
202
+ const [n, ...e] = parts[i];
203
+
204
+ if (!result[n]) {
205
+ if (e.length) {
206
+ result[n] = createChangelogMap([e]);
207
+ } else {
208
+ result[n] = { '': {} };
209
+ }
210
+ } else {
211
+ if (e.length) {
212
+ createChangelogMap([e], result[n]);
213
+ } else {
214
+ result[n][''] = {};
215
+ }
216
+ }
217
+ }
218
+
219
+ return result;
220
+ }
221
+
222
+ /**
223
+ * Creates an array of changelog entries
224
+ *
225
+ * @param {ChangelogMap} map
226
+ * @returns {string[]}
227
+ */
228
+ function createChangelogArr (map) {
229
+ const result = [];
230
+ const entries = Object.entries(map);
231
+
232
+ for (let i = 0, count = entries.length; i < count; i++) {
233
+ const [name, imap] = entries[i];
234
+
235
+ if (name) {
236
+ if (imap['']) {
237
+ result.push(name);
238
+ }
239
+
240
+ const inner = createChangelogArr(imap);
241
+
242
+ if (inner.length === 1) {
243
+ result.push(`${name}-${inner[0]}`);
244
+ } else if (inner.length) {
245
+ result.push(`${name}-{${inner.join(', ')}}`);
246
+ }
247
+ }
248
+ }
249
+
250
+ return result;
251
+ }
252
+
253
+ /**
254
+ * Adds changelog entries
255
+ *
256
+ * @param {string[]} changelog
257
+ * @returns {string}
258
+ */
259
+ function addChangelog (changelog) {
260
+ const [version, ...names] = changelog;
261
+ const entry = `${
262
+ createChangelogArr(
263
+ createChangelogMap(
264
+ names
265
+ .sort()
266
+ .map((n) => n.split('-'))
267
+ )
268
+ ).join(', ')
269
+ } ${version}`;
270
+ const newInfo = `## master\n\n- ${entry}\n`;
271
+
272
+ if (!fs.existsSync('CHANGELOG.md')) {
273
+ fs.writeFileSync('CHANGELOG.md', `# CHANGELOG\n\n${newInfo}`);
274
+ } else {
275
+ const md = fs.readFileSync('CHANGELOG.md', 'utf-8');
276
+
277
+ fs.writeFileSync('CHANGELOG.md', md.includes('## master\n\n')
278
+ ? md.replace('## master\n\n', newInfo)
279
+ : md.replace('# CHANGELOG\n\n', `# CHANGELOG\n\n${newInfo}\n`)
280
+ );
281
+ }
282
+
283
+ return entry;
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @param {string} repo
289
+ * @param {string} clone
290
+ * @param {string[]} names
291
+ */
292
+ function commitClone (repo, clone, names) {
293
+ if (names.length) {
294
+ process.chdir(clone);
295
+
296
+ const entry = addChangelog(names);
297
+
298
+ gitSetup();
299
+ execGit('add --all .');
300
+ execGit(`commit --no-status --quiet -m "${entry}"`);
301
+ execGit(`push ${repo}`, true);
302
+
303
+ process.chdir('..');
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Publishes a specific package to polkadot-js bundles
309
+ *
310
+ * @returns {void}
311
+ */
312
+ function bundlePublishPkg () {
313
+ const { name, version } = npmGetJson();
314
+ const dirName = name.split('/')[1];
315
+ const bundName = `bundle-polkadot-${dirName}.js`;
316
+ const srcPath = path.join('build', bundName);
317
+ const dstDir = path.join('../..', bundClone);
318
+
319
+ if (!fs.existsSync(srcPath)) {
320
+ return;
321
+ }
322
+
323
+ console.log(`\n *** bundle ${name}`);
324
+
325
+ if (shouldBund.length === 0) {
326
+ shouldBund.push(version);
327
+ }
328
+
329
+ shouldBund.push(dirName);
330
+
331
+ rimrafSync(path.join(dstDir, bundName));
332
+ copyFileSync(srcPath, dstDir);
333
+ }
334
+
335
+ /**
336
+ * Publishes all packages to polkadot-js bundles
337
+ *
338
+ * @returns {void}
339
+ */
340
+ function bundlePublish () {
341
+ const { version } = npmGetJson();
342
+
343
+ if (!withBund && version.includes('-')) {
344
+ return;
345
+ }
346
+
347
+ execGit(`clone ${bundRepo} ${bundClone}`, true);
348
+
349
+ loopFunc(bundlePublishPkg);
350
+
351
+ commitClone(bundRepo, bundClone, shouldBund);
352
+ }
353
+
354
+ /**
355
+ * Publishes a specific package to Deno
356
+ *
357
+ * @returns {void}
358
+ */
359
+ function denoPublishPkg () {
360
+ const { name, version } = npmGetJson();
361
+
362
+ if (fs.existsSync('.skip-deno') || !fs.existsSync('build-deno')) {
363
+ return;
364
+ }
365
+
366
+ console.log(`\n *** deno ${name}`);
367
+
368
+ const dirName = denoCreateDir(name);
369
+ const denoPath = `../../${denoClone}/${dirName}`;
370
+
371
+ if (shouldDeno.length === 0) {
372
+ shouldDeno.push(version);
373
+ }
374
+
375
+ shouldDeno.push(dirName);
376
+
377
+ rimrafSync(denoPath);
378
+ mkdirpSync(denoPath);
379
+
380
+ copyDirSync('build-deno', denoPath);
381
+ }
382
+
383
+ /**
384
+ * Publishes all packages to Deno
385
+ *
386
+ * @returns {void}
387
+ */
388
+ function denoPublish () {
389
+ const { version } = npmGetJson();
390
+
391
+ if (!withDeno && version.includes('-')) {
392
+ return;
393
+ }
394
+
395
+ execGit(`clone ${denoRepo} ${denoClone}`, true);
396
+
397
+ loopFunc(denoPublishPkg);
398
+
399
+ commitClone(denoRepo, denoClone, shouldDeno);
400
+ }
401
+
402
+ /**
403
+ * Retrieves flags based on current specifications
404
+ */
405
+ function getFlags () {
406
+ withDeno = rmFile('.123deno');
407
+ withBund = rmFile('.123bundle');
408
+ withNpm = rmFile('.123npm');
409
+ }
410
+
411
+ /**
412
+ * Bumps the current version, also applying to all sub-packages
413
+ */
414
+ function verBump () {
415
+ const { version: currentVersion, versions } = npmGetJson();
416
+ const [version, tag] = currentVersion.split('-');
417
+ const [,, patch] = version.split('.');
418
+ const lastVersion = versions?.npm || currentVersion;
419
+
420
+ if (argv['skip-beta'] || patch === '0') {
421
+ // don't allow beta versions
422
+ execPm('polkadot-dev-version patch');
423
+ withNpm = true;
424
+ } else if (tag || currentVersion === lastVersion) {
425
+ // if we don't want to publish, add an X before passing
426
+ if (!withNpm) {
427
+ npmAddVersionX();
428
+ } else {
429
+ npmDelVersionX();
430
+ }
431
+
432
+ // beta version, just continue the stream of betas
433
+ execPm('polkadot-dev-version pre');
434
+ } else {
435
+ // manually set, got for publish
436
+ withNpm = true;
437
+ }
438
+
439
+ // always ensure we have made some changes, so we can commit
440
+ npmSetVersionFields();
441
+ rmFile('.123trigger');
442
+
443
+ execPm('polkadot-dev-contrib');
444
+ execGit('add --all .');
445
+ }
446
+
447
+ /**
448
+ * Commits and pushes the current version on git
449
+ */
450
+ function gitPush () {
451
+ const version = npmGetVersion();
452
+ let doGHRelease = false;
453
+
454
+ if (process.env['GH_RELEASE_GITHUB_API_TOKEN']) {
455
+ const changes = fs.readFileSync('CHANGELOG.md', 'utf8');
456
+
457
+ if (changes.includes(`## ${version}`)) {
458
+ doGHRelease = true;
459
+ } else if (version.endsWith('.1')) {
460
+ exitFatal(`Unable to release, no CHANGELOG entry for ${version}`);
461
+ }
462
+ }
463
+
464
+ execGit('add --all .');
465
+
466
+ if (fs.existsSync('docs/README.md')) {
467
+ execGit('add --all -f docs');
468
+ }
469
+
470
+ // add the skip checks for GitHub ...
471
+ execGit(`commit --no-status --quiet -m "[CI Skip] ${version.includes('-x') ? 'bump' : 'release'}/${version.includes('-') ? 'beta' : 'stable'} ${version}
472
+
473
+
474
+ skip-checks: true"`);
475
+
476
+ // Make sure the release commit is on top of the latest master
477
+ execGit(`pull --rebase ${repo} master`);
478
+
479
+ // Now push normally
480
+ execGit(`push ${repo} HEAD:${process.env['GITHUB_REF']}`, true);
481
+
482
+ if (doGHRelease) {
483
+ const files = process.env['GH_RELEASE_FILES']
484
+ ? `--assets ${process.env['GH_RELEASE_FILES']}`
485
+ : '';
486
+
487
+ execPm(`polkadot-exec-ghrelease --draft ${files} --yes`);
488
+ }
489
+ }
490
+
491
+ /**
492
+ * Loops through the packages/* (or root), executing the supplied
493
+ * function for each package found
494
+ *
495
+ * @param {() => unknown} fn
496
+ */
497
+ function loopFunc (fn) {
498
+ if (fs.existsSync('packages')) {
499
+ const dirs = fs
500
+ .readdirSync('packages')
501
+ .filter((dir) => {
502
+ const pkgDir = path.join(process.cwd(), 'packages', dir);
503
+
504
+ return fs.statSync(pkgDir).isDirectory() &&
505
+ fs.existsSync(path.join(pkgDir, 'package.json')) &&
506
+ fs.existsSync(path.join(pkgDir, 'build'));
507
+ });
508
+
509
+ topoSort(dirs)
510
+ .forEach((dir) => {
511
+ process.chdir(path.join('packages', dir));
512
+ fn();
513
+ process.chdir('../..');
514
+ });
515
+ } else {
516
+ fn();
517
+ }
518
+ }
519
+
520
+ // first do infrastructure setup
521
+ gitSetup();
522
+ npmSetup();
523
+
524
+ // get flags immediate, then adjust
525
+ getFlags();
526
+ verBump();
527
+
528
+ // perform the actual CI build
529
+ execPm('polkadot-dev-clean-build');
530
+ execPm('lint');
531
+ execPm('test');
532
+ execPm('build');
533
+
534
+ // publish to all GH repos
535
+ gitPush();
536
+ denoPublish();
537
+ bundlePublish();
538
+
539
+ // publish to npm
540
+ loopFunc(npmPublish);
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2017-2025 @polkadot/dev authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import { execPm, GITHUB_REPO, GITHUB_TOKEN_URL, gitSetup, logBin } from './util.mjs';
6
+
7
+ const repo = `${GITHUB_TOKEN_URL}/${GITHUB_REPO}.git`;
8
+
9
+ logBin('polkadot-ci-ghact-docs');
10
+
11
+ gitSetup();
12
+
13
+ execPm('run docs');
14
+ execPm(`polkadot-exec-ghpages --dotfiles --repo ${repo} --dist ${process.env['GH_PAGES_SRC']} --dest .`, true);
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2017-2025 @polkadot/dev authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import fs from 'node:fs';
6
+
7
+ import { execGit, logBin } from './util.mjs';
8
+
9
+ logBin('polkadot-ci-ghpages-force');
10
+
11
+ // ensure we are on master
12
+ execGit('checkout master');
13
+
14
+ // checkout latest
15
+ execGit('fetch');
16
+ execGit('checkout gh-pages');
17
+ execGit('pull');
18
+ execGit('checkout --orphan gh-pages-temp');
19
+
20
+ // ignore relevant files
21
+ fs.writeFileSync('.gitignore', `
22
+ .github/
23
+ .vscode/
24
+ .yarn/
25
+ build/
26
+ coverage/
27
+ node_modules/
28
+ packages/
29
+ test/
30
+ NOTES.md
31
+ `);
32
+
33
+ // add
34
+ execGit('add -A');
35
+ execGit('commit -am "refresh history"');
36
+
37
+ // danger, force new
38
+ execGit('branch -D gh-pages');
39
+ execGit('branch -m gh-pages');
40
+ execGit('push -f origin gh-pages');
41
+
42
+ // switch to master
43
+ execGit('checkout master');
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2017-2025 @polkadot/dev authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+
8
+ import { copyDirSync, logBin, rimrafSync } from './util.mjs';
9
+
10
+ logBin('polkadot-dev-build-docs');
11
+
12
+ let docRoot = path.join(process.cwd(), 'docs');
13
+
14
+ if (fs.existsSync(docRoot)) {
15
+ docRoot = path.join(process.cwd(), 'build-docs');
16
+
17
+ rimrafSync(docRoot);
18
+ copyDirSync(path.join(process.cwd(), 'docs'), docRoot);
19
+ }