Skip to content

Commit 87cf4ad

Browse files
committed
2 parents 39e42e4 + cc460dc commit 87cf4ad

File tree

2,422 files changed

+50696
-46561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,422 files changed

+50696
-46561
lines changed

.github/workflow-resources/.lsifrc.json

-6
This file was deleted.

.github/workflows/ci.yml

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ defaults:
2121

2222
jobs:
2323
test:
24-
runs-on: ubuntu-latest
25-
2624
strategy:
2725
fail-fast: false
2826
matrix:
27+
os:
28+
- ubuntu-latest
29+
- windows-latest
30+
- macos-14
2931
node-version:
3032
- '20'
3133
- '18'
@@ -35,9 +37,15 @@ jobs:
3537
- 'true'
3638
include:
3739
- node-version: '*'
38-
bundle: 'false'
40+
bundle: false
41+
os: ubuntu-latest
42+
exclude:
43+
# No Node 14 on ARM macOS
44+
- node-version: '14'
45+
os: macos-14
3946

40-
name: Test Node ${{ matrix.node-version }} with --bundle=${{ matrix.bundle }}
47+
runs-on: ${{ matrix.os }}
48+
name: Test Node ${{ matrix.node-version }} on ${{ matrix.os }}${{ (!matrix.bundle && ' with --no-bundle') || '' }}
4149

4250
steps:
4351
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -49,9 +57,14 @@ jobs:
4957
- run: npm ci
5058

5159
- name: Tests
60+
id: test
5261
# run tests, but lint separately
5362
run: npm run test -- --no-lint --bundle=${{ matrix.bundle }}
5463

64+
- name: Print baseline diff on failure
65+
if: ${{ failure() && steps.test.conclusion == 'failure' }}
66+
run: git diff --diff-filter=AM --no-index -- ./tests/baselines/reference ./tests/baselines/local
67+
5568
lint:
5669
runs-on: ubuntu-latest
5770

@@ -77,7 +90,7 @@ jobs:
7790
check-latest: true
7891
- run: npm ci
7992

80-
- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
93+
- uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
8194
with:
8295
path: ~/.cache/dprint
8396
key: ${{ runner.os }}-dprint-${{ hashFiles('package-lock.json', '.dprint.jsonc') }}

.github/workflows/codeql.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
49+
uses: github/codeql-action/init@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
5050
with:
5151
config-file: ./.github/codeql/codeql-configuration.yml
5252
# Override language selection by uncommenting this and choosing your languages
@@ -56,7 +56,7 @@ jobs:
5656
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5757
# If this step fails, then you should remove it and run the build manually (see below).
5858
- name: Autobuild
59-
uses: github/codeql-action/autobuild@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
59+
uses: github/codeql-action/autobuild@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
6060

6161
# ℹ️ Command-line programs to run using the OS shell.
6262
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -70,4 +70,4 @@ jobs:
7070
# make release
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
73+
uses: github/codeql-action/analyze@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6

.github/workflows/lkg.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Update LKG
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch_name:
7+
description: Release branch name to LKG
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
# Ensure scripts are run with pipefail. See:
15+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- run: |
25+
if [[ ! "${{ inputs.branch_name }}" =~ ^release- ]]; then
26+
echo "Branch name must start with 'release-'"
27+
exit 1
28+
fi
29+
30+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
31+
with:
32+
ref: ${{ inputs.branch_name }}
33+
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
34+
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
35+
- run: |
36+
npm --version
37+
# corepack enable npm
38+
npm install -g $(jq -r '.packageManager' < package.json)
39+
npm --version
40+
- run: |
41+
npm ci
42+
npx hereby LKG
43+
git add --force ./lib
44+
git config user.email "[email protected]"
45+
git config user.name "TypeScript Bot"
46+
git commit -m 'Update LKG'
47+
git push

.github/workflows/rich-navigation.yml

-40
This file was deleted.

.github/workflows/scorecard.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ jobs:
5555

5656
# Upload the results to GitHub's code scanning dashboard.
5757
- name: 'Upload to code-scanning'
58-
uses: github/codeql-action/upload-sarif@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
58+
uses: github/codeql-action/upload-sarif@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
5959
with:
6060
sarif_file: results.sarif

Herebyfile.mjs

+46-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {
33
CancelToken,
44
} from "@esfx/canceltoken";
5+
import assert from "assert";
56
import chalk from "chalk";
67
import chokidar from "chokidar";
78
import esbuild from "esbuild";
@@ -46,7 +47,7 @@ import {
4647
void 0;
4748

4849
const copyrightFilename = "./scripts/CopyrightNotice.txt";
49-
const copyright = memoize(async () => {
50+
const getCopyrightHeader = memoize(async () => {
5051
const contents = await fs.promises.readFile(copyrightFilename, "utf-8");
5152
return contents.replace(/\r\n/g, "\n");
5253
});
@@ -76,7 +77,7 @@ export const generateLibs = task({
7677
run: async () => {
7778
await fs.promises.mkdir("./built/local", { recursive: true });
7879
for (const lib of libs()) {
79-
let output = await copyright();
80+
let output = await getCopyrightHeader();
8081

8182
for (const source of lib.sources) {
8283
const contents = await fs.promises.readFile(source, "utf-8");
@@ -183,14 +184,18 @@ async function runDtsBundler(entrypoint, output) {
183184
* @typedef BundlerTaskOptions
184185
* @property {boolean} [exportIsTsObject]
185186
* @property {boolean} [treeShaking]
187+
* @property {boolean} [usePublicAPI]
186188
* @property {() => void} [onWatchRebuild]
187189
*/
188190
function createBundler(entrypoint, outfile, taskOptions = {}) {
189191
const getOptions = memoize(async () => {
192+
const copyright = await getCopyrightHeader();
193+
const banner = taskOptions.exportIsTsObject ? "var ts = {}; ((module) => {" : "";
194+
190195
/** @type {esbuild.BuildOptions} */
191196
const options = {
192197
entryPoints: [entrypoint],
193-
banner: { js: await copyright() },
198+
banner: { js: copyright + banner },
194199
bundle: true,
195200
outfile,
196201
platform: "node",
@@ -204,13 +209,24 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
204209
// legalComments: "none", // If we add copyright headers to the source files, uncomment.
205210
};
206211

212+
if (taskOptions.usePublicAPI) {
213+
options.external = ["./typescript.js"];
214+
options.plugins = options.plugins || [];
215+
options.plugins.push({
216+
name: "remap-typescript-to-require",
217+
setup(build) {
218+
build.onLoad({ filter: /src[\\/]typescript[\\/]typescript\.ts$/ }, () => {
219+
return { contents: `export * from "./typescript.js"` };
220+
});
221+
},
222+
});
223+
}
224+
207225
if (taskOptions.exportIsTsObject) {
208-
// We use an IIFE so we can inject the footer, and so that "ts" is global if not loaded as a module.
209-
options.format = "iife";
210-
// Name the variable ts, matching our old big bundle and so we can use the code below.
211-
options.globalName = "ts";
212-
// If we are in a CJS context, export the ts namespace.
213-
options.footer = { js: `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }` };
226+
// Monaco bundles us as ESM by wrapping our code with something that defines module.exports
227+
// but then does not use it, instead using the `ts` variable. Ensure that if we think we're CJS
228+
// that we still set `ts` to the module.exports object.
229+
options.footer = { js: `})(typeof module !== "undefined" && module.exports ? module : { exports: ts });\nif (typeof module !== "undefined" && module.exports) { ts = module.exports; }` };
214230

215231
// esbuild converts calls to "require" to "__require"; this function
216232
// calls the real require if it exists, or throws if it does not (rather than
@@ -227,18 +243,31 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
227243
const fakeName = "Q".repeat(require.length);
228244
const fakeNameRegExp = new RegExp(fakeName, "g");
229245
options.define = { [require]: fakeName };
230-
options.plugins = [
246+
247+
// For historical reasons, TypeScript does not set __esModule. Hack esbuild's __toCommonJS to be a noop.
248+
// We reference `__copyProps` to ensure the final bundle doesn't have any unreferenced code.
249+
const toCommonJsRegExp = /var __toCommonJS .*/;
250+
const toCommonJsRegExpReplacement = "var __toCommonJS = (mod) => (__copyProps, mod); // Modified helper to skip setting __esModule.";
251+
252+
options.plugins = options.plugins || [];
253+
options.plugins.push(
231254
{
232-
name: "fix-require",
255+
name: "post-process",
233256
setup: build => {
234257
build.onEnd(async () => {
235258
let contents = await fs.promises.readFile(outfile, "utf-8");
236259
contents = contents.replace(fakeNameRegExp, require);
260+
let matches = 0;
261+
contents = contents.replace(toCommonJsRegExp, () => {
262+
matches++;
263+
return toCommonJsRegExpReplacement;
264+
});
265+
assert(matches === 1, "Expected exactly one match for __toCommonJS");
237266
await fs.promises.writeFile(outfile, contents);
238267
});
239268
},
240269
},
241-
];
270+
);
242271
}
243272

244273
return options;
@@ -408,7 +437,8 @@ const { main: tsserver, watch: watchTsserver } = entrypointBuildTask({
408437
srcEntrypoint: "./src/tsserver/server.ts",
409438
builtEntrypoint: "./built/local/tsserver/server.js",
410439
output: "./built/local/tsserver.js",
411-
mainDeps: [generateLibs],
440+
mainDeps: [generateLibs, services],
441+
bundlerOptions: { usePublicAPI: true },
412442
});
413443
export { tsserver, watchTsserver };
414444

@@ -450,7 +480,7 @@ export = ts;
450480
* @param {string} contents
451481
*/
452482
async function fileContentsWithCopyright(contents) {
453-
return await copyright() + contents.trim().replace(/\r\n/g, "\n") + "\n";
483+
return await getCopyrightHeader() + contents.trim().replace(/\r\n/g, "\n") + "\n";
454484
}
455485

456486
const lssl = task({
@@ -558,6 +588,8 @@ const { main: typingsInstaller, watch: watchTypingsInstaller } = entrypointBuild
558588
srcEntrypoint: "./src/typingsInstaller/nodeTypingsInstaller.ts",
559589
builtEntrypoint: "./built/local/typingsInstaller/nodeTypingsInstaller.js",
560590
output: "./built/local/typingsInstaller.js",
591+
mainDeps: [services],
592+
bundlerOptions: { usePublicAPI: true },
561593
});
562594

563595
const { main: watchGuard, watch: watchWatchGuard } = entrypointBuildTask({

0 commit comments

Comments
 (0)