aMarCruz / rollup-plugin-cleanup

Rollup plugin to remove comments, trim trailing spaces, compact empty lines, and normalize line endings
MIT License
99 stars 5 forks source link

rollup hang up when running with this plugin in node.js #16

Open Aqours opened 5 years ago

Aqours commented 5 years ago
(async function build() {
    let b = await rollup.rollup({
        input: 'absolute_path_entry.js',
        plugins: [rollupCleanup()],
    }); // hang up here

    let out = {
        format: 'esm',
        sourcemap: true,
        file: path.resolve(__dirname, "dist/test.js"),
    };

    await b.generate(out);
    await b.write(out);
})();
aMarCruz commented 5 years ago

@Aqours I will check it asap. Thanks.

gevalo1 commented 5 years ago

@aMarCruz were you able to look into this? I bumped into this issue today as well.

aMarCruz commented 5 years ago

I'll look at this issue until this week-end.

xania commented 5 years ago

Same issue here! I was able to narrow it down to this line in skip-regex.js. For context the stacktrace is included.

image

R_JS_REGEX: "^\/(?=[^\/])[^[\/\](?:(?:\.|[(?:\.|[^]\])])[^[\\/])?\/[gimuys]*" match[0] "/element.height;var pathData=pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH',{xScaleFactor:1,yScaleFactor:1,containerWidth:element.width,containerHeight:element.height,position:{mx:0.451,my:yPosition}});drawPath(parentGfx,pathData,{strokeWidth:2});}this._drawPath=drawPath;}inherits(BpmnRenderer,BaseRenderer);BpmnRenderer.$inject=['config.bpmnRenderer','eventBus','styles','pathMap','canvas','textRenderer'];BpmnRenderer.prototype.canRender=function(element){return is(element,'bpmn:BaseElement');};BpmnRenderer.prototype.drawShape=function(parentGfx,element){var type=element.type;var h=this.handlers[type];return h(parentGfx,element);};BpmnRenderer.prototype.drawConnection=function(parentGfx,element){var type=element.type;var h=this.handlers[type];return h(parentGfx,element);};BpmnRenderer.prototype.getShapePath=function(element){if(is(element,'bpmn:Event')){return getCirclePath(element);}if(is(element,'bpmn:Activity')){return getRoundRectPath(element,TASK_BORDER_RADIUS);}if(is(element,'bpmn:Gateway')){return getDiamondPath(element);}return getRectPath(element);};"

bwindels commented 4 years ago

I think I am encountering the same issue, rollup hangs forever with this plugin enabled on this particular statement. Removing the statement, or this plugin from my rollup config makes rollup not hang anymore. Let me know if I can provide any further details.

I tried reproducing the problem by passing the same code through js-cleanup but wasn't able to reproduce that way.

aMarCruz commented 4 years ago

@Aqours, @gevalo1, @xania, @bwindels , please try cleanup v3.2.1, it is already in npm.

bwindels commented 4 years ago

@Aqours, @gevalo1, @xania, @bwindels , please try cleanup v3.2.1, it is already in npm.

Still hangs for me with cat node_modules/rollup-plugin-cleanup/package.json | jq ".version": "3.2.1"

aMarCruz commented 4 years ago

@bwindels thanks, I will check it asap.

ssivov commented 4 years ago

Same issue here! I was able to narrow it down to this line in skip-regex.js. For context the stacktrace is included.

image

R_JS_REGEX: "^/(?=[^/])[^[/](?:(?:.|[(?:.|[^]])])[^[\/])?/[gimuys]*" match[0] "/element.height;var pathData=pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH',{xScaleFactor:1,yScaleFactor:1,containerWidth:element.width,containerHeight:element.height,position:{mx:0.451,my:yPosition}});drawPath(parentGfx,pathData,{strokeWidth:2});}this._drawPath=drawPath;}inherits(BpmnRenderer,BaseRenderer);BpmnRenderer.$inject=['config.bpmnRenderer','eventBus','styles','pathMap','canvas','textRenderer'];BpmnRenderer.prototype.canRender=function(element){return is(element,'bpmn:BaseElement');};BpmnRenderer.prototype.drawShape=function(parentGfx,element){var type=element.type;var h=this.handlers[type];return h(parentGfx,element);};BpmnRenderer.prototype.drawConnection=function(parentGfx,element){var type=element.type;var h=this.handlers[type];return h(parentGfx,element);};BpmnRenderer.prototype.getShapePath=function(element){if(is(element,'bpmn:Event')){return getCirclePath(element);}if(is(element,'bpmn:Activity')){return getRoundRectPath(element,TASK_BORDER_RADIUS);}if(is(element,'bpmn:Gateway')){return getDiamondPath(element);}return getRectPath(element);};"

Confirmed, i'm running into the same issue! This might be a problem for a lot of people because this fails to cleanup Google Web Vitals distribution (node_modules/web-vitals/dist/web-vitals.es5.min.js)

Regex used by skip-regex

/^\/(?=[^*/])[^[/\\]*(?:(?:\\.|\[(?:\\.|[^\]\\]*)*\])[^[\\/]*)*?\/[gimuys]*/

String that kills it

/0,c((function(n){var e=n.timeStamp;return t=e}),!0)),{get timeStamp(){return t}}},v=function(t){var n,e=i("FCP"),r=d(),o=a("paint",(function(t){"first-contentful-paint"===t.name&&t.startTime<r.timeStamp&&(e.value=t.startTime,e.isFinal=!0,e.entries.push(t),n())}));o&&(n=l(t,e,o))},f=function(t){var n=i("FID"),e=d(),r=function(t){t.startTime<e.timeStamp&&(n.value=t.processingStart-t.startTime,n.entries.push(t),n.isFinal=!0,s())},o=a("first-input",r),s=l(t,n,o);o?c((function(){o.takeRecords().map(r),o.disconnect()}),!0):window.perfMetrics&&window.perfMetrics.onFirstInputDelay&&window.perfMetrics.onFirstInputDelay((function(t,i){i.timeStamp<e.timeStamp&&(n.value=t,n.isFinal=!0,n.entries=[{entryType:"first-input",name:i.type,target:i.target,cancelable:i.cancelable,startTime:i.timeStamp,processingStart:i.timeStamp+t}],s())}))},m=function(){return n||(n=new Promise((function(t){return["scroll","keydown","pointerdown"].map((function(n){addEventListener(n,t,{once:!0,passive:!0,capture:!0})}))}))),n},g=function(t){var n,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=i("LCP"),o=d(),s=function(t){var e=t.startTime;e<o.timeStamp?(r.value=e,r.entries.push(t)):r.isFinal=!0,n()},u=a("largest-contentful-paint",s);if(u){n=l(t,r,u,e);var p=function(){r.isFinal||(u.takeRecords().map(s),r.isFinal=!0,n())};m().then(p),c(p,!0)}},h=function(t){var n,e=i("TTFB");n=function(){try{var n=performance.getEntriesByType("navigation")[0]||function(){var t=performance.timing,n={entryType:"navigation",startTime:0};for(var e in t)"navigationStart"!==e&&"toJSON"!==e&&(n[e]=Math.max(t[e]-t.navigationStart,0));return n}();e.value=e.delta=n.responseStart,e.entries=[n],e.isFinal=!0,t(e)}catch(t){}},"complete"===document.readyState?setTimeout(n,0):addEventListener("pageshow",n)};export{p as getCLS,v as getFCP,f as getFID,g as getLCP,h as getTTFB};

@aMarCruz I tried using a different regex found on stackoverflow - it solves the performance problem and works fine for my code, however it fails 6 of your test cases. Do you think this performance issue could be resolved any time soon?

smashah commented 4 years ago

I can also confirm that the issue is with using this with web-vitals package