Skip to content

Commit

Permalink
Merge pull request #1325 from input-output-hk/chore/tsc-alias
Browse files Browse the repository at this point in the history
LW-10722 chore: add tsc-alias to make dist/esm files imports complient with latest node.js versions
  • Loading branch information
iccicci authored Jun 12, 2024
2 parents d6b3c7b + 741d794 commit 2b1ac37
Show file tree
Hide file tree
Showing 101 changed files with 276 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
'error',
{
paths: ['lodash'],
patterns: ['@cardano-sdk/*/src/*']
patterns: ['@cardano-sdk/*/src/*', 'lodash/*', '!lodash/*.js']
}
],
'no-shadow': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: 🔨 Build
run: |
yarn install --immutable --inline-builds --mode=skip-build
yarn build
yarn build:cjs
docker build --no-cache .
env:
NODE_OPTIONS: '--max_old_space_size=8192'
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN yarn --immutable --inline-builds --mode=skip-build
COPY packages packages
RUN \
echo "export const unused = 'unused';" > packages/e2e/src/index.ts &&\
NODE_OPTIONS=--max_old_space_size=10240 yarn build
NODE_OPTIONS=--max_old_space_size=10240 yarn build:cjs

FROM nodejs-builder as cardano-services-production-deps
RUN yarn workspaces focus --all --production
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"scripts": {
"build": "yarn workspaces foreach -v run build",
"build:cjs": "yarn workspaces foreach -v run build:cjs",
"circular-deps:check": "yarn workspaces foreach -v run circular-deps:check",
"cleanup-build": "yarn workspaces foreach -v run cleanup && yarn install && yarn workspaces foreach -v run build",
"reinstall": "yarn workspaces foreach -v run cleanup:nm && yarn install",
Expand Down Expand Up @@ -84,6 +85,7 @@
"ts-jest": "^28.0.7",
"ts-node": "^10.0.0",
"ts-node-dev": "^1.1.8",
"tsc-alias": "^1.8.10",
"typedoc": "^0.23.24",
"typedoc-plugin-missing-exports": "^1.0.0",
"typescript": "^4.7.4"
Expand Down
9 changes: 4 additions & 5 deletions packages/cardano-services-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
},
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build:version": "bash -c 'if node ./scripts/createVersionSource.js --check ; then node ./scripts/createVersionSource.js --create && yarn lint:fix ; fi && cp ./package.json ./dist/package.json'",
"build": "yarn build:version && run-s build:cjs build:esm module-fixup",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "yarn build:version && tsc --build src && cp ./package.json dist/ && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"build:version": "bash -c 'if node ./scripts/createVersionSource.js --check ; then node ./scripts/createVersionSource.js --create && yarn lint:fix ; fi'",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"circular-deps:check": "madge --circular dist/cjs",
Expand All @@ -50,6 +48,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/cardano-services-client/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
declare module '*.json';

// exclude from build, as it has to be imported at runtime
declare module '../package.json';
5 changes: 2 additions & 3 deletions packages/cardano-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:cjs": "tsc --build src && chmod +x ./dist/cjs/cli.js",
"build:copy-assets": "bash ./copy-assets.sh",
"build": "run-s build:cjs build:copy-assets",
"build": "yarn build:cjs",
"build:cjs": "tsc --build src && chmod +x ./dist/cjs/cli.js && bash ./copy-assets.sh",
"build:test-db": "./test/jest-setup/rebuild-test-db.sh",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from 'ts-log';
import { TokenMetadataService } from './types';
import { contextLogger } from '@cardano-sdk/util';
import axios, { AxiosInstance } from 'axios';
import pick from 'lodash/pick';
import pick from 'lodash/pick.js';

export const DEFAULT_TOKEN_METADATA_CACHE_TTL = Seconds(10 * 60);
export const DEFAULT_TOKEN_METADATA_REQUEST_TIMEOUT = Milliseconds(3 * 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {
mapTxTokenMap,
mapWithdrawal
} from './mappers';
import omit from 'lodash/omit';
import orderBy from 'lodash/orderBy';
import omit from 'lodash/omit.js';
import orderBy from 'lodash/orderBy.js';

export class ChainHistoryBuilder {
#db: Pool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { QueryResult } from 'pg';
import { TxMetadataService } from '../../Metadata';
import { hexStringToBuffer } from '@cardano-sdk/util';
import { mapBlock, mapTxAlonzo, mapTxIn, mapTxOut } from './mappers';
import orderBy from 'lodash/orderBy';
import orderBy from 'lodash/orderBy.js';

/** Properties that are need to create DbSyncChainHistoryProvider */
export interface ChainHistoryProviderProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Logger } from 'ts-log';
import { NetworkInfoBuilder } from './NetworkInfoBuilder';
import { RunnableModule } from '@cardano-sdk/util';
import { toGenesisParams, toLedgerTip, toProtocolParams, toSupply } from './mappers';
import memoize from 'lodash/memoize';
import memoize from 'lodash/memoize.js';

/** Dependencies that are need to create DbSyncNetworkInfoProvider */
export interface NetworkInfoProviderDependencies extends DbSyncProviderDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { createLogger } from 'bunyan';
import { getConnectionConfig, getOgmiosTxSubmitProvider } from '../services';
import { getEntities } from '../../Projection/prepareTypeormProjection';
import { isNotNil } from '@cardano-sdk/util';
import memoize from 'lodash/memoize';
import memoize from 'lodash/memoize.js';

export const ALLOWED_ORIGINS_DEFAULT = false;
export const DISABLE_DB_CACHE_DEFAULT = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { PromiseOrValue, RunnableModule, resolveObjectValues } from '@cardano-sd
import { StakePoolBuilder } from './StakePoolBuilder';
import { StakePoolMetadataService } from '../types';
import { toStakePoolResults } from './mappers';
import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

/** Properties that are need to create DbSyncStakePoolProvider */
export interface StakePoolProviderProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/cardano-services/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
},
{
"path": "../../util-rxjs/src"
},
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getPort } from 'get-port-please';
import { isNotNil } from '@cardano-sdk/util';
import { logger } from '@cardano-sdk/util-dev';
import axios from 'axios';
import lowerCase from 'lodash/lowerCase';
import lowerCase from 'lodash/lowerCase.js';

const UNSUPPORTED_MEDIA_STRING = 'Request failed with status code 415';
const APPLICATION_CBOR = 'application/cbor';
Expand Down
2 changes: 1 addition & 1 deletion packages/cardano-services/test/data-mocks/tx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Cardano } from '@cardano-sdk/core';
import { Hash28ByteBase16, Hash32ByteBase16 } from '@cardano-sdk/crypto';

import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

export const valueWithCoinOnly: Cardano.Value = {
coins: 7_420_514n
Expand Down
7 changes: 3 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -44,6 +42,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Asset/NftMetadata/fromMetadatum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from 'ts-log';
import { asMetadatumArray, asMetadatumMap } from '../../util/metadatum';
import { asString } from './util';
import { isNotNil } from '@cardano-sdk/util';
import difference from 'lodash/difference';
import difference from 'lodash/difference.js';

const isString = (obj: unknown): obj is string => typeof obj === 'string';
const VersionRegExp = /^\d+\.?\d?$/;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Asset/util/subtractTokenMaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable complexity,sonarjs/cognitive-complexity */
import * as Cardano from '../../Cardano';
import uniq from 'lodash/uniq';
import uniq from 'lodash/uniq.js';

/**
* Given two Cardano.TokenMaps, compute a Cardano.TokenMap with the difference between the left-hand side and the right-hand side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Redeemers } from './Redeemer';
import { SerializationError, SerializationFailure } from '../../errors';
import { VkeyWitness } from './VkeyWitness';
import { hexToBytes } from '../../util/misc';
import _groupBy from 'lodash/groupBy';
import uniqWith from 'lodash/uniqWith';
import _groupBy from 'lodash/groupBy.js';
import uniqWith from 'lodash/uniqWith.js';

/** This type represents the segregated CDDL scripts. */
type CddlScripts = {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/util/slotCalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CustomError } from 'ts-custom-error';
import { EpochNo, NetworkMagics, Slot } from '../Cardano';
import { EraSummary } from '../CardanoNode';
import { NetworkInfoProvider } from '../Provider/NetworkInfoProvider';
import groupBy from 'lodash/groupBy';
import last from 'lodash/last';
import memoize from 'lodash/memoize';
import orderBy from 'lodash/orderBy';
import groupBy from 'lodash/groupBy.js';
import last from 'lodash/last.js';
import memoize from 'lodash/memoize.js';
import orderBy from 'lodash/orderBy.js';

export interface SlotDate {
slot: Slot;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/tokenTransferInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssetProvider } from '../Provider';
import { Inspector, resolveInputs } from './txInspector';
import { coalesceValueQuantities } from './coalesceValueQuantities';
import { subtractValueQuantities } from './subtractValueQuantities';
import uniq from 'lodash/uniq';
import uniq from 'lodash/uniq.js';

export type AssetInfoWithAmount = { amount: Cardano.Lovelace; assetInfo: AssetInfo };

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/util/slotCalc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../src';
import { fromSerializableObject } from '@cardano-sdk/util';

import merge from 'lodash/merge';
import merge from 'lodash/merge.js';

// Era summaries copied from util-dev package.
// Importing directly from util-dev reports Milliseconds types incompatible.
Expand Down
7 changes: 3 additions & 4 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"circular-deps:check": "madge --circular dist/cjs",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -48,6 +46,7 @@
"madge": "^5.0.1",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"peerDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"circular-deps:check": "madge --circular dist/cjs",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -48,6 +46,7 @@
"mock-browser": "^0.92.14",
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"dependencies": {
Expand Down
7 changes: 3 additions & 4 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
"cardano-services:up": "ts-node --transpile-only ../cardano-services/src/cli.ts start-provider-server",
"cardano-services:up:debug": "npx nodemon --legacy-watch --exec 'node -r ts-node/register --inspect=0.0.0.0:9229 ../cardano-services/src/cli.ts start-provider-server'",
"circular-deps:check": "madge --circular dist/cjs",
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand Down Expand Up @@ -171,6 +169,7 @@
"readable-stream": "^3.6.0",
"source-map-loader": "^4.0.1",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typeorm": "^0.3.15",
"typeorm-extension": "^2.7.0",
"typescript": "^4.7.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { createConnectionObject } from '@cardano-ogmios/client';
import { createStubStakePoolProvider } from '@cardano-sdk/util-dev';
import { filter, firstValueFrom } from 'rxjs';
import DeviceConnection from '@cardano-foundation/ledgerjs-hw-app-cardano';
import memoize from 'lodash/memoize';
import memoize from 'lodash/memoize.js';

const isNodeJs = typeof process !== 'undefined' && process.release?.name === 'node';
// tsc doesn't like the 'import' of this package, works with webpack
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { InitializeTxProps } from '@cardano-sdk/tx-construction';
import { TestWallet, networkInfoProviderFactory } from '../factories';
import { getEnv, walletVariables } from '../environment';
import { logger } from '@cardano-sdk/util-dev';
import sortBy from 'lodash/sortBy';
import sortBy from 'lodash/sortBy.js';

const env = getEnv(walletVariables);

Expand Down
8 changes: 4 additions & 4 deletions packages/golden-test-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"circular-deps:check": "madge --circular dist/cjs",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand Down Expand Up @@ -60,6 +58,7 @@
"ts-log": "^2.2.3"
},
"devDependencies": {
"@types/clear": "^0.1.4",
"@types/cli-progress": "^3.9.2",
"@types/fs-extra": "^9.0.12",
"@types/object-hash": "^2.1.1",
Expand All @@ -70,6 +69,7 @@
"npm-run-all": "^4.1.5",
"pkg": "^5.3.0",
"ts-jest": "^28.0.7",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"pkg": {
Expand Down
2 changes: 1 addition & 1 deletion packages/golden-test-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { createLogger } from 'bunyan';
import { ensureDir, writeFile } from 'fs-extra';
import { toSerializableObject } from '@cardano-sdk/util';
import chalk from 'chalk';
import clear from 'clear';
import hash from 'object-hash';
import path from 'path';

const clear = require('clear');
const packageJson = require('../../package.json');

clear();
Expand Down
7 changes: 3 additions & 4 deletions packages/governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
"build:cjs": "tsc --build src",
"build": "run-s build:cjs build:esm module-fixup",
"build": "yarn build:cjs && tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020 && tsc-alias -p src/tsconfig.json --outDir ./dist/esm && cp ../../build/esm-package.json ./dist/esm/package.json",
"build:cjs": "tsc --build src && cp ../../build/cjs-package.json ./dist/cjs/package.json",
"circular-deps:check": "madge --circular dist/cjs",
"module-fixup": "cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
"tscNoEmit": "echo typescript --noEmit command not implemented yet",
"cleanup:dist": "rm -rf dist",
"cleanup:nm": "rm -rf node_modules",
Expand All @@ -45,6 +43,7 @@
"npm-run-all": "^4.1.5",
"ts-jest": "^28.0.7",
"ts-log": "2.2.4",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 2b1ac37

Please sign in to comment.