Skip to content

Commit

Permalink
Merge branch 'canary' into move-display-package
Browse files Browse the repository at this point in the history
  • Loading branch information
beerose authored Dec 3, 2021
2 parents 6446c19 + ad71e15 commit 740dfd0
Show file tree
Hide file tree
Showing 63 changed files with 747 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,15 @@
"contributions": [
"doc"
]
},
{
"login": "divpreet",
"name": "Div",
"avatar_url": "https://avatars.githubusercontent.com/u/2805650?v=4",
"profile": "https://github.com/divpreet",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/compressed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Count size
uses: preactjs/compressed-size-action@v2
with:
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ jobs:
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Setup kernel to increase watchers
if: runner.os == 'Linux'
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Expand All @@ -120,6 +124,10 @@ jobs:
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
# Needed to get cypress binary
- run: yarn cypress install
- name: Install sass
Expand Down Expand Up @@ -222,6 +230,10 @@ jobs:
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"

# TODO: remove after we fix watchpack watching too much
- name: Setup kernel to increase watchers
Expand Down Expand Up @@ -285,7 +297,10 @@ jobs:
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
# TODO: remove after we fix watchpack watching too much
- name: Setup kernel to increase watchers
if: runner.os == 'Linux'
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## Notes For Core Team

### To Publish a new NPM Package under `@blitzjs/` namespace

1. cd into the package directory
2. Run `npm publish --tag danger --access public`
- `--access public` is required because scoped packages are set to private by default

### Syncing Next.js Fork

1. Run `yarn push-nextjs`
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img alt="" src="https://img.shields.io/badge/Join%20our%20community-6700EB.svg?style=for-the-badge&labelColor=000000&logoWidth=20&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAQ9SURBVHgB7d3dVdtAEIbhcSpICUoH0IEogQqSVBBSAU4FSSpIOoAORAfQgSghHXzZ1U/YcMD4R9rZmf2ec3y448LyiNf27iLiGIAmPLrweC9Un3DhrzG6EarLNP09nlwJ1SOZ/lQr5N80/S/p2QMVCBf5N17XCfm1Y/rBHqjAG9PPHvBsz+mf9WAP+HLA9M/YA14cOP2payH7jpj+VCtk1wnTP+vj7xCy6cTpn7EHLMLp059iD1iD8eveJbVCNsSLheX1YA/YgOWnf8YeKB3Wmf7Ud6Fy4f/FHmtpxbl3YlC4MJ/Cj0bWdwPnPbARg+L0S54XQHS32WwuxClzd4CM0z9rPfeAuTtA5ulPXYQ7wZ04Y+oOoDD9KZc9YOoOoDj9s4dwFzgXR6w1wIPoOvPWA9buAHEJ173o3gWiy3AnuBUHLEbgmYwvAk1/wuM8vAgexThzbwPDkx7/DHwVXfFOxP2GmsKd4Ab6zPeAyU8CI7AHFmH2BRCBPXAyk18GzUrqAXCTiR4ssyj0VFw/oCU8+e+RZ33AWz6KMaYbIIWxB+JSLs1bsbkeMN0AqakHvoku9oA2sAfqBvbAQdw0QArsgb25aYBUQT3QgT2gB+yBuqGcHij2UCqXDZACe2Anlw2QYg/QAOyBuoE98CL3DZDCuK4/rh/Q7oGL6U+TOvcNkJoijN8X1C48+T+g75eQDrAH/qmqAVJgDwyqaoAUe4AGYA/UDZX3QLUNkEIZPRCd5+6BahsgVUgPROwBTSijB7jpVAvGHriHvmw9wAZ4BpX1ABvgmakHtPcbRuwBTWAPULgAV9D/jKDY9YRvwvgEaurD44uQHvAol7qBW7WKluVtIHiUS7GyvA0s6CiXDnxrpQfsgbqBS7GKk/2jYHCrVlGyfxTMrVo0ALdq1Q3sgSKofh0M9oA61a+D2QM0AHugbmAPqClmSRjK2apVVQ8UsySsoK1aHdgDesCtWnUDeyCrIpeFg1u3sylyWTi3btMA7IG6gT2wuuK3hoE9sKrit4YVslWLPaAN7IG6ocKt2zmY2h4O9sDiTG0PZw/QANy6XTewBxZj9ogYVHy025LMHhEz9cBn0We6B0yfERReBLfhx0/R1YQHPx/QBPbA0VwcEwf2wNFcHBPHHjiem3MC2QPHcXdSaJjA+KfgTPQ8hhfjBzHC40mhlzJ+Xq9lK4a4PCs43AVaGTed5mZq+iOXZwWHi3AnOj2wFWNcnxYe7gTxLtBKHuamP/J+Wnh8a5irB7ZC5Yk9gPX1QuXC+usHWqGyhYvUYR0a7zboUOFCNVhnk0krZAOW7wFOvzXhom2xnEbIHizTA1wEYhWW6YFGyC6c1gOcfg9wfA80Qj7g8B7g9HuCww+haIR8wf49wOn3Cvv9k8tGyC/s7gFOv3fY3QONkH+v9MBWqB7PeqDn9FcIT//kcitUn6kHOu/T/xfWzlQy3dEHhwAAAABJRU5ErkJggg==">
</a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a aria-label="All Contributors" href="#contributors-"><img alt="" src="https://img.shields.io/badge/all_contributors-371-17BB8A.svg?style=for-the-badge&labelColor=000000"></a>
<a aria-label="All Contributors" href="#contributors-"><img alt="" src="https://img.shields.io/badge/all_contributors-372-17BB8A.svg?style=for-the-badge&labelColor=000000"></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<a aria-label="License" href="https://github.com/blitz-js/blitz/blob/canary/LICENSE">
<img alt="" src="https://img.shields.io/npm/l/blitz.svg?style=for-the-badge&labelColor=000000&color=blue">
Expand Down Expand Up @@ -732,6 +732,9 @@ Thanks to these wonderful people ([emoji key](https://allcontributors.org/docs/e
<td align="center"><a href="https://github.com/davidchristie"><img src="https://avatars.githubusercontent.com/u/12044333?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Christie</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=davidchristie" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/ajanth97"><img src="https://avatars.githubusercontent.com/u/50458502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ajanth</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=ajanth97" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/divpreet"><img src="https://avatars.githubusercontent.com/u/2805650?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Div</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=divpreet" title="Documentation">📖</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
Expand Down
4 changes: 3 additions & 1 deletion examples/cypress/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
process.env.NODE_ENV = "test"
require("dotenv-flow").config({ silent: true })

import { loadEnvConfig } from "@blitzjs/env"
loadEnvConfig()

import "./register-ts-paths"
import db from "db"
Expand Down
4 changes: 3 additions & 1 deletion examples/fauna/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect"
require("dotenv-flow").config({ silent: true })
import { loadEnvConfig } from "@blitzjs/env"

loadEnvConfig()
2 changes: 1 addition & 1 deletion nextjs/packages/next-env/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `@next/env`
# `@blitzjs/env`

Next.js' util for loading dotenv files in with the proper priorities
9 changes: 6 additions & 3 deletions nextjs/packages/next-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function processEnv(
}

export function loadEnvConfig(
dir: string,
dir: string = process.cwd(),
dev?: boolean,
log: Log = console
): {
Expand All @@ -79,8 +79,11 @@ export function loadEnvConfig(

const isTest = process.env.NODE_ENV === 'test'
const mode = isTest ? 'test' : dev ? 'development' : 'production'
const dotenvFiles = [
const appEnv = process.env.APP_ENV
let dotenvFiles = [
`.env.${mode}.local`,
appEnv && `.env.${appEnv}.local`,
appEnv && `.env.${appEnv}`,
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
Expand All @@ -106,7 +109,7 @@ export function loadEnvConfig(
path: envFile,
contents,
})
} catch (err) {
} catch (err: any) {
if (err.code !== 'ENOENT') {
log.error(`Failed to load env from ${envFile}`, err)
}
Expand Down
7 changes: 3 additions & 4 deletions nextjs/packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"private": true,
"name": "@next/env",
"version": "11.1.0",
"name": "@blitzjs/env",
"version": "0.43.0",
"keywords": [
"react",
"next",
Expand All @@ -14,7 +13,7 @@
"url": "https://github.com/vercel/next.js",
"directory": "packages/next-env"
},
"author": "Next.js Team <[email protected]>",
"author": "Blitz.js",
"license": "MIT",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions nextjs/packages/next/bin/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const args = arg(
'--version': Boolean,
'--help': Boolean,
'--inspect': Boolean,
'--env': String,

// Aliases
'-v': '--version',
'-h': '--help',
'-e': '--env'
},
{
permissive: true,
Expand Down Expand Up @@ -61,6 +63,7 @@ if (!foundCommand && args['--help']) {
${Object.keys(commands).join(', ')}
Options
--env, -e App environment name
--version, -v Version number
--help, -h Displays this message
Expand All @@ -83,6 +86,10 @@ if (args['--help']) {
forwardedArgs.push('--help')
}

if (args['--env']) {
process.env.APP_ENV = args['--env']
}

const defaultEnv = command === 'dev' ? 'development' : 'production'

const standardEnv = ['production', 'development', 'test']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const specialImports: Record<string, string> = {
useMutation: 'next/data-client',
queryClient: 'next/data-client',
getQueryKey: 'next/data-client',
getInfiniteQueryKey: 'next/data-client',
invalidateQuery: 'next/data-client',
setQueryData: 'next/data-client',
useQueryErrorResetBoundary: 'next/data-client',
Expand Down
2 changes: 1 addition & 1 deletion nextjs/packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { normalizePagePath } from '../server/normalize-page-path'
import { warn } from './output/log'
import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-loader'
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env'
import { LoadedEnvFiles } from '@blitzjs/env'
import { convertPageFilePathToRoutePath } from './utils'
import { NextConfigComplete } from '../server/config-shared'

Expand Down
2 changes: 1 addition & 1 deletion nextjs/packages/next/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadEnvConfig } from '@next/env'
import { loadEnvConfig } from '@blitzjs/env'
import chalk from 'chalk'
import crypto from 'crypto'
import { promises, writeFileSync } from 'fs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
)

const envLoading = `
const { processEnv } = require('@next/env')
const { processEnv } = require('@blitzjs/env')
processEnv(${Buffer.from(loadedEnvFiles, 'base64').toString()})
`

Expand Down
1 change: 1 addition & 0 deletions nextjs/packages/next/data-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
export {
queryClient,
getQueryKey,
getInfiniteQueryKey,
invalidateQuery,
setQueryData,
} from './react-query-utils'
Expand Down
17 changes: 17 additions & 0 deletions nextjs/packages/next/data-client/react-query-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ export function getQueryKey<TInput, TResult, T extends AsyncFunc>(
return getQueryKeyFromUrlAndParams(sanitizeQuery(resolver)._routePath, params)
}

export function getInfiniteQueryKey<TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
params?: TInput
) {
if (typeof resolver === 'undefined') {
throw new Error(
'getInfiniteQueryKey is missing the first argument - it must be a resolver function'
)
}

const queryKey = getQueryKeyFromUrlAndParams(
sanitizeQuery(resolver)._routePath,
params
)
return [...queryKey, 'infinite']
}

export function invalidateQuery<TInput, TResult, T extends AsyncFunc>(
resolver: T | Resolver<TInput, TResult> | RpcClient<TInput, TResult>,
params?: TInput
Expand Down
54 changes: 42 additions & 12 deletions nextjs/packages/next/data-client/react-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
QueryCacheFunctions,
sanitizeQuery,
sanitizeMutation,
getInfiniteQueryKey,
} from './react-query-utils'
import { useRouter } from '../client/router'

Expand Down Expand Up @@ -166,16 +167,19 @@ export function usePaginatedQuery<
)
}

const suspense =
options?.enabled === false || options?.enabled === null
const suspenseEnabled = Boolean(process.env.__BLITZ_SUSPENSE_ENABLED)
let enabled =
isServer && suspenseEnabled
? false
: options?.suspense
: options?.enabled ?? options?.enabled !== null
const suspense = enabled === false ? false : options?.suspense

const session = useSession({ suspense })
if (session.isLoading) {
options.enabled = false
enabled = false
}

const routerIsReady = useRouter().isReady
const routerIsReady = useRouter().isReady || (isServer && suspenseEnabled)
const enhancedResolverRpcClient = sanitizeQuery(queryFn)
const queryKey = getQueryKey(queryFn, params)

Expand All @@ -186,8 +190,20 @@ export function usePaginatedQuery<
: (emptyQueryFn as any),
...options,
keepPreviousData: true,
enabled,
})

if (
queryRest.isIdle &&
isServer &&
suspenseEnabled !== false &&
!data &&
(!options || !('suspense' in options) || options.suspense) &&
(!options || !('enabled' in options) || options.enabled)
) {
throw new Promise(() => {})
}

const rest = {
...queryRest,
...getQueryCacheFunctions<FirstParam<T>, TResult, T>(queryFn, params),
Expand Down Expand Up @@ -250,33 +266,47 @@ export function useInfiniteQuery<
)
}

const suspense =
options?.enabled === false || options?.enabled === null
const suspenseEnabled = Boolean(process.env.__BLITZ_SUSPENSE_ENABLED)
let enabled =
isServer && suspenseEnabled
? false
: options?.suspense
: options?.enabled ?? options?.enabled !== null
const suspense = enabled === false ? false : options?.suspense
const session = useSession({ suspense })
if (session.isLoading) {
options.enabled = false
enabled = false
}

const routerIsReady = useRouter().isReady
const routerIsReady = useRouter().isReady || (isServer && suspenseEnabled)
const enhancedResolverRpcClient = sanitizeQuery(queryFn)
const queryKey = getQueryKey(queryFn, getQueryParams)
const queryKey = getInfiniteQueryKey(queryFn, getQueryParams)

const { data, ...queryRest } = useInfiniteReactQuery({
// we need an extra cache key for infinite loading so that the cache for
// for this query is stored separately since the hook result is an array of results.
// Without this cache for usePaginatedQuery and this will conflict and break.
queryKey: routerIsReady ? [...queryKey, 'infinite'] : ['_routerNotReady_'],
queryKey: routerIsReady ? queryKey : ['_routerNotReady_'],
queryFn: routerIsReady
? ({ pageParam }) =>
enhancedResolverRpcClient(getQueryParams(pageParam), {
fromQueryHook: true,
})
: (emptyQueryFn as any),
...options,
enabled,
})

if (
queryRest.isIdle &&
isServer &&
suspenseEnabled !== false &&
!data &&
(!options || !('suspense' in options) || options.suspense) &&
(!options || !('enabled' in options) || options.enabled)
) {
throw new Promise(() => {})
}

const rest = {
...queryRest,
...getQueryCacheFunctions<FirstParam<T>, TResult, T>(
Expand Down
2 changes: 1 addition & 1 deletion nextjs/packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
normalizePagePath,
denormalizePagePath,
} from '../server/normalize-page-path'
import { loadEnvConfig } from '@next/env'
import { loadEnvConfig } from '@blitzjs/env'
import { PrerenderManifest } from '../build'
import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import { getPagePath } from '../server/require'
Expand Down
2 changes: 1 addition & 1 deletion nextjs/packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/runtime": "7.12.5",
"@blitzjs/env": "0.43.0",
"@hapi/accept": "5.0.2",
"@next/env": "11.1.0",
"@next/polyfill-module": "11.1.0",
"@next/react-dev-overlay": "11.1.0",
"@next/react-refresh-utils": "11.1.0",
Expand Down
Loading

0 comments on commit 740dfd0

Please sign in to comment.