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

Make TypeScript itself ESM-only, made possible by require(ESM) #58419

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 57 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@ jobs:
- windows-latest
- macos-14
node-version:
- '22'
- '20'
- '18'
- '16'
- '14'
- 23-nightly
bundle:
- 'true'
include:
- node-version: '*'
- node-version: 23-nightly
bundle: false
os: ubuntu-latest
exclude:
# No Node 14 on ARM macOS
- node-version: '14'
os: macos-14

runs-on: ${{ matrix.os }}
name: Test Node ${{ matrix.node-version }} on ${{ matrix.os }}${{ (!matrix.bundle && ' with --no-bundle') || '' }}
Expand All @@ -55,19 +47,29 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
check-latest: true

- run: |
echo "value=--no-warnings=ExperimentalWarning --experimental-require-module" >> "$GITHUB_OUTPUT"
name: Enable require(ESM)
id: node-options

- run: npm ci

- name: Tests
id: test
# run tests, but lint separately
run: npm run test -- --no-lint --bundle=${{ matrix.bundle }}
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Print baseline diff on failure
if: ${{ failure() && steps.test.conclusion == 'failure' }}
run: |
npx hereby baseline-accept
git add tests/baselines/reference
git diff --staged --exit-code
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

lint:
runs-on: ubuntu-latest
Expand All @@ -76,7 +78,7 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true
- run: npm ci

Expand All @@ -90,7 +92,7 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true
- run: npm ci

Expand All @@ -111,7 +113,7 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true
- run: npm ci

Expand All @@ -128,7 +130,7 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true
- run: npm ci

Expand All @@ -143,8 +145,14 @@ jobs:

- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true

- run: |
echo "value=--no-warnings=ExperimentalWarning --experimental-require-module" >> "$GITHUB_OUTPUT"
name: Enable require(ESM)
id: node-options

- run: |
npm --version
# corepack enable npm
Expand All @@ -154,12 +162,16 @@ jobs:
- run: npm ci

- run: npx hereby lkg
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}
- run: |
node ./scripts/addPackageJsonGitHead.mjs package.json
npm pack
mv typescript*.tgz typescript.tgz
echo "package=$PWD/typescript.tgz" >> "$GITHUB_OUTPUT"
id: pack
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Smoke test
run: |
Expand All @@ -175,6 +187,8 @@ jobs:

node $GITHUB_WORKSPACE/scripts/checkModuleFormat.mjs typescript
node $GITHUB_WORKSPACE/scripts/checkModuleFormat.mjs typescript/lib/tsserverlibrary
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

package-size:
runs-on: ubuntu-latest
Expand All @@ -192,7 +206,7 @@ jobs:

- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: '23-nightly'
check-latest: true
- run: |
npm --version
Expand Down Expand Up @@ -226,7 +240,7 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: 23-nightly
check-latest: true
- run: npm ci

Expand All @@ -243,18 +257,30 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: 23-nightly
check-latest: true

- run: |
echo "value=--no-warnings=ExperimentalWarning --experimental-require-module" >> "$GITHUB_OUTPUT"
name: Enable require(ESM)
id: node-options

- run: npm ci

- name: Build tsc
run: npx hereby tsc
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Clean
run: npx hereby clean-src
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Self build
run: npx hereby build-src --built
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

baselines:
runs-on: ubuntu-latest
Expand All @@ -263,20 +289,30 @@ jobs:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '*'
node-version: 23-nightly
check-latest: true

- run: |
echo "value=--no-warnings=ExperimentalWarning --experimental-require-module" >> "$GITHUB_OUTPUT"
name: Enable require(ESM)
id: node-options

- run: npm ci

- name: Remove all baselines
run: rm -rf tests/baselines/reference

- name: Run tests
run: npm test &> /dev/null || exit 0
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Accept baselines
run: |
npx hereby baseline-accept
git add tests/baselines/reference
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Check baselines
id: check-baselines
Expand All @@ -295,6 +331,8 @@ jobs:
git diff --staged > fix_baselines.patch
exit 1
fi
env:
NODE_OPTIONS: ${{ steps.node-options.outputs.value }}

- name: Upload baseline diff artifact
if: ${{ failure() && steps.check-baselines.conclusion == 'failure' }}
Expand Down
8 changes: 6 additions & 2 deletions .gulp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const cp = require("child_process");
const path = require("path");
import cp from "child_process";
import path from "path";
import url from "url";

const __filename = url.fileURLToPath(new URL(import.meta.url));
const __dirname = path.dirname(__filename);

const argv = process.argv.slice(2);

Expand Down