Fix jest alias config (#4377)

* Fix jest alias config

* Dedupe
This commit is contained in:
Jaco
2021-12-22 09:12:02 +02:00
committed by GitHub
parent f11c8f9360
commit f51dbd7df9
10 changed files with 115 additions and 158 deletions
-19
View File
@@ -1,19 +0,0 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable sort-keys */
const alias = {
'^@polkadot/api-(augment|base|derive)(.*)': './packages/api-\\1/src\\2',
'^@polkadot/api(.*)': './packages/api/src/\\1',
'^@polkadot/rpc-(augment|core|provider)(.*)': './packages/rpc-\\1/src\\2',
'^@polkadot/types-(augment-lookup|augment-registry|augment|codec|create|known|metadata|support)(.*)': './packages/types-\\1/src\\2',
'^@polkadot/types(.*)': './packages/types/src\\1'
};
require('@babel/register')({
extensions: ['.js', '.ts'],
plugins: [
['module-resolver', { alias }]
]
});
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = function (file) {
let main;
try {
main = require(`../${file}.cjs`).main;
} catch (error) {
// required for dev-only setups
process.env.JEST_WORKER_ID = '123';
// register aliases
require('@babel/register')({
extensions: ['.js', '.ts'],
plugins: [
['module-resolver', {
alias: {
'^@polkadot/api-(augment|base|derive)(.*)': './packages/api-\\1/src\\2',
// eslint-disable-next-line sort-keys
'^@polkadot/api(.*)': './packages/api/src/\\1',
'^@polkadot/rpc-(augment|core|provider)(.*)': './packages/rpc-\\1/src\\2',
'^@polkadot/types-(augment-lookup|augment-registry|augment|codec|create|known|metadata|support)(.*)': './packages/types-\\1/src\\2',
// eslint-disable-next-line sort-keys
'^@polkadot/types(.*)': './packages/types/src\\1'
}
}]
]
});
// get ts source
main = require(`../src/${file}.ts`).main;
}
main();
};
@@ -2,16 +2,4 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
let main;
try {
main = require('../extractChain.cjs').main;
} catch (error) {
process.env.JEST_WORKER_ID = '123';
require('./aliases.cjs');
main = require('../src/extractChain.ts').main;
}
main();
require('./execWithSrc.cjs')('extractChain');
@@ -2,16 +2,4 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
let main;
try {
main = require('../fromChain.cjs').main;
} catch (error) {
process.env.JEST_WORKER_ID = '123';
require('./aliases.cjs');
main = require('../src/fromChain').main;
}
main();
require('./execWithSrc.cjs')('fromChain');
@@ -2,16 +2,4 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
let main;
try {
main = require('../fromDefs.cjs').main;
} catch (error) {
process.env.JEST_WORKER_ID = '123';
require('./aliases.cjs');
main = require('../src/fromDefs.ts').main;
}
main();
require('./execWithSrc.cjs')('fromDefs');
@@ -2,16 +2,4 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
let main;
try {
main = require('../interfacesTs.cjs').main;
} catch (error) {
process.env.JEST_WORKER_ID = '123';
require('./aliases.cjs');
main = require('../src/interfacesTs.ts').main;
}
main();
require('./execWithSrc.cjs')('interfacesTs');
@@ -2,16 +2,4 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
let main;
try {
main = require('../metadataMd.cjs').main;
} catch (error) {
process.env.JEST_WORKER_ID = '123';
require('./aliases.cjs');
main = require('../src/metadataMd.ts').main;
}
main();
require('./execWithSrc.cjs')('metadataMd');