Skip to content

Commit 510abf7

Browse files
authored
Merge pull request webpack#8565 from NaviMarella/ProfilingPlugin_8503
Fixed error in Profiling Plugin, if given folder path doesn't exist.
2 parents 3b344f2 + 0128118 commit 510abf7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/debug/ProfilingPlugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const fs = require("fs");
2+
const path = require("path");
3+
const mkdirp = require("mkdirp");
24
const { Tracer } = require("chrome-trace-event");
35
const validateOptions = require("schema-utils");
46
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
@@ -93,6 +95,10 @@ const createTrace = outputPath => {
9395
noStream: true
9496
});
9597
const profiler = new Profiler(inspector);
98+
if (/\/|\\/.test(outputPath)) {
99+
const dirPath = path.dirname(outputPath);
100+
mkdirp.sync(dirPath);
101+
}
96102
const fsStream = fs.createWriteStream(outputPath);
97103

98104
let counter = 0;

test/ProfilingPlugin.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
});

0 commit comments

Comments
 (0)