Skip to content

Commit 8d7a4ee

Browse files
Adding vault global inclusion exclusions (#962)
## Links [Preview Link](https://unified-docs-frontend-preview-bmja4z3w4-hashicorp.vercel.app/vault/docs) [Asana task](https://app.asana.com/1/90955849329269/project/1211223868820586/task/1211058606978186?focus=true) ## What This is an implementation of version based directives specifically for Vault- differs from the TFC and TFEnterprise exclusions because those were simplified. Does accurate parsing of the version numbers along with relevant error handling/checks. Created new test suite for the new vault exclusions and added in new test to terraform exclusions. Included support for global partials. ## Why Requested in the above asana ticket ## How Reworked the entire content exclusion process to be more extensible and to have support for global partials. Added in a README to record the current state of the code and to make it easier to build upon. Reworked the AST parsing/traversal logic to find edge cases/bugs that now have tests to check for them. ## Pics **The global partial file:** <img width="691" height="396" alt="Screenshot 2025-10-09 at 10 39 25 AM" src="https://github.com/user-attachments/assets/c9bcb466-7704-4ef7-b205-4dcc01e059ea" /> **The file referenced in 3 different versions (v14, v19, and v20):** **v14:** <img width="704" height="335" alt="Screenshot 2025-10-09 at 10 39 54 AM" src="https://github.com/user-attachments/assets/c7513636-76f9-40b7-838f-4986147c1477" /> **v19:** <img width="701" height="337" alt="Screenshot 2025-10-09 at 10 40 04 AM" src="https://github.com/user-attachments/assets/a76ff5d8-4865-4c97-82a8-000092dcb1c0" /> **v20:** <img width="703" height="331" alt="Screenshot 2025-10-09 at 10 40 17 AM" src="https://github.com/user-attachments/assets/96b41796-802a-49d2-831e-fa28a0b5ba7e" /> The outputs of each post exclusion: **v14:** <img width="707" height="547" alt="Screenshot 2025-10-09 at 10 41 32 AM" src="https://github.com/user-attachments/assets/6fe33d06-3055-4bb8-9970-2d1542c30134" /> **v19:** <img width="713" height="531" alt="Screenshot 2025-10-09 at 10 41 18 AM" src="https://github.com/user-attachments/assets/8379df2e-e73c-476c-a9fe-198bd1ef2c60" /> **v20:** <img width="697" height="402" alt="Screenshot 2025-10-09 at 10 40 50 AM" src="https://github.com/user-attachments/assets/6bc43715-1065-4e52-85f4-d9281ac8c7f4" /> ## Testing Can run to see the entire test suite > `npx vitest scripts/prebuild/mdx-transforms/` To view integration tests with partials+exclusions > `npx vitest scripts/prebuild/mdx-transforms/build-mdx-transforms.test.mjs` Or run this to see specific content exclusion tests > `npx vitest scripts/prebuild/mdx-transforms/exclude-content/index.test.mjs` ## Other info Had to recompile the binaries since these are changes that take place in the scripts folder
2 parents 98b1531 + 8556ae9 commit 8d7a4ee

File tree

16 files changed

+2734
-397
lines changed

16 files changed

+2734
-397
lines changed

content/terraform-docs-common/docs/cloud-docs/api-docs/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ You can use the following types of tokens to authenticate:
7979
<!-- END: TFC:only -->
8080
<!-- BEGIN: TFEnterprise:only name:system-endpoints-auth -->
8181
### System endpoints
82-
@include "api-code-blocks/authentication.mdx"
8382
<!-- END: TFEnterprise:only name:system-endpoints-auth -->
8483

8584
### Blob storage authentication

productConfig.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export const PRODUCT_CONFIG = {
175175
contentDir: 'docs',
176176
dataDir: 'data',
177177
productSlug: 'terraform',
178+
supportsExclusionDirectives: true,
178179
/**
179180
* Note: we need to sort versions for various reasons. Nearly all
180181
* our documentation is semver-versioned. PTFE is not. Rather than
@@ -322,6 +323,7 @@ export const PRODUCT_CONFIG = {
322323
semverCoerce: semver.coerce,
323324
versionedDocs: false,
324325
websiteDir: 'website',
326+
supportsExclusionDirectives: true,
325327
},
326328
'terraform-plugin-framework': {
327329
/**
@@ -463,6 +465,7 @@ export const PRODUCT_CONFIG = {
463465
semverCoerce: semver.coerce,
464466
versionedDocs: true,
465467
websiteDir: 'website',
468+
supportsExclusionDirectives: true,
466469
},
467470
'well-architected-framework': {
468471
/**

scripts/prebuild/mdx-transforms/build-mdx-transforms-file.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
rewriteInternalRedirectsPlugin,
1919
loadRedirects,
2020
} from './rewrite-internal-redirects/rewrite-internal-redirects.mjs'
21-
import { transformExcludeTerraformContent } from './exclude-terraform-content/index.mjs'
21+
import { transformExcludeContent } from './exclude-content/index.mjs'
22+
import { PRODUCT_CONFIG } from '#productConfig.mjs'
2223

2324
const CWD = process.cwd()
2425
const VERSION_METADATA_FILE = path.join(CWD, 'app/api/versionMetadata.json')
@@ -86,10 +87,30 @@ export async function applyFileMdxTransforms(entry, versionMetadata = {}) {
8687

8788
const { data, content } = grayMatter(fileString)
8889

89-
const remarkResults = await remark()
90+
// Check if this file is in a global/partials directory
91+
// Global partials should not have content exclusion applied to them
92+
// as they are version-agnostic and shared across all versions
93+
const isGlobalPartial = filePath.includes('/global/partials/')
94+
95+
const processor = remark()
9096
.use(remarkMdx)
91-
.use(transformExcludeTerraformContent, { filePath })
97+
// Process partials first, then content exclusion
98+
// This ensures exclusion directives in global
9299
.use(remarkIncludePartialsPlugin, { partialsDir, filePath })
100+
101+
// Make sure the content exclusion process skips looking through
102+
// the global partial filepath (it should only be processed once the global
103+
// partial is written to the file)
104+
if (!isGlobalPartial) {
105+
processor.use(transformExcludeContent, {
106+
filePath,
107+
version,
108+
repoSlug: entry.repoSlug,
109+
productConfig: PRODUCT_CONFIG[entry.repoSlug],
110+
})
111+
}
112+
113+
const remarkResults = await processor
93114
.use(paragraphCustomAlertsPlugin)
94115
.use(rewriteInternalRedirectsPlugin, {
95116
redirects,

scripts/prebuild/mdx-transforms/build-mdx-transforms.mjs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
rewriteInternalRedirectsPlugin,
2424
loadRedirects,
2525
} from './rewrite-internal-redirects/rewrite-internal-redirects.mjs'
26-
import { transformExcludeTerraformContent } from './exclude-terraform-content/index.mjs'
26+
27+
import { transformExcludeContent } from './exclude-content/index.mjs'
2728

2829
import { PRODUCT_CONFIG } from '#productConfig.mjs'
2930

@@ -78,11 +79,9 @@ export async function buildMdxTransforms(
7879
)
7980
const redirectsDir = path.join(targetDir, repoSlug, verifiedVersion)
8081
const outPath = path.join(outputDir, relativePath)
81-
return { filePath, partialsDir, outPath, version, redirectsDir }
82+
return { repoSlug, filePath, partialsDir, outPath, version, redirectsDir }
8283
})
83-
/**
84-
* Apply MDX transforms to each file entry, in batches
85-
*/
84+
8685
console.log(`Running MDX transforms on ${mdxFileEntries.length} files...`)
8786
const results = await batchPromises(
8887
'MDX transforms',
@@ -132,10 +131,30 @@ async function applyMdxTransforms(entry, versionMetadata = {}) {
132131
const fileString = fs.readFileSync(filePath, 'utf8')
133132
const { data, content } = grayMatter(fileString)
134133

135-
const remarkResults = await remark()
134+
// Check if this file is in a global/partials directory
135+
// Global partials should not have content exclusion applied to them
136+
// as they are version-agnostic and shared across all versions
137+
const isGlobalPartial = filePath.includes('/global/partials/')
138+
139+
const processor = remark()
136140
.use(remarkMdx)
137-
.use(transformExcludeTerraformContent, { filePath })
141+
// Process partials first, then content exclusion
142+
// This ensures exclusion directives in global partials are properly evaluated
138143
.use(remarkIncludePartialsPlugin, { partialsDir, filePath })
144+
145+
// Make sure the content exclusion process skips looking through
146+
// the global partial filepath (it should only be processed once the global
147+
// partial is written to the file)
148+
if (!isGlobalPartial) {
149+
processor.use(transformExcludeContent, {
150+
filePath,
151+
version,
152+
repoSlug: entry.repoSlug,
153+
productConfig: PRODUCT_CONFIG[entry.repoSlug],
154+
})
155+
}
156+
157+
const remarkResults = await processor
139158
.use(paragraphCustomAlertsPlugin)
140159
.use(rewriteInternalRedirectsPlugin, {
141160
redirects,

0 commit comments

Comments
 (0)