refactor: add src alias to @/
This commit is contained in:
parent
f4649e0dac
commit
2581a8e0e6
|
|
@ -25,7 +25,8 @@ npx vitest run -t "should detect horizontal win for X"
|
||||||
|
|
||||||
### Imports
|
### Imports
|
||||||
- Use **double quotes** for local imports, **single quotes** for npm packages
|
- Use **double quotes** for local imports, **single quotes** for npm packages
|
||||||
- No path aliases — use relative `../` and `./` paths
|
- Use `@/**/*` for `./src/**/*` import alias
|
||||||
|
- Use `@/index` for code in `samples`
|
||||||
|
|
||||||
### Formatting
|
### Formatting
|
||||||
- **4-space indentation**
|
- **4-space indentation**
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {entity, Entity} from "../utils/entity";
|
import {entity, Entity} from "@/utils/entity";
|
||||||
import {
|
import {
|
||||||
Command,
|
Command,
|
||||||
CommandRegistry,
|
CommandRegistry,
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
createCommandRunnerContext,
|
createCommandRunnerContext,
|
||||||
parseCommandSchema,
|
parseCommandSchema,
|
||||||
registerCommand
|
registerCommand
|
||||||
} from "../utils/command";
|
} from "@/utils/command";
|
||||||
|
|
||||||
export interface IGameContext<TState extends Record<string, unknown> = {} > {
|
export interface IGameContext<TState extends Record<string, unknown> = {} > {
|
||||||
state: Entity<TState>;
|
state: Entity<TState>;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {Entity} from "../utils/entity";
|
import {Entity} from "@/utils/entity";
|
||||||
import {Region} from "./region";
|
import {Region} from "./region";
|
||||||
import {RNG} from "../utils/rng";
|
import {RNG} from "@/utils/rng";
|
||||||
|
|
||||||
export type Part = {
|
export type Part = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {Entity} from "../utils/entity";
|
import {Entity} from "@/utils/entity";
|
||||||
import {Part} from "./part";
|
import {Part} from "./part";
|
||||||
import {RNG} from "../utils/rng";
|
import {RNG} from "@/utils/rng";
|
||||||
|
|
||||||
export type Region = {
|
export type Region = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
import {createGameCommandRegistry} from '../';
|
import {createGameCommandRegistry, Part, Entity, entity, Region} from '@/index';
|
||||||
import type { Part } from '../';
|
|
||||||
import {Entity, entity} from "../";
|
|
||||||
import {Region} from "../";
|
|
||||||
|
|
||||||
const BOARD_SIZE = 3;
|
const BOARD_SIZE = 3;
|
||||||
const MAX_TURNS = BOARD_SIZE * BOARD_SIZE;
|
const MAX_TURNS = BOARD_SIZE * BOARD_SIZE;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import type {CommandResult, CommandRunner, CommandRunnerContext, PromptEvent} fr
|
||||||
import { parseCommand } from './command-parse';
|
import { parseCommand } from './command-parse';
|
||||||
import { applyCommandSchema } from './command-validate';
|
import { applyCommandSchema } from './command-validate';
|
||||||
import { parseCommandSchema } from './schema-parse';
|
import { parseCommandSchema } from './schema-parse';
|
||||||
import {AsyncQueue} from "../async-queue";
|
import {AsyncQueue} from "@/utils/async-queue";
|
||||||
|
|
||||||
export type CommandRegistry<TContext> = Map<string, CommandRunner<TContext, unknown>>;
|
export type CommandRegistry<TContext> = Map<string, CommandRunner<TContext, unknown>>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { createGameContext, createGameCommand, createGameCommandRegistry, IGameContext } from '../../src/core/game';
|
import { createGameContext, createGameCommand, createGameCommandRegistry } from '@/core/game';
|
||||||
import { Entity } from '../../src/utils/entity';
|
import type { PromptEvent } from '@/utils/command';
|
||||||
import type { PromptEvent } from '../../src/utils/command';
|
|
||||||
|
|
||||||
type MyState = {
|
type MyState = {
|
||||||
score: number;
|
score: number;
|
||||||
|
|
@ -77,7 +76,7 @@ describe('createGameContext', () => {
|
||||||
|
|
||||||
describe('createGameCommand', () => {
|
describe('createGameCommand', () => {
|
||||||
it('should run a command with access to game context', async () => {
|
it('should run a command with access to game context', async () => {
|
||||||
const { registry } = createGameCommandRegistry<Entity<{ marker: string }>>();
|
const { registry } = createGameCommandRegistry<{ marker: string }>();
|
||||||
const ctx = createGameContext(registry, { marker: '' });
|
const ctx = createGameContext(registry, { marker: '' });
|
||||||
|
|
||||||
createGameCommand(registry, 'set-marker <id>', async function (cmd) {
|
createGameCommand(registry, 'set-marker <id>', async function (cmd) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { applyAlign, shuffle, type Region, type RegionAxis } from '../../src/core/region';
|
import { applyAlign, shuffle, type Region, type RegionAxis } from '@/core/region';
|
||||||
import { createRNG } from '../../src/utils/rng';
|
import { createRNG } from '@/utils/rng';
|
||||||
import { entity, Entity } from '../../src/utils/entity';
|
import { entity, Entity } from '@/utils/entity';
|
||||||
import { type Part } from '../../src/core/part';
|
import { type Part } from '@/core/part';
|
||||||
|
|
||||||
describe('Region', () => {
|
describe('Region', () => {
|
||||||
function createTestRegion(axes: RegionAxis[], parts: Part[]): Entity<Region> {
|
function createTestRegion(axes: RegionAxis[], parts: Part[]): Entity<Region> {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import {
|
||||||
createInitialState,
|
createInitialState,
|
||||||
TicTacToeState,
|
TicTacToeState,
|
||||||
WinnerType, PlayerType
|
WinnerType, PlayerType
|
||||||
} from '../../src/samples/tic-tac-toe';
|
} from '@/samples/tic-tac-toe';
|
||||||
import {Entity} from "../../src/utils/entity";
|
import {Entity} from "@/utils/entity";
|
||||||
import {createGameContext} from "../../src";
|
import {createGameContext} from "@/";
|
||||||
import type { PromptEvent } from '../../src/utils/command';
|
import type { PromptEvent } from '@/utils/command';
|
||||||
|
|
||||||
function createTestContext() {
|
function createTestContext() {
|
||||||
const ctx = createGameContext(registry, createInitialState);
|
const ctx = createGameContext(registry, createInitialState);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { AsyncQueue } from '../../src/utils/async-queue';
|
import { AsyncQueue } from '@/utils/async-queue';
|
||||||
|
|
||||||
describe('AsyncQueue', () => {
|
describe('AsyncQueue', () => {
|
||||||
describe('push', () => {
|
describe('push', () => {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
validateCommand,
|
validateCommand,
|
||||||
parseCommand,
|
parseCommand,
|
||||||
type CommandSchema,
|
type CommandSchema,
|
||||||
} from '../../src/utils/command';
|
} from '@/utils/command';
|
||||||
|
|
||||||
describe('parseCommandSchema with inline-schema', () => {
|
describe('parseCommandSchema with inline-schema', () => {
|
||||||
it('should parse schema with typed params', () => {
|
it('should parse schema with typed params', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { parseCommandSchema } from '../../src/utils/command/schema-parse';
|
import { parseCommandSchema } from '@/utils/command/schema-parse';
|
||||||
import {
|
import {
|
||||||
createCommandRegistry,
|
createCommandRegistry,
|
||||||
registerCommand,
|
registerCommand,
|
||||||
|
|
@ -10,8 +10,8 @@ import {
|
||||||
createCommandRunnerContext,
|
createCommandRunnerContext,
|
||||||
type CommandRegistry,
|
type CommandRegistry,
|
||||||
type CommandRunnerContextExport,
|
type CommandRunnerContextExport,
|
||||||
} from '../../src/utils/command/command-registry';
|
} from '@/utils/command/command-registry';
|
||||||
import type { CommandRunner, PromptEvent } from '../../src/utils/command/command-runner';
|
import type { CommandRunner, PromptEvent } from '@/utils/command/command-runner';
|
||||||
|
|
||||||
type TestContext = {
|
type TestContext = {
|
||||||
counter: number;
|
counter: number;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { parseCommand, parseCommandSchema, validateCommand } from '../../src/utils/command';
|
import { parseCommand, parseCommandSchema, validateCommand } from '@/utils/command';
|
||||||
|
|
||||||
describe('parseCommandSchema', () => {
|
describe('parseCommandSchema', () => {
|
||||||
it('should parse empty schema', () => {
|
it('should parse empty schema', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { parseCommand, type Command } from '../../src/utils/command';
|
import { parseCommand, type Command } from '@/utils/command';
|
||||||
|
|
||||||
describe('parseCommand', () => {
|
describe('parseCommand', () => {
|
||||||
it('should parse empty string', () => {
|
it('should parse empty string', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { createEntityCollection, Entity, entity } from '../../src/utils/entity';
|
import { createEntityCollection, Entity, entity } from '@/utils/entity';
|
||||||
|
|
||||||
type TestEntity = {
|
type TestEntity = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { createRNG } from '../../src/utils/rng';
|
import { createRNG } from '@/utils/rng';
|
||||||
|
|
||||||
describe('createRNG', () => {
|
describe('createRNG', () => {
|
||||||
it('should create RNG with default seed', () => {
|
it('should create RNG with default seed', () => {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"rootDir": "./src"
|
"rootDir": "./src",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules", "dist", "tests"]
|
"exclude": ["node_modules", "dist", "tests"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
import { defineConfig } from 'tsup';
|
import { defineConfig } from 'tsup';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const srcDir = fileURLToPath(new URL('./src', import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ['src/index.ts'],
|
entry: ['src/index.ts'],
|
||||||
|
|
@ -6,4 +9,9 @@ export default defineConfig({
|
||||||
dts: true,
|
dts: true,
|
||||||
clean: true,
|
clean: true,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
esbuildOptions(options) {
|
||||||
|
options.alias = {
|
||||||
|
'@': srcDir,
|
||||||
|
};
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,9 @@ export default defineConfig({
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
include: ['tests/**/*.test.ts'],
|
include: ['tests/**/*.test.ts'],
|
||||||
},
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@/': new URL('./src/', import.meta.url).pathname,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue