Giter Site home page Giter Site logo

Comments (5)

ygweric avatar ygweric commented on June 11, 2024 2

Here is my way to find bug and how to fix it.

I download the source and copy them to my project, then add some log to debug it .

what I found is, the file path in Declaration(decl) and Once(css) is NOT same sometimes.
there is my code

module.exports = (options = {}) => {
  convertLegacyOptions(options);
  const opts = Object.assign({}, defaults, options);
  const satisfyPropList = createPropListMatcher(opts.propList);
  const exclude = opts.exclude;
  let isExcludeFile = false;
  let pathOnec;
  let pxReplace;
  return {
    postcssPlugin: "postcss-pxtorem",
    Once(css) {
      const filePath = css.source.input.file;
      pathOnec = filePath;
      if (
        exclude &&
        ((type.isFunction(exclude) && exclude(filePath)) ||
          (type.isString(exclude) && filePath.indexOf(exclude) !== -1) ||
          filePath.match(exclude) !== null)
      ) {
        isExcludeFile = true;
      } else {
        isExcludeFile = false;
      }

      const rootValue =
        typeof opts.rootValue === "function"
          ? opts.rootValue(css.source.input)
          : opts.rootValue;
      pxReplace = createPxReplace(
        rootValue,
        opts.unitPrecision,
        opts.minPixelValue
      );
    },
    Declaration(decl) {
      if (isExcludeFile) return;
      console.log(` $$$$$$$ step2: Declaration(decl) ${decl.source.input.file}`);
      console.log(` $$$$$$$ step2.1: pathOnec is ${pathOnec === decl.source.input.file ? 'same': `different: ${pathOnec}`}`);


      if (
        decl.value.indexOf("px") === -1 ||
        !satisfyPropList(decl.prop) ||
        blacklistedSelector(opts.selectorBlackList, decl.parent.selector)
      )
        return;

      const value = decl.value.replace(pxRegex, pxReplace);

      // if rem unit already exists, do not add or replace
      if (declarationExists(decl.parent, decl.prop, value)) return;

      if (opts.replace) {
        decl.value = value;
      } else {
        decl.cloneAfter({ value: value });
      }
    },
    AtRule(atRule) {
      if (isExcludeFile) return;

      if (opts.mediaQuery && atRule.name === "media") {
        if (atRule.params.indexOf("px") === -1) return;
        atRule.params = atRule.params.replace(pxRegex, pxReplace);
      }
    }
  };
};

there is part of my full log


 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is same
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:top :70px
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:padding :0 24px
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:width :1872px
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:height :64px
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
 $$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less

After reading the documentation of postcss, I know postcss NEVER ensure that Declaration(decl) and Once(css) always in sync

from postcss-pxtorem.

hq229075284 avatar hq229075284 commented on June 11, 2024 2

Take version fallback to 5.1.1 ๐Ÿ˜‘

from postcss-pxtorem.

angryLid avatar angryLid commented on June 11, 2024 1

hi, so is there any way to solve this problem ?

from postcss-pxtorem.

ygweric avatar ygweric commented on June 11, 2024

hi, so is there any way to solve this problem ?
I fix it in my PR #102, which has NOT been merged
you can use my forked npm with npm i postcss-pxtorem-eric

from postcss-pxtorem.

zhaojjiang avatar zhaojjiang commented on June 11, 2024

hi, so is there any way to solve this problem ?

I fix it in my PR #102, which has NOT been merged
you can use my forked npm with npm i postcss-pxtorem-eric

Here is still a problem in your solution

The problem in 6.0.0 is applying incorrect rootValue to target file

In your solution, some files not in exclude can be skipped too

from postcss-pxtorem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.