rsnext/packages/next/lib/find-pages-dir.ts
JJ Kasper d8155b22ff
Add initial support for new env handling (#10525)
* Add initial support for new env config file

* Fix serverless processEnv call when no env is provided

* Add missing await for test method

* Update env config to .env.json and add dotenv loading

* ncc dotenv package

* Update type

* Update with new discussed behavior removing .env.json

* Update hot-reloader createEntrypoints

* Make sure .env is loaded before next.config.js

* Add tests for all separate .env files

* Remove comments

* Add override tests

* Add test for overriding env vars based on local environment

* Add support for .env.test

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Use chalk for env loaded message

* Remove constant as it’s not needed

* Update test

* Update errsh, taskr, and CNA template ignores

* Make sure to only consider undefined missing

* Remove old .env ignore

* Update to not populate process.env with loaded env

* Add experimental flag and add loading of global env values

Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-03-26 13:32:41 +01:00

31 lines
822 B
TypeScript

import fs from 'fs'
import path from 'path'
export const existsSync = (f: string): boolean => {
try {
fs.accessSync(f, fs.constants.F_OK)
return true
} catch (_) {
return false
}
}
export function findPagesDir(dir: string): string {
// prioritize ./pages over ./src/pages
let curDir = path.join(dir, 'pages')
if (existsSync(curDir)) return curDir
curDir = path.join(dir, 'src/pages')
if (existsSync(curDir)) return curDir
// Check one level up the tree to see if the pages directory might be there
if (existsSync(path.join(dir, '..', 'pages'))) {
throw new Error(
'> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?'
)
}
throw new Error(
"> Couldn't find a `pages` directory. Please create one under the project root"
)
}