Add `--no-content-hash` flag to avoid using hashes in the output file names
This commit is contained in:
parent
636600229c
commit
e4ea08a05b
|
@ -48,6 +48,10 @@ sequenceDiagram
|
|||
CartonDevPlugin->>CartonFrontend: Reload browsers
|
||||
```
|
||||
|
||||
**Additional changes:**
|
||||
|
||||
- `--no-content-hash` option is added to `carton bundle` command. This option disables the use of content hash in the output file name.
|
||||
|
||||
# 0.20.1 (25 Jan 2024)
|
||||
|
||||
This release fixes a bug in `carton test` where it reports missing `sock_accept` syscall.
|
||||
|
|
|
@ -65,6 +65,9 @@ struct Bundle: AsyncParsableCommand {
|
|||
)
|
||||
var wasmOptimizations: WasmOptimizations = .size
|
||||
|
||||
@Flag(inversion: .prefixedNo, help: "Use a content hash for the output file names.")
|
||||
var contentHash: Bool = true
|
||||
|
||||
@Option
|
||||
var output: String
|
||||
|
||||
|
@ -160,7 +163,7 @@ struct Bundle: AsyncParsableCommand {
|
|||
) throws {
|
||||
// Rename the final binary to use a part of its hash to bust browsers and CDN caches.
|
||||
let wasmFileHash = try localFileSystem.readFileContents(wasmOutputFilePath).hexChecksum
|
||||
let mainModuleName = "\(wasmFileHash).wasm"
|
||||
let mainModuleName = contentHash ? "\(wasmFileHash).wasm" : URL(fileURLWithPath: mainWasmPath).lastPathComponent
|
||||
let mainModulePath = try AbsolutePath(validating: mainModuleName, relativeTo: bundleDirectory)
|
||||
try localFileSystem.move(from: wasmOutputFilePath, to: mainModulePath)
|
||||
|
||||
|
@ -174,7 +177,7 @@ struct Bundle: AsyncParsableCommand {
|
|||
with: mainModuleName
|
||||
)
|
||||
)
|
||||
let entrypointName = "\(entrypoint.hexChecksum).js"
|
||||
let entrypointName = contentHash ? "\(entrypoint.hexChecksum).js" : "index.js"
|
||||
try localFileSystem.writeFileContents(
|
||||
AbsolutePath(validating: entrypointName, relativeTo: bundleDirectory),
|
||||
bytes: entrypoint
|
||||
|
|
|
@ -60,6 +60,22 @@ final class BundleCommandTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testWithoutContentHash() throws {
|
||||
try withFixture("EchoExecutable") { packageDirectory in
|
||||
let result = try swiftRun(
|
||||
["carton", "bundle", "--no-content-hash", "--wasm-optimizations", "none"], packageDirectory: packageDirectory.url
|
||||
)
|
||||
result.assertZeroExit()
|
||||
|
||||
let bundleDirectory = packageDirectory.appending(component: "Bundle")
|
||||
guard let wasmBinary = (bundleDirectory.ls().filter { $0.contains("wasm") }).first else {
|
||||
XCTFail("No wasm binary found")
|
||||
return
|
||||
}
|
||||
XCTAssertEqual(wasmBinary, "my-echo.wasm")
|
||||
}
|
||||
}
|
||||
|
||||
func testWasmOptimizationOptions() throws {
|
||||
try withFixture("EchoExecutable") { packageDirectory in
|
||||
func getFileSizeOfWasmBinary(wasmOptimizations: WasmOptimizations) throws -> UInt64 {
|
||||
|
|
Loading…
Reference in New Issue