GeezerVison is showing github.com — Fixed Profiling Output path for creating a folder, if it doesn't exists. · webpack/webpack@eb960cc
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/debug/ProfilingPlugin.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | const fs = require("fs"); |
| 2 | +const path = require("path"); |
2 | 3 | const { Tracer } = require("chrome-trace-event"); |
3 | 4 | const validateOptions = require("schema-utils"); |
4 | 5 | const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json"); |
@@ -86,13 +87,18 @@ class Profiler { |
86 | 87 |
|
87 | 88 | /** |
88 | 89 | * @param {string} outputPath The location where to write the log. |
| 90 | + * @param {Object} compiler Current compiler Instance |
89 | 91 | * @returns {Trace} The trace object |
90 | 92 | */ |
91 | | -const createTrace = outputPath => { |
| 93 | +const createTrace = (outputPath, compiler) => { |
92 | 94 | const trace = new Tracer({ |
93 | 95 | noStream: true |
94 | 96 | }); |
95 | 97 | const profiler = new Profiler(inspector); |
| 98 | + if (outputPath.match(/\/|\\/)) { |
| 99 | + const dir = path.dirname(outputPath); |
| 100 | + compiler.outputFileSystem.mkdirp(dir); |
| 101 | + } |
96 | 102 | const fsStream = fs.createWriteStream(outputPath); |
97 | 103 |
|
98 | 104 | let counter = 0; |
@@ -158,7 +164,7 @@ class ProfilingPlugin { |
158 | 164 | } |
159 | 165 |
|
160 | 166 | apply(compiler) { |
161 | | - const tracer = createTrace(this.outputPath); |
| 167 | + const tracer = createTrace(this.outputPath, compiler); |
162 | 168 | tracer.profiler.startProfiling(); |
163 | 169 |
|
164 | 170 | // Compiler Hooks |
|
Collapse file
Copy file name to clipboardExpand all lines: test/ProfilingPlugin.unittest.js +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | "use strict"; |
2 | 2 |
|
3 | 3 | const ProfilingPlugin = require("../lib/debug/ProfilingPlugin"); |
| 4 | +const path = require("path"); |
| 5 | +const fs = require("fs"); |
| 6 | +const webpack = require("../"); |
4 | 7 |
|
5 | 8 | describe("Profiling Plugin", () => { |
6 | 9 | it("should persist the passed outpath", () => { |
@@ -15,6 +18,26 @@ describe("Profiling Plugin", () => { |
15 | 18 | expect(plugin.outputPath).toBe("events.json"); |
16 | 19 | }); |
17 | 20 |
|
| 21 | + it("should handle outpath with folder", done => { |
| 22 | + const finalPath = "test/fixtures/profilingPath/events.json"; |
| 23 | + const compiler = webpack({ |
| 24 | + context: "/", |
| 25 | + entry: "./fixtures/a.js", |
| 26 | + plugins: [ |
| 27 | + new webpack.debug.ProfilingPlugin({ |
| 28 | + outputPath: finalPath |
| 29 | + }) |
| 30 | + ] |
| 31 | + }); |
| 32 | + const outputPath = path.join(__dirname, "/fixtures/profilingPath"); |
| 33 | + compiler.run(err => { |
| 34 | + if (err) return done(err); |
| 35 | + if (!fs.existsSync(outputPath)) |
| 36 | + return done(new Error("Folder should be created.")); |
| 37 | + done(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
18 | 41 | it("should handle when unable to require the inspector", () => { |
19 | 42 | const profiler = new ProfilingPlugin.Profiler(); |
20 | 43 | return profiler.startProfiling(); |
|