Clarify how to bootstrap?
alper opened this issue ยท 10 comments
Not sure why this isn't working, but:
npm install
does:
โฏ npm install [๐ 03 11:09]
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/alper/Code/contrib/TwirpScript/dist/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/alper/Code/contrib/TwirpScript/dist/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alper/.npm/_logs/2023-02-03T09_09_25_576Z-debug-0.log
Hey @alper, no bootstrapping is necessary other than the installation instructions enumerated in the README. Could you share a minimal reproduction example?
Eg here's a series of steps that should work locally for you:
brew install protobuf
mkdir twirpscript-example
cd twirpscript-example
yarn init -y
yarn add twirpscript
### manual step: create a proto file such as myproto.proto
npx twirpscript
Is there anything exotic with your project structure? The path /Users/alper/Code/contrib/TwirpScript/dist/package.json
looks surprising to me.
I was trying to build/test the project itself. Or is that weird?
I was trying to build/test the project itself. Or is that weird?
Ah, got it. Any particular reason why? I haven't had many contributors yet, so I haven't set aside the time to document local development -- probably a bit of a chicken and egg problem there ๐
having issues with code generation
`npx twirpscript
[TwirpScript] Protobuf Compiler Error:
/opt/homebrew/lib/node_modules/twirpscript/node_modules/prettier/parser-babel.js:22
)+W}h.exports={hasPragma:F,insertPragma:I}}}),mr=K({"src/utils/is-non-empty-array.js"(l,h){"use strict";V();function f(d){return Array.isArray(d)&&d.length>0}h.exports=f}}),Mo=K({"src/language-js/loc.js"(l,h){"use strict";V();var f=mr();function d(S){var F,I;let C=S.range?S.range[0]:S.start,L=(F=(I=S.declaration)===null||I===void 0?void 0:I.decorators)!==null&&F!==void 0?F:S.decorators;return f(L)?Math.min(d(L[0]),C):C}function y(S){return S.range?S.range[1]:S.end}function P(S,F){let I=d(S);return Number.isInteger(I)&&I===d(F)}function g(S,F){let I=y(S);return Number.isInteger(I)&&I===y(F)}function T(S,F){return P(S,F)&&g(S,F)}h.exports={locStart:d,locEnd:y,hasSameLocStart:P,hasSameLoc:T}}}),_o=K({"src/language-js/parse/utils/create-parser.js"(l,h){"use strict";V();var{hasPragma:f}=Uf(),{locStart:d,locEnd:y}=Mo();function P(g){return g=typeof g=="function"?{parse:g}:g,Object.assign({astFormat:"estree",hasPragma:f,locStart:d,locEnd:y},g)}h.exports=P}}),yr=K({"src/common/parser-create-error.js"(l,h){"use strict";V();function f(d,y){let P=new SyntaxError(d+" ("+y.start.line+":"+y.start.column+")");return P.loc=y,P}h.exports=f}}),Ro=K({"src/language-js/parse/utils/create-babel-parse-error.js"(l,h){"use strict";V();var f=yr();function d(y){let{message:P,loc:g}=y;return f(P.replace(/ \(.*\)/,""),{start:{line:g?g.line:0,column:g?g.column+1:0}})}h.exports=d}}),$f=K({"src/language-js/utils/is-ts-keyword-type.js"(l,h){"use strict";V();function f(d){let{type:y}=d;return y.startsWith("TS")&&y.endsWith("Keyword")}h.exports=f}}),Hf=K({"src/language-js/utils/is-block-comment.js"(l,h){"use strict";V();var f=new Set(["Block","CommentBlock","MultiLine"]),d=y=>f.has(y==null?void 0:y.type);h.exports=d}}),zf=K({"src/language-js/utils/is-type-cast-comment.js"(l,h){"use strict";V();var f=Hf();function d(y){return f(y)&&y.value[0]==="*"&&/@(?:type|satisfies)\b/.test(y.value)}h.exports=d}}),Vf=K({"src/utils/get-last.js"(l,h){"use strict";V();var f=d=>d[d.length-1];h.exports=f}}),jo=K({"src/language-js/parse/postprocess/visit-node.js"(l,h){"use strict";V();function f(d,y){if(Array.isArray(d)){for(let P=0;P<d.length;P++)d[P]=f(d[P],y);return d}if(d&&typeof d=="object"&&typeof d.type=="string"){let P=Object.keys(d);for(let g=0;g<P.length;g++)d[P[g]]=f(d[P[g]],y);return y(d)||d}return d}h.exports=f}}),qo=K({"src/language-js/parse/postprocess/throw-syntax-error.js"(l,h){"use strict";V();var f=yr();function d(y,P){let{start:g,end:T}=y.loc;throw f(P,{start:{line:g.line,column:g.column+1},end:{line:T.line,column:T.column+1}})}h.exports=d}}),Kf=K({"src/language-js/parse/postprocess/typescript.js"(l,h){"use strict";V();var f=mr(),d=jo(),y=qo(),P={AbstractKeyword:126,SourceFile:308,PropertyDeclaration:169};function g(I){for(;I&&I.kind!==P.SourceFile;)I=I.parent;return I}function T(I){let{illegalDecorators:C}=I;if(!f(C))return;let[{expression:L}]=C,j=g(L),[k,H]=[L.pos,L.end].map(W=>{let{line:B,character:_}=j.getLineAndCharacterOfPosition(W);return{line:B+1,column:_}});y({loc:{start:k,end:H}},"Decorators are not valid here.")}function S(I,C){I.kind!==P.PropertyDeclaration||I.modifiers&&!I.modifiers.some(L=>L.kind===P.AbstractKeyword)||I.initializer&&C.value===null&&y(C,"Abstract property cannot have an initializer")}function F(I,C){let{esTreeNodeToTSNodeMap:L,tsNodeToESTreeNodeMap:j}=C.tsParseResult;d(I,k=>{let H=L.get(k);if(!H)return;let W=j.get(H);W===k&&(T(H),S(H,W))})}h.exports={throwErrorForInvalidNodes:F}}}),Wf=K({"src/language-js/parse/postprocess/index.js"(l,h){"use strict";V();var{locStart:f,locEnd:d}=Mo(),y=$f(),P=zf(),g=Vf(),T=jo(),{throwErrorForInvalidNodes:S}=Kf(),F=qo();function I(k,H){if(H.parser==="typescript"&&/@|abstract/.test(H.originalText)&&S(k,H),H.parser!=="typescript"&&H.parser!=="flow"&&H.parser!=="acorn"&&H.parser!=="espree"&&H.parser!=="meriyah"){let B=new Set;k=T(k,_=>{_.leadingComments&&_.leadingComments.some(P)&&B.add(f(_))}),k=T(k,_=>{if(_.type==="ParenthesizedExpression"){let{expression:u}=_;if(u.type==="TypeCastExpression")return u.range=_.range,u;let G=f(_);if(!B.has(G))return u.extra=Object.assign(Object.assign({},u.extra),{},{parenthesized:!0}),u}})}return k=T(k,B=>{switch(B.type){case"ChainExpression":return C(B.expression);case"LogicalExpression":{if(L(B))return j(B);break}case"VariableDeclaration":{let _=g(B.declarations);_&&_.init&&W(B,_);break}case"TSParenthesizedType":return y(B.typeAnnotation)||B.typeAnnotation.type==="TSThisType"||(B.typeAnnotation.range=[f(B),d(B)]),B.typeAnnotation;case"TSTypeParameter":if(typeof B.name=="string"){let _=f(B);B.name={type:"Identifier",name:B.name,range:[_,_+B.name.length]}}break;case"ObjectExpression":if(H.parser==="typescript"){let _=B.properties.find(u=>u.type==="Property"&&u.value.type==="TSEmptyBodyFunctionExpression");_&&F(_.value,"Unexpected token.")}break;case"SequenceExpression":{let _=g(B.expressions);B.range=[f(B),Math.min(d(_),d(B))];break}case"TopicReference":H.__isUsingHackPipeline=!0;break;case"ExportAllDeclaration":{let{exported:_}=B;if(H.parser==="meriyah"&&_&&_.type==="Identifier"){let u=H.originalText.slice(f(_),d(_));(u.startsWith('"')||u.startsWith("'"))&&(B.exported=Object.assign(Object.assign({},B.exported),{},{type:"Literal",value:B.exported.name,raw:u}))}break}case"PropertyDefinition":if(H.parser==="meriyah"&&B.static&&!B.computed&&!B.key){let _="static",u=f(B);Object.assign(B,{static:!1,key:{type:"Identifier",name:_,range:[u,u+_.length]}})}break}}),k;function W(B,_){H.originalText[d(_)]!==";"&&(B.range=[f(B),d(_)])}}function C(k){switch(k.type){case"CallExpression":k.type="OptionalCallExpression",k.callee=C(k.callee);break;case"MemberExpression":k.type="OptionalMemberExpression",k.object=C(k.object);break;case"TSNonNullExpression":k.expression=C(k.expression);break}return k}function L(k){return k.type==="LogicalExpression"&&k.right.type==="LogicalExpression"&&k.operator===k.right.operator}function j(k){return L(k)?j({type:"LogicalExpression",operator:k.operator,left:j({type:"LogicalExpression",operator:k.operator,left:k.left,right:k.right.left,range:[f(k.left),d(k.right.left)]}),right:k.right.right,range:[f(k),d(k)]}):k}h.exports=I}}),Uo=K({"node_modules/@babel/parser/lib/index.js"(l){"use strict";V(),Object.defineProperty(l,"__esModule",{value:!0});function h(t,r){if(t==null)return{};var e={},s=Object.keys(t),i,a;for(a=0;a<s.length;a++)i=s[a],!(r.indexOf(i)>=0)&&(e[i]=t[i]);return e}var f=class{constructor(t,r,e){this.line=void 0,this.column=void 0,this.index=void 0,this.line=t,this.column=r,this.index=e}},d=class{constructor(t,r){this.start=void 0,this.end=void 0,this.filename=void 0,this.identifierName=void 0,this.start=t,this.end=r}};function y(t,r){let{line:e,column:s,index:i}=t;return new f(e,s+r,i+r)}var P={SyntaxError:"BABEL_PARSER_SYNTAX_ERROR",SourceTypeModuleError:"BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"},g=function(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t.length-1;return{get(){return t.reduce((e,s)=>e[s],this)},set(e){t.reduce((s,i,a)=>a===r?s[i]=e:s[i],this)}}},T=(t,r,e)=>Object.keys(e).map(s=>[s,e[s]]).filter(s=>{let[,i]=s;return!!i}).map(s=>{let[i,a]=s;return[i,typeof a=="function"?{value:a,enumerable:!1}:typeof a.reflect=="string"?Object.assign({},a,g(a.reflect.split("."))):a]}).reduce((s,i)=>{let[a,n]=i;return Object.defineProperty(s,a,Object.assign({configurable:!0},n))},Object.assign(new t,r)),S={ImportMetaOutsideModule:{message:
import.meta may appear only with 'sourceType: "module"',code:P.SourceTypeModuleError},ImportOutsideModule:{message:
'import' and 'export' may appear only with 'sourceType: "module"'`,code:P.SourceTypeModuleError}},F={ArrayPattern:"array destructuring pattern",AssignmentExpression:"assignment expression",AssignmentPattern:"assignment expression",ArrowFunctionExpression:"arrow function expression",ConditionalExpression:"conditional expression",CatchClause:"catch clause",ForOfStatement:"for-of statement",ForInStatement:"for-in statement",ForStatement:"for-loop",FormalParameters:"function parameter list",Identifier:"identifier",ImportSpecifier:"import specifier",ImportDefaultSpecifier:"import default specifier",ImportName--protoscript_out: protoc-gen-protoscript: Plugin failed with status code 1.
No .pb.ts files were created or updated.`
@aaliomer could you share an example or repo that reproduces this?
i have a test proto file i created all local
`// code generated by scripts/create-crud-proto.py
syntax = "proto3";
package mypkg.gen_proto.test;
option go_package = "gen_proto/test";
service TestService {
rpc get(stream ShiftQuery) returns (Result);
}
message Response {
string error = 1;
}
`
@aaliomer could you share what your project structure looks like? The error path showing twirpscript in /opt/homebrew/lib makes me suspect this is your local setup and not an issue with this library.
So what i did is i installed twirpscript globally. is that a problem?
the proto file is in protos/Test.proto or something
i was testing out the library
@aaliomer Yes, a global install is going to be problematic for the default twirp file finding behavior. Could you install twirpscript locally in your project rather than globally and let me know if this resolves for you?
same error when installing locally. I dont know what else it could be
jayjay@jays-MacBook-Air protos % npx twirpscript
[TwirpScript] Protobuf Compiler Error:
/Users/jayjay/Documents/projects/savior2/protos/node_modules/prettier/parser-babel.js:22
)+W}h.exports={hasPragma:F,insertPragma:I}}}),mr=K({"src/utils/is-non-empty-array.js"(l,h){"use strict";V();function f(d){return Array.isArray(d)&&d.length>0}h.exports=f}}),Mo=K({"src/language-js/loc.js"(l,h){"use strict";V();var f=mr();function d(S){var F,I;let C=S.range?S.range[0]:S.start,L=(F=(I=S.declaration)===null||I===void 0?void 0:I.decorators)!==null&&F!==void 0?F:S.decorators;return f(L)?Math.min(d(L[0]),C):C}function y(S){return S.range?S.range[1]:S.end}function P(S,F){let I=d(S);return Number.isInteger(I)&&I===d(F)}function g(S,F){let I=y(S);return Number.isInteger(I)&&I===y(F)}function T(S,F){return P(S,F)&&g(S,F)}h.exports={locStart:d,locEnd:y,hasSameLocStart:P,hasSameLoc:T}}}),_o=K({"src/language-js/parse/utils/create-parser.js"(l,h){"use strict";V();var{hasPragma:f}=Uf(),{locStart:d,locEnd:y}=Mo();function P(g){return g=typeof g=="function"?{parse:g}:g,Object.assign({astFormat:"estree",hasPragma:f,locStart:d,locEnd:y},g)}h.exports=P}}),yr=K({"src/common/parser-create-error.js"(l,h){"use strict";V();function f(d,y){let P=new SyntaxError(d+" ("+y.start.line+":"+y.start.column+")");return P.loc=y,P}h.exports=f}}),Ro=K({"src/language-js/parse/utils/create-babel-parse-error.js"(l,h){"use strict";V();var f=yr();function d(y){let{message:P,loc:g}=y;return f(P.replace(/ \(.*\)/,""),{start:{line:g?g.line:0,column:g?g.column+1:0}})}h.exports=d}}),$f=K({"src/language-js/utils/is-ts-keyword-type.js"(l,h){"use strict";V();function f(d){let{type:y}=d;return y.startsWith("TS")&&y.endsWith("Keyword")}h.exports=f}}),Hf=K({"src/language-js/utils/is-block-comment.js"(l,h){"use strict";V();var f=new Set(["Block","CommentBlock","MultiLine"]),d=y=>f.has(y==null?void 0:y.type);h.exports=d}}),zf=K({"src/language-js/utils/is-type-cast-comment.js"(l,h){"use strict";V();var f=Hf();function d(y){return f(y)&&y.value[0]==="*"&&/@(?:type|satisfies)\b/.test(y.value)}h.exports=d}}),Vf=K({"src/utils/get-last.js"(l,h){"use strict";V();var f=d=>d[d.length-1];h.exports=f}}),jo=K({"src/language-js/parse/postprocess/visit-node.js"(l,h){"use strict";V();function f(d,y){if(Array.isArray(d)){for(let P=0;P<d.length;P++)d[P]=f(d[P],y);return d}if(d&&typeof d=="object"&&typeof d.type=="string"){let P=Object.keys(d);for(let g=0;g<P.length;g++)d[P[g]]=f(d[P[g]],y);return y(d)||d}return d}h.exports=f}}),qo=K({"src/language-js/parse/postprocess/throw-syntax-error.js"(l,h){"use strict";V();var f=yr();function d(y,P){let{start:g,end:T}=y.loc;throw f(P,{start:{line:g.line,column:g.column+1},end:{line:T.line,column:T.column+1}})}h.exports=d}}),Kf=K({"src/language-js/parse/postprocess/typescript.js"(l,h){"use strict";V();var f=mr(),d=jo(),y=qo(),P={AbstractKeyword:126,SourceFile:308,PropertyDeclaration:169};function g(I){for(;I&&I.kind!==P.SourceFile;)I=I.parent;return I}function T(I){let{illegalDecorators:C}=I;if(!f(C))return;let[{expression:L}]=C,j=g(L),[k,H]=[L.pos,L.end].map(W=>{let{line:B,character:_}=j.getLineAndCharacterOfPosition(W);return{line:B+1,column:_}});y({loc:{start:k,end:H}},"Decorators are not valid here.")}function S(I,C){I.kind!==P.PropertyDeclaration||I.modifiers&&!I.modifiers.some(L=>L.kind===P.AbstractKeyword)||I.initializer&&C.value===null&&y(C,"Abstract property cannot have an initializer")}function F(I,C){let{esTreeNodeToTSNodeMap:L,tsNodeToESTreeNodeMap:j}=C.tsParseResult;d(I,k=>{let H=L.get(k);if(!H)return;let W=j.get(H);W===k&&(T(H),S(H,W))})}h.exports={throwErrorForInvalidNodes:F}}}),Wf=K({"src/language-js/parse/postprocess/index.js"(l,h){"use strict";V();var{locStart:f,locEnd:d}=Mo(),y=$f(),P=zf(),g=Vf(),T=jo(),{throwErrorForInvalidNodes:S}=Kf(),F=qo();function I(k,H){if(H.parser==="typescript"&&/@|abstract/.test(H.originalText)&&S(k,H),H.parser!=="typescript"&&H.parser!=="flow"&&H.parser!=="acorn"&&H.parser!=="espree"&&H.parser!=="meriyah"){let B=new Set;k=T(k,_=>{_.leadingComments&&_.leadingComments.some(P)&&B.add(f(_))}),k=T(k,_=>{if(_.type==="ParenthesizedExpression"){let{expression:u}=_;if(u.type==="TypeCastExpression")return u.range=_.range,u;let G=f(_);if(!B.has(G))return u.extra=Object.assign(Object.assign({},u.extra),{},{parenthesized:!0}),u}})}return k=T(k,B=>{switch(B.type){case"ChainExpression":return C(B.expression);case"LogicalExpression":{if(L(B))return j(B);break}case"VariableDeclaration":{let _=g(B.declarations);_&&_.init&&W(B,_);break}case"TSParenthesizedType":return y(B.typeAnnotation)||B.typeAnnotation.type==="TSThisType"||(B.typeAnnotation.range=[f(B),d(B)]),B.typeAnnotation;case"TSTypeParameter":if(typeof B.name=="string"){let _=f(B);B.name={type:"Identifier",name:B.name,range:[_,_+B.name.length]}}break;case"ObjectExpression":if(H.parser==="typescript"){let _=B.properties.find(u=>u.type==="Property"&&u.value.type==="TSEmptyBodyFunctionExpression");_&&F(_.value,"Unexpected token.")}break;case"SequenceExpression":{let _=g(B.expressions);B.range=[f(B),Math.min(d(_),d(B))];break}case"TopicReference":H.__isUsingHackPipeline=!0;break;case"ExportAllDeclaration":{let{exported:_}=B;if(H.parser==="meriyah"&&_&&_.type==="Identifier"){let u=H.originalText.slice(f(_),d(_));(u.startsWith('"')||u.startsWith("'"))&&(B.exported=Object.assign(Object.assign({},B.exported),{},{type:"Literal",value:B.exported.name,raw:u}))}break}case"PropertyDefinition":if(H.parser==="meriyah"&&B.static&&!B.computed&&!B.key){let _="static",u=f(B);Object.assign(B,{static:!1,key:{type:"Identifier",name:_,range:[u,u+_.length]}})}break}}),k;function W(B,_){H.originalText[d(_)]!==";"&&(B.range=[f(B),d(_)])}}function C(k){switch(k.type){case"CallExpression":k.type="OptionalCallExpression",k.callee=C(k.callee);break;case"MemberExpression":k.type="OptionalMemberExpression",k.object=C(k.object);break;case"TSNonNullExpression":k.expression=C(k.expression);break}return k}function L(k){return k.type==="LogicalExpression"&&k.right.type==="LogicalExpression"&&k.operator===k.right.operator}function j(k){return L(k)?j({type:"LogicalExpression",operator:k.operator,left:j({type:"LogicalExpression",operator:k.operator,left:k.left,right:k.right.left,range:[f(k.left),d(k.right.left)]}),right:k.right.right,range:[f(k),d(k)]}):k}h.exports=I}}),Uo=K({"node_modules/@babel/parser/lib/index.js"(l){"use strict";V(),Object.defineProperty(l,"__esModule",{value:!0});function h(t,r){if(t==null)return{};var e={},s=Object.keys(t),i,a;for(a=0;a<s.length;a++)i=s[a],!(r.indexOf(i)>=0)&&(e[i]=t[i]);return e}var f=class{constructor(t,r,e){this.line=void 0,this.column=void 0,this.index=void 0,this.line=t,this.column=r,this.index=e}},d=class{constructor(t,r){this.start=void 0,this.end=void 0,this.filename=void 0,this.identifierName=void 0,this.start=t,this.end=r}};function y(t,r){let{line:e,column:s,index:i}=t;return new f(e,s+r,i+r)}var P={SyntaxError:"BABEL_PARSER_SYNTAX_ERROR",SourceTypeModuleError:"BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"},g=function(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t.length-1;return{get(){return t.reduce((e,s)=>e[s],this)},set(e){t.reduce((s,i,a)=>a===r?s[i]=e:s[i],this)}}},T=(t,r,e)=>Object.keys(e).map(s=>[s,e[s]]).filter(s=>{let[,i]=s;return!!i}).map(s=>{let[i,a]=s;return[i,typeof a=="function"?{value:a,enumerable:!1}:typeof a.reflect=="string"?Object.assign({},a,g(a.reflect.split("."))):a]}).reduce((s,i)=>{let[a,n]=i;return Object.defineProperty(s,a,Object.assign({configurable:!0},n))},Object.assign(new t,r)),S={ImportMetaOutsideModule:{message:
import.meta may appear only with 'sourceType: "module"',code:P.SourceTypeModuleError},ImportOutsideModule:{message:
'import' and 'export' may appear only with 'sourceType: "module"'`,code:P.SourceTypeModuleError}},F={ArrayPattern:"array destructuring pattern",AssignmentExpression:"assignment expression",AssignmentPattern:"assignment expression",ArrowFunctionExpression:"arrow function expression",ConditionalExpression:"conditional expression",CatchClause:"catch clause",ForOfStatement:"for-of statement",ForInStatement:"for-in statement",ForStatement:"for-loop",FormalParameters:"function parameter list",Identifier:"identifier",ImportSpecifier:"import specifier",ImportDefaultSpecifier:"import default specifier",Impor--protoscript_out: protoc-gen-protoscript: Plugin failed with status code 1.