Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve命令执行到styles后退出,无报错 #83

Open
SmileSmith opened this issue Jul 9, 2018 · 2 comments
Open

Serve命令执行到styles后退出,无报错 #83

SmileSmith opened this issue Jul 9, 2018 · 2 comments

Comments

@SmileSmith
Copy link

SmileSmith commented Jul 9, 2018

问题描述

执行ath s后,log最后如下:

[14:14:11] 开始tuan模块任务styles!
[14:14:12] gulp-postcss: buy.css

然后无错误退出,在其它机器上正常使用

环境

node: 10.3.0 (nvm管理)
npm:6.1.0
athena-html:1.4.14

定位

  1. 打日志发现是lib/build/task/styles.js文件第69行代码
    把自定义包装pipe的代码去掉后,正常使用

.pipe($.if(isServe, athenaMate.plumber())) // 删除这行正常,进一步排查这个函数

  1. 这个函数的作用是返回包装后的through2.obj();
    对应文件是lib/build/athena_mate/athena_plumber.js
    删除第66行代码后正常,具体见下方评论。

疑问

我的疑问是在93行中,每次执行pipe2的时候已经会重新patchPipe了,这里为什么在pathPipe函数中还要监听重新patch一次?

@SmileSmith
Copy link
Author

  function patchPipe(stream) {
    if (stream.pipe2) {
      wrapPanicOnErrorHandler(stream);
      stream._pipe = stream._pipe || stream.pipe;
      stream.pipe = stream.pipe2;
      stream.once('readable', patchPipe.bind(null, stream)); //  第66行,删除后正常使用
      stream._plumbed = true;
    }
  }


  through.pipe2 = function pipe2(dest) {

    if (!dest) {
      throw new gutil.PluginError('plumber', 'Can\'t pipe to undefined');
    }

    this._pipe.apply(this, arguments);

    if (dest._unplumbed) {
      return dest;
    }

    removeDefaultHandler(this, 'error');

    if (dest._plumber) {
      return dest;
    }

    dest.pipe2 = pipe2;

    // Patching pipe method
    if (opts.inherit !== false) {
      patchPipe(dest);               // 第93行
    }

    // Placing custom on error handler
    if (this.errorHandler) {
      dest.errorHandler = this.errorHandler;
      dest.on('error', this.errorHandler.bind(dest));
    }

    dest._plumbed = true;

    return dest;
  };

@SmileSmith
Copy link
Author

SmileSmith commented Sep 29, 2018

问题大概定位到,升级Node 10以上版本,会出现。

解决方案: 注释上面的93行(保留66行)
(全局npm目录)/node_modules/athena-html/lib/build/athena_mate/athena_plumber.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant