Skip to content

Commit 37962e8

Browse files
authored
Merge pull request #121 from svelteplot/fix/axis-types
Fix/axis types
2 parents 4dd29de + 28e1e9a commit 37962e8

File tree

234 files changed

+405
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+405
-1305
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"prepack": "npx svelte-package",
2020
"release-next": "npm version prerelease --preid next && npm publish && git push && git push --tags && sleep 1 && npm dist-tag add svelteplot@$(npm view . version) next",
2121
"docs": "npm run build && cd build && rsync --recursive . vis4.net:svelteplot/alpha0/",
22-
"screenshots": "node screenshot-examples.js"
22+
"screenshots": "node screenshot-examples.js",
23+
"check-js-extensions": "node scripts/check-js-extensions.js src"
2324
},
2425
"exports": {
2526
".": {

scripts/check-js-extensions.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
/**
5+
* This script checks for missing .js extensions in import statements.
6+
* It helps identify issues with ESM imports where TypeScript requires .js extensions.
7+
*/
8+
9+
import { readFile, readdir, stat } from 'fs/promises';
10+
import path from 'path';
11+
import { fileURLToPath } from 'url';
12+
13+
// Convert file:// URLs to paths
14+
const __filename = fileURLToPath(import.meta.url);
15+
const __dirname = path.dirname(__filename);
16+
17+
// Regular expressions to match import statements without .js extensions
18+
const regexImportFrom =
19+
/import\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*|[^;{]*)\s+from\s+['"]([^'"]*)['"]/g;
20+
const regexExportFrom =
21+
/export\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*)\s+from\s+['"]([^'"]*)['"]/g;
22+
23+
// Skip node_modules and build directories
24+
const excludedDirs = ['node_modules', 'build', '.svelte-kit', 'dist', '.git', 'examples', 'tests'];
25+
26+
// Only check certain file types
27+
const includedExtensions = ['.ts', '.js', '.svelte'];
28+
29+
// Paths that should have .js extensions (relative paths and alias paths)
30+
const shouldHaveJsExtension = (importPath) => {
31+
// Skip Svelte imports
32+
if (importPath.endsWith('.svelte')) return false;
33+
34+
// Skip npm package imports (those that don't start with . or /)
35+
if (
36+
!importPath.startsWith('.') &&
37+
!importPath.startsWith('/') &&
38+
!importPath.startsWith('$lib')
39+
)
40+
return false;
41+
42+
// Skip imports with extensions already
43+
if (path.extname(importPath)) return false;
44+
45+
return true;
46+
};
47+
48+
async function* walkDirectory(dir) {
49+
const entries = await readdir(dir, { withFileTypes: true });
50+
51+
for (const entry of entries) {
52+
const fullPath = path.join(dir, entry.name);
53+
54+
if (entry.isDirectory()) {
55+
if (!excludedDirs.includes(entry.name)) {
56+
yield* walkDirectory(fullPath);
57+
}
58+
} else if (includedExtensions.includes(path.extname(entry.name))) {
59+
yield fullPath;
60+
}
61+
}
62+
}
63+
64+
async function checkFile(filePath) {
65+
const content = await readFile(filePath, 'utf8');
66+
const issues = [];
67+
68+
// Find all import statements
69+
let match;
70+
71+
// Check import statements
72+
regexImportFrom.lastIndex = 0;
73+
while ((match = regexImportFrom.exec(content)) !== null) {
74+
const importPath = match[1];
75+
if (shouldHaveJsExtension(importPath)) {
76+
issues.push({
77+
line: content.substring(0, match.index).split('\n').length,
78+
importPath,
79+
statement: match[0]
80+
});
81+
}
82+
}
83+
84+
// Check export from statements
85+
regexExportFrom.lastIndex = 0;
86+
while ((match = regexExportFrom.exec(content)) !== null) {
87+
const importPath = match[1];
88+
if (shouldHaveJsExtension(importPath)) {
89+
issues.push({
90+
line: content.substring(0, match.index).split('\n').length,
91+
importPath,
92+
statement: match[0]
93+
});
94+
}
95+
}
96+
97+
return { filePath, issues };
98+
}
99+
100+
async function main() {
101+
const rootDir = process.argv[2] || process.cwd();
102+
console.log(`Checking for missing .js extensions in ${rootDir}...\n`);
103+
104+
let totalIssues = 0;
105+
let filesWithIssues = 0;
106+
107+
for await (const filePath of walkDirectory(rootDir)) {
108+
const { issues } = await checkFile(filePath);
109+
110+
if (issues.length > 0) {
111+
console.log(`\x1b[33m${filePath}\x1b[0m`);
112+
filesWithIssues++;
113+
114+
for (const issue of issues) {
115+
totalIssues++;
116+
console.log(
117+
` Line ${issue.line}: Missing .js extension in import: ${issue.importPath}`
118+
);
119+
console.log(` ${issue.statement}`);
120+
}
121+
console.log('');
122+
}
123+
}
124+
125+
if (totalIssues === 0) {
126+
console.log('\x1b[32mNo missing .js extensions found!\x1b[0m');
127+
} else {
128+
console.log(
129+
`\x1b[31mFound ${totalIssues} missing .js extensions in ${filesWithIssues} files.\x1b[0m`
130+
);
131+
process.exit(1);
132+
}
133+
}
134+
135+
main().catch((err) => {
136+
console.error('Error:', err);
137+
process.exit(1);
138+
});

src/lib/Plot.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<script lang="ts">
1313
import Plot from './core/Plot.svelte';
1414
15-
import type { PlotDefaults, PlotOptions } from './types/index.js';
15+
import type { PlotOptions } from './types/index.js';
1616
1717
// implicit marks
1818
import AxisX from './marks/AxisX.svelte';

src/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ScaleName, ScaleType, ScaledChannelName } from './types.js';
1+
import type { ScaleName, ScaleType, ScaledChannelName } from './types/index.js';
22

33
export const SCALE_TYPES: Record<ScaleName, symbol> = {
44
opacity: Symbol('opacity'),

src/lib/core/FacetAxes.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
scaleType="band"
3737
ticks={fxValues}
3838
tickFormat={(d) => d}
39+
tickFontSize={11}
3940
tickSize={0}
4041
tickPadding={5}
4142
anchor={plot.options.fx.axis}
@@ -53,6 +54,7 @@
5354
scaleType="band"
5455
ticks={fyValues}
5556
tickFormat={(d) => d}
57+
tickFontSize={11}
5658
tickSize={0}
5759
tickPadding={5}
5860
anchor={plot.options.fy.axis}

src/lib/helpers/autoScales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type {
3232
ScaleName,
3333
ScaleOptions,
3434
ScaleType
35-
} from '../types.js';
35+
} from '../types/index.js';
3636
import {
3737
categoricalSchemes,
3838
isCategoricalScheme,

src/lib/helpers/autoTicks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RawValue, ScaleType } from '$lib/types.js';
1+
import type { RawValue, ScaleType } from '$lib/types/index.js';
22
import { maybeTimeInterval } from './time.js';
33
import { extent, range as rangei } from 'd3-array';
44

src/lib/helpers/autoTimeFormat.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Scale } from '$lib/classes/Scale.svelte.js';
2-
import { isDate } from '$lib/helpers/typeChecks';
1+
import type { PlotScale } from '$lib/types/index.js';
2+
import { isDate } from '$lib/helpers/typeChecks.js';
33

44
const DATE_TIME: Intl.DateTimeFormatOptions = {
55
hour: 'numeric',
@@ -32,9 +32,9 @@ const autoFormatMonthYear = (locale: string) => {
3232
return (date: Date) => format(date).replace(' ', '\n');
3333
};
3434

35-
export default function autoTimeFormat(x: Scale, plotWidth: number, plotLocale: string) {
35+
export default function autoTimeFormat(x: PlotScale, plotWidth: number, plotLocale: string) {
3636
const daysPer100Px =
37-
((toNumber(x.domain[1]) - toNumber(x.domain[0])) / plotWidth / 864e5) * 100;
37+
((toNumber(x.domain[1] as Date) - toNumber(x.domain[0] as Date)) / plotWidth / 864e5) * 100;
3838
const format =
3939
daysPer100Px < 1
4040
? autoFormatDateTime(plotLocale)

src/lib/helpers/callWithProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RawValue } from '$lib/types.js';
1+
import type { RawValue } from '$lib/types/index.js';
22

33
type Setter = (v: any) => void;
44

src/lib/helpers/colors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import {
7777
} from 'd3-scale-chromatic';
7878

7979
import { quantize } from 'd3-interpolate';
80-
import type { ColorScheme } from '$lib/types.js';
80+
import type { ColorScheme } from '$lib/types/index.js';
8181

8282
const schemeObservable10 = [
8383
'#4269d0',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy