lukeed / taskr

A fast, concurrency-focused task automation tool.
MIT License
2.53k stars 75 forks source link

@taskr/postcss failes using options/plugins #295

Closed vedam closed 6 years ago

vedam commented 6 years ago

Unfortunately I have no idea why it failed, because I'm not able to find a fault in that task:

export async function style(task) {
  await task.source(src).stylus(stylusOptions).postcss({
    plugins: [
      require('autoprefixer')
    ]
  }).target(dist)
}

package.json:

{
  ...
  "devDependencies": {
    "@taskr/esnext": "^1.1.0",
    "@taskr/postcss": "^1.1.0",
    "@taskr/stylus": "^1.1.0",
    "@taskr/watch": "^1.1.0",
    "taskr": "^1.1.0",
    "taskr-autoprefixer": "^1.0.0"
  }
}

throws:

@taskr/postcss failed because Invalid PostCSS config! An object is required; recevied: object

any help appreciated. thx in advance vedam

btw. taskr rocks

hzlmn commented 6 years ago

Hello, do you have postcss.config.js or other configuration files for postcss in your folder? Take a look on docs for supported config types.

UPD: And also could you show please full stacktrace for exception?

vedam commented 6 years ago

I tried it without any other options anywhere (as described in #284), just passing the plugins (see above), and it failed. Solved by creating a postcss.config.js-file and passing the plugins there. Thx for your hint

hzlmn commented 6 years ago

In any case, it is not a correct behavior if you can not pass config object to postcss. Can you show your stacktrace?

lukeed commented 6 years ago

Just spun up a test repo locally to try postcss without any config files. Works fine as is 🤔

exports.default = function * (task) {
  yield task.source('src/*.css').postcss({
    plugins: [
      require('autoprefixer')
    ]
  }).target('dist');
}

I'll add the stylus plugin & see what happens.

vedam commented 6 years ago

Hmmm, yeah 🤔 . I made a small isolated local test.

package.json

{
  "name": "test-case-css-plugins",
  "version": "0.1.0",
  "scripts": {
    "css": "taskr"
  },
  "devDependencies": {
    "@taskr/esnext": "^1.1.0",
    "@taskr/postcss": "^1.1.0",
    "@taskr/stylus": "^1.1.0",
    "@taskr/watch": "^1.1.0",
    "autoprefixer": "^7.1.2",
    "taskr": "^1.1.0"
  }
}

taskfile.js

export async function style(task) {
  await task.source('*.styl')
    .stylus({
      errors: true,
      'include css': true
    })
    .postcss({
      plugins: [
        require('autoprefixer')({
          browsers: ['last 2 versions']
        })
      ]
    })
    .target('./')
}

export default async function(task) {
  await task.watch('*.styl', 'style')
}

console:

[17:13:33] Running with /Users/acve/Sites/lab/svelte/12-testcase/taskfile.js
[17:13:33] Starting default
[17:13:33] Watching files...
[17:13:33] Finished default in 63ms
[17:13:42] File changed: reset.styl
[17:13:42] Starting style
[17:13:42] @taskr/postcss failed because Invalid PostCSS config! An object is required; recevied: object
[17:13:42] Finished style in 260ms
lukeed commented 6 years ago

Also worked with Stylus attached:

exports.default = function * (task) {
  yield task.source('src/*.styl').stylus().postcss({
    plugins: [
      require('autoprefixer')
    ]
  }).target('dist');
}

Not sure where to go from here @vedam

If you keep seeing that error, please add a console.log(config) after this line inside your node_modules.

Thanks~

vedam commented 6 years ago

@lukeed: I've added console.log(config) and it outputs:

[17:27:05] Running with /Users/acve/Sites/lab/svelte/12-testcase/taskfile.js
[17:27:05] Starting default
[17:27:05] Watching files...
[17:27:05] Finished default in 71ms
[17:27:24] File changed: reset.styl
[17:27:24] Starting style
{ plugins: 
   [ { [Function: plugin]
       options: [Object],
       info: [Function],
       postcssPlugin: 'autoprefixer',
       postcssVersion: '6.0.8' } ] }
[17:27:25] @taskr/postcss failed because Invalid PostCSS config! An object is required; recevied: object
[17:27:25] Finished style in 259ms

I'm really sorry for the noise. I got it running with a postcss.config.js-file and that's ok for me. I just wondered.

Thx for your help. Maybe I'm the only one. vedam

lukeed commented 6 years ago

Interesting, it's because of @taskr/esnext!

Once the taskfile (with any options defined) is passed returned from esnext, the isObject helper doesn't consider the options an object anymore, seemingly because of its constructor? I've never heard of this before, I feel like it's a Node bug maybe??

I'll add a quick fix for postcss to adjust. It's the only plugin that uses that helper.


Not noise at all 😄 Thanks for the report

lukeed commented 6 years ago

@vedam You can give taskr/postcss@v1.1.2 a spin 😄

vedam commented 6 years ago

Wow, that's fast. Ask-and-solve-on-demand. Working here. 👏 thx vedam

lukeed commented 6 years ago

Lol no problem. Thank you both~