Skip to content

Commit

Permalink
chore(root): Prevent multi-level imports for @novu/* packages (#6596)
Browse files Browse the repository at this point in the history
  • Loading branch information
rifont authored Oct 4, 2024
1 parent 1142df0 commit d8348b0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Logger } from '@nestjs/common';
import sinon from 'sinon';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
// eslint-disable-next-line no-restricted-imports
import { StripeBillingIntervalEnum, StripeUsageTypeEnum } from '@novu/ee-billing/src/stripe/types';
import { GetFeatureFlag } from '@novu/application-generic';

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/testing/billing/get-prices.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sinon from 'sinon';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
// eslint-disable-next-line no-restricted-imports
import { StripeBillingIntervalEnum } from '@novu/ee-billing/src/stripe/types';

describe('GetPrices', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sinon from 'sinon';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
// eslint-disable-next-line no-restricted-imports
import { StripeBillingIntervalEnum } from '@novu/ee-billing/src/stripe/types';

describe('Upsert setup intent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sinon from 'sinon';
import { CommunityOrganizationRepository, IntegrationRepository } from '@novu/dal';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
// eslint-disable-next-line no-restricted-imports
import { StripeBillingIntervalEnum, StripeUsageTypeEnum } from '@novu/ee-billing/src/stripe/types';

describe('UpsertSubscription', () => {
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/testing/billing/webhook.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sinon from 'sinon';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
// eslint-disable-next-line no-restricted-imports
import { StripeBillingIntervalEnum } from '@novu/ee-billing/src/stripe/types';
import { GetFeatureFlag } from '@novu/application-generic';

Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/layout/components/ListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from '@emotion/styled';
import { IPaginationProps, PageContainer, Pagination, colors } from '@novu/design-system';
import { ITableProps } from '@novu/design-system/dist/types/table/Table';
import { IPaginationProps, PageContainer, Pagination, colors, ITableProps } from '@novu/design-system';
import { ComponentProps, PropsWithChildren } from 'react';
import PageHeader from './PageHeader';

Expand Down
28 changes: 22 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({ baseDirectory: import.meta.dirname });

/**
* REUSED RULE CONFIGURATIONS
*
* This is necessary because Eslint doesn't merge rule configurations
* when they are targeting different paths.
*/

/**
* This rule ensures that "multi-level" imports are not used for `@novu/*` packages.
*/
const noRestrictedImportsMultiLevelNovuPattern = {
group: [
'@novu/*/**/*',
// These packages have legitimate exports 1 path part below the root level
// This flatMap logic ignores the path 1 below the root level and prevents deeper imports.
...['framework', 'js', 'novui'].flatMap((pkg) => [`!@novu/${pkg}/**/*`, `@novu/${pkg}/*/**/*`]),
],
message: "Please import only from the root package entry point. For example, use 'import { Client } from '@novu/node';' instead of 'import { Client } from '@novu/node/src';'",
};

export default tsEslint.config(
/* ******************** RECOMMENDED CONFIG ******************** */
jsEslint.configs.recommended,
Expand Down Expand Up @@ -155,12 +175,7 @@ export default tsEslint.config(
'error',
{
patterns: [
'@novu/shared/*',
'!@novu/shared/utils',
'@novu/dal/*',
'*../libs/dal/*',
'*../packages/shared/*',
'*../libs/stateless/*',
noRestrictedImportsMultiLevelNovuPattern,
],
},
],
Expand Down Expand Up @@ -275,6 +290,7 @@ export default tsEslint.config(
'error',
{
patterns: [
noRestrictedImportsMultiLevelNovuPattern,
{
/**
* This rule ensures that the overridden Swagger decorators are used,
Expand Down
2 changes: 1 addition & 1 deletion libs/design-system/src/table/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Table } from './Table';
export type { IExtendedColumn, IExtendedCellProps, IRow } from './Table';
export type { IExtendedColumn, IExtendedCellProps, IRow, ITableProps } from './Table';
export { withCellLoading } from './withCellLoading';
2 changes: 1 addition & 1 deletion packages/node/src/lib/novu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosInstance } from 'axios';
import { getEnvVariable } from '@novu/shared/utils';
import { getEnvVariable } from '@novu/shared';
import { EventEmitter } from 'events';
import { Subscribers } from './subscribers/subscribers';
import { Changes } from './changes/changes';
Expand Down
1 change: 1 addition & 0 deletions packages/notification-center-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { App } from 'vue';
import FloatingVue from '@novu/floating-vue';
// eslint-disable-next-line no-restricted-imports
import '@novu/floating-vue/dist/style.css';
import { NotificationCenterContentWebComponent } from '@novu/notification-center';

Expand Down

0 comments on commit d8348b0

Please sign in to comment.