rsnext/packages/next/compiled/amphtml-validator/index.js

2 lines
34 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
module.exports=function(e,t){"use strict";var n={};function __webpack_require__(t){if(n[t]){return n[t].exports}var r=n[t]={i:t,l:false,exports:{}};e[t].call(r.exports,r,r.exports,__webpack_require__);r.l=true;return r.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(236)}return startup()}({2:function(e,t,n){"use strict";var r=n(324);e.exports=r;r.prototype.done=function(e,t){var n=arguments.length?this.then.apply(this,arguments):this;n.then(null,function(e){setTimeout(function(){throw e},0)})}},60:function(e,t,n){"use strict";var r=n(928);var o=[];e.exports=asap;function asap(e){var t;if(o.length){t=o.pop()}else{t=new RawTask}t.task=e;t.domain=process.domain;r(t)}function RawTask(){this.task=null;this.domain=null}RawTask.prototype.call=function(){if(this.domain){this.domain.enter()}var e=true;try{this.task.call();e=false;if(this.domain){this.domain.exit()}}finally{if(e){r.requestFlush()}this.task=null;this.domain=null;o.push(this)}}},87:function(e){e.exports=require("os")},129:function(e){e.exports=require("child_process")},184:function(e){e.exports=require("vm")},191:function(e){e.exports=require("querystring")},211:function(e){e.exports=require("https")},229:function(e){e.exports=require("domain")},234:function(e,t,n){var r=n(697);e.exports=function(){return function(e,t,n){if(e===" ")return e;switch(t%3){case 0:return r.red(e);case 1:return r.white(e);case 2:return r.blue(e)}}}()},236:function(__unusedmodule,exports,__webpack_require__){"use strict";const colors=__webpack_require__(493);const fs=__webpack_require__(747);const http=__webpack_require__(605);const https=__webpack_require__(211);const path=__webpack_require__(622);const program=__webpack_require__(721);const Promise=__webpack_require__(700);const querystring=__webpack_require__(191);const url=__webpack_require__(835);const util=__webpack_require__(669);const vm=__webpack_require__(184);const DEFAULT_USER_AGENT="amphtml-validator";function hasPrefix(e,t){return e.indexOf(t)==0}function isHttpOrHttpsUrl(e){return hasPrefix(e,"http://")||hasPrefix(e,"https://")}function readFromFile(e){return new Promise(function(t,n){fs.readFile(e,"utf8",function(e,r){if(e){n(e)}else{t(r.trim())}})})}function readFromReadable(e,t){return new Promise(function(n,r){const o=[];t.setEncoding("utf8");t.on("data",function(e){o.push(e)});t.on("end",function(){n(o.join(""))});t.on("error",function(t){r(new Error("Could not read from "+e+" - "+t.message))})})}function readFromStdin(){return readFromReadable("stdin",process.stdin).then(function(e){process.stdin.resume();return e})}function readFromUrl(e,t){return new Promise(function(n,r){const o=hasPrefix(e,"http://")?http:https;const i=o.request(e,function(t){if(t.statusCode!==200){t.resume();r(new Error("Unable to fetch "+e+" - HTTP Status "+t.statusCode))}else{n(t)}});i.setHeader("User-Agent",t);i.on("error",function(t){r(new Error("Unable to fetch "+e+" - "+t.message))});i.end()}).then(readFromReadable.bind(null,e))}function ValidationResult(){this.status="UNKNOWN";this.errors=[]}function ValidationError(){this.severity="UNKNOWN_SEVERITY";this.line=1;this.col=0;this.message="";this.specUrl=null;this.code="UNKNOWN_CODE";this.params=[]}function Validator(e){this.sandbox=vm.createContext();try{new vm.Script(e).runInContext(this.sandbox)}catch(e){throw new Error("Could not instantiate validator.js - "+e.message)}}Validator.prototype.validateString=function(e,t){const n=this.sandbox.amp.validator.validateString(e,t);const r=new ValidationResult;r.status=n.status;for(let e=0;e<n.errors.length;e++){const t=n.errors[e];const o=new ValidationError;o.severity=t.severity;o.line=t.line;o.col=t.col;o.message=this.sandbox.amp.validator.renderErrorMessage(t);o.specUrl=t.specUrl;o.code=t.code;o.params=t.params;r.errors.push(o)}return r};const instanceByValidatorJs={};function getInstance(e,t){const n=e||"https://cdn.ampproject.org/v0/validator.js";const r=t||DEFAULT_USER_AGENT;if(instanceByValidatorJs.hasOwnProperty(n)){return Promise.resolve(instanceByValidatorJs[n])}const o=isHttpOrHttpsUrl(n)?readF