Skip to content

Commit

Permalink
refactor: Better tmp dir generation (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jan 8, 2023
1 parent a526a00 commit bc12317
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/cli/src/lib/webpack/render-html-plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { resolve, join } = require('path');
const os = require('os');
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
const { existsSync, mkdtempSync, readFileSync, writeFileSync } = require('fs');
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const prerender = require('./prerender');
Expand Down Expand Up @@ -45,13 +45,7 @@ module.exports = async function (config) {

// Unfortunately html-webpack-plugin expects a true file,
// so we'll create a temporary one.
const tmpDir = join(
os.tmpdir(),
`preact-cli-${Math.floor(Math.random() * 100000)}`
);
if (!existsSync(tmpDir)) {
mkdirSync(tmpDir);
}
const tmpDir = mkdtempSync(join(os.tmpdir(), 'preact-cli-'));
template = resolve(tmpDir, 'template.tmp.ejs');
writeFileSync(template, content);
}
Expand Down

0 comments on commit bc12317

Please sign in to comment.