polkadot-js / apps

Basic Polkadot/Substrate UI for interacting with a Polkadot and Substrate node. This is the main user-facing application, allowing access to all features available on Substrate chains.
https://dotapps.io
Apache License 2.0
1.74k stars 1.54k forks source link

Opaque error when running `build:typesBundle` #10904

Open timbrinded opened 1 week ago

timbrinded commented 1 week ago

In developing the storage hub chain, we have been testing against a pre-release typesbundle. The PolkadotJS app has been rejecting latest versions of the storage-hub.

The @polkadot/dev process is very idiosyncratic so not apparent what is failing or why.

❯ yarn build:typesBundle
$ polkadot-dev-run-test --env node --loader extensionless typesBundle
$ /home/tim/.nvm/versions/node/v20.14.0/bin/node --no-warnings --enable-source-maps --loader extensionless --require @polkadot/dev-test/node --loader @polkadot/dev-ts/cached /home/tim/workspace/pjs-ui/node_modules/@polkadot/dev/scripts/polkadot-exec-node-test.mjs packages/apps-config/src/api/typesBundle.spec.ts packages/apps-config/src/api/typesBundleCheck.spec.ts

    0:00.000  xx

         x /home/timbo/workspace/pjs-ui/packages/apps-config/src/api/typesBundle.spec.ts
           packages/apps-config/src/api/typesBundle.spec.ts

                 testCodeFailure / ERR_TEST_FAILURE

         x /home/timbo/workspace/pjs-ui/packages/apps-config/src/api/typesBundleCheck.spec.ts
           packages/apps-config/src/api/typesBundleCheck.spec.ts

                 testCodeFailure / ERR_TEST_FAILURE

          passed :: 0
          failed :: 2
         skipped :: 0
            todo :: 0
           total :: 2
         elapsed :: 2.430s

        tests 2
        suites 0
        pass 0
        fail 2
        cancelled 0
        skipped 0
        todo 0
        duration_ms 2428.100591

[!CAUTION]
No indication or why it is failing or how to fix it. Adding console.log() steps similarly don't appear to do anything.

So that latest runtimeApi and RPC methods can be used on the FE

Package: @storagehub/types-bundle : 0.1.4

Node 20 & 22

timbrinded commented 1 day ago

TBH this code can almost entirely be ripped out. I've rewritten the test spec as a normal script, and just run it with tsx.

// Copyright 2017-2024 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

import fs from 'node:fs';

import { objectSpread } from '@polkadot/util';

import chain from './chain/index.js';
import spec from './spec/index.js';

const specEntries = Object.entries(spec);
const chainEntries = Object.entries(chain);
const typesBundle: { chain: Record<string, unknown>, spec: Record<string, unknown> } = { chain: {}, spec: {} };

// Process specs
for (const [k, v] of specEntries) {
  const value = objectSpread<{ derives: unknown }>({}, v);

  delete value.derives;
  typesBundle.spec[k] = value;
}

// Process chains
for (const [k, v] of chainEntries) {
  const value = objectSpread<{ derives: unknown }>({}, v);

  delete value.derives;
  typesBundle.chain[k] = value;
}

// Generate the typesBundle.ts file
const content = `// Copyright 2017-2024 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Do not edit, auto-generated by @polkadot/apps-config

import type { OverrideBundleType } from '@polkadot/types/types';

/* eslint-disable quotes */
/* eslint-disable quote-props */
/* eslint-disable sort-keys */

export const typesBundle = ${JSON.stringify(typesBundle, null, 2)} as unknown as OverrideBundleType;
`;

fs.writeFileSync('packages/apps-config/src/api/typesBundle.ts', content);

console.log('typesBundle.ts has been generated successfully.');

run with: yarn tsx packages/apps-config/src/api/bundleGen.ts