Skip to content

Commit

Permalink
Merge branch 'canary' into feat/support-node-sass-6
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Sep 8, 2021
2 parents ed3c042 + ee71f9d commit b36e823
Show file tree
Hide file tree
Showing 48 changed files with 349 additions and 161 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build_native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ jobs:
include:
- os: ubuntu-18.04
target: x86_64-unknown-linux-gnu
name: linux-x64-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
name: win32-x64-msvc
- os: macos-latest
target: x86_64-apple-darwin
name: darwin-x64
- os: macos-latest
target: aarch64-apple-darwin
name: darwin-arm64
description: m1

name: next-swc - ${{ matrix.os }} - ${{ matrix.target }} - node@14
Expand Down Expand Up @@ -69,7 +73,7 @@ jobs:
uses: actions/upload-artifact@v2.2.4
with:
name: next-swc-binaries
path: packages/next/native/next-swc.*.node
path: packages/next/native/next-swc.${{ matrix.name }}.node
- name: Clear the cargo caches
run: |
cargo install cargo-cache --no-default-features --features ci-autoclean
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/head.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function IndexPage() {
export default IndexPage
```

In this case only the second `<meta property="og:title" />` is rendered. `meta` tags with duplicate `name` attributes are automatically handled.
In this case only the second `<meta property="og:title" />` is rendered. `meta` tags with duplicate `key` attributes are automatically handled.

> The contents of `head` get cleared upon unmounting the component, so make sure each page completely defines what it needs in `head`, without making assumptions about what other pages added.
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/next/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default Posts

## If the child is a custom component that wraps an `<a>` tag

If the child of `Link` is a custom component that wraps an `<a>` tag, you must add `passHref` to `Link`. This is necessary if you’re using libraries like [styled-components](https://styled-components.com/). Without this, the `<a>` tag will not have the `href` attribute, which might hurt your site’s SEO.
If the child of `Link` is a custom component that wraps an `<a>` tag, you must add `passHref` to `Link`. This is necessary if you’re using libraries like [styled-components](https://styled-components.com/). Without this, the `<a>` tag will not have the `href` attribute, which hurts your site's accessibility and might affect SEO. If you're using [ESLint](/docs/basic-features/eslint.md#eslint-plugin), there is a built-in rule `next/link-passhref` to ensure correct usage of `passHref`.

```jsx
import Link from 'next/link'
Expand Down
14 changes: 7 additions & 7 deletions examples/cms-prepr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ After that

Import the [`models/post.json`](models/post.json) file.

Click on the Author field and select `Author` at the option `Publication model` and click **Save**.

### Step 3. Set up environment variables
### Step 3. Set up environment variables (for production)

Copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git):

Expand All @@ -73,15 +71,17 @@ cp .env.local.example .env.local

Inside your environment, navigate to **Settings > Development > Access Tokens**.

Click **Add access token**, enter the name `Next.js Preview` and add the scope `graphql_preview` and click **Save**.
Click **Add access token**, enter the name `Next.js Production` and add the scope `graphql_published` and click **Save**.

Copy the generated access token and set the variable `PREPRIO_PREVIEW_TOKEN` in `.env.local`.
Copy the generated access token and set the variable `PREPRIO_PRODUCTION_TOKEN` in `.env.local`.

### Step 3.1 Set up environment variables (for preview)

Go back to the Access token overview and click **Add access token**.

Enter the name `Next.js Production` and add the scope `graphql_published` and click **Save**.
Click **Add access token**, enter the name `Next.js Preview` and add the scope `graphql_preview` and click **Save**.

Copy the generated access token and set the variable `PREPRIO_PRODUCTION_TOKEN` in `.env.local`.
Copy the generated access token and set the variable `PREPRIO_PREVIEW_TOKEN` in `.env.local`.

The `PREPRIO_PREVIEW_KEY` can be any random string (but avoid spaces), like a UUID`, this is used
for [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).
Expand Down
13 changes: 11 additions & 2 deletions examples/cms-prepr/models/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"seo_score": false,
"ab_testing": false,
"versioning": false,
"slug": null,
"slug": "{title}",
"for": null,
"fields": [
{
Expand Down Expand Up @@ -133,7 +133,16 @@
"description": null,
"disable_editing": false,
"appearance": null,
"accept_restrictions": null
"accept_restrictions": null,
"publication_models": {
"items": [
{
"id": "7214e365-1b4c-4de3-8412-e311250fb4da",
"body": "Author"
}
],
"total": 1
}
},
{
"type": "Slug",
Expand Down
4 changes: 2 additions & 2 deletions examples/with-eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_mediu
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example with-eslint with-eslint
npx create-next-app --example with-eslint with-eslint-app
# or
yarn create next-app --example with-eslint with-eslint
yarn create next-app --example with-eslint with-eslint-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
6 changes: 3 additions & 3 deletions examples/with-three-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"start": "next start"
},
"dependencies": {
"@react-three/drei": "4.3.3",
"@react-three/fiber": "6.0.19",
"next": "10.2.0",
"@react-three/drei": "7.6.1",
"@react-three/fiber": "7.0.6",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"three": "0.128.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/with-typescript-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"@graphql-codegen/typescript-resolvers": "^1.17.8",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"@types/react-test-renderer": "16.9.3",
"@types/react-test-renderer": "^17.0.1",
"babel-jest": "26.3.0",
"graphql-let": "0.x",
"graphql-tag": "2.11.0",
"jest": "26.4.0",
"react-test-renderer": "16.13.1",
"react-test-renderer": "^17.0.1",
"typescript": "^3.9.7",
"yaml-loader": "0.6.0"
}
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "11.1.3-canary.13"
"version": "11.1.3-canary.14"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"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": "11.1.3-canary.13",
"@next/eslint-plugin-next": "11.1.3-canary.14",
"@rushstack/eslint-patch": "^1.0.6",
"@typescript-eslint/parser": "^4.20.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "11.1.3-canary.13",
"version": "11.1.3-canary.14",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
10 changes: 10 additions & 0 deletions packages/next/build/swc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@ function toBuffer(t) {
return Buffer.from(JSON.stringify(t))
}

export async function minify(src, opts) {
return bindings.minify(src, toBuffer(opts ?? {}))
}

export function minifySync(src, opts) {
return bindings.minifySync(src, toBuffer(opts ?? {}))
}

module.exports.transform = transform
module.exports.transformSync = transformSync
module.exports.minify = minify
module.exports.minifySync = minifySync
4 changes: 4 additions & 0 deletions packages/next/build/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use swc_common::{

mod amp_attributes;
mod hook_optimizer;
mod minify;
mod next_dynamic;
pub mod next_ssg;
mod transform;
Expand Down Expand Up @@ -76,6 +77,9 @@ fn init(mut exports: JsObject) -> napi::Result<()> {
exports.create_named_method("transform", transform::transform)?;
exports.create_named_method("transformSync", transform::transform_sync)?;

exports.create_named_method("minify", minify::minify)?;
exports.create_named_method("minifySync", minify::minify_sync)?;

Ok(())
}

Expand Down
83 changes: 83 additions & 0 deletions packages/next/build/swc/src/minify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright (c) 2017 The swc Project Developers
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.
*/
use crate::{
complete_output, get_compiler,
util::{CtxtExt, MapErr},
};
use napi::{CallContext, JsObject, JsString, Task};
use std::sync::Arc;
use swc::TransformOutput;
use swc_common::FileName;

struct MinifyTask {
c: Arc<swc::Compiler>,
code: String,
opts: swc::config::JsMinifyOptions,
}

impl Task for MinifyTask {
type Output = TransformOutput;

type JsValue = JsObject;

fn compute(&mut self) -> napi::Result<Self::Output> {
let fm = self.c.cm.new_source_file(FileName::Anon, self.code.clone());

self.c.minify(fm, &self.opts).convert_err()
}

fn resolve(self, env: napi::Env, output: Self::Output) -> napi::Result<Self::JsValue> {
complete_output(&env, output)
}
}

#[js_function(2)]
pub fn minify(cx: CallContext) -> napi::Result<JsObject> {
let code = cx.get::<JsString>(0)?.into_utf8()?.into_owned()?;
let opts = cx.get_deserialized(1)?;

let c = get_compiler(&cx);

let task = MinifyTask { c, code, opts };

cx.env.spawn(task).map(|t| t.promise_object())
}

#[js_function(2)]
pub fn minify_sync(cx: CallContext) -> napi::Result<JsObject> {
let code = cx.get::<JsString>(0)?.into_utf8()?.into_owned()?;
let opts = cx.get_deserialized(1)?;

let c = get_compiler(&cx);

let fm = c.cm.new_source_file(FileName::Anon, code.clone());

let output = c.minify(fm, &opts).convert_err()?;

complete_output(&cx.env, output)
}

0 comments on commit b36e823

Please sign in to comment.