From 3caacd570424625c776d16c29e80ec13b05f1600 Mon Sep 17 00:00:00 2001 From: remorses Date: Tue, 22 Sep 2020 12:01:41 +0200 Subject: [PATCH 1/4] fix check of symlinked files --- packages/next/build/webpack-config.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 780677c9f28bbe4..2ed6d178d561baa 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() } } From be7cc80ff295182c4462e2a79c73808a80bff6a9 Mon Sep 17 00:00:00 2001 From: remorses Date: Tue, 22 Sep 2020 12:33:29 +0200 Subject: [PATCH 2/4] handle null baseRes case --- packages/next/build/webpack-config.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 2ed6d178d561baa..d89e6edaa353770 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -666,10 +666,10 @@ export default async function getBaseWebpackConfig( // would be different from what the real resolution would use, we // cannot externalize it. if ( - baseRes && - baseRes !== res && - // if res and baseRes are symlinks they could point to the the same file - realpathSync(baseRes) !== realpathSync(res) + !baseRes || + (baseRes !== res && + // if res and baseRes are symlinks they could point to the the same file + realpathSync(baseRes) !== realpathSync(res)) ) { return callback() } From 7e948d88ddad24d6e58bfb2283343138031ed575 Mon Sep 17 00:00:00 2001 From: remorses Date: Mon, 28 Sep 2020 16:53:50 +0200 Subject: [PATCH 3/4] added test for pnpm --- .../basic-pnpm/pages/about.js | 3 + .../basic-pnpm/pages/about2.js | 3 + .../basic-pnpm/pages/day/index.js | 3 + .../basic-pnpm/pages/index.js | 11 ++++ .../basic-pnpm/test/index.test.js | 63 +++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 test/package-managers-tests/basic-pnpm/pages/about.js create mode 100644 test/package-managers-tests/basic-pnpm/pages/about2.js create mode 100644 test/package-managers-tests/basic-pnpm/pages/day/index.js create mode 100644 test/package-managers-tests/basic-pnpm/pages/index.js create mode 100644 test/package-managers-tests/basic-pnpm/test/index.test.js 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..ec36e177aef6ffa --- /dev/null +++ b/test/package-managers-tests/basic-pnpm/test/index.test.js @@ -0,0 +1,63 @@ +/* eslint-env jest */ +import { execSync } from 'child_process' +import fs from 'fs-extra' +import path from 'path' + +jest.setTimeout(100 * 1000) + +beforeAll(async () => { + exec('npm i -g pnpm') + await clean() +}) + +afterAll(async () => { + await clean() +}) + +test('pnpm installs', async () => { + exec('pnpm init -y') + exec('pnpm add next react react-dom') + await useLocalNextjs() + // exec('pnpm install') +}) + +test('nextjs builds with pnpm', () => { + exec('pnpx next build') +}) + +const exec = (cmd) => { + return execSync(cmd, { + env: process.env, + shell: true, + stdio: 'inherit', + cwd: path.resolve(__dirname, '..'), + }) +} + +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')) +} From 15a991d7d8e08bf324661c39a7ded7b64d4888e6 Mon Sep 17 00:00:00 2001 From: remorses Date: Mon, 28 Sep 2020 19:03:36 +0200 Subject: [PATCH 4/4] use local pnpm instad of global install --- package.json | 1 + .../basic-pnpm/test/index.test.js | 19 +++++++++++++++---- yarn.lock | 5 +++++ 3 files changed, 21 insertions(+), 4 deletions(-) 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/test/package-managers-tests/basic-pnpm/test/index.test.js b/test/package-managers-tests/basic-pnpm/test/index.test.js index ec36e177aef6ffa..f1340f8e06dff50 100644 --- a/test/package-managers-tests/basic-pnpm/test/index.test.js +++ b/test/package-managers-tests/basic-pnpm/test/index.test.js @@ -6,7 +6,6 @@ import path from 'path' jest.setTimeout(100 * 1000) beforeAll(async () => { - exec('npm i -g pnpm') await clean() }) @@ -15,14 +14,16 @@ afterAll(async () => { }) test('pnpm installs', async () => { - exec('pnpm init -y') - exec('pnpm add next react react-dom') + 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', () => { - exec('pnpx next build') + const pnpx = getStdout(`yarn bin pnpx`) + exec(pnpx + ' next build') }) const exec = (cmd) => { @@ -34,6 +35,16 @@ const exec = (cmd) => { }) } +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')) diff --git a/yarn.lock b/yarn.lock index 30c492a6a51f73b..8b7e77ca3e22560 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12567,6 +12567,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"