Skip to content

Commit d68baeb

Browse files
Emit RenderIndex JSON by default (#100)
Removes the feature flag gating emitting RenderIndex JSON so that the JSON representation of the navigator index is emitted during every conversion of documentation by default. Also bumps the RenderNode minor version to `0.3.0` so that clients of Swift-DocC archives can detect based on the RenderNode version if a given DocC archive will contain an `index.json` file. Resolves rdar://89003698.
1 parent bef86be commit d68baeb

File tree

9 files changed

+46
-28
lines changed

9 files changed

+46
-28
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public struct RenderNode: VariantContainer {
109109
/// > Note: The patch value is currently unused and always set to `0`.
110110
public var schemaVersion = SemanticVersion(
111111
major: 0,
112-
minor: 2,
112+
minor: 3,
113113
patch: 0
114114
)
115115

Sources/SwiftDocC/SwiftDocC.docc/Resources/RenderNode.spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "Render Node API",
5-
"version": "0.2.0",
5+
"version": "0.3.0",
66
"title": "Render Node API"
77
},
88
"paths": { },

Sources/SwiftDocC/Utility/FeatureFlags.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,21 @@ public struct FeatureFlags: Codable {
2222

2323
/// Whether or not experimental support for emitting a JSON representation of the converted
2424
/// documentation's navigator index is enabled.
25-
///
26-
/// This can be enabled on the command-line by passing `--enable-experimental-json-index`.
27-
/// to docc.
28-
public var isExperimentalJSONIndexEnabled = false
25+
@available(*, deprecated, message: "Render Index JSON is now emitted by default.")
26+
public var isExperimentalJSONIndexEnabled = true
2927

3028
/// Creates a set of feature flags with the given values.
3129
///
3230
/// - Parameters:
3331
/// - enableObjectiveCSupport: Whether or not experimental language support for Objective-C should be enabled.
3432
///
35-
/// - enableExperimentalJSONIndex: Whether or not experimental support for emitting a JSON
36-
/// representation of the navigator index should be enabled.
37-
///
3833
/// - additionalFlags: Any additional flags to set.
3934
///
4035
/// This field allows clients to set feature flags without adding new API.
4136
public init(
4237
enableExperimentalObjectiveCSupport: Bool = false,
43-
enableExperimentalJSONIndex: Bool = false,
4438
additionalFlags: [String : Bool] = [:]
4539
) {
4640
self.isExperimentalObjectiveCSupportEnabled = enableExperimentalObjectiveCSupport
47-
self.isExperimentalJSONIndexEnabled = enableExperimentalJSONIndex
4841
}
4942
}

Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct ConvertAction: Action, RecreatingContext {
3434
let emitDigest: Bool
3535
let inheritDocs: Bool
3636
let experimentalEnableCustomTemplates: Bool
37-
let buildIndex: Bool
37+
let buildLMDBIndex: Bool
3838
let documentationCoverageOptions: DocumentationCoverageOptions
3939
let diagnosticLevel: DiagnosticSeverity
4040
let diagnosticEngine: DiagnosticEngine
@@ -72,6 +72,10 @@ public struct ConvertAction: Action, RecreatingContext {
7272
private var durationMetric: Benchmark.Duration?
7373

7474
/// Initializes the action with the given validated options, creates or uses the given action workspace & context.
75+
/// - Parameter buildIndex: Whether or not the convert action should emit an LMDB representation
76+
/// of the navigator index.
77+
///
78+
/// A JSON representation is built and emitted regardless of this value.
7579
/// - Parameter workspace: A provided documentation workspace. Creates a new empty workspace if value is `nil`
7680
/// - Parameter context: A provided documentation context. Creates a new empty context in the workspace if value is `nil`
7781
/// - Parameter dataProvider: A data provider to use when registering bundles
@@ -105,7 +109,7 @@ public struct ConvertAction: Action, RecreatingContext {
105109
self.targetDirectory = targetDirectory
106110
self.htmlTemplateDirectory = htmlTemplateDirectory
107111
self.emitDigest = emitDigest
108-
self.buildIndex = buildIndex
112+
self.buildLMDBIndex = buildIndex
109113
self.workspace = workspace
110114
self.injectedDataProvider = dataProvider
111115
self.fileManager = fileManager
@@ -330,8 +334,7 @@ public struct ConvertAction: Action, RecreatingContext {
330334
// An optional indexer, if indexing while converting is enabled.
331335
var indexer: Indexer? = nil
332336

333-
let shouldBuildIndex = buildIndex || FeatureFlags.current.isExperimentalJSONIndexEnabled
334-
if shouldBuildIndex, let bundleIdentifier = converter.firstAvailableBundle()?.identifier {
337+
if let bundleIdentifier = converter.firstAvailableBundle()?.identifier {
335338
// Create an index builder and prepare it to receive nodes.
336339
indexer = try Indexer(outputURL: temporaryFolder, bundleIdentifier: bundleIdentifier)
337340
}
@@ -367,10 +370,9 @@ public struct ConvertAction: Action, RecreatingContext {
367370

368371
// If we're building a navigation index, finalize the process and collect encountered problems.
369372
if let indexer = indexer {
370-
let indexerProblems = indexer.finalize(
371-
emitJSON: FeatureFlags.current.isExperimentalJSONIndexEnabled,
372-
emitLMDB: buildIndex
373-
)
373+
// Always emit a JSON representation of the index but only emit the LMDB
374+
// index if the user has explicitly opted in with the `--emit-lmdb-index` flag.
375+
let indexerProblems = indexer.finalize(emitJSON: true, emitLMDB: buildLMDBIndex)
374376
allProblems.append(contentsOf: indexerProblems)
375377
}
376378

Sources/SwiftDocCUtilities/ArgumentParsing/ActionExtensions/ConvertAction+CommandInitialization.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extension ConvertAction {
2121
let outOfProcessResolver: OutOfProcessReferenceResolver?
2222

2323
FeatureFlags.current.isExperimentalObjectiveCSupportEnabled = convert.enableExperimentalObjectiveCSupport
24-
FeatureFlags.current.isExperimentalJSONIndexEnabled = convert.enableExperimentalJSONIndex
2524

2625
// If the user-provided a URL for an external link resolver, attempt to
2726
// initialize an `OutOfProcessReferenceResolver` with the provided URL.
@@ -72,7 +71,7 @@ extension ConvertAction {
7271
htmlTemplateDirectory: convert.templateOption.templateURL ?? fallbackTemplateURL,
7372
emitDigest: convert.emitDigest,
7473
currentPlatforms: parsedPlatforms,
75-
buildIndex: convert.index,
74+
buildIndex: convert.emitLMDBIndex || convert.index,
7675
temporaryDirectory: FileManager.default.temporaryDirectory,
7776
documentationCoverageOptions: DocumentationCoverageOptions(
7877
from: convert.experimentalDocumentationCoverageOptions

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Convert.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,21 @@ extension Docc {
8282
@Flag(help: "Writes additional metadata files to the output directory.")
8383
public var emitDigest = false
8484

85-
/// A user-provided value that is true if the navigator index should be produced.
85+
/// A user-provided value that is true if the LMDB representation of the
86+
/// navigator index should be produced.
8687
///
8788
/// Defaults to false.
88-
@Flag(help: "Writes the navigator index to the output directory.")
89+
@Flag(
90+
help: ArgumentHelp(
91+
"Writes an LMDB representation of the navigator index to the output directory.",
92+
discussion: "A JSON representation of the navigator index is emitted by default."
93+
)
94+
)
95+
public var emitLMDBIndex = false
96+
97+
/// This value is provided for backwards compatibility with existing clients but
98+
/// will be removed soon. Renamed to '--emit-lmdb-index'.
99+
@Flag(help: .hidden)
89100
public var index = false
90101

91102
/// A user-provided value that is true if fix-its should be written to output.
@@ -115,8 +126,10 @@ extension Docc {
115126
/// A user-provided value that is true if the user enables experimental support for emitting
116127
/// a JSON index.
117128
///
118-
/// Defaults to false.
129+
/// This property exists for backwards compatibility with existing clients but is
130+
/// deprecated and will be removed soon.
119131
@Flag(help: .hidden)
132+
@available(*, deprecated, message: "Render Index JSON is now emitted by default.")
120133
public var enableExperimentalJSONIndex = false
121134

122135
/// A user-provided value that is true if experimental documentation inheritance is to be enabled.

Tests/SwiftDocCUtilitiesTests/ArgumentParsing/ConvertSubcommandTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,20 @@ class ConvertSubcommandTests: XCTestCase {
294294

295295
let action = try ConvertAction(fromConvertCommand: convertOptions)
296296

297-
XCTAssertEqual(action.buildIndex, true)
297+
XCTAssertEqual(action.buildLMDBIndex, true)
298+
}
299+
300+
func testEmitLMDBIndex() throws {
301+
let convertOptions = try Docc.Convert.parse([
302+
testBundleURL.path,
303+
"--emit-lmdb-index",
304+
])
305+
306+
XCTAssertTrue(convertOptions.emitLMDBIndex)
307+
308+
let action = try ConvertAction(fromConvertCommand: convertOptions)
309+
310+
XCTAssertTrue(action.buildLMDBIndex)
298311
}
299312

300313
func testWithoutBundle() throws {

Tests/SwiftDocCUtilitiesTests/ConvertActionStaticHostableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ConvertActionStaticHostableTests: StaticHostingBaseTests {
4848
_ = try action.perform(logHandle: .standardOutput)
4949

5050
// Test the content of the output folder.
51-
var expectedContent = ["data", "documentation", "tutorials", "downloads", "images", "metadata.json" ,"videos", "index.html"]
51+
var expectedContent = ["data", "documentation", "tutorials", "downloads", "images", "metadata.json" ,"videos", "index.html", "index"]
5252
expectedContent += templateFolder.content.filter { $0 is Folder }.map{ $0.name }
5353

5454
let output = try fileManager.contentsOfDirectory(atPath: targetBundleURL.path)

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,8 +2298,6 @@ class ConvertActionTests: XCTestCase {
22982298
let indexDirectory = targetDirectory.appendingPathComponent("index", isDirectory: true)
22992299
let renderIndexJSON = indexDirectory.appendingPathComponent("index.json", isDirectory: false)
23002300

2301-
enableFeatureFlag(\.isExperimentalJSONIndexEnabled)
2302-
23032301
try action.performAndHandleResult()
23042302
XCTAssertTrue(FileManager.default.directoryExists(atPath: indexDirectory.path))
23052303
XCTAssertTrue(FileManager.default.fileExists(atPath: renderIndexJSON.path))

0 commit comments

Comments
 (0)