Skip to content

Commit 35cea78

Browse files
authored
Move inLiquid to lib function (#50333)
1 parent b44b485 commit 35cea78

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

Diff for: src/workflows/content-changes-table-comment.ts

+1-24
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import nonEnterpriseDefaultVersion from '@/versions/lib/non-enterprise-default-v
2525
import { allVersionShortnames } from '@/versions/lib/all-versions.js'
2626
import { waitUntilUrlIsHealthy } from './wait-until-url-is-healthy.js'
2727
import readFrontmatter from '@/frame/lib/read-frontmatter.js'
28-
import { getLiquidTokens } from '@/content-linter/lib/helpers/liquid-utils.js'
28+
import { inLiquid } from './lib/in-liquid'
2929

3030
const { GITHUB_TOKEN, APP_URL } = process.env
3131
const context = github.context
@@ -181,29 +181,6 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
181181
return markdownTable
182182
}
183183

184-
type Token = {
185-
name?: string
186-
args?: string
187-
}
188-
189-
const parsedLiquidTokensCache = new Map<string, Token[]>()
190-
191-
function inLiquid(filePath: string, fileContents: string, needle: string) {
192-
if (!parsedLiquidTokensCache.has(filePath)) {
193-
parsedLiquidTokensCache.set(filePath, getLiquidTokens(fileContents))
194-
}
195-
const tokens = parsedLiquidTokensCache.get(filePath) as Token[]
196-
for (const token of tokens) {
197-
if (token.name === 'data') {
198-
const { args } = token
199-
if (args === needle) {
200-
return true
201-
}
202-
}
203-
}
204-
return false
205-
}
206-
207184
function makeBlobUrl(owner: string, repo: string, sha: string, filePath: string) {
208185
return `https://github.com/${owner}/${repo}/blob/${sha}/${encodeURIComponent(filePath)}`
209186
}

Diff for: src/workflows/lib/in-liquid.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getLiquidTokens } from '@/content-linter/lib/helpers/liquid-utils.js'
2+
3+
type Token = {
4+
name?: string
5+
args?: string
6+
}
7+
8+
const parsedLiquidTokensCache = new Map<string, Token[]>()
9+
10+
export function inLiquid(filePath: string, fileContents: string, needle: string) {
11+
if (!parsedLiquidTokensCache.has(filePath)) {
12+
parsedLiquidTokensCache.set(filePath, getLiquidTokens(fileContents))
13+
}
14+
const tokens = parsedLiquidTokensCache.get(filePath) as Token[]
15+
for (const token of tokens) {
16+
if (token.name === 'data') {
17+
const { args } = token
18+
if (args === needle) {
19+
return true
20+
}
21+
}
22+
}
23+
return false
24+
}

0 commit comments

Comments
 (0)