Skip to content

Commit

Permalink
Merge pull request #12224 from bbc/1453-update-imports
Browse files Browse the repository at this point in the history
WSTEAM1-1453  Update imports to resolve all import/no-relative-packages errors
  • Loading branch information
Louis-Matsika authored Dec 11, 2024
2 parents a3ad68b + 3f7a211 commit f02d40d
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 80 deletions.
6 changes: 6 additions & 0 deletions dirAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const resolvePath = relativePath => path.resolve(appDirectory, relativePath);
module.exports = {
webpackDirAlias: {
'#app': resolvePath('src/app'),
'#src': resolvePath('src'),
'#nextjs': resolvePath('ws-nextjs-app/'),
'#contexts': resolvePath('src/app/contexts'),
'#components': resolvePath('src/app/legacy/components'),
'#containers': resolvePath('src/app/legacy/containers'),
Expand All @@ -23,6 +25,8 @@ module.exports = {
},
jestDirAlias: {
'^#app(.*)$': '<rootDir>/src/app$1',
'^#src(.*)$': '<rootDir>/src$1',
'^#nextjs(.*)$': '<rootDir>/ws-nextjs-app$1',
'^#contexts(.*)$': '<rootDir>/src/app/contexts$1',
'^#components(.*)$': '<rootDir>/src/app/legacy/components$1',
'^#containers(.*)$': '<rootDir>/src/app/legacy/containers$1',
Expand All @@ -39,6 +43,8 @@ module.exports = {
eslintDirAlias: {
map: [
['#app', './src/app'],
['#src', './src'],
['#nextjs', './ws-nextjs-app'],
['#contexts', './src/app/contexts'],
['#components', './src/app/legacy/components'],
['#containers', './src/app/legacy/containers'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Post } from '../../../../../ws-nextjs-app/pages/[service]/live/[id]/Post/types';
import { Post } from '#nextjs/pages/[service]/live/[id]/Post/types';
import { samplePost, twitterSamplePost, videoSamplePost } from './fixtures';
import getLiveBlogPostingSchema from '.';

Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/seoUtils/getLiveBlogPostingSchema/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import buildIChefURL from '#app/lib/utilities/ichefURL';
import { OptimoBlock } from '#app/models/types/optimo';
import { Post } from '../../../../../ws-nextjs-app/pages/[service]/live/[id]/Post/types';
import { Post } from '#nextjs/pages/[service]/live/[id]/Post/types';

export default ({
posts,
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/utilities/getBrandedImage/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnvConfig } from '../getEnvConfig';
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';

const getBrandedImage = (locator, service) =>
`${
Expand Down
13 changes: 7 additions & 6 deletions src/app/routes/article/getInitialData/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Agent } from 'undici';
import * as getOnwardsPageData from '../utils/getOnwardsData';
import * as fetchPageData from '../../utils/fetchPageData';
import nodeLogger from '../../../../testHelpers/loggerMock';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import * as getOnwardsPageData from '#app/routes/article/utils/getOnwardsData';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import pidginArticleWithLatestMedia from '#data/pidgin/articles/cw0x29n2pvqo.json';
import { ARTICLE_PAGE } from '#app/routes/utils/pageTypes';
import nodeLogger from '#src/testHelpers/loggerMock';

import getInitialData from '.';
import pidginArticleWithLatestMedia from '../../../../../data/pidgin/articles/cw0x29n2pvqo.json';
import { ARTICLE_PAGE } from '../../utils/pageTypes';

process.env.BFF_PATH = 'https://mock-bff-path';

Expand Down
25 changes: 14 additions & 11 deletions src/app/routes/article/getInitialData/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import pipe from 'ramda/src/pipe';
import nodeLogger from '../../../lib/logger.node';
import { Services, Toggles, Variants } from '../../../models/types/global';
import getOnwardsPageData from '../utils/getOnwardsData';
import addAnalyticsCounterName from '../utils/addAnalyticsCounterName';
import augmentWithDisclaimer from '../utils/augmentWithDisclaimer';
import { advertisingAllowed, isSfv } from '../utils/paramChecks';
import { FetchError, GetAgent } from '../../../models/types/fetch';
import handleError from '../../utils/handleError';
import fetchDataFromBFF from '../../utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import certsRequired from '../../utils/certsRequired';
import nodeLogger from '#lib/logger.node';
import { Services, Toggles, Variants } from '#models/types/global';
import getOnwardsPageData from '#app/routes/article/utils/getOnwardsData';
import addAnalyticsCounterName from '#app/routes/article/utils/addAnalyticsCounterName';
import augmentWithDisclaimer from '#app/routes/article/utils/augmentWithDisclaimer';
import {
advertisingAllowed,
isSfv,
} from '#app/routes/article/utils/paramChecks';
import { FetchError, GetAgent } from '#models/types/fetch';
import handleError from '#app/routes/utils/handleError';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import certsRequired from '#app/routes/utils/certsRequired';

const logger = nodeLogger(__filename);

Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/article/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
FEATURE_INDEX_PAGE,
} from '#app/routes/utils/pageTypes';
import { Article } from '#app/models/types/optimo';
import getInitialData from './getInitialData';
import getInitialData from '#app/routes/article/getInitialData';

type SupportedPageTypes =
| typeof ARTICLE_PAGE
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/article/utils/getOnwardsData.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Agent } from 'undici';
import recommendationsJson from '#data/mundo/recommendations/index.json';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import hasArticleRecommendations from './hasArticleRecommendations';
import getOnwardsPageData from './getOnwardsData';
import * as fetchPageData from '../../utils/fetchPageData';

jest.mock('./hasArticleRecommendations', () => jest.fn());

Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/article/utils/getOnwardsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import isEmpty from 'ramda/src/isEmpty';
import { DATA_FETCH_ERROR } from '#lib/logger.const';
import getRecommendationsUrl from '#app/lib/utilities/getUrlHelpers/getRecommendationsUrl';
import { SECONDARY_DATA_TIMEOUT } from '#app/lib/utilities/getFetchTimeouts';
import fetchPageData from '../../utils/fetchPageData';
import nodeLogger from '../../../lib/logger.node';
import fetchPageData from '#app/routes/utils/fetchPageData';
import nodeLogger from '#app/lib/logger.node';
import hasArticleRecommendations from './hasArticleRecommendations';

const logger = nodeLogger(__filename);
Expand Down
8 changes: 4 additions & 4 deletions src/app/routes/frontPage/getInitialData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import addIdsToGroups from '#app/routes/utils/sharedDataTransformers/addIdsToGro
import filterGroupsWithoutStraplines from '#app/routes/utils/sharedDataTransformers/filterGroupsWithoutStraplines';
import handleError from '#app/routes/utils/handleError';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import getErrorStatusCode from '../../utils/fetchPageData/utils/getErrorStatusCode';
import { CPS_ASSET } from '../../utils/pageTypes';
import nodeLogger from '../../../lib/logger.node';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import { CPS_ASSET } from '#app/routes/utils/pageTypes';
import nodeLogger from '#app/lib/logger.node';
import { BFF_FETCH_ERROR } from '#app/lib/logger.const';

const logger = nodeLogger(__filename);

Expand Down
8 changes: 4 additions & 4 deletions src/app/routes/frontPage/getInitialData/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import frontPageJsonSerbian from '#data/serbian/frontpage/lat.json';
import radioScheduleJson from '#data/hausa/bbc_hausa_radio/schedule.json';
import { CPS_ASSET as pageType } from '../../utils/pageTypes';
import * as fetchPageData from '../../utils/fetchPageData';
import nodeLogger from '../../../../testHelpers/loggerMock';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import { CPS_ASSET as pageType } from '#app/routes/utils/pageTypes';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import { BFF_FETCH_ERROR } from '#app/lib/logger.const';
import nodeLogger from '#src/testHelpers/loggerMock';
import getInitialData from '.';

jest.mock('#app/lib/utilities/onClient', () =>
Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/homePage/getInitialData/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Agent } from 'undici';
import KyrgyzHomeFixture from '#data/kyrgyz/homePage/index.json';
import * as fetchPageData from '../../utils/fetchPageData';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import { HOME_PAGE } from '#app/routes/utils/pageTypes';
import getInitialData from '.';
import { HOME_PAGE } from '../../utils/pageTypes';

process.env.BFF_PATH = 'https://mock-bff-path';

Expand Down
10 changes: 5 additions & 5 deletions src/app/routes/homePage/getInitialData/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { InitialDataProps } from '#app/models/types/initialData';
import nodeLogger from '../../../lib/logger.node';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import { FetchError } from '../../../models/types/fetch';
import fetchDataFromBFF from '../../utils/fetchDataFromBFF';
import { HOME_PAGE } from '../../utils/pageTypes';
import nodeLogger from '#app/lib/logger.node';
import { BFF_FETCH_ERROR } from '#app/lib/logger.const';
import { FetchError } from '#app/models/types/fetch';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import { HOME_PAGE } from '#app/routes/utils/pageTypes';

const logger = nodeLogger(__filename);

Expand Down
7 changes: 4 additions & 3 deletions src/app/routes/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import sportArticlePageJson from '#data/sport/judo/articles/cj80n66ddnko.json';
import mediaAssetPageJson from '#data/yoruba/cpsAssets/media-23256797.json';

import { ERROR_PAGE, FRONT_PAGE } from '#app/routes/utils/pageTypes';
import * as fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import gahuzaOnDemandAudio from '#data/gahuza/bbc_gahuza_radio/p02pcb5c.json';
// eslint-disable-next-line import/order
import routes from '.';
import {
act,
render,
screen,
} from '../components/react-testing-library-with-providers';
import { suppressPropWarnings } from '../legacy/psammead/psammead-test-helpers/src';
import * as fetchDataFromBFF from './utils/fetchDataFromBFF';
} from '#app/components/react-testing-library-with-providers';
import { suppressPropWarnings } from '#psammead/psammead-test-helpers/src';

global.performance.getEntriesByName = jest.fn(() => []);

Expand Down
10 changes: 5 additions & 5 deletions src/app/routes/liveRadio/getInitialData/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'ramda/src/path';
import getErrorStatusCode from '../../utils/fetchPageData/utils/getErrorStatusCode';
import { LIVE_RADIO_PAGE } from '../../utils/pageTypes';
import fetchDataFromBFF from '../../utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import nodeLogger from '../../../lib/logger.node';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import { LIVE_RADIO_PAGE } from '#app/routes/utils/pageTypes';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import nodeLogger from '#lib/logger.node';

const logger = nodeLogger(__filename);
const getScheduleToggle = path(['liveRadioSchedule', 'enabled']);
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/liveRadio/getInitialData/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import liveRadioJson from '#data/korean/bbc_korean_radio/liveradio.json';
import { LIVE_RADIO_PAGE } from '#app/routes/utils/pageTypes';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import getInitialData from '.';
import * as fetchPageData from '../../utils/fetchPageData';

fetch.mockResponse(JSON.stringify(liveRadioJson));

Expand Down
12 changes: 6 additions & 6 deletions src/app/routes/mostRead/getInitialData/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import getErrorStatusCode from '../../utils/fetchPageData/utils/getErrorStatusCode';
import { MOST_READ_PAGE } from '../../utils/pageTypes';
import handleError from '../../utils/handleError';
import fetchDataFromBFF from '../../utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import nodeLogger from '../../../lib/logger.node';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import { MOST_READ_PAGE } from '#app/routes/utils/pageTypes';
import handleError from '#app/routes/utils/handleError';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import nodeLogger from '#lib/logger.node';

const logger = nodeLogger(__filename);

Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/mostRead/getInitialData/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MOST_READ_PAGE } from '#app/routes/utils/pageTypes';
import * as fetchPageData from '../../utils/fetchPageData';
import mostReadJson from '../../../../../data/pidgin/mostRead/index.json';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import mostReadJson from '#data/pidgin/mostRead/index.json';
import getInitialData from '.';

process.env.BFF_PATH = 'https://mock-bff-path';
Expand Down
6 changes: 3 additions & 3 deletions src/app/routes/onDemandAudio/getInitialData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { InitialDataProps } from '#app/models/types/initialData';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import overrideRendererOnTest from '#app/routes/utils/overrideRendererOnTest';
import isTest from '#app/lib/utilities/isTest';
import getErrorStatusCode from '../../utils/fetchPageData/utils/getErrorStatusCode';
import { getPodcastExternalLinks } from '../tempData/podcastExternalLinks';
import nodeLogger from '../../../lib/logger.node';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import { getPodcastExternalLinks } from '#app/routes/onDemandAudio/tempData/podcastExternalLinks';
import nodeLogger from '#lib/logger.node';

const logger = nodeLogger(__filename);
const getScheduleToggle = path(['onDemandRadioSchedule', 'enabled']);
Expand Down
12 changes: 6 additions & 6 deletions src/app/routes/topic/getInitialData/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Url from 'url-parse';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import nodeLogger from '../../../lib/logger.node';
import getErrorStatusCode from '../../utils/fetchPageData/utils/getErrorStatusCode';
import fetchDataFromBFF from '../../utils/fetchDataFromBFF';
import { TOPIC_PAGE } from '../../utils/pageTypes';
import isTest from '../../../lib/utilities/isTest';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import nodeLogger from '#lib/logger.node';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import fetchDataFromBFF from '#app/routes/utils/fetchDataFromBFF';
import { TOPIC_PAGE } from '#app/routes/utils/pageTypes';
import isTest from '#lib/utilities/isTest';

const logger = nodeLogger(__filename);

Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/topic/getInitialData/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assocPath from 'ramda/src/assocPath';
import * as fetchPageData from '../../utils/fetchPageData';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import { TOPIC_PAGE } from '#app/routes/utils/pageTypes';
import getInitialData from '.';
import { TOPIC_PAGE } from '../../utils/pageTypes';

process.env.BFF_PATH = 'https://mock-bff-path';

Expand Down
6 changes: 3 additions & 3 deletions src/app/routes/utils/fetchDataFromBFF/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Agent } from 'undici';
import fetchDataFromBFF from '.';
import {
ARTICLE_PAGE,
CPS_ASSET,
HOME_PAGE,
MOST_READ_PAGE,
TOPIC_PAGE,
} from '../pageTypes';
import * as fetchPageData from '../fetchPageData';
} from '#app/routes/utils/pageTypes';
import * as fetchPageData from '#app/routes/utils/fetchPageData';
import fetchDataFromBFF from '.';

jest.mock('../fetchPageData', () =>
jest.fn().mockImplementation(() => {
Expand Down
18 changes: 9 additions & 9 deletions src/app/routes/utils/fetchDataFromBFF/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import constructPageFetchUrl from '../constructPageFetchUrl';
import getEnvironment from '../getEnvironment';
import { Services, Variants, PageTypes } from '../../../models/types/global';
import fetchPageData from '../fetchPageData';
import getErrorStatusCode from '../fetchPageData/utils/getErrorStatusCode';
import { BFF_FETCH_ERROR } from '../../../lib/logger.const';
import { FetchError, GetAgent } from '../../../models/types/fetch';
import nodeLogger from '../../../lib/logger.node';
import certsRequired from '../certsRequired';
import constructPageFetchUrl from '#app/routes/utils/constructPageFetchUrl';
import getEnvironment from '#app/routes/utils/getEnvironment';
import { Services, Variants, PageTypes } from '#models/types/global';
import fetchPageData from '#app/routes/utils/fetchPageData';
import getErrorStatusCode from '#app/routes/utils/fetchPageData/utils/getErrorStatusCode';
import { BFF_FETCH_ERROR } from '#lib/logger.const';
import { FetchError, GetAgent } from '#models/types/fetch';
import nodeLogger from '#lib/logger.node';
import certsRequired from '#app/routes/utils/certsRequired';

const logger = nodeLogger(__filename);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import services from '../../../../../../lib/config/services/loadableConfig';
import services from '#lib/config/services/loadableConfig';

export default url => {
const [service] = url.split('/').filter(Boolean);
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"noFallthroughCasesInSwitch": true,
"paths": {
"#app/*": ["src/app/*"],
"#src/*": ["src/*"],
"#nextjs/*": ["ws-nextjs-app/*"],
"#contexts/*": ["src/app/contexts/*"],
"#components/*": ["src/app/legacy/components/*"],
"#containers/*": ["src/app/legacy/containers/*"],
Expand Down

0 comments on commit f02d40d

Please sign in to comment.