Skip to content

Commit

Permalink
works in development but not production
Browse files Browse the repository at this point in the history
  • Loading branch information
flybayer committed Apr 18, 2020
1 parent 936b77e commit 4e74220
Show file tree
Hide file tree
Showing 21 changed files with 1,180 additions and 211 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ dist
**/.env.development.local
**/.env.test.local
**/.env.production.local

.generated-prisma-client
8 changes: 4 additions & 4 deletions examples/store/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# testing
/coverage

# next.js
/.next/
/out/
/.blitz/
# blitz.js
.next
.blitz
*.sqlite
.generated-prisma-client

# production
/build
Expand Down
2 changes: 1 addition & 1 deletion examples/store/app/admin/pages/admin/products/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ProductForm from 'app/products/components/ProductForm'

function Product() {
const router = useRouter()
const id = parseInt(router.query.id as string)
const id = parseInt(router?.query.id as string)
const [product] = useQuery(getProduct, {where: {id}})

return <ProductForm product={product} onSuccess={() => router.push('/admin/products')} />
Expand Down
8 changes: 4 additions & 4 deletions examples/store/app/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Document, Html, DocumentHead, Main, NextScript, DocumentContext} from '@blitzjs/core'

class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)
return {...initialProps}
}
// static async getInitialProps(ctx: DocumentContext) {
// const initialProps = await Document.getInitialProps(ctx)
// return {...initialProps}
// }

render() {
return (
Expand Down
19 changes: 8 additions & 11 deletions examples/store/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
module.exports = {
webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
return config
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
return config
},
// webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
// // Perform customizations to webpack config here
// return config
// },
// webpackDevMiddleware: (config) => {
// // Perform customizations to webpack dev middleware config here
// return config
// },
}
4 changes: 2 additions & 2 deletions examples/store/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PrismaClient} from '@prisma/client'
export * from '@prisma/client'
import {PrismaClient} from '.generated-prisma-client'
export * from '.generated-prisma-client'

const prisma = new PrismaClient()

Expand Down
1 change: 1 addition & 0 deletions examples/store/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ datasource postgresql {

generator client {
provider = "prisma-client-js"
output = "../.generated-prisma-client"
}


Expand Down
3 changes: 2 additions & 1 deletion examples/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"@blitzjs/cli": "0.0.2-canary.1.2",
"@blitzjs/core": "0.0.2-canary.1",
"@blitzjs/server": "0.0.2-canary.1.4",
"@prisma/cli": "2.0.0-beta.2",
"@prisma/client": "2.0.0-beta.2",
"final-form": "4.19.1",
"react": "0.0.0-experimental-e5d06e34b",
Expand All @@ -19,6 +18,8 @@
},
"NOTE": "Next.js dependency is only required for deploying to zeit, for now",
"devDependencies": {
"@types/react": "16.9.34",
"@prisma/cli": "2.0.0-beta.2",
"next": "9.3.4"
}
}
24 changes: 23 additions & 1 deletion examples/vanilla-next/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
const {withBlitz} = require('@blitzjs/server')
const path = require('path')

module.exports = withBlitz({})
module.exports = withBlitz({
webpack: (config, options) => {
// const firstRule = config.module.rules[0]
// const origExclude = firstRule.exclude
// firstRule.exclude = (path) => {
// if (path.includes('pclient')) {
// console.log('EXCLUDING')
// return true
// }
// return origExclude(path)
// }

// config.node.__dirname = false

config.externals = {
// 'db/.generated-prisma-client': 'db/.generated-prisma-client',
pclient: path.resolve(__dirname, 'pclient'),
}

return config
},
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"examples/*"
],
"nohoist": [
"husky",
"**/@prisma",
"**/@prisma/**"
]
Expand All @@ -24,6 +23,8 @@
"test": "lerna run test --parallel"
},
"devDependencies": {
"react": "0.0.0-experimental-e5d06e34b",
"react-dom": "0.0.0-experimental-e5d06e34b",
"@types/debug": "^4.1.5",
"@types/jest": "^25.1.3",
"@types/node": "^13.7.4",
Expand Down
19 changes: 8 additions & 11 deletions packages/cli/templates/app/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
module.exports = {
webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
return config
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
return config
},
// webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
// // Perform customizations to webpack config here
// return config
// },
// webpackDevMiddleware: (config) => {
// // Perform customizations to webpack dev middleware config here
// return config
// },
}
4 changes: 2 additions & 2 deletions packages/cli/templates/app/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PrismaClient} from '@prisma/client'
export * from '@prisma/client'
import {PrismaClient} from '.generated-prisma-client'
export * from '.generated-prisma-client'

const prisma = new PrismaClient()

Expand Down
1 change: 1 addition & 0 deletions packages/cli/templates/app/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ datasource postgresql {

generator client {
provider = "prisma-client-js"
output = "../.generated-prisma-client"
}


Expand Down
6 changes: 3 additions & 3 deletions packages/cli/templates/app/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
/coverage

# blitz.js
/.blitz/
/.next/
/out/
.blitz
.next
*.sqlite
.generated-prisma-client

# production
/build
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
"type": "git",
"url": "https://github.com/blitz-js/blitz"
},
"dependencies": {
"@types/react-query": "1.1.2",
"@types/serialize-error": "4.0.1",
"pretty-ms": "6.0.1",
"react-query": "1.2.1",
"serialize-error": "6.0.0"
},
"devDependencies": {
"@prisma/client": "2.0.0-beta.2",
"@testing-library/jest-dom": "5.5.0",
Expand All @@ -59,12 +66,5 @@
"next": "^9.3.0",
"ts-jest": "24.3.0"
},
"dependencies": {
"@types/react-query": "1.1.2",
"@types/serialize-error": "4.0.1",
"pretty-ms": "6.0.1",
"react-query": "1.2.1",
"serialize-error": "6.0.0"
},
"gitHead": "6719104cb3e78948e7f06aa948ff72bbb84cb682"
}
35 changes: 21 additions & 14 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,10 @@
},
"module": "dist/webpack.esm.js",
"types": "dist/packages/server/src/index.d.ts",
"devDependencies": {
"@types/cross-spawn": "^6.0.1",
"@types/gulp-if": "^0.0.33",
"@types/jest": "^25.1.3",
"@types/path-is-absolute": "^1.0.0",
"@types/readable-stream": "^2.3.5",
"@types/through2": "^2.0.34",
"@types/vinyl-fs": "^2.4.11",
"directory-tree": "^2.2.4",
"husky": "^4.2.3",
"tsdx": "^0.13.1",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
"dependencies": {
"cross-spawn": "^7.0.2",
"fast-glob": "^3.2.2",
"find-parent-dir": "0.3.0",
"gulp-if": "^3.0.0",
"next": "9.3.4",
"next-compose-plugins": "2.2.0",
Expand All @@ -54,10 +41,30 @@
"pirates": "^4.0.1",
"readable-stream": "^3.6.0",
"resolve-bin": "^0.4.0",
"resolve-cwd": "3.0.0",
"through2": "^3.0.1",
"vinyl": "^2.2.0",
"vinyl-file": "^3.0.0",
"vinyl-fs": "^3.0.3"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.1",
"@types/find-parent-dir": "0.3.0",
"@types/gulp-if": "^0.0.33",
"@types/jest": "^25.1.3",
"@types/path-is-absolute": "^1.0.0",
"@types/readable-stream": "^2.3.5",
"@types/through2": "^2.0.34",
"@types/vinyl-fs": "^2.4.11",
"directory-tree": "^2.2.4",
"husky": "^4.2.3",
"tsdx": "^0.13.1",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
"peerDependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"gitHead": "6719104cb3e78948e7f06aa948ff72bbb84cb682"
}
5 changes: 3 additions & 2 deletions packages/server/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {resolve} from 'path'
import {ciLog} from './ciLog'
import {resolveBinAsync} from './resolve-bin-async'

export type ServerConfig = {
rootFolder: string
interceptNextErrors?: boolean
Expand Down Expand Up @@ -50,8 +51,8 @@ export async function enhance(config: ServerConfig) {

return ciLog(
`
Logging the following to understand what is happening in our CI environment
and investigate why we have been getting random CI test failures.
Logging the following to understand what is happening in our CI environment
and investigate why we have been getting random CI test failures.
This will be temporary.
`,
{
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/next-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export async function nextBuild(nextBin: string, cwd: string) {
cwd,
stdio: 'inherit',
})
.on('exit', res)
.on('exit', (code) => {
code === 0 ? res() : rej(`Failed with status code: ${code}`)
})
.on('error', rej)
})
}
Expand Down
31 changes: 29 additions & 2 deletions packages/server/src/resolve-bin-async.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import resolveBin from 'resolve-bin'
// import resolveBin from 'resolve-bin'
import resolveCwd from 'resolve-cwd'
import findParentDir from 'find-parent-dir'
import path from 'path'

function resolveBin(name: string, cb: Function) {
var executable = name

var mod
try {
mod = resolveCwd(name)
} catch (err) {
return cb(err)
}

findParentDir(mod, 'package.json', function (err, dir) {
if (err) return cb(err)

var pack = require(path.join(dir as string, 'package.json'))
var binfield = pack.bin

var binpath = typeof binfield === 'object' ? binfield[executable] : binfield
if (!binpath) return cb(new Error('No bin `' + executable + '` in module `' + name + '`'))

var bin = path.join(dir as string, binpath)
cb(null, bin)
})
}

export function resolveBinAsync(pkg: string) {
return new Promise<string>((resolve, reject) => {
resolveBin(pkg, (err, bin) => {
resolveBin(pkg, (err: any, bin: string) => {
if (err) {
reject(err)
}
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/withBlitz.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const withPlugins = require('next-compose-plugins')
const withTM = require('next-transpile-modules')(['@blitzjs/core'])
const resolveCwd = require('resolve-cwd')

export function withBlitz(nextConfig: Record<any, any> = {}) {
const plugins = []
Expand All @@ -22,6 +23,13 @@ export function withBlitz(nextConfig: Record<any, any> = {}) {
config.module.rules.push({test: /_rpc/, loader: require.resolve('null-loader')})
}

if (options.isServer) {
config.externals = config.externals || []
config.externals.push({
'.generated-prisma-client': resolveCwd('./.generated-prisma-client'),
})
}

if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
Expand Down
Loading

0 comments on commit 4e74220

Please sign in to comment.