Skip to content
Open
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
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 31e333d6769adbaae042c92ea0930fab168a0e06fc1bda406d49fd1042a7a9c7
checksum: 4dc4b2a0693ba40fd503cf52d6d69b577ec87018e4f9ab52415608c65c14f6aa
version: '1.0'
5 changes: 2 additions & 3 deletions packages/contentstack-content-type/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"name": "contentstack-cli-content-type",
"description": "Retrieve information about Content Types in a Stack.",
"version": "1.5.3",
"version": "1.5.4",
"author": "Contentstack Developer",
"bugs": "https://github.com/contentstack/cli-plugins/issues",
"dependencies": {
"@contentstack/cli-command": "^1.8.5",
"@contentstack/cli-utilities": "^1.19.0",
"@types/diff2html": "^3.0.3",
"@types/git-diff": "^2.0.7",
"@types/hogan.js": "^3.0.5",
"@types/table": "^6.3.2",
"@types/tmp": "^0.2.6",
"axios": "^1.18.1",
"cli-ux": "^6.0.9",
"diff": "^9.0.0",
"diff2html": "^3.4.56",
"git-diff": "^2.0.7",
"moment": "^2.30.1",
"node-graphviz": "^0.1.1",
"table": "^6.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: >-
## When to use

- Reviewing a PR or diff before merge.
- Auditing dependency upgrades (axios, diff2html, git-diff, node-graphviz, tmp, cli-ux).
- Auditing dependency upgrades (axios, diff2html, diff, node-graphviz, tmp, cli-ux).
- Changes touching compare HTML, temp files, diagram output, or `src/core/contentstack/`.

## Instructions
Expand All @@ -24,7 +24,7 @@ Use **Critical** / **Important** / **Suggestion** when leaving feedback.

- **Secrets**: Never approve logging of tokens, `authtoken` / `authorization` values, or raw management tokens.
- **Compare / diagram**: Changes to [src/core/content-type/compare.ts](../../src/core/content-type/compare.ts) or [diagram.ts](../../src/core/content-type/diagram.ts) deserve extra scrutiny (temp files, browser open, paths, binary dependency).
- **Dependencies**: axios, diff2html, git-diff, node-graphviz, tmp, cli-ux—review changelog and supply-chain for version bumps.
- **Dependencies**: axios, diff2html, diff, node-graphviz, tmp, cli-ux—review changelog and supply-chain for version bumps.
- **Quality**: TypeScript and **eslint-config-oclif-typescript** ([.eslintrc](../../.eslintrc)); behavioral changes should include or update **Jest** tests where appropriate.

### Security and privacy
Expand Down Expand Up @@ -57,7 +57,7 @@ Use **Critical** / **Important** / **Suggestion** when leaving feedback.
| Severity | Item |
|----------|------|
| Important | **axios**: security advisories; upgrade notes. |
| Important | **diff2html**, **git-diff**, **tmp**, **cli-ux**: behavior changes affecting compare UX. |
| Important | **diff2html**, **diff**, **tmp**, **cli-ux**: behavior changes affecting compare UX. |
| Important | **node-graphviz**: compatibility with supported Node and system Graphviz. |
| Suggestion | **moment** (if touched): prefer minimal churn; note maintenance status of dependencies. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Errors: response `data.errors` → `ContentstackError`; optional suffix with sta

### Compare and diagram pipelines

- **Compare**: `core/content-type/compare.ts` builds a unified diff from two JSON snapshots (`git-diff`), parses with **diff2html**, writes a **temporary HTML** file, opens it in the browser (`cli-ux` / `cli.open`). Not a terminal table.
- **Compare**: `core/content-type/compare.ts` builds a unified diff from two JSON snapshots (`diff`), parses with **diff2html**, writes a **temporary HTML** file, opens it in the browser (`cli-ux` / `cli.open`). Not a terminal table.
- **Diagram**: `core/content-type/diagram.ts` builds a DOT graph, runs **node-graphviz** (`graphviz` binary must be available on the system for SVG rendering). Output path is sanitized where utilities apply.

### Commands (flags and behavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cli from 'cli-ux'
import * as fs from 'fs'
import * as tmp from 'tmp'
import * as Diff2html from 'diff2html'
import gitDiff from 'git-diff'
import {createTwoFilesPatch} from 'diff'
import {BuildOutput} from '../../types'

export default async function buildOutput(contentTypeName: string, previous: any, current: any): Promise<BuildOutput> {
Expand Down Expand Up @@ -30,10 +30,13 @@ export default async function buildOutput(contentTypeName: string, previous: any
}

function buildDiffString(previous: any, current: any) {
return (
`--- ${previous.uid}\t${current.updated_at}\n` +
`+++ ${current.uid}\t${current.updated_at}\n` +
gitDiff(JSON.stringify(previous, null, 2), JSON.stringify(current, null, 2))
return createTwoFilesPatch(
previous.uid,
current.uid,
JSON.stringify(previous, null, 2),
JSON.stringify(current, null, 2),
current.updated_at,
current.updated_at,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ jest.mock('diff2html', () => ({
html: jest.fn(() => '<div class="d2h">diff-html</div>'),
}))

jest.mock('git-diff', () =>
jest.fn(() => '@@ -1 +1 @@\n+changed')
)

import fs from 'fs'
import * as Diff2html from 'diff2html'

import buildOutput from '../../../src/core/content-type/compare'

Expand All @@ -53,4 +50,23 @@ describe('compare buildOutput', () => {
expect(written).toContain('diff-html')
expect(written).toContain('diff2html')
})

it('feeds diff2html a unified patch with file headers and the changed lines', async () => {
await buildOutput('my-ct', prev, curr)

const patch = (Diff2html.parse as jest.Mock).mock.calls[0][0] as string
expect(patch).toContain(`--- ${prev.uid}\t${curr.updated_at}`)
expect(patch).toContain(`+++ ${curr.uid}\t${curr.updated_at}`)
expect(patch).toMatch(/^@@ .* @@$/m)
expect(patch).toContain('- "updated_at": "2020-01-01"')
expect(patch).toContain('+ "updated_at": "2021-01-01"')
})

it('produces a patch with no hunks when both versions are identical', async () => {
await buildOutput('my-ct', prev, prev)

const patch = (Diff2html.parse as jest.Mock).mock.calls[0][0] as string
expect(patch).not.toContain('@@')
expect(patch).not.toContain('undefined')
})
})
Loading
Loading