Skip to content

Commit

Permalink
Enforce relative imports when importing from core (#1616)
Browse files Browse the repository at this point in the history
* Use relative imports instead of aliasing to core

* Changeset
  • Loading branch information
emma-imber authored Oct 15, 2024
1 parent c464008 commit 4c04b4b
Show file tree
Hide file tree
Showing 74 changed files with 146 additions and 129 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-gifts-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Use relative imports when importing from core
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ module.exports = {
'no-use-before-define': ['error', { functions: true, classes: true }],
'import/exports-last': 'error',
'no-else-return': 'error',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['core/*'],
message:
'Paths starting with “core”, are forbidden. Please use a relative path instead',
},
],
},
],
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/merchandising-high.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';
import { isDefined } from 'core/types';
import { isDefined } from '../../src/core/types';
import { breakpoints } from '../fixtures/breakpoints';
import { articles, blogs } from '../fixtures/pages';
import type { GuPage } from '../fixtures/pages/Page';
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/merchandising.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';
import { isDefined } from 'core/types';
import { isDefined } from '../../src/core/types';
import { breakpoints } from '../fixtures/breakpoints';
import { articles, blogs } from '../fixtures/pages';
import type { GuPage } from '../fixtures/pages/Page';
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/mostpop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';
import { isDefined } from 'core/types';
import { isDefined } from '../../src/core/types';
import { testAtBreakpoints } from '../fixtures/breakpoints';
import { articles, blogs } from '../fixtures/pages';
import type { GuPage } from '../fixtures/pages/Page';
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/video-interscroller-progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { once } from 'lodash-es';
import { checkConsent as checkConsentForReporting } from 'core/send-commercial-metrics';
import { checkConsent as checkConsentForReporting } from '../send-commercial-metrics';

const endpoint = window.guardian.config.page.isDev
? '//logs.code.dev-guardianapis.com/log'
Expand Down
10 changes: 5 additions & 5 deletions src/core/messenger/background.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isObject } from '@guardian/libs';
import {
initVideoProgressReporting,
updateVideoProgress,
} from 'core/lib/video-interscroller-progress';
import type { RegisterListener } from 'core/messenger';
import fastdom from 'utils/fastdom-promise';
import {
renderAdvertLabel,
renderStickyScrollForMoreLabel,
} from '../../events/render-advert-label';
import {
initVideoProgressReporting,
updateVideoProgress,
} from '../lib/video-interscroller-progress';
import type { RegisterListener } from '../messenger';

const isGallery = window.guardian.config.page.contentType === 'Gallery';

Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/disable-refresh.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RegisterListener } from 'core/messenger';
import { dfpEnv } from '../../lib/dfp/dfp-env';
import type { RegisterListener } from '../messenger';

// This message is intended to be used with a DFP creative wrapper.
// For reference, the wrapper will post a message, with an iFrameId, like so:
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/full-width.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isBoolean } from '@guardian/libs';
import fastdom from 'fastdom';
import type { RegisterListener } from 'core/messenger';
import type { RegisterListener } from '../messenger';

const fullWidth = (fullWidth: boolean, slotContainer: HTMLElement) =>
fastdom.mutate(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/get-page-targeting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RegisterListener } from 'core/messenger';
import type { RegisterListener } from '../messenger';

/**
* Register a listener for iframes to request shared ad targeting
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/get-page-url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RegisterListener } from 'core/messenger';
import type { RegisterListener } from '../messenger';

const init = (register: RegisterListener): void => {
register(
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/get-stylesheet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject } from '@guardian/libs';
import type { RegisterListener } from 'core/messenger';
import type { RegisterListener } from '../messenger';

interface StylesheetSpecs {
selector: string;
Expand Down
4 changes: 2 additions & 2 deletions src/core/messenger/measure-ad-load.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isObject, isString } from '@guardian/libs';
import { EventTimer } from 'core/event-timer';
import type { RegisterListener } from 'core/messenger';
import { EventTimer } from '../event-timer';
import type { RegisterListener } from '../messenger';

// This message is intended to be used with a GAM creative wrapper.
// For reference, the wrapper will post a message, like so:
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/passback-refresh.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isString } from '@guardian/libs';
import type { RegisterListener } from 'core/messenger';
import { refreshAdvert } from '../../display/load-advert';
import { getAdvertById } from '../../lib/dfp/get-advert-by-id';
import type { RegisterListener } from '../messenger';

const passbackRefresh = (specs: string, adSlot: HTMLElement) => {
const advert = getAdvertById(adSlot.id);
Expand Down
4 changes: 2 additions & 2 deletions src/core/messenger/passback.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { log } from '@guardian/libs';
import { breakpoints } from '@guardian/source/foundations';
import { adSizes } from 'core/ad-sizes';
import type { RegisterListener } from 'core/messenger';
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import { getAdvertById } from 'lib/dfp/get-advert-by-id';
import fastdom from 'utils/fastdom-promise';
import { adSlotIdPrefix } from '../../lib/dfp/dfp-env-globals';
import { adSizes } from '../ad-sizes';
import type { RegisterListener } from '../messenger';

type PassbackMessagePayload = { source: string };

Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/resize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isObject, isString } from '@guardian/libs';
import type { RegisterListener } from 'core/messenger';
import fastdom from 'utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

interface Styles {
width?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RegisterListener } from 'core/messenger';
import type { Viewport } from 'lib/detect/detect-viewport';
import { getViewport } from 'lib/detect/detect-viewport';
import { addEventListener } from 'lib/events';
import fastdom from 'utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

type Respond = (...args: unknown[]) => void;

Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isString } from '@guardian/libs';
import type { RegisterListener } from 'core/messenger';
import fastdom from 'utils/fastdom-promise';
import type { RegisterListener } from '../messenger';

const setType = (adSlotType: string, adSlot: Element) =>
fastdom.mutate(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/messenger/viewport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RegisterPersistentListener, RespondProxy } from 'core/messenger';
import { getViewport } from 'lib/detect/detect-viewport';
import type { Viewport } from 'lib/detect/detect-viewport';
import fastdom from 'utils/fastdom-promise';
import type { RegisterPersistentListener, RespondProxy } from '../messenger';

type IFrameMapValue = {
node: HTMLIFrameElement;
Expand Down
4 changes: 2 additions & 2 deletions src/define/Advert.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as AdSizesType from 'core/ad-sizes';
import { slotSizeMappings as slotSizeMappings_ } from 'core/ad-sizes';
import type * as AdSizesType from '../core/ad-sizes';
import { slotSizeMappings as slotSizeMappings_ } from '../core/ad-sizes';
import { _, Advert, findSmallestAdHeightForSlot } from './Advert';

const { getSlotSizeMapping } = _;
Expand Down
10 changes: 5 additions & 5 deletions src/define/Advert.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { breakpoints as sourceBreakpoints } from '@guardian/source/foundations';
import type { AdSize, SizeMapping, SlotName } from 'core/ad-sizes';
import fastdom from 'utils/fastdom-promise';
import {
createAdSize,
findAppliedSizesForBreakpoint,
slotSizeMappings,
} from 'core/ad-sizes';
import { concatSizeMappings } from 'core/create-ad-slot';
import type { Breakpoint } from 'core/lib/breakpoint';
import fastdom from 'utils/fastdom-promise';
} from '../core/ad-sizes';
import type { AdSize, SizeMapping, SlotName } from '../core/ad-sizes';
import { concatSizeMappings } from '../core/create-ad-slot';
import type { Breakpoint } from '../core/lib/breakpoint';
import { breakpointNameToAttribute } from '../lib/breakpoint-name-to-attribute';
import type { HeaderBiddingSize } from '../lib/header-bidding/prebid-types';
import { buildGoogletagSizeMapping, defineSlot } from './define-slot';
Expand Down
2 changes: 1 addition & 1 deletion src/define/create-advert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@guardian/libs';
import type { SizeMapping } from 'core/ad-sizes';
import type { SizeMapping } from '../core/ad-sizes';
import { reportError } from '../utils/report-error';
import { Advert } from './Advert';

Expand Down
4 changes: 2 additions & 2 deletions src/define/define-slot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SizeMapping } from 'core/ad-sizes';
import { adSizes, createAdSize } from 'core/ad-sizes';
import { toGoogleTagSize } from 'utils/googletag-ad-size';
import type { SizeMapping } from '../core/ad-sizes';
import { adSizes, createAdSize } from '../core/ad-sizes';
import {
buildGoogletagSizeMapping,
collectSizes,
Expand Down
2 changes: 1 addition & 1 deletion src/define/define-slot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { breakpoints as sourceBreakpoints } from '@guardian/source/foundations';
import { once } from 'lodash-es';
import { EventTimer } from 'core';
import type { SizeMapping, SlotName } from 'core/ad-sizes';
import { toGoogleTagSize } from 'utils/googletag-ad-size';
import { getUrlVars } from 'utils/url';
import type { SizeMapping, SlotName } from '../core/ad-sizes';
import { initSlotIas } from './init-slot-ias';

const breakpointViewports: Record<keyof SizeMapping, [number, number]> = {
Expand Down
2 changes: 1 addition & 1 deletion src/display/load-advert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastdom from 'fastdom';
import { EventTimer } from 'core/event-timer';
import { EventTimer } from '../core/event-timer';
import type { Advert } from '../define/Advert';
import { stripDfpAdPrefixFrom } from '../lib/header-bidding/utils';
import { refreshBidsForAd, requestBidsForAd } from './request-bids';
Expand Down
2 changes: 1 addition & 1 deletion src/display/request-bids.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AdSize } from 'core/ad-sizes';
import type { AdSize } from '../core/ad-sizes';
import type { Advert } from '../define/Advert';
import { a9 } from '../lib/header-bidding/a9/a9';
import { prebid } from '../lib/header-bidding/prebid/prebid';
Expand Down
2 changes: 1 addition & 1 deletion src/events/on-slot-load.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { postMessage } from 'core/messenger/post-message';
import { postMessage } from '../core/messenger/post-message';
import { getAdvertById } from '../lib/dfp/get-advert-by-id';

const host = `${window.location.protocol}//${window.location.host}`;
Expand Down
4 changes: 2 additions & 2 deletions src/events/on-slot-render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isString } from '@guardian/libs';
import type { AdSize } from 'core/ad-sizes';
import { createAdSize } from 'core/ad-sizes';
import type { AdSize } from '../core/ad-sizes';
import { createAdSize } from '../core/ad-sizes';
import { getAdvertById } from '../lib/dfp/get-advert-by-id';
import { reportError } from '../utils/report-error';
import { emptyAdvert } from './empty-advert';
Expand Down
4 changes: 2 additions & 2 deletions src/events/on-slot-viewable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { log } from '@guardian/libs';
import { EventTimer } from 'core';
import { outstreamSizes } from 'core/ad-sizes';
import { AD_LABEL_HEIGHT } from 'core/constants/ad-label-height';
import fastdom from 'utils/fastdom-promise';
import { getUrlVars } from 'utils/url';
import { outstreamSizes } from '../core/ad-sizes';
import { AD_LABEL_HEIGHT } from '../core/constants/ad-label-height';
import type { Advert } from '../define/Advert';
import { isAdSize } from '../define/Advert';
import { enableLazyLoad } from '../display/lazy-load';
Expand Down
2 changes: 1 addition & 1 deletion src/events/render-advert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { adSizes } from 'core/ad-sizes';
import { $$ } from 'utils/$$';
import fastdom from 'utils/fastdom-promise';
import { adSizes } from '../core/ad-sizes';
import type { Advert } from '../define/Advert';
import { getAdIframe } from '../lib/dfp/get-ad-iframe';
import { reportError } from '../utils/report-error';
Expand Down
2 changes: 1 addition & 1 deletion src/experiments/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bypassCoreWebVitalsSampling } from '@guardian/core-web-vitals';
import { bypassCommercialMetricsSampling } from 'core/send-commercial-metrics';
import { bypassCommercialMetricsSampling } from '../core/send-commercial-metrics';

export const bypassMetricsSampling = (): void => {
void bypassCommercialMetricsSampling();
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { log } from '@guardian/libs';
import { EventTimer } from 'core/event-timer';
import { adFreeSlotRemove } from 'init/consented/ad-free-slot-remove';
import { init as initComscore } from 'init/consented/comscore';
import { initFillSlotListener } from 'init/consented/fill-slot-listener';
Expand All @@ -19,6 +18,7 @@ import { init as setAdTestInLabelsCookie } from 'init/shared/set-adtest-in-label
import { init as prepareAdVerification } from 'lib/ad-verification/prepare-ad-verification';
import { commercialFeatures } from 'lib/commercial-features';
import { adSlotIdPrefix } from 'lib/dfp/dfp-env-globals';
import { EventTimer } from '../core/event-timer';
import { reportError } from '../utils/report-error';
import { catchErrorsAndReport } from '../utils/robust';
import { initDfpListeners } from './consented/dfp-listeners';
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/ipsos-mori.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
log,
onConsent,
} from '@guardian/libs';
import { ipsosMoriStub } from 'core/__vendor/ipsos-mori';
import { ipsosMoriStub } from '../../core/__vendor/ipsos-mori';

const loadIpsosScript = (locale: 'au' | 'uk') => {
ipsosMoriStub();
Expand Down
28 changes: 14 additions & 14 deletions src/init/consented/messenger.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { init as initMessenger } from 'core/messenger';
import { init as background } from 'core/messenger/background';
import { init as disableRefresh } from 'core/messenger/disable-refresh';
import { init as fullwidth } from 'core/messenger/full-width';
import { init as initGetPageTargeting } from 'core/messenger/get-page-targeting';
import { init as initGetPageUrl } from 'core/messenger/get-page-url';
import { init as getStyles } from 'core/messenger/get-stylesheet';
import { init as initMeasureAdLoad } from 'core/messenger/measure-ad-load';
import { init as passback } from 'core/messenger/passback';
import { init as passbackRefresh } from 'core/messenger/passback-refresh';
import { init as resize } from 'core/messenger/resize';
import { init as scroll } from 'core/messenger/scroll';
import { init as type } from 'core/messenger/type';
import { init as viewport } from 'core/messenger/viewport';
import { init as initMessenger } from '../../core/messenger';
import { init as background } from '../../core/messenger/background';
import { init as disableRefresh } from '../../core/messenger/disable-refresh';
import { init as fullwidth } from '../../core/messenger/full-width';
import { init as initGetPageTargeting } from '../../core/messenger/get-page-targeting';
import { init as initGetPageUrl } from '../../core/messenger/get-page-url';
import { init as getStyles } from '../../core/messenger/get-stylesheet';
import { init as initMeasureAdLoad } from '../../core/messenger/measure-ad-load';
import { init as passback } from '../../core/messenger/passback';
import { init as passbackRefresh } from '../../core/messenger/passback-refresh';
import { init as resize } from '../../core/messenger/resize';
import { init as scroll } from '../../core/messenger/scroll';
import { init as type } from '../../core/messenger/type';
import { init as viewport } from '../../core/messenger/viewport';

/**
* Messenger gets to skip the promise chain and run immediately.
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-a9.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getConsentFor, log, onConsent } from '@guardian/libs';
import { once } from 'lodash-es';
import { a9Apstag } from 'core/__vendor/a9-apstag';
import { commercialFeatures } from 'lib/commercial-features';
import { isGoogleProxy } from 'lib/detect/detect-google-proxy';
import { isInCanada } from 'utils/geo-utils';
import { a9Apstag } from '../../core/__vendor/a9-apstag';
import { a9 } from '../../lib/header-bidding/a9/a9';
import { shouldIncludeOnlyA9 } from '../../lib/header-bidding/utils';

Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-googletag.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ConsentState, USNATConsentState } from '@guardian/libs';
import { getConsentFor, loadScript, onConsent } from '@guardian/libs';
import type * as AdSizesType from 'core/ad-sizes';
import { commercialFeatures } from 'lib/commercial-features';
import _config from 'lib/config';
import { getCurrentBreakpoint as getCurrentBreakpoint_ } from 'lib/detect/detect-breakpoint';
import type * as AdSizesType from '../../core/ad-sizes';
import { loadAdvert } from '../../display/load-advert';
import { dfpEnv } from '../../lib/dfp/dfp-env';
import { init as prepareGoogletag } from './prepare-googletag';
Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-googletag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ConsentState } from '@guardian/libs';
import { getConsentFor, loadScript, log, onConsent } from '@guardian/libs';
import { EventTimer } from 'core/event-timer';
import { getPageTargeting } from 'lib/build-page-targeting';
import { commercialFeatures } from 'lib/commercial-features';
import { getGoogleTagId, isUserLoggedInOktaRefactor } from 'lib/identity/api';
import { EventTimer } from '../../core/event-timer';
import { removeSlots } from './remove-slots';
import { fillStaticAdvertSlots } from './static-ad-slots';

Expand Down
2 changes: 1 addition & 1 deletion src/init/consented/prepare-permutive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Edition } from 'core/types';
import type { Config, PageConfig, Permutive, UserConfig } from 'types/global';
import type { Edition } from '../../core/types';
import { reportError } from '../../utils/report-error';

interface PermutivePageConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/init/consented/static-ad-slots.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isNonNullable, log } from '@guardian/libs';
import type { SizeMapping } from 'core/ad-sizes';
import { adSizes, createAdSize } from 'core/ad-sizes';
import { isUserInVariant } from 'experiments/ab';
import { mpuWhenNoEpic } from 'experiments/tests/mpu-when-no-epic';
import { setupPrebidOnce } from 'init/consented/prepare-prebid';
import { removeDisabledSlots } from 'init/consented/remove-slots';
import { commercialFeatures } from 'lib/commercial-features';
import { getCurrentBreakpoint } from 'lib/detect/detect-breakpoint';
import { isInUk, isInUsa } from 'utils/geo-utils';
import { adSizes, createAdSize } from '../../core/ad-sizes';
import type { SizeMapping } from '../../core/ad-sizes';
import { createAdvert } from '../../define/create-advert';
import { displayAds } from '../../display/display-ads';
import { displayLazyAds } from '../../display/display-lazy-ads';
Expand Down
Loading

0 comments on commit 4c04b4b

Please sign in to comment.