@@ -3,11 +3,19 @@ import PackagePlugin
33
44/// Plans the build for packaging.
55struct PackagingPlanner {
6+ /// The options of the plugin
67 let options : PackageToJS . Options
8+ /// The context of the plugin
79 let context : PluginContext
10+ /// The package that contains this plugin
811 let selfPackage : Package
12+ /// The path of this file itself, used to capture changes of planner code
913 let selfPath : String
14+ /// The directory for the final output
1015 let outputDir : URL
16+ /// The directory for intermediate files
17+ let intermediatesDir : URL
18+ /// The filename of the .wasm file
1119 let wasmFilename = " main.wasm "
1220
1321 init (
@@ -18,6 +26,7 @@ struct PackagingPlanner {
1826 self . context = context
1927 self . selfPackage = selfPackage
2028 self . outputDir = outputDir
29+ self . intermediatesDir = context. pluginWorkDirectoryURL. appending ( path: outputDir. lastPathComponent + " .tmp " )
2130 self . selfPath = String ( #filePath)
2231 }
2332
@@ -98,19 +107,18 @@ struct PackagingPlanner {
98107
99108 if let wasmOptPath = wasmOptPath, shouldOptimize {
100109 // Optimize the wasm in release mode
101- let tmpDir = outputDir. deletingLastPathComponent ( ) . appending ( path: " \( outputDir. lastPathComponent) .tmp " )
102- let tmpDirTask = make. addTask (
103- inputFiles: [ selfPath] , output: tmpDir. path, attributes: [ . silent]
110+ let intermediatesDirTask = make. addTask (
111+ inputFiles: [ selfPath] , output: intermediatesDir. path, attributes: [ . silent]
104112 ) {
105113 try Self . createDirectory ( atPath: $0. output)
106114 }
107115 // If splitDebug is true, we need to place the DWARF-stripped wasm file (but "name" section remains)
108116 // in the output directory.
109- let stripWasmPath = ( splitDebug ? outputDir : tmpDir ) . appending ( path: wasmFilename + " .debug " ) . path
117+ let stripWasmPath = ( splitDebug ? outputDir : intermediatesDir ) . appending ( path: wasmFilename + " .debug " ) . path
110118
111119 // First, strip DWARF sections as their existence enables DWARF preserving mode in wasm-opt
112120 let stripWasm = make. addTask (
113- inputFiles: [ selfPath, wasmProductArtifact. path] , inputTasks: [ outputDirTask, tmpDirTask ] ,
121+ inputFiles: [ selfPath, wasmProductArtifact. path] , inputTasks: [ outputDirTask, intermediatesDirTask ] ,
114122 output: stripWasmPath
115123 ) {
116124 print ( " Stripping DWARF debug info... " )
0 commit comments