Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/no-relative-imports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"scripts": {
"package": "tsc",
"test": "vitest run",
"typecheck:tests": "bash typecheck-tests.sh",
"prepare": "pnpm package"
},
"exports": {
Expand Down
12 changes: 12 additions & 0 deletions packages/no-relative-imports/src/configParsing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* TS Configs... I hate them.
*
* TS Configs can point to other configs in two way:
*
* - `extends`, which is a "super" config that you need to fall back on.
* An important note about "super" configs, is that the paths are relative
* to the folder that the "super" config is in. OR the baseUrl.
* - `references`, which lets you provide an array of TS Configs or directories
* that include TS Configs.
* These configs have different file includes and excludes.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const A = 69;
2 changes: 2 additions & 0 deletions packages/no-relative-imports/test/basic-base-url/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { A } from 'foo';
void A;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./src/",
"paths": {
"foo": ["./foo"]
}
}
}
1 change: 1 addition & 0 deletions packages/no-relative-imports/test/basic/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const A = 69;
2 changes: 2 additions & 0 deletions packages/no-relative-imports/test/basic/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { A } from 'foo';
void A;
7 changes: 7 additions & 0 deletions packages/no-relative-imports/test/basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"foo": ["./src/foo"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"bar": ["./bar"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const B = 69;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const A = 69;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { B } from 'bar';
import { A } from 'foo';
void A;
void B;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./base-config/tsconfig.json",
"compilerOptions": {
"baseUrl": "./src/",
"paths": {
"foo": ["./foo"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"bar": ["../src/bar"]
}
}
}
1 change: 1 addition & 0 deletions packages/no-relative-imports/test/extends/src/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const B = 69;
1 change: 1 addition & 0 deletions packages/no-relative-imports/test/extends/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const A = 69;
6 changes: 6 additions & 0 deletions packages/no-relative-imports/test/extends/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// As far as I can tell now, you can't have paths in a base/super config if you don't have a baseUrl set???
// How does it work for svelte though???....
import { A } from 'foo';
// import { B } from 'bar';
void A;
// void B;
8 changes: 8 additions & 0 deletions packages/no-relative-imports/test/extends/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./base-config/tsconfig.json",
"compilerOptions": {
"paths": {
"foo": ["./src/foo"]
}
}
}
78 changes: 78 additions & 0 deletions packages/no-relative-imports/typecheck-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Exit on any error
set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

# Track if any typecheck fails
FAILED=0

# Check if a specific test case was provided
# Skip the "--" argument if present (from pnpm run)
TEST_CASE="$1"
if [ "$1" = "--" ]; then
TEST_CASE="$2"
fi

if [ -n "$TEST_CASE" ]; then
# Specific test case requested
TEST_DIR="test/$TEST_CASE"

if [ ! -d "$TEST_DIR" ]; then
echo -e "${RED}Error: Test directory '$TEST_DIR' does not exist${NC}"
echo ""
echo "Available test cases:"
for dir in test/*/; do
if [ -f "$dir/tsconfig.json" ]; then
basename "$dir"
fi
done
exit 1
fi

if [ ! -f "$TEST_DIR/tsconfig.json" ]; then
echo -e "${YELLOW}Warning: No tsconfig.json found in '$TEST_DIR'${NC}"
exit 1
fi

echo "Running TypeScript type checking on $TEST_DIR..."
echo ""

if pnpm tsc --noEmit -p "$TEST_DIR"; then
echo -e "${GREEN}✓${NC} $TEST_DIR passed"
exit 0
else
echo -e "${RED}✗${NC} $TEST_DIR failed"
exit 1
fi
else
# Run on all test directories
echo "Running TypeScript type checking on all test directories..."
echo ""

for dir in test/*/; do
if [ -f "$dir/tsconfig.json" ]; then
echo "Checking $dir..."
if pnpm tsc --noEmit -p "$dir"; then
echo -e "${GREEN}✓${NC} $dir passed"
else
echo -e "${RED}✗${NC} $dir failed"
FAILED=1
fi
echo ""
fi
done

if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}All type checks passed!${NC}"
exit 0
else
echo -e "${RED}Some type checks failed${NC}"
exit 1
fi
fi
Loading