Skip to content

Commit

Permalink
Next12 now supports ESM (github#29295)
Browse files Browse the repository at this point in the history
* Next12 now supports ESM

* No more michael jackson script extensions

* Fix test running

* Update jest-puppeteer.config.cjs

* Update package.json
  • Loading branch information
heiskr authored Jul 26, 2022
1 parent d1ea358 commit 2182ff2
Show file tree
Hide file tree
Showing 31 changed files with 38 additions and 46 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion .github/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check-all-english-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
# Don't care about CDN caching image URLs
DISABLE_REWRITE_ASSET_URLS: true
run: |
node server.mjs > /tmp/stdout.log 2> /tmp/stderr.log &
node server.js > /tmp/stdout.log 2> /tmp/stderr.log &
sleep 6
curl --retry-connrefused --retry 5 -I http://localhost:4000/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-broken-links-github-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
DISABLE_RENDERING_CACHE: true
run: |
node server.mjs &
node server.js &
sleep 5
curl --retry-connrefused --retry 3 -I http://localhost:4000/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
- '**.yaml'
- '**.yml'
- '**.scss'
- .eslintrc.js
- .eslintrc.cjs
# In case something like eslint or tsc or prettier upgrades
- 'package-lock.json'
# Ultimately, for debugging this workflow itself
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dry-run-elasticsearch-indexing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- gh-readonly-queue/main/**
pull_request:
paths:
- script/search/index-elasticsearch.mjs
- script/search/index-elasticsearch.js
- 'package*.json'
- .github/workflows/dry-run-elasticsearch-indexing.yml

Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
env:
ELASTICSEARCH_URL: 'http://localhost:9200'
run: |
./script/search/index-elasticsearch.mjs --verbose \
./script/search/index-elasticsearch.js --verbose \
-l en -l ja \
-V dotcom -V ghes-3.5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/link-check-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
# Don't care about CDN caching image URLs
DISABLE_REWRITE_ASSET_URLS: true
run: |
./script/rendered-content-link-checker.mjs \
./script/rendered-content-link-checker.js \
--language en \
--max 100 \
--check-anchors \
Expand All @@ -66,7 +66,7 @@ jobs:
# Don't care about CDN caching image URLs
DISABLE_REWRITE_ASSET_URLS: true
run: |
./script/rendered-content-link-checker.mjs \
./script/rendered-content-link-checker.js \
--language en \
--exit \
--verbose \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/orphaned-assets-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
set -e
./script/find-orphaned-assets.mjs | xargs git rm
./script/find-orphaned-assets.js | xargs git rm
# If nothing to commit, exit now. It's fine. No orphans.
git status | grep 'nothing to commit' && exit 0
Expand All @@ -58,6 +58,6 @@ jobs:
gh pr create \
--title "Delete orphaned assets ($date)" \
--body "Found with the find-orphaned-assets.mjs script" \
--body "Found with the find-orphaned-assets.js script" \
--repo github/docs-internal \
--label docs-content-fr
2 changes: 1 addition & 1 deletion .github/workflows/sync-search-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Index into Elasticsearch
run: |
./script/search/index-elasticsearch.mjs \
./script/search/index-elasticsearch.js \
--language ${{ matrix.language }} \
--source-directory /tmp/records
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ENV NODE_ENV production
# Whether to hide iframes, add warnings to external links
ENV AIRGAP false

# Preferred port for server.mjs
# Preferred port for server.js
ENV PORT 4000

ENV ENABLED_LANGUAGES "en"
Expand All @@ -94,12 +94,12 @@ COPY --chown=node:node middleware ./middleware
COPY --chown=node:node feature-flags.json ./
COPY --chown=node:node data ./data
COPY --chown=node:node next.config.js ./
COPY --chown=node:node server.mjs ./server.mjs
COPY --chown=node:node start-server.mjs ./start-server.mjs
COPY --chown=node:node server.js ./server.js
COPY --chown=node:node start-server.js ./start-server.js

EXPOSE $PORT

CMD ["node", "server.mjs"]
CMD ["node", "server.js"]

# --------------------------------------------------------------------------------
# PRODUCTION IMAGE - includes all translations
Expand Down
1 change: 0 additions & 1 deletion data/package.json

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (testTranslation) {
reporters.push('jest-github-actions-reporter')
}

module.exports = {
export default {
coverageThreshold: {
global: {
branches: 95,
Expand Down Expand Up @@ -41,6 +41,6 @@ module.exports = {
],
testMatch: ['**/tests/**/*.js'],
testLocationInResults: isActions,
globalSetup: './script/start-server-for-jest.mjs',
globalTeardown: './script/kill-server-for-jest.mjs',
globalSetup: './script/start-server-for-jest.js',
globalTeardown: './script/kill-server-for-jest.js',
}
1 change: 0 additions & 1 deletion lib/package.json

This file was deleted.

1 change: 0 additions & 1 deletion middleware/package.json

This file was deleted.

11 changes: 4 additions & 7 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// import { productIds } from './lib/all-products.js'
// import languages from './lib/languages.js'

const fs = require('fs')
const frontmatter = require('gray-matter')
const path = require('path')
import fs from 'fs'
import frontmatter from 'gray-matter'
import path from 'path'
const homepage = path.posix.join(process.cwd(), 'content/index.md')
const { data } = frontmatter(fs.readFileSync(homepage, 'utf8'))
const productIds = data.children

module.exports = {
export default {
// speed up production `next build` by ignoring typechecking during that step of build.
// type-checking still occurs in the Dockerfile build
typescript: {
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"engines": {
"node": ">=16.x"
},
"exports": "./server.mjs",
"exports": "./server.js",
"license": "(MIT AND CC-BY-4.0)",
"name": "docs.github.com",
"optionalDependencies": {
Expand All @@ -183,9 +183,9 @@
"private": true,
"repository": "https://github.com/github/docs",
"scripts": {
"browser-test": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules jest tests/browser/browser.js",
"browser-test": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest tests/browser/browser.js",
"build": "next build",
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.mjs",
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.js",
"dev": "npm start",
"lint": "eslint '**/*.{js,mjs,ts,tsx}'",
"lint-translation": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_TRANSLATION=true jest tests/linting/lint-files.js",
Expand All @@ -195,14 +195,14 @@
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
"rest-dev": "script/rest/update-files.js && npm run dev",
"show-action-deps": "echo 'Action Dependencies:' && rg '^[\\s|-]*(uses:.*)$' .github -I -N --no-heading -r '$1$2' | sort | uniq | cut -c 7-",
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs",
"start-all-languages": "cross-env NODE_ENV=development nodemon server.mjs",
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.js",
"start-all-languages": "cross-env NODE_ENV=development nodemon server.js",
"sync-search": "cross-env NODE_OPTIONS='--max_old_space_size=8192' start-server-and-test sync-search-server 4002 sync-search-indices",
"sync-search-ghes-release": "cross-env GHES_RELEASE=1 start-server-and-test sync-search-server 4002 sync-search-indices",
"sync-search-indices": "script/search/sync-search-indices.js",
"sync-search-server": "cross-env NODE_ENV=production PORT=4002 CHANGELOG_DISABLED=true DISABLE_RENDERING_CACHE=true DISABLE_OVERLOAD_PROTECTION=true node server.mjs",
"sync-search-server": "cross-env NODE_ENV=production PORT=4002 CHANGELOG_DISABLED=true DISABLE_RENDERING_CACHE=true DISABLE_OVERLOAD_PROTECTION=true node server.js",
"translation-check": "start-server-and-test translation-check-server 4002 translation-check-test",
"translation-check-server": "cross-env NODE_ENV=test PORT=4002 node server.mjs",
"translation-check-server": "cross-env NODE_ENV=test PORT=4002 node server.js",
"translation-check-test": "script/i18n/test-html-pages.js",
"test": "cross-env NODE_OPTIONS='--max_old_space_size=4096 --experimental-vm-modules' jest --logHeapUsage",
"test-watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch --notify --notifyMode=change --coverage",
Expand All @@ -211,5 +211,6 @@
"lint-staged": {
"*.{js,mjs,ts,tsx}": "eslint --cache --fix",
"*.{js,mjs,scss,ts,tsx,yml,yaml}": "prettier --write"
}
},
"type": "module"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

export default async () => {
if (START_JEST_SERVER) {
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion script/package.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

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

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

export default async () => {
if (START_JEST_SERVER) {
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main } from './start-server.js'

main()
3 changes: 0 additions & 3 deletions server.mjs

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ since the server won't need to start and stop every time you run tests.
In one terminal type:

```sh
NODE_ENV=test PORT=4000 node server.mjs
NODE_ENV=test PORT=4000 node server.js
```

and then, in another terminal type:
Expand Down
1 change: 0 additions & 1 deletion tests/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion tests/rendering/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ describe('static routes', () => {
it('does not serve repo contents that live outside the /assets directory', async () => {
expect((await get('/package.json', { followRedirects: true })).statusCode).toBe(404)
expect((await get('/README.md', { followRedirects: true })).statusCode).toBe(404)
expect((await get('/server.mjs', { followRedirects: true })).statusCode).toBe(404)
expect((await get('/server.js', { followRedirects: true })).statusCode).toBe(404)
})
})

Expand Down

0 comments on commit 2182ff2

Please sign in to comment.