From 329c5cd0c051963b194e722c24a27dabf36789d9 Mon Sep 17 00:00:00 2001 From: azu Date: Wed, 17 Jan 2018 19:55:42 +0900 Subject: [PATCH] fix(remove): fix --- scripts/remove-ChangedPayload.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/remove-ChangedPayload.js b/scripts/remove-ChangedPayload.js index fb663f9..a3497b6 100644 --- a/scripts/remove-ChangedPayload.js +++ b/scripts/remove-ChangedPayload.js @@ -52,12 +52,15 @@ function isNewExpressionChangedPayload(path) { module.exports = function transformer(file, api) { const j = api.jscodeshift; // Remove `import { ChangedPayload } from "almin" + let hasAlmin = false; + return ( j( j(file.source) .find(j.ImportSpecifier) .filter(path => { - return isChangedPayloadImportSpecifier(path); + hasAlmin = isChangedPayloadImportSpecifier(path); + return hasAlmin; }) .remove() .toSource() @@ -65,13 +68,13 @@ module.exports = function transformer(file, api) { // Rewrite new ChangedPayload() => { type: "ChangedPayload" } .find(j.NewExpression) .filter(path => { - let newExpressionChangedPayload = isNewExpressionChangedPayload(path); - console.log(newExpressionChangedPayload); - return newExpressionChangedPayload; + if (!hasAlmin) { + return false; + } + return isNewExpressionChangedPayload(path); }) .replaceWith(path => { return `{ type: "ChangedPayload" }`; - R; }) .toSource() );