GeezerVison is showing github.com — Merge pull request #8565 from NaviMarella/ProfilingPlugin_8503 · webpack/webpack@510abf7
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 +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | const fs = require("fs"); |
| 2 | +const path = require("path"); |
| 3 | +const mkdirp = require("mkdirp"); |
2 | 4 | const { Tracer } = require("chrome-trace-event"); |
3 | 5 | const validateOptions = require("schema-utils"); |
4 | 6 | const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json"); |
@@ -93,6 +95,10 @@ const createTrace = outputPath => { |
93 | 95 | noStream: true |
94 | 96 | }); |
95 | 97 | const profiler = new Profiler(inspector); |
| 98 | + if (/\/|\\/.test(outputPath)) { |
| 99 | + const dirPath = path.dirname(outputPath); |
| 100 | + mkdirp.sync(dirPath); |
| 101 | + } |
96 | 102 | const fsStream = fs.createWriteStream(outputPath); |
97 | 103 |
|
98 | 104 | let counter = 0; |
|
Collapse file
Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const path = require("path"); |
| 4 | +const fs = require("fs"); |
| 5 | +const webpack = require("../"); |
| 6 | +const rimraf = require("rimraf"); |
| 7 | + |
| 8 | +describe("Profiling Plugin", function() { |
| 9 | + it("should handle output path with folder creation", done => { |
| 10 | + const finalPath = "test/js/profilingPath/events.json"; |
| 11 | + const outputPath = path.join(__dirname, "/js/profilingPath"); |
| 12 | + rimraf(outputPath, () => { |
| 13 | + const compiler = webpack({ |
| 14 | + context: "/", |
| 15 | + entry: "./fixtures/a.js", |
| 16 | + plugins: [ |
| 17 | + new webpack.debug.ProfilingPlugin({ |
| 18 | + outputPath: finalPath |
| 19 | + }) |
| 20 | + ] |
| 21 | + }); |
| 22 | + compiler.run(err => { |
| 23 | + if (err) return done(err); |
| 24 | + if (!fs.existsSync(outputPath)) |
| 25 | + return done(new Error("Folder should be created.")); |
| 26 | + done(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | +}); |