Skip to content

Commit

Permalink
Merge branch 'canary' into fix/ssr-data-cache-key-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
visnup committed Aug 15, 2022
2 parents 59e067e + 4cd8b23 commit 3588dd2
Show file tree
Hide file tree
Showing 88 changed files with 3,957 additions and 3,587 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -68,7 +68,7 @@
"@typescript-eslint/no-use-before-define": [
"warn",
{
"functions": false,
"functions": true,
"classes": true,
"variables": true,
"enums": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/next-forms/pages/js-form.js
Expand Up @@ -45,7 +45,7 @@ export default function PageWithJSbasedForm() {

<p className={styles.description}>
Get started by looking at{' '}
<code className={styles.code}>pages/js-from.js</code>
<code className={styles.code}>pages/js-form.js</code>
</p>

<form onSubmit={handleSubmit}>
Expand Down
2 changes: 1 addition & 1 deletion examples/next-forms/pages/no-js-form.js
Expand Up @@ -13,7 +13,7 @@ export default function Form() {
</h1>
<p className={styles.description}>
Get started by looking at{' '}
<code className={styles.code}>pages/no-js-from.js</code>
<code className={styles.code}>pages/no-js-form.js</code>
</p>

{/*action: The action attribute defines where the data gets sent. Its value must be a valid relative or absolute URL. If this attribute isn't provided, the data will be sent to the URL of the page containing the form — the current page.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.2.5"
"version": "12.2.6-canary.0"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.2.5",
"@next/eslint-plugin-next": "12.2.6-canary.0",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.21.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/next-env/index.ts
Expand Up @@ -13,6 +13,7 @@ export type LoadedEnvFiles = Array<{
let initialEnv: Env | undefined = undefined
let combinedEnv: Env | undefined = undefined
let cachedLoadedEnvFiles: LoadedEnvFiles = []
let previousLoadedEnvFiles: LoadedEnvFiles = []

type Log = {
info: (...args: any[]) => void
Expand Down Expand Up @@ -49,7 +50,13 @@ export function processEnv(

result = dotenvExpand(result)

if (result.parsed) {
if (
result.parsed &&
!previousLoadedEnvFiles.some(
(item) =>
item.contents === envFile.contents && item.path === envFile.path
)
) {
log.info(`Loaded env from ${path.join(dir || '', envFile.path)}`)
}

Expand Down Expand Up @@ -88,6 +95,7 @@ export function loadEnvConfig(
return { combinedEnv, loadedEnvFiles: cachedLoadedEnvFiles }
}
process.env = Object.assign({}, initialEnv)
previousLoadedEnvFiles = cachedLoadedEnvFiles
cachedLoadedEnvFiles = []

const isTest = process.env.NODE_ENV === 'test'
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.2.5",
"version": "12.2.6-canary.0",
"private": true,
"scripts": {
"build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi native --features plugin",
Expand Down
92 changes: 46 additions & 46 deletions packages/next/build/analysis/extract-const-value.ts
Expand Up @@ -17,52 +17,6 @@ import type {

export class NoSuchDeclarationError extends Error {}

/**
* Extracts the value of an exported const variable named `exportedName`
* (e.g. "export const config = { runtime: 'experimental-edge' }") from swc's AST.
* The value must be one of (or throws UnsupportedValueError):
* - string
* - boolean
* - number
* - null
* - undefined
* - array containing values listed in this list
* - object containing values listed in this list
*
* Throws NoSuchDeclarationError if the declaration is not found.
*/
export function extractExportedConstValue(
module: Module,
exportedName: string
): any {
for (const moduleItem of module.body) {
if (!isExportDeclaration(moduleItem)) {
continue
}

const declaration = moduleItem.declaration
if (!isVariableDeclaration(declaration)) {
continue
}

if (declaration.kind !== 'const') {
continue
}

for (const decl of declaration.declarations) {
if (
isIdentifier(decl.id) &&
decl.id.value === exportedName &&
decl.init
) {
return extractValue(decl.init, [exportedName])
}
}
}

throw new NoSuchDeclarationError()
}

function isExportDeclaration(node: Node): node is ExportDeclaration {
return node.type === 'ExportDeclaration'
}
Expand Down Expand Up @@ -247,3 +201,49 @@ function extractValue(node: Node, path?: string[]): any {
)
}
}

/**
* Extracts the value of an exported const variable named `exportedName`
* (e.g. "export const config = { runtime: 'experimental-edge' }") from swc's AST.
* The value must be one of (or throws UnsupportedValueError):
* - string
* - boolean
* - number
* - null
* - undefined
* - array containing values listed in this list
* - object containing values listed in this list
*
* Throws NoSuchDeclarationError if the declaration is not found.
*/
export function extractExportedConstValue(
module: Module,
exportedName: string
): any {
for (const moduleItem of module.body) {
if (!isExportDeclaration(moduleItem)) {
continue
}

const declaration = moduleItem.declaration
if (!isVariableDeclaration(declaration)) {
continue
}

if (declaration.kind !== 'const') {
continue
}

for (const decl of declaration.declarations) {
if (
isIdentifier(decl.id) &&
decl.id.value === exportedName &&
decl.init
) {
return extractValue(decl.init, [exportedName])
}
}
}

throw new NoSuchDeclarationError()
}

0 comments on commit 3588dd2

Please sign in to comment.