Skip to content

Commit

Permalink
wip - broken
Browse files Browse the repository at this point in the history
  • Loading branch information
flybayer committed Jan 21, 2021
1 parent 7ab1d73 commit a9c4935
Show file tree
Hide file tree
Showing 15 changed files with 1,359 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ["next/babel"],
presets: ["blitz"],
plugins: [],
}
29 changes: 12 additions & 17 deletions examples/store/app/products/pages/products/ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import {useMemo} from "react"
import {invokeWithMiddleware, GetServerSideProps, Link, BlitzPage, PromiseReturnType} from "blitz"
import {invokeWithMiddleware, Link, BlitzPage, InferGetServerSidePropsType} from "blitz"
import getProducts from "app/products/queries/getProducts"
import superjson from "superjson"

type PageProps = {
dataString: string
}

type Products = PromiseReturnType<typeof getProducts>

export const getServerSideProps: GetServerSideProps = async ({req, res}) => {
const products = await invokeWithMiddleware(getProducts, {orderBy: {id: "desc"}}, {req, res})
const dataString = superjson.stringify(products)
export const getServerSideProps = async ({req, res}) => {
const result = await invokeWithMiddleware(
getProducts,
{take: 2, orderBy: {id: "desc"}},
{req, res},
)
return {
props: {
dataString,
products: result.products,
},
}
}
type PageProps = InferGetServerSidePropsType<typeof getServerSideProps>

const Page: BlitzPage<PageProps> = function ({dataString}) {
const {products} = useMemo(() => superjson.parse(dataString), [dataString]) as Products

const Page: BlitzPage<PageProps> = function (props) {
console.log("PROPS", props)
return (
<div>
<h1>Products</h1>
<div id="products">
{products.map((product) => (
{props.products.map((product) => (
<p key={product.id}>
<Link href="/products/[handle]" as={`/products/${product.handle}`}>
<a>{product.name}</a>
Expand Down
1 change: 1 addition & 0 deletions examples/store/app/products/queries/getProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default async function getProducts(
const products = await db.product.findMany({
where,
orderBy,
select: {id: true, name: true, handle: true, createdAt: true},
skip,
cursor,
take,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ["next/babel"],
presets: ["blitz"],
plugins: [],
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-unicorn": "25.0.1",
"husky": "4.3.7",
"@size-limit/preset-small-lib": "4.9.1",
"size-limit": "4.9.1",
"jest": "26.6.3",
"jest-environment-jsdom-sixteen": "1.0.3",
"lerna": "3.22.1",
Expand Down
32 changes: 32 additions & 0 deletions packages/babel-preset/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push]
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['10.x', '12.x', '14.x']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2

- name: Build
run: yarn build
12 changes: 12 additions & 0 deletions packages/babel-preset/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: size
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions packages/babel-preset/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.log
.DS_Store
node_modules
dist
21 changes: 21 additions & 0 deletions packages/babel-preset/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Brandon Bayer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions packages/babel-preset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[![npm version](https://badge.fury.io/js/babel-preset-blitz.svg)](https://badge.fury.io/js/babel-preset-blitz)

# babel-preset-blitz

## Setup

1. Install it using npm: `npm install -D babel-preset-blitz`.
2. Add `blitz` preset in your `babel.config.js`.

Example `babel.config.js`:

```js
module.exports = {
presets: ['blitz'],
presets: [],
};
```

3. You're done!
42 changes: 42 additions & 0 deletions packages/babel-preset/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "babel-preset-blitz",
"version": "0.29.2",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"clean": "rimraf dist",
"dev": "tsdx watch --verbose",
"build": "tsdx build",
"test": "tsdx test --passWithNoTests",
"test:watch": "tsdx test --watch --passWithNoTests",
"size": "size-limit",
"analyze": "size-limit --why"
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"author": "Brandon Bayer",
"module": "dist/babel-preset.esm.js",
"size-limit": [
{
"path": "dist/babel-preset-blitz.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/babel-preset-blitz.esm.js",
"limit": "10 KB"
}
],
"dependencies": {
"babel-plugin-superjson-next": "0.1.10"
},
"devDependencies": {}
}
10 changes: 10 additions & 0 deletions packages/babel-preset/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line import/no-default-export
export default function preset() {
console.log();
console.log('Loading blitz babel...');
console.log();
return {
presets: [require('next/babel')],
plugins: [require('babel-plugin-superjson-next')],
};
}
7 changes: 7 additions & 0 deletions packages/babel-preset/test/blah.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from '../src';

describe('blah', () => {
it('works', () => {
expect(sum(1, 1)).toEqual(2);
});
});
9 changes: 9 additions & 0 deletions packages/babel-preset/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "types"],
"compilerOptions": {
"rootDir": "./src",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
Loading

0 comments on commit a9c4935

Please sign in to comment.