Skip to content

Commit 5bf2e3e

Browse files
Stop copying main resources twice and create symlinks instead
1 parent 1a0a29a commit 5bf2e3e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/CartonCLI/Commands/Bundle.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct Bundle: AsyncParsableCommand {
132132
wasmOutputFilePath: wasmOutputFilePath,
133133
buildDirectory: buildDirectory,
134134
bundleDirectory: bundleDirectory,
135-
resourcesPaths: resources
135+
topLevelResourcePaths: resources
136136
)
137137

138138
terminal.write("Bundle generation finished successfully\n", inColor: .green, bold: true)
@@ -166,7 +166,7 @@ struct Bundle: AsyncParsableCommand {
166166
wasmOutputFilePath: AbsolutePath,
167167
buildDirectory: AbsolutePath,
168168
bundleDirectory: AbsolutePath,
169-
resourcesPaths: [String]
169+
topLevelResourcePaths: [String]
170170
) throws {
171171
// Rename the final binary to use a part of its hash to bust browsers and CDN caches.
172172
let wasmFileHash = try localFileSystem.readFileContents(wasmOutputFilePath).hexChecksum
@@ -208,18 +208,19 @@ struct Bundle: AsyncParsableCommand {
208208
try localFileSystem.copy(from: resourcesPath, to: targetDirectory)
209209
}
210210

211-
for resourcesPath in resourcesPaths {
211+
for resourcesPath in topLevelResourcePaths {
212212
let resourcesPath = try AbsolutePath(
213213
validating: resourcesPath, relativeTo: localFileSystem.currentWorkingDirectory!)
214214
for file in try localFileSystem.traverseRecursively(resourcesPath) {
215215
let targetPath = bundleDirectory.appending(component: file.basename)
216+
let sourcePath = bundleDirectory.appending(component: resourcesPath.basename).appending(component: file.basename)
216217

217-
guard localFileSystem.exists(resourcesPath, followSymlink: true),
218+
guard localFileSystem.exists(sourcePath, followSymlink: true),
218219
!localFileSystem.exists(targetPath, followSymlink: true)
219220
else { continue }
220221

221-
terminal.logLookup("Copying this resource to the root bundle directory ", file)
222-
try localFileSystem.copy(from: file, to: targetPath)
222+
terminal.logLookup("Creating symlink ", targetPath)
223+
try localFileSystem.createSymbolicLink(targetPath, pointingAt: sourcePath, relative: true)
223224
}
224225
}
225226
}

0 commit comments

Comments
 (0)