Skip to content

Commit

Permalink
Avoid file locks + overwrites by using a temp file for HTML templates
Browse files Browse the repository at this point in the history
This fixes #1331.
  • Loading branch information
developit authored and rschristian committed Dec 24, 2022
1 parent 70d192f commit 0887318
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/cli/src/lib/webpack/render-html-plugin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { resolve, join } = require('path');
const os = require('os');
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const tempy = require('tempy');
const prerender = require('./prerender');
const createLoadManifest = require('./create-load-manifest');
const { esmImport, tryResolveConfig, warn } = require('../../util');
Expand Down Expand Up @@ -45,11 +45,8 @@ 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');
if (!existsSync(tmpDir)) {
mkdirSync(tmpDir);
}
template = resolve(tmpDir, 'template.tmp.ejs');

template = tempy.file({name: 'template.tmp.ejs'});
writeFileSync(template, content);
}

Expand Down

0 comments on commit 0887318

Please sign in to comment.