diff --git a/package.json b/package.json index 9660e457a1ce555..ffe1716f1b2a81b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 10d7232e30d4f3b..f15a47b65a8c326 100644 --- a/packages/next/build/webpack-config.ts +++ b/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' @@ -665,7 +665,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() } } diff --git a/test/package-managers-tests/basic-pnpm/pages/about.js b/test/package-managers-tests/basic-pnpm/pages/about.js new file mode 100644 index 000000000000000..46817af02a5c141 --- /dev/null +++ b/test/package-managers-tests/basic-pnpm/pages/about.js @@ -0,0 +1,3 @@ +export default function About() { + return
About us
+} diff --git a/test/package-managers-tests/basic-pnpm/pages/about2.js b/test/package-managers-tests/basic-pnpm/pages/about2.js new file mode 100644 index 000000000000000..2b8fe3f38cba603 --- /dev/null +++ b/test/package-managers-tests/basic-pnpm/pages/about2.js @@ -0,0 +1,3 @@ +export default function About2() { + return
About 2
+} diff --git a/test/package-managers-tests/basic-pnpm/pages/day/index.js b/test/package-managers-tests/basic-pnpm/pages/day/index.js new file mode 100644 index 000000000000000..a3cd64f29174d13 --- /dev/null +++ b/test/package-managers-tests/basic-pnpm/pages/day/index.js @@ -0,0 +1,3 @@ +export default function Day() { + return
Hello Day
+} diff --git a/test/package-managers-tests/basic-pnpm/pages/index.js b/test/package-managers-tests/basic-pnpm/pages/index.js new file mode 100644 index 000000000000000..7bb25eccba89ef5 --- /dev/null +++ b/test/package-managers-tests/basic-pnpm/pages/index.js @@ -0,0 +1,11 @@ +import Link from 'next/link' +export default function Home() { + return ( +
+ Hello World.{' '} + + About + +
+ ) +} diff --git a/test/package-managers-tests/basic-pnpm/test/index.test.js b/test/package-managers-tests/basic-pnpm/test/index.test.js new file mode 100644 index 000000000000000..f1340f8e06dff50 --- /dev/null +++ b/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')) +} diff --git a/yarn.lock b/yarn.lock index 2ac55160d99d7af..86363b87b344fde 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"