From f24f939ad6a953924473c5e72d9182cde9428593 Mon Sep 17 00:00:00 2001 From: Kevin Fabre Date: Fri, 21 Jun 2024 09:53:00 +0200 Subject: [PATCH] chore: add path aliases --- package-lock.json | 70 +++++++++++++++++++ packages/visualizations/.eslintrc.js | 5 ++ packages/visualizations/package.json | 2 + packages/visualizations/rollup.config.js | 10 +++ .../src/components/Chart/Chart.svelte | 15 ++-- .../src/components/Chart/datasets.ts | 4 +- .../src/components/Chart/legend.ts | 4 +- .../src/components/Chart/scales.ts | 2 +- .../src/components/Chart/types.ts | 6 +- .../src/components/Chart/utils.ts | 2 +- .../WebGl/ChoroplethGeoJson.svelte | 2 +- .../WebGl/ChoroplethVectorTiles.svelte | 2 +- .../ChoroplethMap/WebGl/MapRender.svelte | 12 ++-- .../src/components/ChoroplethMap/types.ts | 4 +- .../src/components/ChoroplethMap/utils.ts | 2 +- .../src/components/KpiCard/KpiCard.svelte | 6 +- .../src/components/KpiCard/types.ts | 4 +- .../src/components/Legend/ColorsLegend.svelte | 4 +- .../src/components/Legend/types.ts | 2 +- .../src/components/Map/Poi/Poi.svelte | 4 +- .../src/components/Map/Poi/types.ts | 6 +- .../src/components/Map/WebGl/WebGl.svelte | 2 +- .../src/components/Map/WebGl/constants.ts | 2 +- .../src/components/Map/WebGl/types.ts | 2 +- .../src/components/Map/WebGl/utils.ts | 2 +- .../src/components/MarkdownText/types.ts | 2 +- .../Table/Cell/Format/GeoFormat.svelte | 4 +- .../src/components/Table/Table.svelte | 4 +- .../src/components/Table/TableCard.svelte | 4 +- .../src/components/Table/types.ts | 6 +- .../src/components/utils/Card.svelte | 2 +- .../src/components/utils/MiniMap.svelte | 6 +- .../src/components/utils/SourceLink.svelte | 2 +- packages/visualizations/src/index.ts | 34 ++++----- packages/visualizations/tsconfig.json | 8 ++- 35 files changed, 172 insertions(+), 76 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8bf25300c..09c6471ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12850,6 +12850,53 @@ "ms": "^2.1.1" } }, + "node_modules/eslint-import-resolver-typescript": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.1.tgz", + "integrity": "sha512-xgdptdoi5W3niYeuQxKmzVDTATvLYqhpwmykwsh7f6HIOStGWEIL9iqZgQDF9u9OEzrRwR8no5q2VT+bjAujTg==", + "dev": true, + "dependencies": { + "debug": "^4.3.4", + "enhanced-resolve": "^5.12.0", + "eslint-module-utils": "^2.7.4", + "fast-glob": "^3.3.1", + "get-tsconfig": "^4.5.0", + "is-core-module": "^2.11.0", + "is-glob": "^4.0.3" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts/projects/eslint-import-resolver-ts" + }, + "peerDependencies": { + "eslint": "*", + "eslint-plugin-import": "*" + } + }, + "node_modules/eslint-import-resolver-typescript/node_modules/enhanced-resolve": { + "version": "5.17.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.0.tgz", + "integrity": "sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/eslint-import-resolver-typescript/node_modules/tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/eslint-module-utils": { "version": "2.8.1", "dev": true, @@ -14699,6 +14746,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.7.5", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.5.tgz", + "integrity": "sha512-ZCuZCnlqNzjb4QprAzXKdpp/gh6KTxSJuw3IBsPnV/7fV4NxC9ckB+vPTt8w7fJA0TaSD7c55BR47JD6MEDyDw==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/get-value": { "version": "2.0.6", "license": "MIT", @@ -24312,6 +24371,15 @@ "node": ">=8" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/resolve-protobuf-schema": { "version": "2.1.0", "license": "MIT", @@ -29187,6 +29255,7 @@ "devDependencies": { "@babel/core": "^7.13.10", "@babel/preset-env": "^7.13.10", + "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-json": "^4.1.0", @@ -29210,6 +29279,7 @@ "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-prettier": "^8.3.0", + "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-svelte": "^2.35.1", diff --git a/packages/visualizations/.eslintrc.js b/packages/visualizations/.eslintrc.js index cf6a20650..32f9d38d0 100644 --- a/packages/visualizations/.eslintrc.js +++ b/packages/visualizations/.eslintrc.js @@ -3,6 +3,11 @@ module.exports = { browser: true, es2021: true, }, + settings: { + "import/resolver": { + typescript: {} + }, + }, extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', diff --git a/packages/visualizations/package.json b/packages/visualizations/package.json index 6054a44f8..3914a727b 100644 --- a/packages/visualizations/package.json +++ b/packages/visualizations/package.json @@ -44,6 +44,7 @@ "devDependencies": { "@babel/core": "^7.13.10", "@babel/preset-env": "^7.13.10", + "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-json": "^4.1.0", @@ -67,6 +68,7 @@ "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-prettier": "^8.3.0", + "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-svelte": "^2.35.1", diff --git a/packages/visualizations/rollup.config.js b/packages/visualizations/rollup.config.js index 4b97dde0f..50cb1a822 100644 --- a/packages/visualizations/rollup.config.js +++ b/packages/visualizations/rollup.config.js @@ -2,6 +2,7 @@ import svelte from 'rollup-plugin-svelte'; import autoPreprocess from 'svelte-preprocess'; import postcss from 'rollup-plugin-postcss'; import autoprefixer from 'autoprefixer'; +import path from 'path'; // import visualizer from 'rollup-plugin-visualizer'; import { terser } from 'rollup-plugin-terser'; import typescript from '@rollup/plugin-typescript'; @@ -10,13 +11,22 @@ import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import { babel } from '@rollup/plugin-babel'; import replace from '@rollup/plugin-replace'; +import alias from '@rollup/plugin-alias'; import { defineConfig } from 'rollup'; import pkg from './package.json'; const production = !process.env.ROLLUP_WATCH; +const projectRootDir = path.resolve(__dirname); function basePlugins() { return [ + alias({ + entries: { + "components": path.resolve(projectRootDir, 'src/components'), + "stores": path.resolve(projectRootDir, 'src/stores'), + "types": path.resolve(projectRootDir, 'src/types'), + }, + }), svelte({ // enable run-time checks when not in production dev: !production, diff --git a/packages/visualizations/src/components/Chart/Chart.svelte b/packages/visualizations/src/components/Chart/Chart.svelte index 4747fc88a..2ec1eba10 100644 --- a/packages/visualizations/src/components/Chart/Chart.svelte +++ b/packages/visualizations/src/components/Chart/Chart.svelte @@ -3,12 +3,15 @@ import type { ChartConfiguration } from 'chart.js'; import { Chart } from 'chart.js'; import 'chartjs-adapter-luxon'; - import type { DataFrame } from '../types'; - import { generateId } from '../utils'; - import SourceLink from '../utils/SourceLink.svelte'; - import { defaultNumberFormat } from '../utils/formatter'; - import CategoryLegend from '../Legend/CategoryLegend.svelte'; - import type { LegendPositions, CategoryLegend as CategoryLegendType } from '../Legend/types'; + import type { DataFrame } from 'components/types'; + import { generateId } from 'components/utils'; + import SourceLink from 'components/utils/SourceLink.svelte'; + import { defaultNumberFormat } from 'components/utils/formatter'; + import CategoryLegend from 'components/Legend/CategoryLegend.svelte'; + import type { + LegendPositions, + CategoryLegend as CategoryLegendType, + } from 'components/Legend/types'; import { ChartSeriesType } from './types'; import type { ChartProps, diff --git a/packages/visualizations/src/components/Chart/datasets.ts b/packages/visualizations/src/components/Chart/datasets.ts index e1c5a99af..0dc1c45a5 100644 --- a/packages/visualizations/src/components/Chart/datasets.ts +++ b/packages/visualizations/src/components/Chart/datasets.ts @@ -1,13 +1,13 @@ import type { ChartDataset } from 'chart.js'; import type { Options as DataLabelsOptions } from 'chartjs-plugin-datalabels/types/options'; +import { defaultCompactNumberFormat, assureMaxLength } from 'components/utils/formatter'; +import type { DataFrame } from 'components/types'; import type { ChartSeries, DataLabelsConfiguration, FillConfiguration, ScriptableTreemapContext, } from './types'; -import type { DataFrame } from '../types'; -import { defaultCompactNumberFormat, assureMaxLength } from '../utils/formatter'; import { defaultValue, singleChartJsColor, diff --git a/packages/visualizations/src/components/Chart/legend.ts b/packages/visualizations/src/components/Chart/legend.ts index a364162c8..1b900eb69 100644 --- a/packages/visualizations/src/components/Chart/legend.ts +++ b/packages/visualizations/src/components/Chart/legend.ts @@ -1,9 +1,9 @@ import type { LegendOptions, ChartConfiguration, Chart } from 'chart.js'; import type { _DeepPartialObject } from 'chart.js/dist/types/utils'; +import { assureMaxLength } from 'components/utils/formatter'; +import { CATEGORY_ITEM_VARIANT } from 'components/Legend/types'; import type { ChartOptions } from './types'; -import { assureMaxLength } from '../utils/formatter'; import { defaultValue, DEFAULT_GREY_COLOR } from './utils'; -import { CATEGORY_ITEM_VARIANT } from '../Legend/types'; const LEGEND_MAX_LENGTH = 50; diff --git a/packages/visualizations/src/components/Chart/scales.ts b/packages/visualizations/src/components/Chart/scales.ts index 18905a20a..064ff4800 100644 --- a/packages/visualizations/src/components/Chart/scales.ts +++ b/packages/visualizations/src/components/Chart/scales.ts @@ -8,6 +8,7 @@ import type { } from 'chart.js'; import { DateTime } from 'luxon'; import type { DeepPartial } from 'chart.js/dist/types/utils'; +import { assureMaxLength, defaultCompactNumberFormat } from 'components/utils/formatter'; import type { CartesianAxisConfiguration, ChartOptions, @@ -16,7 +17,6 @@ import type { TimeCartesianAxisConfiguration, } from './types'; import { defaultValue, singleChartJsColor } from './utils'; -import { assureMaxLength, defaultCompactNumberFormat } from '../utils/formatter'; const TICK_MAX_LENGTH = 40; diff --git a/packages/visualizations/src/components/Chart/types.ts b/packages/visualizations/src/components/Chart/types.ts index 9c69ce8e0..790914671 100644 --- a/packages/visualizations/src/components/Chart/types.ts +++ b/packages/visualizations/src/components/Chart/types.ts @@ -1,6 +1,6 @@ -import type { Color, DataFrame, Source } from '../types'; -import type { LegendConfiguration } from '../Legend/types'; -import type { Async } from '../../types'; +import type { Async } from 'types'; +import type { Color, DataFrame, Source } from 'components/types'; +import type { LegendConfiguration } from 'components/Legend/types'; export interface ChartOptions { /** Specify label column in DataFrame (mandatory for all charts except Treemap) */ diff --git a/packages/visualizations/src/components/Chart/utils.ts b/packages/visualizations/src/components/Chart/utils.ts index cb93ea0e8..fa9259596 100644 --- a/packages/visualizations/src/components/Chart/utils.ts +++ b/packages/visualizations/src/components/Chart/utils.ts @@ -1,4 +1,4 @@ -import type { Color } from '../types'; +import type { Color } from 'components/types'; export const DEFAULT_GREY_COLOR = '#F0F0F0'; diff --git a/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethGeoJson.svelte b/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethGeoJson.svelte index ce049f724..4d6c99846 100644 --- a/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethGeoJson.svelte +++ b/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethGeoJson.svelte @@ -3,7 +3,7 @@ import type { ExpressionSpecification, SourceSpecification, GestureOptions } from 'maplibre-gl'; import type { BBox, FeatureCollection } from 'geojson'; import { debounce } from 'lodash'; - import type { ColorScale, DataBounds, Color, Source } from '../../types'; + import type { ColorScale, DataBounds, Color, Source } from 'components/types'; import MapRender from './MapRender.svelte'; import { BLANK } from '../mapStyles'; import { diff --git a/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethVectorTiles.svelte b/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethVectorTiles.svelte index 5dbbccf77..dedb6c0a0 100644 --- a/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethVectorTiles.svelte +++ b/packages/visualizations/src/components/ChoroplethMap/WebGl/ChoroplethVectorTiles.svelte @@ -7,7 +7,7 @@ } from 'maplibre-gl'; import type { BBox } from 'geojson'; import { debounce } from 'lodash'; - import type { ColorScale, DataBounds, Color, Source } from '../../types'; + import type { ColorScale, DataBounds, Color, Source } from 'components/types'; import MapRender from './MapRender.svelte'; import { BLANK } from '../mapStyles'; import { diff --git a/packages/visualizations/src/components/ChoroplethMap/WebGl/MapRender.svelte b/packages/visualizations/src/components/ChoroplethMap/WebGl/MapRender.svelte index ec02ee310..604c83f3e 100644 --- a/packages/visualizations/src/components/ChoroplethMap/WebGl/MapRender.svelte +++ b/packages/visualizations/src/components/ChoroplethMap/WebGl/MapRender.svelte @@ -16,13 +16,13 @@ import { onMount } from 'svelte'; import { debounce } from 'lodash'; import type { BBox } from 'geojson'; - import SourceLink from '../../utils/SourceLink.svelte'; + import SourceLink from 'components/utils/SourceLink.svelte'; + import ColorsLegend from 'components/Legend/ColorsLegend.svelte'; + import BackButton from 'components/utils/BackButton.svelte'; + import MiniMap from 'components/utils/MiniMap.svelte'; + import type { ColorScale, DataBounds, Source } from 'components/types'; + import type { LegendVariant } from 'components/Legend/types'; import { computeMaxZoomFromGeoJsonFeatures, getFixedTooltips } from '../utils'; - import ColorsLegend from '../../Legend/ColorsLegend.svelte'; - import BackButton from '../../utils/BackButton.svelte'; - import MiniMap from '../../utils/MiniMap.svelte'; - import type { ColorScale, DataBounds, Source } from '../../types'; - import type { LegendVariant } from '../../Legend/types'; import type { ChoroplethFixedTooltipDescription, MapLayer, diff --git a/packages/visualizations/src/components/ChoroplethMap/types.ts b/packages/visualizations/src/components/ChoroplethMap/types.ts index 152c2d05f..42da60259 100644 --- a/packages/visualizations/src/components/ChoroplethMap/types.ts +++ b/packages/visualizations/src/components/ChoroplethMap/types.ts @@ -1,8 +1,8 @@ import type { Feature, FeatureCollection, Position, BBox } from 'geojson'; import type { FillLayerSpecification, Popup, GestureOptions, LngLatBoundsLike } from 'maplibre-gl'; import type { DebouncedFunc } from 'lodash'; -import type { LegendPositions } from '../Legend/types'; -import type { ColorScale, Color, Source } from '../types'; +import type { LegendPositions } from 'components/Legend/types'; +import type { ColorScale, Color, Source } from 'components/types'; export interface ChoroplethOptions { /** Configuration for the color scale used to color the choropleth shapes. */ diff --git a/packages/visualizations/src/components/ChoroplethMap/utils.ts b/packages/visualizations/src/components/ChoroplethMap/utils.ts index 9af44367c..3ae61f24a 100644 --- a/packages/visualizations/src/components/ChoroplethMap/utils.ts +++ b/packages/visualizations/src/components/ChoroplethMap/utils.ts @@ -4,8 +4,8 @@ import maplibregl, { ExpressionInputType, ExpressionSpecification } from 'maplib import { viewport } from '@placemarkio/geo-viewport'; import type { Feature, FeatureCollection, Position, BBox } from 'geojson'; import type { Scale } from 'chroma-js'; +import { assertUnreachable } from 'components/utils'; import { DEFAULT_COLORS } from './constants'; -import { assertUnreachable } from '../utils'; import { Color, ColorScale, diff --git a/packages/visualizations/src/components/KpiCard/KpiCard.svelte b/packages/visualizations/src/components/KpiCard/KpiCard.svelte index 11b468f73..38b811e31 100644 --- a/packages/visualizations/src/components/KpiCard/KpiCard.svelte +++ b/packages/visualizations/src/components/KpiCard/KpiCard.svelte @@ -1,8 +1,8 @@