同时为所有包装运行纱线原因

时间:2017-08-08 17:34:09

标签: node.js yarnpkg

通常情况下,我会为yarn why <package-name>中的每个模块运行package.json。有没有办法告诉yarn一次为项目中的每个包运行yarn why

2 个答案:

答案 0 :(得分:1)

看起来这是不可能的...当使用命令fileId时,纱线会输出以下信息:

  

参数太多,最多1个。

这让我相信无法在多个软件包上调用//Load the Moment.js library once. //MFSDXCPBYb-JUlxKtMlncfZPjmlt5YPXB var moment = Moment.load(); var formInput = (function() { return { formId: "xxxxx", calendarId: "xxxxx", formMap: { ticket: "Ticket Number", eventTitle: "Event Title", startTime : "Event Date and Start Time", duration: "Event Duration in Hours", description: "Event Description", location: "Event Location", setup: "Set Up Required?", eventDocs: "Event Docs" } } })(); function onFormSubmit() { getFormResponse.formResponse(); createEvent.newEvent(); } var getFormResponse = (function() { // Get a form object by opening the form using the // form id stored in the formInput variable object return { formResponse: function() { var form = FormApp.openById(formInput.formId); //Get all responses from the form. //This method returns an array of form responses responses = form.getResponses(); //find the length of the responses array length = responses.length; //find the index of the most recent form response //since arrays are zero indexed, the last response //is the total number of responses minus one lastResponse = responses[length-1]; //get an array of responses to every question item //within the form for which the respondent provided an answer itemResponses = lastResponse.getItemResponses(); //create an empty object to store data from the last //form response //that will be used to create a calendar event eventObject = {}; //Loop through each item response in the item response array for (var i = 0, x = itemResponses.length; i<x; i++) { //Get the title of the form item being iterated on var thisItem = itemResponses[i].getItem().getTitle(), //get the submitted response to the form item being //iterated on thisResponse = itemResponses[i].getResponse(); //based on the form question title, map the response of the //item being iterated on into our eventObject variable //use the formInput variable formMap sub object to match //form question titles to property keys in the event object switch (thisItem) { case formInput.formMap.ticket: eventObject.ticket = thisResponse; //Logger.log(eventObject.ticket); break; case formInput.formMap.eventTitle: eventObject.title = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.startTime: eventObject.startTime = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.duration: eventObject.duration = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.description: eventObject.description = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.location: eventObject.location = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.setup: eventObject.setup = thisResponse; //Logger.log(thisResponse); break; case formInput.formMap.eventDocs: eventObject.eventDocs = thisResponse; //Logger.log(thisResponse); break; } } return eventObject; } }; })(); var createEvent = (function() { return { newEvent: function() { var eventStartTime = moment(eventObject.startTime); var eventEndTime = eventStartTime.clone().add(eventObject.duration, 'hours'); var eventSetupStart = eventStartTime.clone().subtract(2, 'hours'); var eventSetupEnd = eventSetupStart.clone().add(1, 'hour'); var eventTeardownStart = eventEndTime.clone().add(30, 'minutes'); var eventTeardownEnd = eventTeardownStart.clone().add(30, 'minutes'); // create if else loop to test if setup is needed if (eventObject.setup === 'Yes') { // create base event with default calendar color label var event = { summary: eventObject.ticket + " | " + eventObject.title, start: { dateTime: eventStartTime.format() }, end: { dateTime: eventEndTime.format() }, location: eventObject.location, description: eventObject.description, attachments: [{ 'fileUrl': 'https://drive.google.com/file/d/' + eventObject.eventDocs }] }; // create setup event with green label var setup = { summary: eventObject.ticket + " | " + "Set Up -", start: { dateTime: eventSetupStart.format() }, end: { dateTime: eventSetupEnd.format() }, location: eventObject.location, description: eventObject.description, colorId: 10 }; // create teardown event with green label var teardown = { summary: eventObject.ticket + " | " + "Tear Down -", start: { dateTime: eventTeardownStart.format() }, end: { dateTime: eventTeardownEnd.format() }, location: eventObject.location, description: "", colorId: 10 }; event = Calendar.Events.insert(event, formInput.calendarId, { 'supportsAttachments': true }); setup = Calendar.Events.insert(setup, formInput.calendarId); teardown = Calendar.Events.insert(teardown, formInput.calendarId); } else { // create monitoring-only event with grey label var eventMon = { summary: eventObject.ticket + " | " + eventObject.title, start: { dateTime: eventStartTime.format() }, end: { dateTime: eventEndTime.format() }, location: eventObject.location, description: eventObject.description, colorId: 8 }; eventMon = Calendar.Events.insert(eventMon, formInput.calendarId, { 'supportsAttachments': true }); } } } })();

答案 1 :(得分:0)

由于yarn似乎没有提供检查为什么安装所有软件包的内置方法,因此您只需在每个软件包的for循环中调用yarn why即可。

对于多个包装来说,这绝对是麻烦的。因此,我们需要一种简单的方法来获取包列表。

您可以使用jq将依赖项过滤到临时文件中,或者只使用您选择的文本编辑器并手动保存dependency - package.json部分。

无论哪种方式,引号都需要去;所以使用以下参数运行搜索和替换操作:

搜索:^.+"(.+?)",$
替换:\1

现在,您可以在临时文件中的每个条目的for循环中执行yarn why

# Print json-array into installed_modules
cat package.json | jq '.dependencies | keys' > installed_modules                                   

# edit / search-replace in file 
[…]  

# Loop through each module and run `yarn why` on it
# This is fish-shell for-loop syntax. 
# You might have to look up how your shell (i.e. bash) does this
for module in (cat installed_modules); 
    yarn why $module;
end