From 93eedb5cead6dc3a183f02613b36ecaa2ae1ed67 Mon Sep 17 00:00:00 2001 From: zodern Date: Mon, 28 Feb 2022 14:00:28 -0600 Subject: [PATCH] Allow minifiers to get source path of file --- packages/standard-minifier-css/plugin/minify-css.js | 3 +-- tools/isobuild/bundler.js | 13 ++++++++++++- tools/isobuild/compiler-plugin.js | 1 + tools/isobuild/minifier-plugin.js | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/standard-minifier-css/plugin/minify-css.js b/packages/standard-minifier-css/plugin/minify-css.js index ddb887e292..1441a61654 100644 --- a/packages/standard-minifier-css/plugin/minify-css.js +++ b/packages/standard-minifier-css/plugin/minify-css.js @@ -127,8 +127,7 @@ const mergeCss = Profile("mergeCss", async function (css, postcssConfig) { const result = await postcssConfig.postcss( postcssConfig.plugins ).process(content, { - // TODO: provide a better way to get the file's path - from: process.cwd() + file._source.url?.replace('/__cordova', ''), + from: file.getSourcePath(), parser: postcssConfig.options.parser }); diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index 66bd74546a..56ba64de63 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -1126,11 +1126,17 @@ class Target { return null; } + let sourcePath; + if (resource.data && resource.sourceRoot && resource.sourcePath) { + sourcePath = files.pathJoin(resource.sourceRoot, resource.sourcePath); + } + const file = new File({ info: 'resource ' + resource.servePath, arch: target.arch, data: resource.data, hash: resource.hash, + sourcePath }); file.setTargetPathFromRelPath( @@ -1279,13 +1285,18 @@ class Target { return; } + let sourcePath; + if (resource.data && resource.sourceRoot && resource.sourcePath) { + sourcePath = files.pathJoin(resource.sourceRoot, resource.sourcePath); + } const f = new File({ info: 'resource ' + resource.servePath, arch: this.arch, data: resource.data, hash: resource.hash, cacheable: false, - replaceable: resource.type === 'js' && sourceBatch.hmrAvailable + replaceable: resource.type === 'js' && sourceBatch.hmrAvailable, + sourcePath }); const relPath = stripLeadingSlash(resource.servePath); diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index 1990da7116..c544db83ee 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -892,6 +892,7 @@ class OutputResource { sourcePath, targetPath, servePath, + sourceRoot: resourceSlot.packageSourceBatch.sourceRoot, // Remember the source hash so that changes to the source that // disappear after compilation can still contribute to the hash. // Bypassing SourceResource.hash getter so if the compiler plugin doesn't diff --git a/tools/isobuild/minifier-plugin.js b/tools/isobuild/minifier-plugin.js index df54ad0fa8..a561c853e7 100644 --- a/tools/isobuild/minifier-plugin.js +++ b/tools/isobuild/minifier-plugin.js @@ -36,6 +36,9 @@ class InputFile extends buildPluginModule.InputFile { getArch() { return this._arch; } + getSourcePath() { + return this._source.sourcePath || null; + } error({message, sourcePath, line, column, func}) { const relPath = this.getPathInBundle();