Skip to content

Commit

Permalink
Merge branch 'canary' into fix/hide-learn-more-when-fresh
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 27, 2023
2 parents fa8bec7 + aa61463 commit f81043c
Show file tree
Hide file tree
Showing 49 changed files with 462 additions and 175 deletions.
1 change: 0 additions & 1 deletion packages/create-next-app/templates/app/js/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
Expand Down
1 change: 0 additions & 1 deletion packages/create-next-app/templates/app/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-nocheck
/* eslint-disable */
import { Oswald } from "@next/font/google";
import localFont1 from "@next/font/local";
import type { AdjustFontFallback } from "@next/font"

const oswald = Oswald({ subsets: ["latin"] });
const myFont = localFont1({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-nocheck
/* eslint-disable */
import { Oswald } from "next/font/google";
import localFont1 from "next/font/local";
import type { AdjustFontFallback } from "next/font"

const oswald = Oswald({ subsets: ["latin"] });
const myFont = localFont1({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// @ts-nocheck
/* eslint-disable */
import Image from "next/legacy/image";
import Named, { Blarg } from "next/legacy/image";
import type { ImageProps } from "next/legacy/image";
import { type ImageLoaderProps } from "next/legacy/image";
import Foo from "foo";
import img from "../public/img.jpg";

Expand Down Expand Up @@ -30,4 +34,4 @@ export default function Home() {
<Image src="/test.dot" width="200" height="300" layout="responsive" style={{...myStyle}} />
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// @ts-nocheck
/* eslint-disable */
import Image from "next/image";
import Named, { Blarg } from "next/image";
import type { ImageProps } from "next/image";
import { type ImageLoaderProps } from "next/image";
import Foo from "foo";
import img from "../public/img.jpg";

Expand Down Expand Up @@ -99,4 +103,4 @@ export default function Home() {
}} />
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck
/* eslint-disable */
const Image = require("next/legacy/image");
const Named = require("next/legacy/image");
const Foo = require("foo");
Expand All @@ -11,4 +13,4 @@ export default function Home() {
<Foo />
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck
/* eslint-disable */
const Image = require("next/image");
const Named = require("next/image");
const Foo = require("foo");
Expand All @@ -11,4 +13,4 @@ export default function Home() {
<Foo />
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { type ImageLoaderProps } from "next/image";
import Foo from "foo";
import Future1 from "next/future/image";
import Future2 from "next/future/image";
import type { ImageProps as ImageFutureProps } from "next/future/image";
import { type ImageLoaderProps as ImageFutureLoaderProps } from "next/future/image";

export default function Home() {
return (<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { type ImageLoaderProps } from "next/legacy/image";
import Foo from "foo";
import Future1 from "next/image";
import Future2 from "next/image";
import type { ImageProps as ImageFutureProps } from "next/image";
import { type ImageLoaderProps as ImageFutureLoaderProps } from "next/image";

export default function Home() {
return (<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const { join } = require('path')
const fixtureDir = 'built-in-next-font'
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir)
const fixtures = readdirSync(fixtureDirPath)
.filter(file => file.endsWith('.input.js'))
.map(file => file.replace('.input.js', ''))
.filter(file => file.endsWith('.input.tsx'))
.map(file => file.replace('.input.tsx', ''))

for (const fixture of fixtures) {
const prefix = `${fixtureDir}/${fixture}`;
defineTest(__dirname, fixtureDir, null, prefix)
defineTest(__dirname, fixtureDir, null, prefix, { parser: 'tsx' });
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const { join } = require('path')
const fixtureDir = 'next-image-experimental'
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir)
const fixtures = readdirSync(fixtureDirPath)
.filter(file => file.endsWith('.input.js'))
.map(file => file.replace('.input.js', ''))
.filter(file => file.endsWith('.input.tsx'))
.map(file => file.replace('.input.tsx', ''))

for (const fixture of fixtures) {
const prefix = `${fixtureDir}/${fixture}`;
defineTest(__dirname, fixtureDir, null, prefix)
defineTest(__dirname, fixtureDir, null, prefix, { parser: 'tsx' })
}
28 changes: 14 additions & 14 deletions packages/next-codemod/transforms/built-in-next-font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ export default function transformer(
const j = api.jscodeshift.withParser('tsx')
const root = j(file.source)

// Before: import { ... } from '@next/font'
// After: import { ... } from 'next/font'
root
.find(j.ImportDeclaration, {
source: { value: '@next/font' },
})
.forEach((fontImport) => {
fontImport.node.source = j.stringLiteral('next/font')
})

// Before: import { ... } from '@next/font/google'
// After: import { ... } from 'next/font/google'
root
.find(j.ImportDeclaration, {
source: { value: '@next/font/google' },
})
.forEach((imageImport) => {
j(imageImport).replaceWith(
j.importDeclaration(
imageImport.node.specifiers,
j.stringLiteral('next/font/google')
)
)
.forEach((fontImport) => {
fontImport.node.source = j.stringLiteral('next/font/google')
})

// Before: import localFont from '@next/font/local'
Expand All @@ -29,13 +34,8 @@ export default function transformer(
.find(j.ImportDeclaration, {
source: { value: '@next/font/local' },
})
.forEach((imageImport) => {
j(imageImport).replaceWith(
j.importDeclaration(
imageImport.node.specifiers,
j.stringLiteral('next/font/local')
)
)
.forEach((fontImport) => {
fontImport.node.source = j.stringLiteral('next/font/local')
})

return root.toSource(options)
Expand Down
8 changes: 1 addition & 7 deletions packages/next-codemod/transforms/next-image-experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,8 @@ export default function transformer(
(node) => node.type === 'ImportDefaultSpecifier'
) as ImportDefaultSpecifier | undefined
const tagName = defaultSpecifier?.local?.name

imageImport.node.source = j.stringLiteral('next/image')
if (tagName) {
j(imageImport).replaceWith(
j.importDeclaration(
imageImport.node.specifiers,
j.stringLiteral('next/image')
)
)
findAndReplaceProps(j, root, tagName)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ export default function transformer(
source: { value: 'next/future/image' },
})
.forEach((imageFutureImport) => {
j(imageFutureImport).replaceWith(
j.importDeclaration(
imageFutureImport.node.specifiers,
j.stringLiteral('next/image')
)
)
imageFutureImport.node.source = j.stringLiteral('next/image')
})

// Before: const Image = await import("next/future/image")
Expand Down
37 changes: 33 additions & 4 deletions packages/next-swc/crates/core/src/auto_cjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ impl Visit for CjsFinder {
fn visit_member_expr(&mut self, e: &MemberExpr) {
if let Expr::Ident(obj) = &*e.obj {
if let MemberProp::Ident(prop) = &e.prop {
if &*obj.sym == "module" && &*prop.sym == "exports" {
// Detect `module.exports` and `exports.__esModule`
if (&*obj.sym == "module" && &*prop.sym == "exports")
|| (&*obj.sym == "exports" && &*prop.sym == "__esModule")
{
self.found = true;
return;
}
Expand All @@ -31,9 +34,35 @@ impl Visit for CjsFinder {
e.prop.visit_with(self);
}

fn visit_str(&mut self, s: &Str) {
if s.value.contains("__esModule") {
self.found = true;
// Detect `Object.defineProperty(exports, "__esModule", ...)`
// Note that `Object.defineProperty(module.exports, ...)` will be handled by
// `visit_member_expr`.
fn visit_call_expr(&mut self, e: &CallExpr) {
if let Callee::Expr(expr) = &e.callee {
if let Expr::Member(member_expr) = &**expr {
if let (Expr::Ident(obj), MemberProp::Ident(prop)) =
(&*member_expr.obj, &member_expr.prop)
{
if &*obj.sym == "Object" && &*prop.sym == "defineProperty" {
if let Some(ExprOrSpread { expr: expr0, .. }) = e.args.get(0) {
if let Expr::Ident(arg0) = &**expr0 {
if &*arg0.sym == "exports" {
if let Some(ExprOrSpread { expr: expr1, .. }) = e.args.get(1) {
if let Expr::Lit(Lit::Str(arg1)) = &**expr1 {
if &*arg1.value == "__esModule" {
self.found = true;
return;
}
}
}
}
}
}
}
}
}
}

e.callee.visit_with(self);
}
}
2 changes: 2 additions & 0 deletions packages/next-swc/crates/core/tests/full/auto-cjs/2/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default 1
Object.defineProperty(exports, "__esModule", { value: true });
13 changes: 13 additions & 0 deletions packages/next-swc/crates/core/tests/full/auto-cjs/2/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), Object.defineProperty(exports, "default", {
enumerable: !0,
get: function() {
return e;
}
});
var e = 1;
Object.defineProperty(exports, "__esModule", {
value: !0
});
4 changes: 4 additions & 0 deletions packages/next-swc/crates/core/tests/full/auto-cjs/3/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default 1
console.log("__esModule")
Object.defineProperty({}, '__esModule', { value: true })
Object.defineProperty()
4 changes: 4 additions & 0 deletions packages/next-swc/crates/core/tests/full/auto-cjs/3/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default 1;
console.log("__esModule"), Object.defineProperty({}, "__esModule", {
value: !0
}), Object.defineProperty();

0 comments on commit f81043c

Please sign in to comment.