@getmikk/core 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from 'bun:test'
2
+ import * as path from 'node:path'
3
+ import * as fs from 'node:fs/promises'
4
+ import { TypeScriptParser } from '../src/parser/typescript/ts-parser'
5
+ import { getParser } from '../src/parser/index'
6
+
7
+ describe('ts-parser config "extends" resolution', () => {
8
+ const FIXTURE_DIR = path.join(process.cwd(), '.test-fixture-tsconfig')
9
+
10
+ beforeAll(async () => {
11
+ // Create a temporary directory structure to test tsconfig extends
12
+ await fs.mkdir(FIXTURE_DIR, { recursive: true })
13
+ await fs.mkdir(path.join(FIXTURE_DIR, 'node_modules', '@tsconfig', 'node20'), { recursive: true })
14
+
15
+ // 1. node_modules package tsconfig
16
+ await fs.writeFile(
17
+ path.join(FIXTURE_DIR, 'node_modules', '@tsconfig', 'node20', 'tsconfig.json'),
18
+ JSON.stringify({
19
+ compilerOptions: {
20
+ target: 'es2022',
21
+ module: 'commonjs',
22
+ paths: { '@base/*': ['src/base/*'] }
23
+ }
24
+ })
25
+ )
26
+
27
+ // 2. Local tsconfig.base.json extending the node_modules one
28
+ await fs.writeFile(
29
+ path.join(FIXTURE_DIR, 'tsconfig.base.json'),
30
+ JSON.stringify({
31
+ extends: '@tsconfig/node20/tsconfig.json',
32
+ compilerOptions: {
33
+ baseUrl: '.',
34
+ paths: {
35
+ '@lib/*': ['src/lib/*']
36
+ }
37
+ }
38
+ })
39
+ )
40
+
41
+ // 3. Project tsconfig.json extending local base
42
+ await fs.writeFile(
43
+ path.join(FIXTURE_DIR, 'tsconfig.json'),
44
+ `{
45
+ "extends": "./tsconfig.base.json",
46
+ // Comments should be ignored!
47
+ /* Block comments too */
48
+ "compilerOptions": {
49
+ "paths": {
50
+ "@app/*": ["src/app/*"]
51
+ }
52
+ }
53
+ }`
54
+ )
55
+ })
56
+
57
+ afterAll(async () => {
58
+ await fs.rm(FIXTURE_DIR, { recursive: true, force: true })
59
+ })
60
+
61
+ it('recursively merges compiler paths from extended configs', async () => {
62
+ // We'll test this indirectly by creating a dummy file and parsing it
63
+ // and letting ts-parser resolve its imports based on the merged tsconfig
64
+ const parser = new TypeScriptParser()
65
+
66
+ // Write a test source file
67
+ const srcDir = path.join(FIXTURE_DIR, 'src', 'app')
68
+ await fs.mkdir(srcDir, { recursive: true })
69
+ const filePath = path.join(srcDir, 'index.ts')
70
+ await fs.writeFile(filePath, `
71
+ import { a } from '@app/local'
72
+ import { b } from '@lib/shared'
73
+ import { c } from '@base/core'
74
+ `)
75
+
76
+ // Parse and resolve imports
77
+ const parsed = parser.parse(filePath, await fs.readFile(filePath, 'utf-8'))
78
+ const resolved = parser.resolveImports([parsed], FIXTURE_DIR)[0]
79
+
80
+ // Check if the aliases mapped correctly using all 3 layers of paths
81
+ // Base config mapping: @base/* -> src/base/*
82
+ const impBase = resolved.imports.find(i => i.source === '@base/core')
83
+ expect(impBase?.resolvedPath).toBe('src/base/core.ts')
84
+
85
+ // Mid config mapping: @lib/* -> src/lib/*
86
+ const impLib = resolved.imports.find(i => i.source === '@lib/shared')
87
+ expect(impLib?.resolvedPath).toBe('src/lib/shared.ts')
88
+
89
+ // Top config mapping: @app/* -> src/app/*
90
+ const impApp = resolved.imports.find(i => i.source === '@app/local')
91
+ expect(impApp?.resolvedPath).toBe('src/app/local.ts')
92
+ })
93
+ })