foxundermoon / vs-shell-format

the shellscript、Dockerfile、properties ...... format extension
MIT License
444 stars 47 forks source link

Apple Silicon (ARM M1 Processor) Support #136

Open sammcj opened 3 years ago

sammcj commented 3 years ago

At present this plugin fails on the new generation Apple machines with the Apple Silicon M1 (ARM) processor.

It appears to be trying to download shfmt but it doesn't have a darwin_arm package available (see https://github.com/mvdan/sh/issues/642) thus breaking this plugin for M1 users.

Error details:

shfmt hasn't downloaded yet!Error: ENOENT: no such file or directory, stat '/Users/samm/.vscode-insiders/extensions/foxundermoon.shell-format-7.0.1/bin/shfmt_v3.0.1_darwin_arm'
Shfmt will be downloaded automatically!
download url: https://github.com/mvdan/sh/releases/download/v3.0.1/shfmt_v3.0.1_darwin_arm
download to: /Users/samm/.vscode-insiders/extensions/foxundermoon.shell-format-7.0.1/bin/shfmt_v3.0.1_darwin_arm
If the download fails, you can manually download it to the dest directory.
Or download to another directory, and then set the "shellformat.path" as the path
download shfmt page: https://github.com/mvdan/sh/releases
You can't use this plugin until the download is successful.
download failed: Error: HTTP status 404 : Not Found

https://github.com/mvdan/sh/releases

zephyrpathsofglory commented 3 years ago

Currently, the newest version mvdan/sh:v3.2.4 has darwin_arm64 build. So we need to bump shfmt dependency to v3.2.4.

smktpd commented 9 months ago

@foxundermoon generally, this ticket can be closed. However, VSCodium users won't see the fix until someone updates the available release of your extension on VSCodium's marketplace.

kelzenberg commented 8 months ago

@foxundermoon is this going to be released any time soon? Would much appreciate it as this blocks all MacBook users who upgraded to M-chips :)

For anyone needing a dirty quick-fix right now, update

~/.{vscode|vscode-oss}/extensions/foxundermoon.shell-format-7.0.1-universal/dist/extension.js
with the code below:

```javascript module.exports=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";function i(){}function r(e,t,n,i,r){for(var o=0,s=t.length,a=0,l=0;oe.length?n:e})),u.value=e.join(c)}else u.value=e.join(n.slice(a,a+u.count));a+=u.count,u.added||(l+=u.count)}}var d=t[s-1];return s>1&&"string"==typeof d.value&&(d.added||d.removed)&&e.equals("",d.value)&&(t[s-2].value+=d.value,t.pop()),t}function o(e){return{newPos:e.newPos,components:e.components.slice(0)}}t.__esModule=!0,t.default=i,i.prototype={diff:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n.callback;"function"==typeof n&&(i=n,n={}),this.options=n;var s=this;function a(e){return i?(setTimeout((function(){i(void 0,e)}),0),!0):e}e=this.castInput(e),t=this.castInput(t),e=this.removeEmpty(this.tokenize(e));var l=(t=this.removeEmpty(this.tokenize(t))).length,u=e.length,f=1,c=l+u,d=[{newPos:-1,components:[]}],h=this.extractCommon(d[0],t,e,0);if(d[0].newPos+1>=l&&h+1>=u)return a([{value:this.join(t),count:t.length}]);function p(){for(var n=-1*f;n<=f;n+=2){var i=void 0,c=d[n-1],h=d[n+1],p=(h?h.newPos:0)-n;c&&(d[n-1]=void 0);var g=c&&c.newPos+1=l&&p+1>=u)return a(r(s,i.components,t,e,s.useLongestToken));d[n]=i}else d[n]=void 0}f++}if(i)!function e(){setTimeout((function(){if(f>c)return i();p()||e()}),0)}();else for(;f<=c;){var g=p();if(g)return g}},pushComponent:function(e,t,n){var i=e[e.length-1];i&&i.added===t&&i.removed===n?e[e.length-1]={count:i.count+1,added:t,removed:n}:e.push({count:1,added:t,removed:n})},extractCommon:function(e,t,n,i){for(var r=t.length,o=n.length,s=e.newPos,a=s-i,l=0;s+11&&void 0!==arguments[1]?arguments[1]:{},n=e.split(/\r\n|[\n\v\f\r\x85]/),i=e.match(/\r\n|[\n\v\f\r\x85]/g)||[],r=[],o=0;function s(){var e={};for(r.push(e);o{1===e.reason&&function(e){const t=i.workspace.getConfiguration(r.configurationPrefix).get(r.ConfigItemName.EffectLanguages),{scheme:n}=e.uri;if(t){if(t.find(t=>t===e.languageId))return n===s.File||n===s.Untitled}return!1}(e.document)&&i.commands.executeCommand(l)})},t.deactivate=function(){}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(1),r=n(7),o=(n(2),n(8)),s=n(13),a=n(1),l=n(12);var u;t.configurationPrefix="shellformat",function(e){e.Flag="flag",e.Path="path",e.EffectLanguages="effectLanguages",e.ShowError="showError"}(u=t.ConfigItemName||(t.ConfigItemName={}));const f="/usr/local/bin",c=`${f}/shfmt`;class d{constructor(e,t){this.context=e,this.output=t,this.diagnosticCollection=i.languages.createDiagnosticCollection("shell-format")}getShfmtPath(){return l.getDestPath(this.context)}formatDocument(e,t){const n=new a.Position(0,0),r=new i.Position(e.lineCount-1,e.lineAt(e.lineCount-1).text.length),o=new i.Range(n,r),s=e.getText(o);return this.formatDocumentWithContent(s,e,o,t)}formatDocumentWithContent(e,n,l,u){return new Promise((l,f)=>{try{let c=[],h=i.workspace.getConfiguration(t.configurationPrefix),p=!1;if(h){let e=h.flag;if(e){e.includes("-w")&&(i.window.showWarningMessage("can not set -w flag please fix config"),f("-w config error")),e.includes("-i")&&(p=!0);let t=e.split(" ");c.push(...t)}let t=h.path;t?o.fileExists(t)?d.formatCommand=t:i.window.showErrorMessage("the config shellformat.path file not exists please fix it"):d.formatCommand=this.getShfmtPath()}u&&u.insertSpaces&&!p&&c.push("-i",u.tabSize);let g=r.spawn(d.formatCommand,c),m=[],v=[],w=[];g.stdout.on("data",e=>{let t;t=e instanceof Buffer?e:new Buffer(e),m.push(t)}),g.stderr.on("data",e=>{let t;t=e instanceof Buffer?e:new Buffer(e),v.push(t)}),g.on("close",(t,r)=>{if(0==t)if(this.diagnosticCollection.delete(n.uri),0==m.length)l(null);else{let t=Buffer.concat(m).toString();s.getEdits(n.fileName,e,t).edits.forEach(e=>{w.push(e.apply())}),l(w)}else{let e="";if(0!=v.length){e=Buffer.concat(v).toString();let t=/^:(\d+):(\d+):/.exec(e);if(null!==t&&t.length>2){let r=parseInt(t[1]),o=parseInt(t[2]);const s={range:new i.Range(new i.Position(r,o),new i.Position(r,o)),message:e.slice(":".length,e.length),severity:a.DiagnosticSeverity.Error};this.diagnosticCollection.delete(n.uri),this.diagnosticCollection.set(n.uri,[s])}}f(e)}}),g.stdin.write(e),g.stdin.end()}catch(e){f("Internal issues when formatted content")}})}}d.formatCommand="shfmt",t.Formatter=d;function h(){i.window.showErrorMessage(`[${t.configurationPrefix}.${u.Path}]not found! please install manually https://mvdan.cc/sh/cmd/shfmt `)}t.ShellDocumentFormattingEditProvider=class{constructor(e,n){this.formatter=e,this.settings=void 0===n?i.workspace.getConfiguration(t.configurationPrefix):n}provideDocumentFormattingEdits(e,t,n){return this.formatter.formatDocument(e,t)}},t.checkEnv=function(){const e=i.workspace.getConfiguration(t.configurationPrefix);let n=!1;if(e){let r=e.get(u.Flag);r&&r.includes("-w")&&i.window.showWarningMessage("can not set -w flag please fix config");let s=e.get(u.Path);s&&(n=!0,o.fileExists(s)?this.formatCommand=s:i.window.showErrorMessage(`the config [${t.configurationPrefix}.${u.Path}] file not exists please fix it`))}n||null!=o.getExecutableFileUnderPath(d.formatCommand)||o.fileExists(c)||("darwin"==process.platform?function(){if(o.getExecutableFileUnderPath("brew")){i.window.showInformationMessage("will install shfmt by brew");const e=i.window.createTerminal();e.show(),e.sendText("brew install shfmt",!0),e.sendText("echo '**Enjoy shellscript!**'",!0),e.sendText("echo 'fork or star https://github.com/foxundermoon/vs-shell-format'",!0)}}():(["freebsd","linux","openbsd"].includes(process.platform),h()))},t.getSettings=function(e){let n=i.workspace.getConfiguration(t.configurationPrefix);return void 0!==e?n[e]:null}},function(e,t){e.exports=require("child_process")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(2),r=n(9);let o={};function s(e){try{return i.statSync(e).isFile()}catch(e){return!1}}t.getExecutableFileUnderPath=function(e){let t=o[e];if(t)return t;var n;n=e,e="win32"===process.platform?n+".exe":n;let i=process.env.PATH.split(r.delimiter);for(let t=0;t0?f(a.lines.slice(-l.context)):[],d-=p.length,h-=p.length)}(s=p).push.apply(s,r(i.map((function(e){return(t.added?"+":"-")+e})))),t.added?m+=i.length:g+=i.length}else{if(d)if(i.length<=2*l.context&&e=u.length-2&&i.length<=l.context){var E=/\n$/.test(n),P=/\n$/.test(o);0!=i.length||E?E&&P||p.push("\\ No newline at end of file"):p.splice(x.oldLines,0,"\\ No newline at end of file")}c.push(x),d=0,h=0,p=[]}g+=i.length,m+=i.length}},w=0;wi(this,void 0,void 0,(function*(){let i;for(let t=0;tr.get(e,t)),i.statusCode>=300&&i.statusCode<400&&i.headers.location);++t)e=i.headers.location;if((i.statusCode<200||i.statusCode>=300)&&a(new Error(`HTTP status ${i.statusCode} : ${i.statusMessage}`)),"application/octet-stream"!=i.headers["content-type"])a(new Error("HTTP response does not contain an octet stream"));else{let e=o.createWriteStream(t,{mode:493}),r=i.pipe(e);if(n){let e=i.headers["content-length"]?Number.parseInt(i.headers["content-length"]):null,t=0,r=0;i.on("data",i=>{r=t,t+=i.length,n(t,e,r)})}r.on("finish",s),r.on("error",a),i.on("error",a)}})))}))}var p,g;function m(){switch(process.arch){case"arm":return p.arm;case"arm64":return p.arm64;case"ia32":case"x32":return p.i386;case"x64":return p.x64;case"mips":return p.mips;default:return p.unknown}}function v(){switch(process.platform){case"win32":return g.windows;case"freebsd":return g.freebsd;case"openbsd":return g.openbsd;case"darwin":return g.darwin;case"linux":return g.linux;default:return g.unknown}}function w(){const e=m(),t=v();if(e===p.unknown||t==g.unknown)throw new Error("do not find release shfmt for your platform");return`shfmt_${s.config.shfmtVersion}_${t}_${e}${"win32"===process.platform?".exe":""}`}function y(){return`https://github.com/mvdan/sh/releases/download/${s.config.shfmtVersion}/${w()}`}function x(e){return f.getSettings("path")||l.join(e.extensionPath,"bin",w())}t.download=function(e,t,n){return i(this,void 0,void 0,(function*(){}))},t.download2=h,function(e){e.arm="arm",e.arm64="arm64",e.i386="386",e.mips="mips",e.x64="amd64",e.unknown="unknown"}(p||(p={})),function(e){e.darwin="darwin",e.freebsd="freebsd",e.linux="linux",e.netbsd="netbsd",e.openbsd="openbsd",e.windows="windows",e.unknown="unknown"}(g||(g={})),t.getArchExtension=m,t.getPlatform=v,t.getPlatFormFilename=w,t.getReleaseDownloadUrl=y,t.getDestPath=x,t.checkInstall=function(e,t){return i(this,void 0,void 0,(function*(){if(!s.config.needCheckInstall)return;const n=x(e);if(yield function e(t){return i(this,void 0,void 0,(function*(){(yield new Promise(e=>o.exists(t,t=>e(t))))||(yield e(l.dirname(t)),yield new Promise((e,n)=>o.mkdir(t,t=>{t?n(t):e()})))}))}(l.dirname(n)),yield function(e,t){return i(this,void 0,void 0,(function*(){try{const n=a.workspace.getConfiguration().get(c.shellformatPath);if(n)try{return yield o.promises.access(n,o.constants.X_OK),s.config.needCheckInstall=!1,!1}catch(e){t.appendLine(`"${c.shellformatPath}": "${n}" find config shellformat path ,but the file cannot execute or not exists, so will auto download shfmt`)}const r=yield function(e){return i(this,void 0,void 0,(function*(){if((yield o.promises.stat(e)).isFile()){return u.execFileSync(e,["--version"],{encoding:"utf8"}).replace("\n","")}throw new Error(`[${e}] is not file`)}))}(e),l=r!==s.config.shfmtVersion;return l?t.appendLine(`current shfmt version : ${r} ,is outdate to new version : ${s.config.shfmtVersion}`):s.config.needCheckInstall=!1,l}catch(e){return t.appendLine("shfmt hasn't downloaded yet!"+e),t.show(),!0}}))}(n,t)){t.show();try{yield function(e){return i(this,void 0,void 0,(function*(){try{yield o.promises.access(e)}catch(e){return}yield o.promises.unlink(e)}))}(n)}catch(e){return t.appendLine(`clean old file failed:[ ${n} ] ,please delete it mutual`),void t.show()}const e=y();try{t.appendLine("Shfmt will be downloaded automatically!"),t.appendLine(`download url: ${e}`),t.appendLine(`download to: ${n}`),t.appendLine("If the download fails, you can manually download it to the dest directory."),t.appendLine('Or download to another directory, and then set the "shellformat.path" as the path'),t.appendLine("download shfmt page: https://github.com/mvdan/sh/releases"),t.appendLine("You can't use this plugin until the download is successful."),t.show(),yield h(e,n,(e,n,i)=>{Math.floor(i/5){let n=null,r=[];e.hunks.forEach(e=>{let t=e.oldStart;e.lines.forEach(e=>{switch(e.substr(0,1)){case"-":null==n&&(n=new l(a.EDIT_DELETE,new i.Position(t-1,0))),n.end=new i.Position(t,0),t++;break;case"+":null==n?n=new l(a.EDIT_INSERT,new i.Position(t-1,0)):n.action===a.EDIT_DELETE&&(n.action=a.EDIT_REPLACE),n.text+=e.substr(1)+"\n";break;case" ":t++,null!=n&&r.push(n),n=null}}),null!=n&&r.push(n)}),t.push({fileName:e.oldFileName,edits:r})}),t}t.Edit=l,t.getEdits=function(e,t,n){return"win32"===process.platform&&(t=t.split("\r\n").join("\n"),n=n.split("\r\n").join("\n")),u([o.structuredPatch(e,e,t,n,"","")])[0]},t.getEditsFromUnifiedDiffStr=function(e){return e.startsWith("---")&&(e=e.split("---").join("Index\n---")),u(o.parsePatch(e))}},function(e,t,n){"use strict";t.__esModule=!0,t.canonicalize=t.convertChangesToXML=t.convertChangesToDMP=t.merge=t.parsePatch=t.applyPatches=t.applyPatch=t.createPatch=t.createTwoFilesPatch=t.structuredPatch=t.diffArrays=t.diffJson=t.diffCss=t.diffSentences=t.diffTrimmedLines=t.diffLines=t.diffWordsWithSpace=t.diffWords=t.diffChars=t.Diff=void 0;var i,r=n(0),o=(i=r)&&i.__esModule?i:{default:i},s=n(15),a=n(16),l=n(3),u=n(17),f=n(18),c=n(19),d=n(20),h=n(21),p=n(4),g=n(23),m=n(11),v=n(25),w=n(26);t.Diff=o.default,t.diffChars=s.diffChars,t.diffWords=a.diffWords,t.diffWordsWithSpace=a.diffWordsWithSpace,t.diffLines=l.diffLines,t.diffTrimmedLines=l.diffTrimmedLines,t.diffSentences=u.diffSentences,t.diffCss=f.diffCss,t.diffJson=c.diffJson,t.diffArrays=d.diffArrays,t.structuredPatch=m.structuredPatch,t.createTwoFilesPatch=m.createTwoFilesPatch,t.createPatch=m.createPatch,t.applyPatch=h.applyPatch,t.applyPatches=h.applyPatches,t.parsePatch=p.parsePatch,t.merge=g.merge,t.convertChangesToDMP=v.convertChangesToDMP,t.convertChangesToXML=w.convertChangesToXML,t.canonicalize=c.canonicalize},function(e,t,n){"use strict";t.__esModule=!0,t.characterDiff=void 0,t.diffChars=function(e,t,n){return s.diff(e,t,n)};var i,r=n(0),o=(i=r)&&i.__esModule?i:{default:i};var s=t.characterDiff=new o.default},function(e,t,n){"use strict";t.__esModule=!0,t.wordDiff=void 0,t.diffWords=function(e,t,n){return n=(0,s.generateOptions)(n,{ignoreWhitespace:!0}),u.diff(e,t,n)},t.diffWordsWithSpace=function(e,t,n){return u.diff(e,t,n)};var i,r=n(0),o=(i=r)&&i.__esModule?i:{default:i},s=n(10);var a=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,l=/\S/,u=t.wordDiff=new o.default;u.equals=function(e,t){return this.options.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e===t||this.options.ignoreWhitespace&&!l.test(e)&&!l.test(t)},u.tokenize=function(e){for(var t=e.split(/(\s+|\b)/),n=0;n2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof t&&(t=(0,r.parsePatch)(t)),Array.isArray(t)){if(t.length>1)throw new Error("applyPatch only works with a single input.");t=t[0]}var i=e.split(/\r\n|[\n\v\f\r\x85]/),o=e.match(/\r\n|[\n\v\f\r\x85]/g)||[],a=t.hunks,l=n.compareLine||function(e,t,n,i){return t===i},u=0,f=n.fuzzFactor||0,c=0,d=0,h=void 0,p=void 0;function g(e,t){for(var n=0;n0?r[0]:" ",s=r.length>0?r.substr(1):r;if(" "===o||"-"===o){if(!l(t+1,i[t],o,s)&&++u>f)return!1;t++}}return!0}for(var m=0;m0?C[0]:" ",T=C.length>0?C.substr(1):C,D=L.linedelimiters[S];if(" "===k)b++;else if("-"===k)i.splice(b,1),o.splice(b,1);else if("+"===k)i.splice(b,0,T),o.splice(b,0,D),b++;else if("\\"===k){var F=L.lines[S-1]?L.lines[S-1][0]:null;"+"===F?h=!0:"-"===F&&(p=!0)}}}if(h)for(;!i[i.length-1];)i.pop(),o.pop();else p&&(i.push(""),o.push("\n"));for(var M=0;Me.length)return!1;for(var n=0;n/g,">")).replace(/"/g,""")}t.__esModule=!0,t.convertChangesToXML=function(e){for(var t=[],n=0;n"):r.removed&&t.push(""),t.push(i(r.value)),r.added?t.push(""):r.removed&&t.push("")}return t.join("")}},function(e,t){e.exports=require("https")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.config={shfmtVersion:"v3.2.4",needCheckInstall:!0}}]); //# sourceMappingURL=extension.js.map ```

I manually edited in the changes from saltchang's PR to the file.