shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Typescript??

Open j-d-carmichael opened this issue 3 years ago • 28 comments

Issue summary

The full codebase is JS not TS.. where as clearly the shopify team writes in modern typescript https://github.com/Shopify/shopify-node-api

Expected behavior

To see typescript

Actual behavior

See javascript

j-d-carmichael avatar Jan 21 '22 22:01 j-d-carmichael

I would be interested to know if typescript for this repo is in the pipeline?

Would it make sense to use something like NestJS for the server and continue to use NextJS for the client?

Anyone else be interested in this?

lukeclifton avatar Jan 25 '22 15:01 lukeclifton

I don't know why this thing is even using nextjs.. there is zero requirement for SSR... sticking a heavily opinionated angular style backend framework on top.. that sounds like a whole world pain unless you happen to be a next & nest dev...

how about just a super simple and regular react app (without next) talking to a simple koa or express api.. let folk have a super easy entry to this shopify world and coupled with docs that are simple to follow :D

j-d-carmichael avatar Jan 25 '22 15:01 j-d-carmichael

Yeah i see your point. Keeping it simple works for easy entry but i find that most commercial projects really benefit from a more opinionated framework with the normal required features.

Maybe theres a need for a two projects, one for starters and one for more advanced commercial use.

But either way, having this repo support typescript would be most ideal.

lukeclifton avatar Jan 25 '22 15:01 lukeclifton

I cannot imagine that any company is using this code as-is.. the biggest hurdle we found was understanding the shopify code to be able to reverse engineer it into our own style of working :) so the simpler the better.. but yea it's 2022 Shopify.. bring the typescript :D

j-d-carmichael avatar Jan 25 '22 15:01 j-d-carmichael

I have only just started build an app and it is extremely frustrating to use the node app from the cli. It seems to have been hacked together to run in development as a learning material rather than a foundation for producing a production app. How do people here build the server after converting to typescript, I'm really struggling with unpicking the babel-preset and the server/index.js ?

nikolan avatar Jan 31 '22 16:01 nikolan

@nikolan I build the server with: "build:server": "tsc --project tsconfig.server.json", (package.json script)

I use tsc for building and ts-node for development.

The server has its own tsconfig.json file.

lukeclifton avatar Jan 31 '22 16:01 lukeclifton

Thanks, @lukeclifton! Do you call "build:server" separately from your build pipeline or is it perhaps a naming convention to integrate with the rest of the build? What do you deploy in? I'm using docker and the final image is about 104MB when pushed in the registry. I thought of trying some bundeling with esbuild. I don't have much experience running nodejs in production, so filtering noise from signal is still difficult. Thus I found out that the server/index.js should not be run in production. Does anyone have any advice on how to build the server with esbuild or perhaps webpack?

nikolan avatar Jan 31 '22 17:01 nikolan

I got a fork of this working with next.js and typescript You can find it here https://github.com/solvedata/shopify-app-nextjs-typescript

jono-allen avatar Feb 04 '22 01:02 jono-allen

@jono-allen that's cool - we hit another issue.

The koa-middleware from shopify is somewhat covertly being deprecated. We submitted our app and it got rejected based on an outdated api attribute:

https://github.com/Shopify/koa-shopify-auth/issues/134

https://github.com/Shopify/shopify-node-api/tree/main/docs looks to be the new way.

Shopify are being wildly unprofessional here and incredibly cavalier with other businesses money in dev time, it is completely ridiculous.

j-d-carmichael avatar Feb 04 '22 09:02 j-d-carmichael

Thanks @jono-allen, this looks great! @j-d-carmichael I appreciate the feedback on the auth. It is a shame they haven't at least documented it.

nikolan avatar Feb 04 '22 17:02 nikolan

@j-d-carmichael thanks for pointing that out, our plan was to start building our app out but good now we know we need another starter project before then. Very disappointing the readme hasn't been updated to reflect this on the cli.

I found a link to this repo on the shopify-node-api repo

I'm going to try that and then might convert it to typescript and go from there

jono-allen avatar Feb 07 '22 19:02 jono-allen

@jono-allen This repo looks great. Thanks for sharing.

I have actually been working on a project which uses a similar approach using only NextJS and going serverless on Vercel. Seems to work really well and for most simple apps should make a great commercial choice.

lukeclifton avatar Feb 09 '22 18:02 lukeclifton

@lukeclifton did you get it to generate both online and offline tokens? I am thinking to retrofit a shopify cli generated app to this approach.

nikolan avatar Feb 14 '22 22:02 nikolan

Hey @nikolan. I have only implemented auth for offline tokens but it would be simple enough to implement both.

lukeclifton avatar Feb 16 '22 12:02 lukeclifton

Looks like Shopify are pivoting towards Express.

npx degit shopify/shopify-app-node#sample_app_updates

I started building our app with their early release of the example app. It has been an upward struggle for me to convert it to Typescript.

nikolan avatar Feb 20 '22 13:02 nikolan

@nikolan Thanks. Hadn't noticed the update until seeing your message.

lukeclifton avatar Feb 21 '22 12:02 lukeclifton

I can help convert to typescript once its stabilised

lukeclifton avatar Feb 21 '22 12:02 lukeclifton

Yea we released our app using their Koa garbage patch code in pure js.. not ideal but.. our api only acts as a gateway/proxy to the rest of our systems internally

We found in one of the many issue other people also raised on their code, someone forked and got working their original koa auth package, "simple-koa-shopify-auth" https://www.npmjs.com/package/simple-koa-shopify-auth hats off to this fella! With this we were able to publish our app using shopify's latest api, so bypassed the 6-8 month deprecation deadline.

(We did find though that when you explain to the app reviewer the situation and point to these issue and that their own systems are a mess, they will allow you to publish your app with the use of the old API... but.. it will die soon.. hence the switch)

We will wait now for shopify to finalise their changes on the express migration, hopefully it is a better system that the outdated files that get lumped onto your drive via their "shopify cli tool"

We also found that removing that ngroc thing actually speeds up the development time, just syncing code through a public domain.. which essentially leaves the "cli tool" a redundant waste of space :D

the frustration with shopify... it is insane that they can existing on the market as they do.. feels like the have left the door wide wide open for a competitor

j-d-carmichael avatar Feb 22 '22 14:02 j-d-carmichael

Kinda related to the starter app being a pain, is there any good documentation or another custom starter template that is made for a standalone app instead of an embedded one? I'm starting to create a quite complex custom app and I don't want it embedded in the admin.

imjuniper avatar Feb 28 '22 14:02 imjuniper

Has anyone managed to get their latest node-app running with TS?

nikolan avatar May 26 '22 22:05 nikolan

This is the closest thing I found to a working example. Hats off to @LeonelAimar for building it. https://github.com/LeonelAimar/new-shopify-node-ts-app-boilerplate

I had to go get acquainted with esm modules (Node.js TS is my second language). So in the end this is what my scripts look like:

 "scripts": {
    "build": "npx tsc && yarn run build:client",
    "build:client": "vite build --outDir dist/client",
    "debug": "node --inspect-brk server/index.js",
    "newDev": "cross-env NODE_ENV=development nodemon",
    "dev": "tsc && cross-env NODE_ENV=development nodemon --experimental-specifier-resolution=node dist/server/index.js --watch ./src/**/*",
    "prepare": "husky install",
    "serve": "node --experimental-specifier-resolution=node dist/server/index.js",
    "start": "yarn run serve",
    "test": "vitest --reporter=verbose"
  },

nikolan avatar Jun 06 '22 21:06 nikolan

This is the closest thing I found to a working example. Hats off to @LeonelAimar for building it. https://github.com/LeonelAimar/new-shopify-node-ts-app-boilerplate/blob/master/src/server/middlewares/authHandlers.ts

I had to go get acquainted with esm modules (Node.js TS is my second language). So in the end this is what my scripts look like:

 "scripts": {
    "build": "npx tsc && yarn run build:client",
    "build:client": "vite build --outDir dist/client",
    "debug": "node --inspect-brk server/index.js",
    "newDev": "cross-env NODE_ENV=development nodemon",
    "dev": "tsc && cross-env NODE_ENV=development nodemon --experimental-specifier-resolution=node dist/server/index.js --watch ./src/**/*",
    "prepare": "husky install",
    "serve": "node --experimental-specifier-resolution=node dist/server/index.js",
    "start": "yarn run serve",
    "test": "vitest --reporter=verbose"
  },

hey @nikolan ! ty so much, i'm glad to hear that you found that middleware useful, i was working a lot on creating that folder structure and POO based on their boilerplate app, but then got overburned at work and still haha. The idea of building this was just to keeping the back & front separated so everyone would be able to use either frontend framework they want, also to have the backend on a more default folder structure. Also glad that Shopify decided to rollback from that Nextjs version of the boilerplate, i just find more scalable and for more people to be comfortable with this type of app structure, backend and frontend separated as you can use (or not) any framework.

LeonelAimar avatar Jun 07 '22 05:06 LeonelAimar

@LeonelAimar I found the whole setup useful, I meant to link the repo but seem to have copied a link to a particular file. I've edited the original comment with the correct link now. Thanks again for putting it out there and I hope you get the time you need to keep it up as I am sure other people will be flocking to it for the TS goodness.

nikolan avatar Jun 07 '22 07:06 nikolan

Hey guys! I've come up with this setup https://github.com/kanzitelli/shopify-app-template-typescript. Fully bootstrapped from their template and just wrapped with TS configuration (not an expert tho). I've been testing on my machine with dev and prod environments, and it seems to be working well. Would be great if you could test it on your side too :)

kanzitelli avatar Jun 08 '22 04:06 kanzitelli

@kanzitelli that's pretty neat. I like that you are talking about production setup in your README. Running apps in production and building resilient apps are topics I find seriously lacking in any Shopify documentation aimed at onboarding new developers.

nikolan avatar Jun 08 '22 21:06 nikolan

@LeonelAimar I found the whole setup useful, I meant to link the repo but seem to have copied a link to a particular file. I've edited the original comment with the correct link now. Thanks again for putting it out there and I hope you get the time you need to keep it up as I am sure other people will be flocking to it for the TS goodness.

Oh well, that's awesome! i really appreciate that!! I'll try to keep updating it with some upgrades! Take care bud 👍 !!

LeonelAimar avatar Jun 09 '22 20:06 LeonelAimar

I got a fork of this working with next.js and typescript You can find it here https://github.com/solvedata/shopify-app-nextjs-typescript

@jono-allen Do you still have a working version of this? I think I'd rather use Next

stevepsharpe avatar Jul 04 '22 17:07 stevepsharpe

Here are the steps to add TS, ESLint & Prettier to an Shopify 3.x CLI generated app, at least to the frontend side.

archiemcquaid avatar Aug 03 '22 17:08 archiemcquaid

Ive started a port of the CLI generated app to typescript. Frontend is done and most of the express backend is done.

Feel free to use this to get started :) https://github.com/KaiSpencer/shopify-app-template-node-ts

KaiSpencer avatar Oct 06 '22 15:10 KaiSpencer

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] avatar Dec 06 '22 02:12 github-actions[bot]