Skip to content

Commit

Permalink
Pass real filepath to transform plugins (#3483)
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Jun 24, 2021
1 parent f60e163 commit 33cd564
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/plugin-postcss/plugin.js
Expand Up @@ -23,7 +23,7 @@ module.exports = function postcssPlugin(snowpackConfig, options) {

return {
name: '@snowpack/postcss-transform',
async transform({id, fileExt, contents}) {
async transform({id, srcPath, fileExt, contents}) {
let {input = ['.css'], config} = options;

if (!input.includes(fileExt) || !contents) return;
Expand All @@ -37,7 +37,7 @@ module.exports = function postcssPlugin(snowpackConfig, options) {

const encodedResult = await worker.transformAsync(contents, {
config,
filepath: id,
filepath: srcPath,
cwd: snowpackConfig.root || process.cwd(),
map:
snowpackConfig.buildOptions && snowpackConfig.buildOptions.sourceMaps
Expand Down
1 change: 1 addition & 0 deletions snowpack/src/build/build-pipeline.ts
Expand Up @@ -182,6 +182,7 @@ async function runPipelineTransformStep(
isPackage,
fileExt: destExt,
id: filePath,
srcPath,
// @ts-ignore: Deprecated
filePath: fileName,
// @ts-ignore: Deprecated
Expand Down
4 changes: 3 additions & 1 deletion snowpack/src/types.ts
Expand Up @@ -137,8 +137,10 @@ export interface PluginLoadOptions {
}

export interface PluginTransformOptions {
/** The absolute file path of the source file, on disk. */
/** The final build file path (note: this may differ from the source, e.g. `.vue` will yield `.js` and `.css` IDs) */
id: string;
/** The original source location on disk (it may differ from ID) */
srcPath: string;
/** The extension of the file */
fileExt: string;
/** Contents of the file to transform */
Expand Down

1 comment on commit 33cd564

@vercel
Copy link

@vercel vercel bot commented on 33cd564 Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.