@inspecto-dev/cli 0.2.0-alpha.5 → 0.2.0-alpha.6
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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +6 -0
- package/README.md +58 -11
- package/bin/inspecto.js +5 -1
- package/dist/bin.d.ts +5 -1
- package/dist/bin.js +89 -50
- package/dist/{chunk-MIHQGC3L.js → chunk-PDDFPQJS.js} +1949 -1064
- package/dist/index.d.ts +128 -2
- package/dist/index.js +15 -3
- package/package.json +2 -1
- package/src/bin.ts +139 -67
- package/src/commands/apply.ts +114 -0
- package/src/commands/detect.ts +59 -0
- package/src/commands/doctor.ts +225 -72
- package/src/commands/init.ts +106 -183
- package/src/commands/plan.ts +41 -0
- package/src/detect/build-tool.ts +107 -3
- package/src/index.ts +13 -2
- package/src/inject/ast-injector.ts +2 -2
- package/src/inject/extension.ts +3 -1
- package/src/instructions.ts +60 -46
- package/src/onboarding/apply.ts +325 -0
- package/src/onboarding/context.ts +36 -0
- package/src/onboarding/planner.ts +278 -0
- package/src/prompts.ts +54 -11
- package/src/types.ts +95 -0
- package/src/utils/fs.ts +2 -1
- package/src/utils/logger.ts +9 -0
- package/src/utils/output.ts +40 -0
- package/tests/apply.test.ts +537 -0
- package/tests/ast-injector.test.ts +50 -0
- package/tests/build-tool.test.ts +3 -5
- package/tests/detect.test.ts +94 -0
- package/tests/doctor.test.ts +224 -0
- package/tests/init.test.ts +333 -0
- package/tests/instructions.test.ts +61 -0
- package/tests/logger.test.ts +100 -0
- package/tests/plan.test.ts +713 -0
- package/tests/workspace-build-tool.test.ts +75 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
2
|
+
import { printNextJsManualInstructions, printNuxtManualInstructions } from '../src/instructions.js'
|
|
3
|
+
import { log } from '../src/utils/logger.js'
|
|
4
|
+
|
|
5
|
+
vi.mock('../src/utils/logger.js', () => ({
|
|
6
|
+
log: {
|
|
7
|
+
blank: vi.fn(),
|
|
8
|
+
hint: vi.fn(),
|
|
9
|
+
copyableCodeBlock: vi.fn(),
|
|
10
|
+
},
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
describe('manual framework instructions', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.resetAllMocks()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('prints detailed Next.js instructions with step-by-step code blocks', () => {
|
|
19
|
+
printNextJsManualInstructions()
|
|
20
|
+
|
|
21
|
+
expect(log.blank).toHaveBeenCalled()
|
|
22
|
+
expect(log.hint).toHaveBeenCalledWith('Next.js requires manual setup in the current version.')
|
|
23
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
24
|
+
'1. Update `next.config.mjs` to register the Inspecto webpack plugin:',
|
|
25
|
+
)
|
|
26
|
+
expect(log.copyableCodeBlock).toHaveBeenCalledWith(
|
|
27
|
+
expect.arrayContaining([
|
|
28
|
+
"import { webpackPlugin as inspecto } from '@inspecto-dev/plugin'",
|
|
29
|
+
'export default nextConfig',
|
|
30
|
+
]),
|
|
31
|
+
)
|
|
32
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
33
|
+
'2. Initialize `@inspecto-dev/core` from a client component such as `app/layout.tsx` or `pages/_app.tsx`:',
|
|
34
|
+
)
|
|
35
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
36
|
+
'3. Restart your Next.js dev server after updating the config.',
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('prints detailed Nuxt instructions with step-by-step code blocks', () => {
|
|
41
|
+
printNuxtManualInstructions()
|
|
42
|
+
|
|
43
|
+
expect(log.blank).toHaveBeenCalled()
|
|
44
|
+
expect(log.hint).toHaveBeenCalledWith('Nuxt requires manual setup in the current version.')
|
|
45
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
46
|
+
'1. Update `nuxt.config.ts` to register the Inspecto Vite plugin:',
|
|
47
|
+
)
|
|
48
|
+
expect(log.copyableCodeBlock).toHaveBeenCalledWith(
|
|
49
|
+
expect.arrayContaining([
|
|
50
|
+
"import { vitePlugin as inspecto } from '@inspecto-dev/plugin'",
|
|
51
|
+
'export default defineNuxtConfig({',
|
|
52
|
+
]),
|
|
53
|
+
)
|
|
54
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
55
|
+
'2. Create `plugins/inspecto.client.ts` to mount `@inspecto-dev/core` in development:',
|
|
56
|
+
)
|
|
57
|
+
expect(log.hint).toHaveBeenCalledWith(
|
|
58
|
+
'3. Restart your Nuxt dev server after updating the config.',
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { log } from '../src/utils/logger.js'
|
|
3
|
+
import { reportCommandError, writeCommandOutput } from '../src/utils/output.js'
|
|
4
|
+
|
|
5
|
+
describe('logger copyable code blocks', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
vi.restoreAllMocks()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('prints copyable code without box drawing characters', () => {
|
|
11
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
12
|
+
|
|
13
|
+
log.copyableCodeBlock(['const answer = 42', 'console.log(answer)'])
|
|
14
|
+
|
|
15
|
+
const output = consoleSpy.mock.calls.map(call => String(call[0]))
|
|
16
|
+
|
|
17
|
+
expect(output).not.toContain(expect.stringContaining('┌'))
|
|
18
|
+
expect(output).not.toContain(expect.stringContaining('│'))
|
|
19
|
+
expect(output).not.toContain(expect.stringContaining('└'))
|
|
20
|
+
expect(output).toContain(' const answer = 42')
|
|
21
|
+
expect(output).toContain(' console.log(answer)')
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('command output utility', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.restoreAllMocks()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('prints formatted JSON and skips the plain-text renderer in json mode', () => {
|
|
31
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
32
|
+
const renderText = vi.fn()
|
|
33
|
+
const result = { status: 'ok', nested: { value: 1 } }
|
|
34
|
+
|
|
35
|
+
const returned = writeCommandOutput(result, true, renderText)
|
|
36
|
+
|
|
37
|
+
expect(returned).toBe(result)
|
|
38
|
+
expect(renderText).not.toHaveBeenCalled()
|
|
39
|
+
expect(consoleSpy).toHaveBeenCalledWith(JSON.stringify(result, null, 2))
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('uses the plain-text renderer when json mode is disabled', () => {
|
|
43
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
44
|
+
const renderText = vi.fn()
|
|
45
|
+
const result = { status: 'ok' }
|
|
46
|
+
|
|
47
|
+
const returned = writeCommandOutput(result, false, renderText)
|
|
48
|
+
|
|
49
|
+
expect(returned).toBe(result)
|
|
50
|
+
expect(renderText).toHaveBeenCalledWith(result)
|
|
51
|
+
expect(consoleSpy).not.toHaveBeenCalled()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('prints machine-safe JSON errors when json mode is enabled', () => {
|
|
55
|
+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
56
|
+
const loggerSpy = vi.spyOn(log, 'error').mockImplementation(() => {})
|
|
57
|
+
const error = new Error('boom')
|
|
58
|
+
error.stack = 'Error: boom\n at fake'
|
|
59
|
+
|
|
60
|
+
reportCommandError(error, { json: true })
|
|
61
|
+
|
|
62
|
+
expect(loggerSpy).not.toHaveBeenCalled()
|
|
63
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
64
|
+
JSON.stringify(
|
|
65
|
+
{
|
|
66
|
+
status: 'error',
|
|
67
|
+
error: {
|
|
68
|
+
message: 'boom',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
null,
|
|
72
|
+
2,
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('includes the stack in JSON error output when debug mode is enabled', () => {
|
|
78
|
+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
79
|
+
const loggerSpy = vi.spyOn(log, 'error').mockImplementation(() => {})
|
|
80
|
+
const error = new Error('boom')
|
|
81
|
+
error.stack = 'Error: boom\n at fake'
|
|
82
|
+
|
|
83
|
+
reportCommandError(error, { json: true, debug: true })
|
|
84
|
+
|
|
85
|
+
expect(loggerSpy).not.toHaveBeenCalled()
|
|
86
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
87
|
+
JSON.stringify(
|
|
88
|
+
{
|
|
89
|
+
status: 'error',
|
|
90
|
+
error: {
|
|
91
|
+
message: 'boom',
|
|
92
|
+
stack: 'Error: boom\n at fake',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
null,
|
|
96
|
+
2,
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
})
|