Skip to content

Commit

Permalink
Resolve to real path before checking for path inequality (#17279)
Browse files Browse the repository at this point in the history
Co-authored-by: Luis Alvarez D <luis@vercel.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
  • Loading branch information
3 people committed Oct 14, 2020
1 parent fad07cc commit 5c4d0bd
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -98,6 +98,7 @@
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"pixrem": "5.0.0",
"pnpm": "5.8.0",
"postcss-nested": "4.2.1",
"postcss-pseudoelements": "5.0.0",
"postcss-short-size": "4.0.0",
Expand Down
9 changes: 7 additions & 2 deletions packages/next/build/webpack-config.ts
@@ -1,7 +1,7 @@
import { codeFrameColumns } from '@babel/code-frame'
import ReactRefreshWebpackPlugin from '@next/react-refresh-utils/ReactRefreshWebpackPlugin'
import crypto from 'crypto'
import { readFileSync } from 'fs'
import { readFileSync, realpathSync } from 'fs'
import chalk from 'next/dist/compiled/chalk'
import semver from 'next/dist/compiled/semver'
import TerserPlugin from 'next/dist/compiled/terser-webpack-plugin'
Expand Down Expand Up @@ -685,7 +685,12 @@ export default async function getBaseWebpackConfig(
// Same as above: if the package, when required from the root,
// would be different from what the real resolution would use, we
// cannot externalize it.
if (baseRes !== res) {
if (
!baseRes ||
(baseRes !== res &&
// if res and baseRes are symlinks they could point to the the same file
realpathSync(baseRes) !== realpathSync(res))
) {
return callback()
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/package-managers-tests/basic-pnpm/pages/about.js
@@ -0,0 +1,3 @@
export default function About() {
return <div>About us</div>
}
3 changes: 3 additions & 0 deletions test/package-managers-tests/basic-pnpm/pages/about2.js
@@ -0,0 +1,3 @@
export default function About2() {
return <div>About 2</div>
}
3 changes: 3 additions & 0 deletions test/package-managers-tests/basic-pnpm/pages/day/index.js
@@ -0,0 +1,3 @@
export default function Day() {
return <div>Hello Day</div>
}
11 changes: 11 additions & 0 deletions test/package-managers-tests/basic-pnpm/pages/index.js
@@ -0,0 +1,11 @@
import Link from 'next/link'
export default function Home() {
return (
<div>
Hello World.{' '}
<Link href="/about">
<a>About</a>
</Link>
</div>
)
}
74 changes: 74 additions & 0 deletions test/package-managers-tests/basic-pnpm/test/index.test.js
@@ -0,0 +1,74 @@
/* eslint-env jest */
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'

jest.setTimeout(100 * 1000)

beforeAll(async () => {
await clean()
})

afterAll(async () => {
await clean()
})

test('pnpm installs', async () => {
const pnpm = getStdout('yarn bin pnpm')
exec(pnpm + ' init -y')
exec(pnpm + ' add next react react-dom')
await useLocalNextjs()
// exec('pnpm install')
})

test('nextjs builds with pnpm', () => {
const pnpx = getStdout(`yarn bin pnpx`)
exec(pnpx + ' next build')
})

const exec = (cmd) => {
return execSync(cmd, {
env: process.env,
shell: true,
stdio: 'inherit',
cwd: path.resolve(__dirname, '..'),
})
}

const getStdout = (cmd) => {
return execSync(cmd, {
env: process.env,
shell: true,
stdio: 'pipe',
})
.toString()
.trim()
}

async function useLocalNextjs() {
// installed nextjs
const nextPath = path.dirname(require.resolve('next/package.json'))

// repository root
const root = path.dirname(
require.resolve(path.resolve(process.cwd(), 'package.json'))
)

// local nextjs
const currentNextPath = path.resolve(root, 'packages/next')

// copy local nextjs to node_modules
await fs.copy(
path.resolve(currentNextPath, 'dist'),
path.resolve(nextPath, 'dist')
)

console.log('copied local nextjs to node_modules')
}

async function clean() {
// jest test cannot be found if a package.json exists in test directory
await fs.remove(path.resolve(__dirname, '../package.json'))
await fs.remove(path.resolve(__dirname, '../node_modules'))
await fs.remove(path.resolve(__dirname, '../pnpm-lock.yaml'))
}
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -12587,6 +12587,11 @@ pnp-webpack-plugin@1.6.4:
dependencies:
ts-pnp "^1.1.6"

pnpm@5.8.0:
version "5.8.0"
resolved "https://registry.yarnpkg.com/pnpm/-/pnpm-5.8.0.tgz#a933d6c756efe8795b12004bbff1b82c622e771b"
integrity sha512-J2rAxEXnohwcDkR4KNI6UsYhDs9hJ/tje/BahHpXawi406pmxd6caJUXfRxZPbKvKdyVqfBRKhlX1vyhYbM8lQ==

posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
Expand Down

0 comments on commit 5c4d0bd

Please sign in to comment.