lemmabit / rollup-plugin-hypothetical

gives Rollup an imaginary file system, e.g. for testing other plugins
MIT License
42 stars 14 forks source link

Potential windows bug #5

Closed quantizor closed 3 years ago

quantizor commented 6 years ago

We started using this plugin in styled-components, but our appveyor builds fail consistently. The linux ones are all fine though...

Here's our config, for reference:

https://github.com/styled-components/styled-components/blob/master/rollup.config.js#L66-L71

It seems like the fallthrough isn't working quite right? The plugin appears to be failing on the first normal internal import: https://github.com/styled-components/styled-components/blob/a43caefff2b20e98df0464546af80a5267bda9dd/src/index.js#L4

lemmabit commented 6 years ago

First impression, you may be able to work around this for now by enabling allowRelativeExternalFallthrough (or whatever it's called--check the readme, sorry). I'll look at it more closely tomorrow.

On Jan 23, 2018 23:21, "Evan Scott" notifications@github.com wrote:

We started using this plugin styled-components, but our appveyor builds fail consistently https://ci.appveyor.com/project/mxstbr/styled-components/build/2629/job/altu38ln2ipama5r. The linux ones are all fine though...

Here's our config, for reference:

https://github.com/styled-components/styled-components/ blob/master/rollup.config.js#L66-L71

It seems like the fallthrough isn't working quite right?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Permutatrix/rollup-plugin-hypothetical/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/AMZwmXKXTnczGfwA_i63nUQNemABEHiQks5tNtoNgaJpZM4Rq0j3 .

AndyOGo commented 5 years ago

Well I have a similar issue, at macOS Mojave it works, but at windows it throws:

C:\eplatform\git-repos\aletheia\src\aletheia.js → lib\aletheia.es.js... [!] Error: "container/AppContainer" does not exist in the hypothetical file system! Error: "container/AppContainer" does not exist in the hypothetical file system!

My rollup config: https://github.com/axa-ch/aletheia/blob/0ab53751309aa0abe1c257596ac88c916c4f23b0/build/rollup-lib.config.js#L27-L34

storm1ng commented 5 years ago

Just in case no one can access the posted rollup config from @AndyOGo:


const babel = require('rollup-plugin-babel')
const replace = require('rollup-plugin-replace')
const sass = require('rollup-plugin-sass')
const autoprefixer = require('autoprefixer')
const stripFontFace = require('postcss-strip-font-face')
const hypothetical = require('rollup-plugin-hypothetical')
const postcss = require('postcss')

const path = require('path')
const fs = require('fs')
const project = require('../project.config')
const babelOptions = JSON.parse(fs.readFileSync('.babelrc'))

const inProject = path.resolve.bind(path, project.basePath)
const inProjectSrc = (file) => inProject(project.srcDir, file)

const fPath = path.resolve(process.cwd(), project.libDir)

export default {
  input: `${inProjectSrc(project.aletheia)}.js`,
  output: {
    file: `${fPath}/${project.aletheia}.es.js`,
    format: 'es',
  },
  plugins: [
    // @todo: only use this until dynamic imports are properly supported by rollup
    // link: https://rollupjs.org/guide/en#experimentaldynamicimport-experimentaldynamicimport
    hypothetical({
      files: {
        './src/test/components/AppTest.js': `export default null;`,
      },
      allowFallthrough: true,
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
    }),
    sass({
      insert: true,
      include: [ '**/*.scss' ],
      options: {
        includePaths: [
          'node_modules',
        ],
        // reboot is an external dependency and has to be used carfully from the
        // user of aletheia. Here we take it out for integration purposes (dont import twice)
        importer: function importer(url, prev) {
          if (url.match(/@axa-ch\/patterns-library\/.*\/reboot$/)) {
            return { contents: '' }
          }
          return null
        },
      },
      processor: css => postcss([autoprefixer, stripFontFace])
        .process(css)
        .then(result => result.css),
    }),
    babel({
      ...babelOptions,
      plugins: [
        'inline-json-import', // @TODO add this to the webpack build
        'external-helpers', // @TODO add this to the webpack build
        'babel-plugin-transform-decorators-legacy',
        'babel-plugin-transform-class-properties',
        'babel-plugin-transform-es2015-function-name',
        'babel-plugin-transform-react-stateless-component-name',
        'babel-plugin-transform-object-rest-spread',
        'babel-plugin-version-transform',
        'inline-react-svg',
        ['transform-imports', {
          'redux-form': {
            transform: 'redux-form/es/${member}', // eslint-disable-line no-template-curly-in-string
            preventFullImport: true,
          },
          lodash: {
            transform: 'lodash-es/${member}', // eslint-disable-line no-template-curly-in-string
            preventFullImport: true,
          },
        }],
        'lodash',
        ['minify-replace', { // @TODO add this to the webpack build
          'replacements': [{
            identifierName: '__DEV__',
            replacement: {
              type: 'numericLiteral',
              value: 0,
            },
          }, {
            identifierName: '__LOCAL__',
            replacement: {
              type: 'numericLiteral',
              value: 0,
            },
          }, {
            identifierName: '__PROD__',
            replacement: {
              type: 'numericLiteral',
              value: 1,
            },
          }, {
            identifierName: '__TEST__',
            replacement: {
              type: 'numericLiteral',
              value: 0,
            },
          }],
        }],
      ],
      babelrc: false,
      exclude: [
        'node_modules/**',
      ],
      runtimeHelpers: true,
    }),
    resolve({
      jsnext: true,
      module: true,
      only: [/^\.{0,2}\/|\.scss$/i], // threat all node_modules as external
    }),
  ],
}```