GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • lib/debug
    • ProfilingPlugin.js
  • test
    • ProfilingPlugin.unittest.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/debug/ProfilingPlugin.js‎

Copy file name to clipboardExpand all lines: lib/debug/ProfilingPlugin.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require("fs");
2+
const path = require("path");
23
const { Tracer } = require("chrome-trace-event");
34
const validateOptions = require("schema-utils");
45
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
@@ -86,13 +87,18 @@ class Profiler {
8687

8788
/**
8889
* @param {string} outputPath The location where to write the log.
90+
* @param {Object} compiler Current compiler Instance
8991
* @returns {Trace} The trace object
9092
*/
91-
const createTrace = outputPath => {
93+
const createTrace = (outputPath, compiler) => {
9294
const trace = new Tracer({
9395
noStream: true
9496
});
9597
const profiler = new Profiler(inspector);
98+
if (outputPath.match(/\/|\\/)) {
99+
const dir = path.dirname(outputPath);
100+
compiler.outputFileSystem.mkdirp(dir);
101+
}
96102
const fsStream = fs.createWriteStream(outputPath);
97103

98104
let counter = 0;
@@ -158,7 +164,7 @@ class ProfilingPlugin {
158164
}
159165

160166
apply(compiler) {
161-
const tracer = createTrace(this.outputPath);
167+
const tracer = createTrace(this.outputPath, compiler);
162168
tracer.profiler.startProfiling();
163169

164170
// Compiler Hooks
Collapse file

‎test/ProfilingPlugin.unittest.js‎

Copy file name to clipboardExpand all lines: test/ProfilingPlugin.unittest.js
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use strict";
22

33
const ProfilingPlugin = require("../lib/debug/ProfilingPlugin");
4+
const path = require("path");
5+
const fs = require("fs");
6+
const webpack = require("../");
47

58
describe("Profiling Plugin", () => {
69
it("should persist the passed outpath", () => {
@@ -15,6 +18,26 @@ describe("Profiling Plugin", () => {
1518
expect(plugin.outputPath).toBe("events.json");
1619
});
1720

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+
1841
it("should handle when unable to require the inspector", () => {
1942
const profiler = new ProfilingPlugin.Profiler();
2043
return profiler.startProfiling();

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.