From 0072496834c651dff283a680924835caadf7f27f Mon Sep 17 00:00:00 2001 From: Hamid Pourrabi Date: Thu, 1 Jun 2023 15:00:45 +0200 Subject: [PATCH] fix: file copy --- index.js | 29 +++-------------------------- package.json | 2 +- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 889127f..c38e492 100644 --- a/index.js +++ b/index.js @@ -13,24 +13,9 @@ const schema = { baseDir: { type: "string", }, - baseOutputDir: { - type: "string", - }, }, } -function mkDirP(dir) { - this.addDependency(dir) - const baseDir = "/" - dir.split(path.sep).reduce((parent, child) => { - const full = path.resolve(baseDir, parent, child) - if (!fs.existsSync(full)) { - fs.mkdirSync(full) - } - return full - }) -} - module.exports = function chromeUrlLoader(contents) { const options = this.getOptions() || {} const callback = this.async() @@ -41,8 +26,6 @@ module.exports = function chromeUrlLoader(contents) { options.baseDir = options.baseDir || process.cwd() options.baseDir = options.baseDir.endsWith("/") ? options.baseDir.slice(0, -1) : options.baseDir - options.baseOutputDir = options.baseOutputDir || process.cwd() - options.baseOutputDir = options.baseOutputDir.endsWith("/") ? options.baseOutputDir.slice(0, -1) : options.baseOutputDir options.publicDir = options.publicDir || "" options.publicDir = options.publicDir.endsWith("/") ? options.publicDir.slice(0, -1) @@ -56,17 +39,11 @@ module.exports = function chromeUrlLoader(contents) { const fileName = path.basename(relativeFilePath) const relativeDir = options.publicDir.split(path.sep).slice(1).join(path.sep) - const outputPath = path.join(options.baseOutputDir, options.publicDir, fileName) + const outputPath = path.join(options.publicDir, fileName) const outputDir = path.dirname(outputPath) - mkDirP.call(this, outputDir) - - fs.writeFile(outputPath, contents, (err) => { - if (err) { - return callback(err) - } - callback(null, `module.exports = chrome.runtime.getURL('${relativeDir}/${fileName}')`) - }) + this.emitFile(outputPath, contents, null) + callback(null, `module.exports = chrome.runtime.getURL('${relativeDir}/${fileName}')`) } module.exports.raw = true; \ No newline at end of file diff --git a/package.json b/package.json index 8161aae..7ff9159 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-url-loader", - "version": "1.3.1", + "version": "1.3.2", "description": "chrome extension URL loader for webpack", "main": "index.js", "repository": "https://github.com/chenasraf/chrome-url-loader.git",