Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move core files to src folder and move JS files to TypeScript #44405

Merged
merged 27 commits into from
Jan 3, 2023

Conversation

timneutkens
Copy link
Member

@timneutkens timneutkens commented Dec 28, 2022

  • Move core files to src folder at packages/next/src.
  • Refactor all .js files to TypeScript, note that many of these were external packages so I've added any for many of them but it caught a few bugs already. Just making sure all code is consistently TypeScript.

First in a series of smaller changes to the folder structure.

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have a helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • e2e tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have a helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running pnpm build && pnpm lint
  • The "examples guidelines" are followed from our contributing doc

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. type: next labels Dec 28, 2022
@ijjk
Copy link
Member

ijjk commented Dec 28, 2022

Failing test suites

Commit: bf492f4

pnpm testheadless test/unit/web-runtime/next-response.test.ts

Expand output

● Test suite failed to run

Cannot find module 'next/server/web/spec-extension/response' from 'unit/web-runtime/next-response.test.ts'

   5 | import { NextResponse } from 'next/server/web/spec-extension/response'
   6 |
>  7 | const toJSON = async (response: Response) => ({
     |                   ^
   8 |   body: await response.json(),
   9 |   contentType: response.headers.get('content-type'),
  10 |   status: response.status,

  at Resolver.resolveModule (../node_modules/.pnpm/jest-resolve@27.5.1/node_modules/jest-resolve/build/resolver.js:324:11)
  at Object.<anonymous> (unit/web-runtime/next-response.test.ts:7:19)

Read more about building and testing Next.js in contributing.md.

@ijjk
Copy link
Member

ijjk commented Dec 28, 2022

Stats from current PR

Default Build (Decrease detected ✓)
General Overall decrease ✓
vercel/next.js canary timneutkens/next.js add/src-folder Change
buildDuration 44.1s 41.9s -2.3s
buildDurationCached 12.4s 12.5s ⚠️ +122ms
nodeModulesSize 95.1 MB 95.1 MB
nextStartRea..uration (ms) 339ms 334ms -5ms
Client Bundles (main, webpack)
vercel/next.js canary timneutkens/next.js add/src-folder Change
152-HASH.js gzip 64.5 kB 64.5 kB
53.HASH.js gzip 182 B 182 B
main-app-HASH.js gzip 205 B 205 B
main-HASH.js gzip 79.2 kB 79.2 kB
webpack-HASH.js gzip 1.7 kB 1.7 kB
Overall change 146 kB 146 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary timneutkens/next.js add/src-folder Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary timneutkens/next.js add/src-folder Change
_app-HASH.js gzip 192 B 192 B
_error-HASH.js gzip 179 B 179 B
amp-HASH.js gzip 484 B 484 B
css-HASH.js gzip 804 B 804 B
dynamic-HASH.js gzip 2.27 kB 2.27 kB
edge-ssr-HASH.js gzip 255 B 255 B
head-HASH.js gzip 827 B 827 B
hooks-HASH.js gzip 848 B 848 B
image-HASH.js gzip 4.3 kB 4.3 kB
index-HASH.js gzip 252 B 252 B
link-HASH.js gzip 2.69 kB 2.69 kB
routerDirect..HASH.js gzip 782 B 782 B
script-HASH.js gzip 857 B 857 B
withRouter-HASH.js gzip 781 B 781 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 15.6 kB 15.6 kB
Client Build Manifests
vercel/next.js canary timneutkens/next.js add/src-folder Change
_buildManifest.js gzip 482 B 482 B
Overall change 482 B 482 B
Rendered Page Sizes
vercel/next.js canary timneutkens/next.js add/src-folder Change
index.html gzip 489 B 489 B
link.html gzip 504 B 504 B
withRouter.html gzip 485 B 485 B
Overall change 1.48 kB 1.48 kB
Edge SSR bundle Size
vercel/next.js canary timneutkens/next.js add/src-folder Change
edge-ssr.js gzip 110 kB 110 kB
page.js gzip 98.4 kB 98.4 kB
Overall change 209 kB 209 kB
Middleware size
vercel/next.js canary timneutkens/next.js add/src-folder Change
middleware-b..fest.js gzip 582 B 582 B
middleware-r..fest.js gzip 145 B 145 B
middleware.js gzip 27 kB 27 kB
edge-runtime..pack.js gzip 1.83 kB 1.83 kB
Overall change 29.6 kB 29.6 kB

Diffs

Diff for page.js
@@ -8618,7 +8618,7 @@ Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime`;
       /***/
     },
 
-    /***/ 1708: /***/ (
+    /***/ 1036: /***/ (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -8627,13 +8627,13 @@ Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime`;
         __webpack_require__.bind(__webpack_require__, 1210)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.bind(__webpack_require__, 6448)
+        __webpack_require__.bind(__webpack_require__, 2973)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.bind(__webpack_require__, 9916)
+        __webpack_require__.bind(__webpack_require__, 6448)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.bind(__webpack_require__, 2973)
+        __webpack_require__.bind(__webpack_require__, 9916)
       );
 
       /***/
Diff for middleware-b..-manifest.js
@@ -9,7 +9,7 @@ self.__BUILD_MANIFEST = {
   rootMainFiles: [
     "static/chunks/webpack-c452a3e31b73f504.js",
     "static/chunks/152-792c0b16c9234019.js",
-    "static/chunks/main-app-4d7c16c03a2fbff0.js"
+    "static/chunks/main-app-c9a0aaff35eafcb5.js"
   ],
   pages: {
     "/": [
Diff for main-app-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [744],
   {
-    /***/ 3731: /***/ function(
+    /***/ 9915: /***/ function(
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -10,13 +10,13 @@
         __webpack_require__.t.bind(__webpack_require__, 429, 23)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.t.bind(__webpack_require__, 8138, 23)
+        __webpack_require__.t.bind(__webpack_require__, 1161, 23)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.t.bind(__webpack_require__, 9379, 23)
+        __webpack_require__.t.bind(__webpack_require__, 8138, 23)
       );
       Promise.resolve(/* import() eager */).then(
-        __webpack_require__.t.bind(__webpack_require__, 1161, 23)
+        __webpack_require__.t.bind(__webpack_require__, 9379, 23)
       );
 
       /***/
@@ -28,7 +28,7 @@
       return __webpack_require__((__webpack_require__.s = moduleId));
     };
     /******/ __webpack_require__.O(0, [152], function() {
-      return __webpack_exec__(7070), __webpack_exec__(3731);
+      return __webpack_exec__(7070), __webpack_exec__(9915);
     });
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Commit: 5f5da1e

@timneutkens timneutkens changed the title Move core files to src folder Move core files to src folder and move JS files to TypeScript Dec 30, 2022
@timneutkens timneutkens merged commit efcec4c into vercel:canary Jan 3, 2023
ijjk added a commit that referenced this pull request Jan 31, 2023
This fixes a regression in our source map generating which got lost in
the big diff from the `src` folder restructure in
#44405

These invalid source maps broken plugins that attempted to leverage them
like `@sentry/nextjs` which only attempts in a production environment
https://github.com/getsentry/sentry-javascript/blob/15ec85bead77100413381be821f42841ae114f93/packages/nextjs/src/config/webpack.ts#L586

For a regression test in a follow-up we will need to investigate a
production test fixture with `@sentry/nextjs` although this requires a
DSN be configured.

This also ensures we setup `unhandledRejection` and `uncaughtException`
listeners during build so that we have proper stack information when
these occur and the process isn't left hanging.

This also moves the `extensionAlias` config from
#44177 to an experimental config
as it seems to cause conflicts with ESM packages that define `exports`
in their `package.json` which can be considered a breaking change.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Fixes: #45419
x-ref: [slack
thread](https://vercel.slack.com/archives/C03DQ3QFV7C/p1674937545579229)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants