-
Notifications
You must be signed in to change notification settings - Fork 42
Fix catalog interactive data module #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ import ts from 'typescript' | |
|
|
||
| const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') | ||
| const casesRoot = path.join(root, 'benchmarks', 'conformance', 'cases') | ||
| const demoDataRoot = path.join(root, 'packages', 'charts-demo-data', 'src') | ||
| const sourceExtensions = ['.ts', '.tsx', '.js', '.jsx', '.json', '.css'] | ||
| const browserModuleExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs'] | ||
| const demoDataPrefixes = ['@charts-poc/demo-data/', '@tanstack/charts-data/'] | ||
| const forbiddenPublicNames = | ||
| /\b(?:Conformance|tanstackCase|tanstackMount|reactMount|catalogPreviewDefinition)\b/ | ||
|
|
||
|
|
@@ -69,6 +72,23 @@ for (const directory of directories) { | |
| } | ||
|
|
||
| for (const specifier of importSpecifiers(source, sourcePath)) { | ||
| const demoDataPrefix = demoDataPrefixes.find((prefix) => | ||
| specifier.startsWith(prefix), | ||
| ) | ||
| if (demoDataPrefix) { | ||
| const demoDataSpecifier = specifier.slice(demoDataPrefix.length) | ||
| const resolved = await resolveImport( | ||
| demoDataRoot, | ||
| `./${demoDataSpecifier}`, | ||
| browserModuleExtensions, | ||
| ) | ||
| if (!resolved) { | ||
| failures.push( | ||
| `${directory}/${relativePath}: demo-data import is not a browser module (${specifier})`, | ||
| ) | ||
| } | ||
| continue | ||
| } | ||
| if (!specifier.startsWith('.')) continue | ||
| const resolved = await resolveImport(path.dirname(sourcePath), specifier) | ||
| if (!resolved) { | ||
|
|
@@ -190,13 +210,13 @@ function importSpecifiers(source, sourcePath) { | |
| return specifiers | ||
| } | ||
|
|
||
| async function resolveImport(parent, specifier) { | ||
| async function resolveImport(parent, specifier, extensions = sourceExtensions) { | ||
| const target = path.resolve(parent, specifier) | ||
| const candidates = path.extname(target) | ||
| ? [target] | ||
| : [ | ||
| ...sourceExtensions.map((extension) => `${target}${extension}`), | ||
| ...sourceExtensions.map((extension) => | ||
| ...extensions.map((extension) => `${target}${extension}`), | ||
| ...extensions.map((extension) => | ||
| path.join(target, `index${extension}`), | ||
| ), | ||
| ] | ||
|
Comment on lines
+213
to
222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- target file outline ---'
ast-grep outline scripts/check-catalog-examples.mjs
printf '%s\n' '--- relevant implementation ---'
sed -n '55,100p;190,250p' scripts/check-catalog-examples.mjs
printf '%s\n' '--- resolveImport call sites ---'
rg -n -C 4 'resolveImport\(' scripts/check-catalog-examples.mjs
printf '%s\n' '--- F-286 references ---'
rg -n -C 5 'F-286|browserModuleExtensions|sourceExtensions|\.d\.ts' API-FRICTION.md scripts/check-catalog-examples.mjsRepository: TanStack/charts Length of output: 9307 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- F-286 details ---'
sed -n '8266,8315p' API-FRICTION.md
printf '%s\n' '--- explicit demo-data imports ---'
rg -n '(`@charts-poc/demo-data`|`@tanstack/charts-data`)/[^"`'\'' ]+\.(json|css|d\.ts|ts|tsx|js|jsx|mjs)(['"`'\'' ]|$)' benchmarks packages scripts --glob '!**/node_modules/**' || true
printf '%s\n' '--- candidate browser-module files in demo data ---'
find packages/charts-demo-data/src -type f \( -name '*.json' -o -name '*.css' -o -name '*.d.ts' -o -name '*.mjs' \) -print 2>/dev/null | sort
printf '%s\n' '--- path.extname behavior and resolver model ---'
node - <<'JS'
import path from 'node:path'
const sourceExtensions = ['.ts', '.tsx', '.js', '.jsx', '.json', '.css']
const browserModuleExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs']
for (const specifier of [
'./foo.json',
'./foo.css',
'./foo.d.ts',
'./foo.ts',
'./foo.mjs',
'./foo',
'./.d.ts',
]) {
const explicitExtension = path.extname(path.resolve('/tmp/parent', specifier))
const current = explicitExtension ? 'explicit target accepted without allow-list check' : 'extension probing'
const proposed =
explicitExtension === ''
? 'extension probing'
: (browserModuleExtensions.includes(explicitExtension) &&
!path.resolve('/tmp/parent', specifier).endsWith('.d.ts')
? 'explicit target allowed'
: 'explicit target rejected')
console.log(JSON.stringify({specifier, explicitExtension, current, proposed}))
}
JSRepository: TanStack/charts Length of output: 1248 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- explicit demo-data imports ---'
rg -n -e '`@charts-poc/demo-data/`[^"'\''[:space:]]+' \
-e '`@tanstack/charts-data/`[^"'\''[:space:]]+' \
benchmarks packages scripts --glob '!**/node_modules/**' || true
printf '%s\n' '--- candidate browser-module files in demo data ---'
find packages/charts-demo-data/src -type f \( -name '*.json' -o -name '*.css' -o -name '*.d.ts' -o -name '*.mjs' \) -print 2>/dev/null | sort
printf '%s\n' '--- path.extname behavior and resolver model ---'
node - <<'JS'
import path from 'node:path'
const browserModuleExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs']
for (const specifier of [
'./foo.json', './foo.css', './foo.d.ts', './foo.ts',
'./foo.mjs', './foo', './.d.ts',
]) {
const target = path.resolve('/tmp/parent', specifier)
const explicitExtension = path.extname(target)
const proposed = explicitExtension === ''
? 'extension probing'
: (browserModuleExtensions.includes(explicitExtension) &&
!target.endsWith('.d.ts')
? 'explicit target allowed'
: 'explicit target rejected')
console.log(JSON.stringify({
specifier,
explicitExtension,
current: explicitExtension
? 'explicit target accepted without allow-list check'
: 'extension probing',
proposed,
}))
}
JSRepository: TanStack/charts Length of output: 50371 Apply When a demo-data specifier has an explicit suffix, 🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/charts
Length of output: 50371
🏁 Script executed:
Repository: TanStack/charts
Length of output: 1264
🏁 Script executed:
Repository: TanStack/charts
Length of output: 4238
🏁 Script executed:
Repository: TanStack/charts
Length of output: 3481
Validate demo-data imports against the package export map.
This branch accepts internal files such as
parse-csvand explicit paths such asanscombe.js, although neither is exported by@charts-poc/demo-data. Validate both aliases against the packageexportskeys before resolving the browser module.🤖 Prompt for AI Agents