Skip to content

Commit 2182ff2

Browse files
authored
Next12 now supports ESM (github#29295)
* Next12 now supports ESM * No more michael jackson script extensions * Fix test running * Update jest-puppeteer.config.cjs * Update package.json
1 parent d1ea358 commit 2182ff2

31 files changed

+38
-46
lines changed

.eslintrc.js .eslintrc.cjs

File renamed without changes.

.github/package.json

-1
This file was deleted.

.github/workflows/check-all-english-links.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# Don't care about CDN caching image URLs
6363
DISABLE_REWRITE_ASSET_URLS: true
6464
run: |
65-
node server.mjs > /tmp/stdout.log 2> /tmp/stderr.log &
65+
node server.js > /tmp/stdout.log 2> /tmp/stderr.log &
6666
sleep 6
6767
curl --retry-connrefused --retry 5 -I http://localhost:4000/
6868

.github/workflows/check-broken-links-github-github.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
DISABLE_RENDERING_CACHE: true
6565
run: |
6666
67-
node server.mjs &
67+
node server.js &
6868
sleep 5
6969
curl --retry-connrefused --retry 3 -I http://localhost:4000/
7070

.github/workflows/code-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- '**.yaml'
1616
- '**.yml'
1717
- '**.scss'
18-
- .eslintrc.js
18+
- .eslintrc.cjs
1919
# In case something like eslint or tsc or prettier upgrades
2020
- 'package-lock.json'
2121
# Ultimately, for debugging this workflow itself

.github/workflows/dry-run-elasticsearch-indexing.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- gh-readonly-queue/main/**
1111
pull_request:
1212
paths:
13-
- script/search/index-elasticsearch.mjs
13+
- script/search/index-elasticsearch.js
1414
- 'package*.json'
1515
- .github/workflows/dry-run-elasticsearch-indexing.yml
1616

@@ -63,7 +63,7 @@ jobs:
6363
env:
6464
ELASTICSEARCH_URL: 'http://localhost:9200'
6565
run: |
66-
./script/search/index-elasticsearch.mjs --verbose \
66+
./script/search/index-elasticsearch.js --verbose \
6767
-l en -l ja \
6868
-V dotcom -V ghes-3.5
6969

.github/workflows/link-check-all.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
# Don't care about CDN caching image URLs
5454
DISABLE_REWRITE_ASSET_URLS: true
5555
run: |
56-
./script/rendered-content-link-checker.mjs \
56+
./script/rendered-content-link-checker.js \
5757
--language en \
5858
--max 100 \
5959
--check-anchors \
@@ -66,7 +66,7 @@ jobs:
6666
# Don't care about CDN caching image URLs
6767
DISABLE_REWRITE_ASSET_URLS: true
6868
run: |
69-
./script/rendered-content-link-checker.mjs \
69+
./script/rendered-content-link-checker.js \
7070
--language en \
7171
--exit \
7272
--verbose \

.github/workflows/orphaned-assets-check.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: |
4141
set -e
4242
43-
./script/find-orphaned-assets.mjs | xargs git rm
43+
./script/find-orphaned-assets.js | xargs git rm
4444
4545
# If nothing to commit, exit now. It's fine. No orphans.
4646
git status | grep 'nothing to commit' && exit 0
@@ -58,6 +58,6 @@ jobs:
5858
5959
gh pr create \
6060
--title "Delete orphaned assets ($date)" \
61-
--body "Found with the find-orphaned-assets.mjs script" \
61+
--body "Found with the find-orphaned-assets.js script" \
6262
--repo github/docs-internal \
6363
--label docs-content-fr

.github/workflows/sync-search-elasticsearch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
110110
- name: Index into Elasticsearch
111111
run: |
112-
./script/search/index-elasticsearch.mjs \
112+
./script/search/index-elasticsearch.js \
113113
--language ${{ matrix.language }} \
114114
--source-directory /tmp/records
115115

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ENV NODE_ENV production
7474
# Whether to hide iframes, add warnings to external links
7575
ENV AIRGAP false
7676

77-
# Preferred port for server.mjs
77+
# Preferred port for server.js
7878
ENV PORT 4000
7979

8080
ENV ENABLED_LANGUAGES "en"
@@ -94,12 +94,12 @@ COPY --chown=node:node middleware ./middleware
9494
COPY --chown=node:node feature-flags.json ./
9595
COPY --chown=node:node data ./data
9696
COPY --chown=node:node next.config.js ./
97-
COPY --chown=node:node server.mjs ./server.mjs
98-
COPY --chown=node:node start-server.mjs ./start-server.mjs
97+
COPY --chown=node:node server.js ./server.js
98+
COPY --chown=node:node start-server.js ./start-server.js
9999

100100
EXPOSE $PORT
101101

102-
CMD ["node", "server.mjs"]
102+
CMD ["node", "server.js"]
103103

104104
# --------------------------------------------------------------------------------
105105
# PRODUCTION IMAGE - includes all translations

data/package.json

-1
This file was deleted.
File renamed without changes.

jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (testTranslation) {
1313
reporters.push('jest-github-actions-reporter')
1414
}
1515

16-
module.exports = {
16+
export default {
1717
coverageThreshold: {
1818
global: {
1919
branches: 95,
@@ -41,6 +41,6 @@ module.exports = {
4141
],
4242
testMatch: ['**/tests/**/*.js'],
4343
testLocationInResults: isActions,
44-
globalSetup: './script/start-server-for-jest.mjs',
45-
globalTeardown: './script/kill-server-for-jest.mjs',
44+
globalSetup: './script/start-server-for-jest.js',
45+
globalTeardown: './script/kill-server-for-jest.js',
4646
}

lib/package.json

-1
This file was deleted.

middleware/package.json

-1
This file was deleted.

next.config.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// import { productIds } from './lib/all-products.js'
2-
// import languages from './lib/languages.js'
3-
4-
const fs = require('fs')
5-
const frontmatter = require('gray-matter')
6-
const path = require('path')
1+
import fs from 'fs'
2+
import frontmatter from 'gray-matter'
3+
import path from 'path'
74
const homepage = path.posix.join(process.cwd(), 'content/index.md')
85
const { data } = frontmatter(fs.readFileSync(homepage, 'utf8'))
96
const productIds = data.children
107

11-
module.exports = {
8+
export default {
129
// speed up production `next build` by ignoring typechecking during that step of build.
1310
// type-checking still occurs in the Dockerfile build
1411
typescript: {

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"engines": {
170170
"node": ">=16.x"
171171
},
172-
"exports": "./server.mjs",
172+
"exports": "./server.js",
173173
"license": "(MIT AND CC-BY-4.0)",
174174
"name": "docs.github.com",
175175
"optionalDependencies": {
@@ -183,9 +183,9 @@
183183
"private": true,
184184
"repository": "https://github.com/github/docs",
185185
"scripts": {
186-
"browser-test": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules jest tests/browser/browser.js",
186+
"browser-test": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest tests/browser/browser.js",
187187
"build": "next build",
188-
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.mjs",
188+
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.js",
189189
"dev": "npm start",
190190
"lint": "eslint '**/*.{js,mjs,ts,tsx}'",
191191
"lint-translation": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_TRANSLATION=true jest tests/linting/lint-files.js",
@@ -195,14 +195,14 @@
195195
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
196196
"rest-dev": "script/rest/update-files.js && npm run dev",
197197
"show-action-deps": "echo 'Action Dependencies:' && rg '^[\\s|-]*(uses:.*)$' .github -I -N --no-heading -r '$1$2' | sort | uniq | cut -c 7-",
198-
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs",
199-
"start-all-languages": "cross-env NODE_ENV=development nodemon server.mjs",
198+
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.js",
199+
"start-all-languages": "cross-env NODE_ENV=development nodemon server.js",
200200
"sync-search": "cross-env NODE_OPTIONS='--max_old_space_size=8192' start-server-and-test sync-search-server 4002 sync-search-indices",
201201
"sync-search-ghes-release": "cross-env GHES_RELEASE=1 start-server-and-test sync-search-server 4002 sync-search-indices",
202202
"sync-search-indices": "script/search/sync-search-indices.js",
203-
"sync-search-server": "cross-env NODE_ENV=production PORT=4002 CHANGELOG_DISABLED=true DISABLE_RENDERING_CACHE=true DISABLE_OVERLOAD_PROTECTION=true node server.mjs",
203+
"sync-search-server": "cross-env NODE_ENV=production PORT=4002 CHANGELOG_DISABLED=true DISABLE_RENDERING_CACHE=true DISABLE_OVERLOAD_PROTECTION=true node server.js",
204204
"translation-check": "start-server-and-test translation-check-server 4002 translation-check-test",
205-
"translation-check-server": "cross-env NODE_ENV=test PORT=4002 node server.mjs",
205+
"translation-check-server": "cross-env NODE_ENV=test PORT=4002 node server.js",
206206
"translation-check-test": "script/i18n/test-html-pages.js",
207207
"test": "cross-env NODE_OPTIONS='--max_old_space_size=4096 --experimental-vm-modules' jest --logHeapUsage",
208208
"test-watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch --notify --notifyMode=change --coverage",
@@ -211,5 +211,6 @@
211211
"lint-staged": {
212212
"*.{js,mjs,ts,tsx}": "eslint --cache --fix",
213213
"*.{js,mjs,scss,ts,tsx,yml,yaml}": "prettier --write"
214-
}
214+
},
215+
"type": "module"
215216
}
File renamed without changes.

script/kill-server-for-jest.mjs script/kill-server-for-jest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import teardownJestPuppeteer from 'jest-environment-puppeteer/teardown.js'
44

5-
import { START_JEST_SERVER, isServerHealthy, killServer } from './server-for-jest.mjs'
5+
import { START_JEST_SERVER, isServerHealthy, killServer } from './server-for-jest.js'
66

77
export default async () => {
88
if (START_JEST_SERVER) {
File renamed without changes.

script/package.json

-1
This file was deleted.
File renamed without changes.
File renamed without changes.

script/start-server-for-jest.mjs script/start-server-for-jest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import setupJestPuppeteer from 'jest-environment-puppeteer/setup.js'
44

5-
import { main } from '../start-server.mjs'
5+
import { main } from '../start-server.js'
66

7-
import { PORT, START_JEST_SERVER, isServerHealthy, isPortRunning } from './server-for-jest.mjs'
7+
import { PORT, START_JEST_SERVER, isServerHealthy, isPortRunning } from './server-for-jest.js'
88

99
export default async () => {
1010
if (START_JEST_SERVER) {

server.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { main } from './start-server.js'
2+
3+
main()

server.mjs

-3
This file was deleted.

start-server.mjs start-server.js

File renamed without changes.

tests/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ since the server won't need to start and stop every time you run tests.
8989
In one terminal type:
9090

9191
```sh
92-
NODE_ENV=test PORT=4000 node server.mjs
92+
NODE_ENV=test PORT=4000 node server.js
9393
```
9494

9595
and then, in another terminal type:

tests/package.json

-1
This file was deleted.

tests/rendering/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ describe('static routes', () => {
10291029
it('does not serve repo contents that live outside the /assets directory', async () => {
10301030
expect((await get('/package.json', { followRedirects: true })).statusCode).toBe(404)
10311031
expect((await get('/README.md', { followRedirects: true })).statusCode).toBe(404)
1032-
expect((await get('/server.mjs', { followRedirects: true })).statusCode).toBe(404)
1032+
expect((await get('/server.js', { followRedirects: true })).statusCode).toBe(404)
10331033
})
10341034
})
10351035

0 commit comments

Comments
 (0)