Boilerplate / monorepo setup intended for npm package development

Overview

Assemble Package

Set up:

After creating your new repo from the github template plan out what your package(s) will be named and modify the contents of the packages directory to reflect this planning. Use the examples in the packages directory as reference, although you could rename both the directory and the name in the package.json file of any of the examples and work off of them.

  • Install Dependencies: yarn
  • Initialize Yarn (you will need to import the yarn/workspaces plugin): init:workspaces

Core concepts:

This is a monorepo and therefore introduces a few additional steps to getting all set up.

There are also mandatory concepts & dependencies that assist in a smooth development process:


Initialization:

  1. Removing the sample packages in the packages directory.
  2. Make a new directory with your package folder name.
  3. Navigate to that directory and run yarn init to create a fresh package.json file.
  4. Make sure to add a namespace / scope to the package name.
  5. Once that is all set up run yarn preconstruct init: this will add the necessary config for development and publishing.
  6. Start adding dependencies and building! when adding dependencies stay on the root level and make sure to specify the workspace you are targeting. yarn workspace [package-name] add ....
  7. If you don't want to bundle the dependency in the package make sure to use the --peer flag when adding to the workspace!
  8. If you ran the example apps before all this setup make sure to remove any .next / .parcel-cache and dist directories! If you don't clean up you will have problems moving forward.

Publishing:

Note: in order to leverage the monorepo approach in a npm publishing workflow you need to have a paid NPM account - this unlocks private packages (sadly a mandatory in this context).

Example:

Currently there are 2 example apps you can use to view your work. Simply import your package into either or both. Both examples have been configured to support web3 technologies out of the box with the below dependencies:

  • ethers, peed dep for the below web3 packages

  • wagmi for web3 integration

  • rainbowkit to handle wallet connection

  • tailwind css for basic styling / css integration

  • swr for fetch utils / caching

  • @zoralabs/nft-hooks for reading nft data

  • @zoralabs/zdk for querying the zora api

  • A Next Js app. Note that this is the most recent version of react and nextjs which introduces more stringent methodolgies around server and client side rendering. This is a good test environment to illustrate optimal package usage especially when content is not hydrated.

  • Vanilla React App: Less strict of a development environment in that you will not have to be as careful around SSR issues that are present with the combination of React 18 & Next.js 12+

TUTORIAL

  1. Getting started: Using the template and exploring the Repo: https://www.loom.com/share/2c06e5556bc4416095491d5ecb595703
  2. Exploring the repo further, running the example apps to demo the development process and how packages are consumed in development: https://www.loom.com/share/1bc4f356142046088f40fd02b804eb5d
  3. Creating a new package (and removing the examples and references in sample apps to the example packages in the repo template): https://www.loom.com/share/7a925693f28f4031a8588dd0483d7828
  4. Demonstrating importing our new package into the example apps: https://www.loom.com/share/775d05ae0e7e4a15baf941ce6b519f95
  5. Lets publish a package with changesets: https://www.loom.com/share/c60acbc744f745abacf7aa1af0b467ab
  6. And finally lets consume the package in another project, make some changes to it and publish again - and then update in the consumer app: https://www.loom.com/share/92ef615552c9401d81f3b5f21702afe4

The sample repo:

https://github.com/dblodorn/dains-really-fly-package

Further Reading:

Comments
  • Discussion: Animation Libraries / Auditing External Dependencies

    Discussion: Animation Libraries / Auditing External Dependencies

    @salieflewis raised the question around using framer motion in work that is intended to be published as a package any user can install with their react project.

    The question was specifically around using framer motion as a dependency to handle transitions, animations etc.

    We are already assuming and specifying peer dependencies for mandatory web3 libraries, and leveraging tailwind and postcss as the default styling utility.

    In general the gold standard is to keep your bundles as small as possible, reducing load times. It's preemptive optimization.

    My opinion around this is to be library agnostic as much as possible when the included library introduces and api or markup that may become "black boxy" to consumers of the package... hence if this is something that could be achieved with browser native apis (like css animations / transitions) we try that first with the design intention of letting a user opt out or override with ease.

    For UI components this could introduce a modular design approach where we split smaller chunks of UI into composable elements that leverage a parent provider to allow for reordering.

    Prior work that inspires this approach can be seen in NFT Components

    Theoretically if you can read for state change and can wrap a component with the animation library of choice api then the user can decide for themselves what addition libraries they want to introduce to their project.

    Also when selecting libraries checking out info like this article Reduce Bundle Size(framer.motion) is really helpful.

    opened by dblodorn 4
  • app wrapper doesn't enable goerli

    app wrapper doesn't enable goerli

    @dblodorn sorry for not making the pull request directly, but line 9 of AppWrapper.tsx in the examples/nextjs (assume same for react too) should have chain.goerli as well so that the test apps are compatible with testnet. without this u cant use goerli in local dev, just burned an hour or so figuring this out

    photo of where it needs to be added Screen Shot 2022-09-23 at 12 50 03 AM

    enhancement 
    opened by 0xTranqui 3
  • [WIP]: upgrade to next13 and bump rainbowkit and wagmi versions to latest

    [WIP]: upgrade to next13 and bump rainbowkit and wagmi versions to latest

    Staging this for a little feedback... probably going to hold off on pushing into main for a little bit.

    This next13 upgrade is actually a little tricky... next13 introduces a fair amount of new concepts to next.js Still feel it's important to move forward with the most up to date configurations / so this isn't stale.

    https://beta.nextjs.org/docs/upgrade-guide#upgrading

    https://nextjs.org/blog/next-13

    Also - nice writeup on hydration errors: https://codingwithmanny.medium.com/understanding-hydration-errors-in-nextjs-13-with-a-web3-wallet-connection-8155c340fbd5

    opened by dblodorn 2
  • Package monorepo development environment

    Package monorepo development environment

    This PR introduces three configured examples of a package being developed in the packages directory being consumed by a sample next.js app that has been configured as a basic "web3" dapp skeleton.

    Meaning there are included dependencies to emulate the baseline requirements for an Ethereum Dapp:

    "@rainbow-me/rainbowkit": "^0.6.0",
    "@zoralabs/nft-hooks": "^1.1.9",
    "@zoralabs/zdk": "^2.1.8",
    "ethers": "^5.7.1",
    "next": "^12.3.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "swr": "^1.3.0",
    "wagmi": "^0.6.6"
    

    Changesets Cli has also been integrated for the publishing step, this enforces keep a change log and assists with semantic versioning.

    I've followed this guide somewhat, most specifically for setting up changesets. https://monorepo.guide/getting-started

    One small issue that is most likely related to react 18+ / next.js 12 + has arisen around ssr hydration errors. Not fatal - but annoying, and forces the question around optimization for react 18 - and how much additional research and work that entails.

    WIP Video: https://www.loom.com/share/e73dc50a1c634221b3e7a8f77a49be65

    opened by dblodorn 2
  • Upgrade test next app to next13

    Upgrade test next app to next13

    This upgrade is a little tricky... next13 introduces a fair amount of new concepts to next.js Still feel it's important to move forward with the most up to date configurations / so this isn't stale.

    https://beta.nextjs.org/docs/upgrade-guide#upgrading

    https://nextjs.org/blog/next-13

    Also - nice writeup on hydration errors: https://codingwithmanny.medium.com/understanding-hydration-errors-in-nextjs-13-with-a-web3-wallet-connection-8155c340fbd5

    enhancement 
    opened by dblodorn 1
  • Update yarn config

    Update yarn config

    Yarn config updates

    TLDR Spent a bunch of time messing around with yarn 2/3 but just ended up modifying the yarn config a little and adding a clean command - and slipped an edit to the changesets config defaulting the access property to public https://github.com/changesets/changesets/issues/503

    ☠️ Upgrading to yarn 3 notes--- 🥴

    Ok so the new version of Yarn (yarn >3.X) is kinda hellish and has introduced numerous bugs tracing into dependencies of dependencies. Bottom line it seems like a lot of work to get everything working correctly and the older version of yarn just works... seemingly for most everyone using it, and that's better for a template which is meant to be an easy starting point.

    I'm going to revert back to a stable setup...

    just a pile of errors like this - that were not an issue with older version of yarn:

    Screen Shot 2022-09-22 at 9 25 56 AM

    Initial motivation to upgrade was the excitment around using @yarnpkg/plugin-workspace-tools - this resulted in needed to upgrade the version of yarn i was using to a version that supported yarn plugins: https://yarnpkg.com/features/plugins

    Some links collected from this rabbit hole 🕳:

    https://yarnpkg.com/getting-started/migration https://github.com/yarnpkg/berry/issues/454 https://yarnpkg.com/api/modules/plugin_workspace_tools.html https://dev.to/arcanis/yarn-3-0-performances-esbuild-better-patches-e07 https://github.com/parcel-bundler/parcel/issues/7697 https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored https://www.digitalocean.com/community/tutorials/how-to-install-and-use-the-yarn-package-manager-for-node-js https://semaphoreci.com/blog/javascript-monorepos-yarn-workspaces https://twitter.com/arcanis/status/1301151739375161344?lang=en https://stackoverflow.com/questions/71747609/how-to-specify-packagemanager-in-package-json

    opened by dblodorn 1
  • Update boilerplate to avoid error when trying to install yarn.

    Update boilerplate to avoid error when trying to install yarn.

    When I pulled this down, I was getting the error "Workspaces can only be enabled in private projects." when trying to install yarn. I ended up adding "private" : true, to the package.json file that exists outside of the app workspace. That seemed to fix things.

    opened by salieflewis 1
  • Add husky precommit hooks for code cleanup pre commit.

    Add husky precommit hooks for code cleanup pre commit.

    opened by dblodorn 0
  • Feedback Post Speedrun

    Feedback Post Speedrun

    @dblodorn Feedback post completing this speedrun tutorial video: https://www.loom.com/share/2eb3b86c9c304fdc80fb6699b4bf6891

    React dep issue upon package consumption:

    • ran into same issue (skip to 21:10 of the loom video) where the package installed component wouldnt render in a test consumption app because "react could not be found" in the component. ended up solving this by adding in an unused import + reference to react, but really confused why that works (see below for what I did to fix it). Would love to get a better understanding of what is causing this problem, plus how to avoid (theres no way adding an unused react reference is what I should be doing???) in the future
    Screen Shot 2022-09-21 at 8 38 32 PM

    Potential Pull Requests

    -currently .changeset/config.json “access” needs to be updated to public to allow the npm package publish to go through. would be nice to have this set correctly out the gate (correct set up below)

    Screen Shot 2022-09-21 at 8 41 47 PM

    -something that makes it so we dont have to manually copy paste the “files” : “[/dist]” reference into the package.json of the package we are publishing (code reference below)

    Screen Shot 2022-09-21 at 8 43 03 PM

    Misc

    • when I create a template repo using the create template button on github, it creates the repo in my personal repository rather than in public assembly. not sure how to get it to be created as a new public assembly repo ?? EDIT: ok im stupid you can assign the owner of the repo upon fork, so I can just set this to public-assembly. all set !
    opened by 0xTranqui 0
  • Include example react app.

    Include example react app.

    This pull request introduces a vanilla react testing environment to the monorepo.

    motivation: add a less strict development environment in that you will not have to be as careful around SSR issues that are present with the combination of React 18 & Next.js 12+

    Also have included some updates to documentation.

    These additions should be ample for a first cut of the template repo.

    opened by dblodorn 0
  • Smooth out the setup process after cloning the repo

    Smooth out the setup process after cloning the repo

    It's a bit cumbersome getting through renaming the package, updating references, installing dependencies and then publishing to vercel.

    vercel does not pick up on the framework and autofills the build command with something that results in a build error.

    Maybe there's some sort of setup script that could be added.

    documentation enhancement 
    opened by dblodorn 1
  • Add Storybook UI

    Add Storybook UI

    Would be nice to have the option and an example of storybook usage to preview UI components.

    Storybook

    This Article: Why build UIs in isolation frames the approach nicely.

    enhancement 
    opened by dblodorn 0
Owner
Public Assembly
Create what's missing
Public Assembly
A boilerplate for ExpressJs projects configured with ESLint, Prettier & Airbnb Setup. The boilerplate utilises RESTful architecture and uses Mongodb.

ExpressJs-Boilerplate An ExpressJs boilerplate configured with ESLint, Prettier & Airbnb Setup. The boilerplate utilises RESTful architecture and uses

Hammas bin Farrukh 4 Mar 8, 2023
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Projen project type for Turborepo monorepo setup.

?? projen-turborepo Projen project type for Turborepo monorepo setup. Getting Started To create a new project, run the following command and follow th

Roman 23 Oct 4, 2022
A NPM package powered by Yeoman that generates a scaffolding boilerplate for back-end workflow with Node.js.

generator-noderplate Generate Node.js starter files with just one command! We have deployed a npm package that will generate a boilerplate for nodejs

Samarjeet 3 Jan 24, 2022
Get packages from a monorepo (pnpm, yarn, npm, lerna)

?? You can help the author become a full-time open-source maintainer by sponsoring him on GitHub. @egoist/get-packages Get packages from a monorepo (p

EGOIST 45 Jun 1, 2022
A monorepo that uses the AWS Cloud Development Kit to deploy and configure nanomdm on AWS lambda.

NanoMDM on AWS This repo builds and configures a nanomdm server to run on AWS lambda. It uses the Cloud Development Kit and tries to follow best pract

Stevie Clifton 4 May 26, 2022
This is boilerplate of express, typescript and postgreSql with typeorm and docker based setup

express-typescript-postgres-typeorm-docker-swagger-boilerplate This is boilerplate of express, typescript and postgreSql with typeorm and docker based

beBhavyhere 2 Jun 2, 2022
React-typescript-boilerplate setup🌐🚀

A react-typescript boilerplate including prettier eslint lint-staged husky Docs TypeScript is a strongly typed programming language that builds on Jav

Shubham Jadhav 12 Dec 29, 2022
A simple browser extension, intended to get you "Back To Work" when you start slacking off to one of those really addictive sites.

Back to Work A simple browser extension, intended to get you Back To Work when you start slacking off to one of those really addictive sites. What doe

Dheeraj Lalwani 29 Nov 19, 2022
Massive Open-Source Anti-agression Intelligence Collection is intended for civilians to be able to submit and verify intelligence items about an attacking force.

Massive Open-Source Anti-agression Intelligence Collection is intended for civilians to be able to submit and verify intelligence items about an attacking force.

William Brochmann 3 Mar 1, 2022
Updog is an open-source social media webapp intended to allow everyday people to share their thoughts in a welcoming community.

SE701-Updog Updog is an open-source social media webapp intended to allow everyday people to share their thoughts in a welcoming community. This proje

SE 701 Team 2 UoA 14 Apr 18, 2022
A minimal & self-hostable alternative to pastebin intended for code

minBin A minimal & self-hostable alternative to pastebin intended for code Use ⌨️ A public instance is available at https://bin.kio.dev/ Building ?? n

Kio 4 Dec 29, 2022
An action intended to run on pull request and post a comment summarizing any changes to DevCycle variables.

Overview With this Github action, information on which DevCycle features have been added or removed in a code change will be shown directly on each Pu

DevCycle 20 Jun 14, 2022
A tiny script and component intended to be used with Astro for generating images with eleventy-img.

Astro + eleventy-img A tiny script and component intended to be used with Astro for generating images with eleventy-img. It also supports creating blu

Erika 36 Dec 16, 2022
🪆 Template intended to serve as a starting point if you want to bootstrap a Figma Plugin in TypeScript.

?? Codely Figma Plugin Skeleton Template intended to serve as a starting point if you want to bootstrap a Figma Plugin in TypeScript. Take a look, pla

CodelyTV 26 Dec 22, 2022
NPM Package that simplifies Auth with Google OAuth2 🔐

Node Google OAuth2 ?? A simple authentication flow for Google OAuth2 Explore the docs » Report Bug Table of Contents About The Project Getting Started

Adarsh C 8 Jun 17, 2022