Skip to content

Commit 7d23697

Browse files
committed
Merge branch 'main' into typeRefUpdates
2 parents 128fff1 + 2a8436c commit 7d23697

File tree

6,472 files changed

+419352
-250889
lines changed

Some content is hidden

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

6,472 files changed

+419352
-250889
lines changed

.eslintrc.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"es6": true
1212
},
1313
"plugins": [
14-
"@typescript-eslint", "no-null", "import", "eslint-plugin-local"
14+
"@typescript-eslint", "no-null", "import", "eslint-plugin-local", "simple-import-sort"
1515
],
1616
"ignorePatterns": [
1717
"**/node_modules/**",
@@ -25,11 +25,8 @@
2525
"/coverage/**"
2626
],
2727
"rules": {
28-
"sort-imports": ["error", {
29-
"ignoreCase": true,
30-
"ignoreDeclarationSort": true,
31-
"allowSeparatedGroups": true
32-
}],
28+
"simple-import-sort/imports": "error",
29+
"simple-import-sort/exports": "error",
3330

3431
"@typescript-eslint/adjacent-overload-signatures": "error",
3532
"@typescript-eslint/array-type": "error",
@@ -180,6 +177,14 @@
180177
{ "name": "exports" }
181178
]
182179
}
180+
},
181+
{
182+
// These files contain imports in a specific order that are generally unsafe to modify.
183+
"files": ["**/_namespaces/**"],
184+
"rules": {
185+
"simple-import-sort/imports": "off",
186+
"simple-import-sort/exports": "off"
187+
}
183188
}
184189
]
185190
}

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.js linguist-language=TypeScript
2+
**/*.json linguist-language=jsonc
23
* -text

.github/codeql/codeql-configuration.yml

+1-27
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@ name : CodeQL Configuration
33
paths:
44
- src
55
- scripts
6-
- Gulpfile.mjs
6+
- Herebyfile.mjs
77
paths-ignore:
88
- src/lib
9-
10-
# These queries appear to time out after the module conversion.
11-
# https://github.com/github/codeql/issues/10937
12-
query-filters:
13-
- exclude:
14-
id: js/path-injection # TaintedPath.ql
15-
- exclude:
16-
id: js/command-line-injection # CommandInjection.ql
17-
- exclude:
18-
id: js/code-injection # CodeInjection.ql
19-
- exclude:
20-
id: js/bad-code-sanitization # ImproperCodeSanitization.ql
21-
- exclude:
22-
id: js/unsafe-dynamic-method-access # UnsafeDynamicMethodAccess.ql
23-
- exclude:
24-
id: js/clear-text-logging # CleartextLogging.ql
25-
- exclude:
26-
id: js/regex-injection # RegExpInjection.ql
27-
- exclude:
28-
id: js/unvalidated-dynamic-method-call # UnvalidatedDynamicMethodCall.ql
29-
- exclude:
30-
id: js/insecure-download # InsecureDownload.ql
31-
- exclude:
32-
id: js/prototype-polluting-assignment # PrototypePollutingAssignment.ql
33-
- exclude:
34-
id: js/request-forgery # RequestForgery.ql

.github/fabricbot.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"name": "addReply",
3333
"parameters": {
34-
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, and @minestarks for you. Feel free to loop in other consumers/maintainers if necessary"
34+
"comment": "Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary"
3535
}
3636
}
3737
],
@@ -487,7 +487,7 @@
487487
{
488488
"name": "addReply",
489489
"parameters": {
490-
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat and @minestarks so they are aware of the changes."
490+
"comment": "Thanks for the PR! It looks like you've changed 'preProcess.ts' in some way. Please ensure that any changes here don't break consumers with unique project systems such as Visual Studio. Pinging @sheetalkamat, @zkat, and @joj so they are aware of the changes."
491491
}
492492
}
493493
]

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
# Test the latest version of Node.js plus the last two LTS versions.
2019
node-version:
21-
- "*"
22-
- lts/*
23-
- lts/-1
20+
- "19"
21+
- "18"
22+
- "16"
23+
- "14"
2424
bundle:
2525
- "true"
2626
include:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ tests/cases/user/puppeteer/puppeteer
8484
tests/cases/user/axios-src/axios-src
8585
tests/cases/user/prettier/prettier
8686
.eslintcache
87+
*v8.log

.vscode/settings.template.json

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
// ".git-blame-ignore-revs"
1414
// ]
1515

16+
// Match eslint-plugin-simple-import-sort in organize/auto-imports.
17+
"typescript.unstable": {
18+
"organizeImportsCollation": "unicode",
19+
"organizeImportsCaseFirst": "upper",
20+
"organizeImportsIgnoreCase": false,
21+
"organizeImportsNumericCollation": true
22+
},
23+
1624
// These options search the repo recursively and slow down
1725
// the build task menu. We define our own in tasks.json.
1826
"typescript.tsc.autoDetect": "off",

.vscode/tasks.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// https://github.com/microsoft/vscode/issues/93001
1515
"label": "gulp: tests",
1616
"type": "npm",
17-
"script": "build:tests -- --no-typecheck",
17+
"script": "build:tests:notypecheck",
1818
"group": "build",
1919
"hide": true,
2020
"problemMatcher": [
@@ -44,7 +44,7 @@
4444
{
4545
"label": "npm: build:tests",
4646
"type": "npm",
47-
"script": "build:tests -- --no-typecheck",
47+
"script": "build:tests:notypecheck",
4848
"group": "build",
4949
"problemMatcher": [
5050
"$tsc"

Herebyfile.mjs

+78-82
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
// @ts-check
2-
import path from "path";
3-
import fs from "fs";
2+
import { CancelToken } from "@esfx/canceltoken";
3+
import chalk from "chalk";
4+
import chokidar from "chokidar";
45
import del from "del";
5-
import { task } from "hereby";
6+
import esbuild from "esbuild";
7+
import { EventEmitter } from "events";
8+
import fs from "fs";
9+
import fsExtra from "fs-extra";
610
import _glob from "glob";
11+
import { task } from "hereby";
12+
import path from "path";
713
import util from "util";
8-
import chalk from "chalk";
9-
import { Debouncer, Deferred, exec, getDiffTool, getDirSize, memoize, needsUpdate, readJson } from "./scripts/build/utils.mjs";
10-
import { localBaseline, localRwcBaseline, refBaseline, refRwcBaseline, runConsoleTests } from "./scripts/build/tests.mjs";
11-
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";
14+
1215
import { localizationDirectories } from "./scripts/build/localization.mjs";
1316
import cmdLineOptions from "./scripts/build/options.mjs";
14-
import esbuild from "esbuild";
15-
import chokidar from "chokidar";
16-
import { EventEmitter } from "events";
17-
import { CancelToken } from "@esfx/canceltoken";
17+
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";
18+
import { localBaseline, localRwcBaseline, refBaseline, refRwcBaseline, runConsoleTests } from "./scripts/build/tests.mjs";
19+
import { Debouncer, Deferred, exec, getDiffTool, getDirSize, memoize, needsUpdate, readJson } from "./scripts/build/utils.mjs";
1820

1921
const glob = util.promisify(_glob);
2022

@@ -58,10 +60,7 @@ export const generateLibs = task({
5860

5961
for (const source of lib.sources) {
6062
const contents = await fs.promises.readFile(source, "utf-8");
61-
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
62-
// are sensitive to the positions of things in the lib files. Eventually remove this,
63-
// or remove lib.d.ts line numbers from our baselines.
64-
output += "\n\n" + contents.replace(/\r\n/g, "\n");
63+
output += "\n" + contents.replace(/\r\n/g, "\n");
6564
}
6665

6766
await fs.promises.writeFile(lib.target, output);
@@ -160,10 +159,9 @@ async function runDtsBundler(entrypoint, output) {
160159
* @param {BundlerTaskOptions} [taskOptions]
161160
*
162161
* @typedef BundlerTaskOptions
163-
* @property {string[]} [external]
164162
* @property {boolean} [exportIsTsObject]
165163
* @property {boolean} [treeShaking]
166-
* @property {esbuild.WatchMode} [watchMode]
164+
* @property {() => void} [onWatchRebuild]
167165
*/
168166
function createBundler(entrypoint, outfile, taskOptions = {}) {
169167
const getOptions = memoize(async () => {
@@ -179,53 +177,9 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
179177
sourcemap: "linked",
180178
sourcesContent: false,
181179
treeShaking: taskOptions.treeShaking,
182-
external: [
183-
...(taskOptions.external ?? []),
184-
"source-map-support",
185-
],
180+
packages: "external",
186181
logLevel: "warning",
187182
// legalComments: "none", // If we add copyright headers to the source files, uncomment.
188-
plugins: [
189-
{
190-
name: "no-node-modules",
191-
setup: (build) => {
192-
build.onLoad({ filter: /[\\/]node_modules[\\/]/ }, () => {
193-
// Ideally, we'd use "--external:./node_modules/*" here, but that doesn't work; we
194-
// will instead end up with paths to node_modules rather than the package names.
195-
// Instead, we'll return a load error when we see that we're trying to bundle from
196-
// node_modules, then explicitly declare which external dependencies we rely on, which
197-
// ensures that the correct module specifier is kept in the output (the non-wildcard
198-
// form works properly). It also helps us keep tabs on what external dependencies we
199-
// may be importing, which is handy.
200-
//
201-
// See: https://github.com/evanw/esbuild/issues/1958
202-
return {
203-
errors: [{ text: 'Attempted to bundle from node_modules; ensure "external" is set correctly.' }]
204-
};
205-
});
206-
}
207-
},
208-
{
209-
name: "fix-require",
210-
setup: (build) => {
211-
build.onEnd(async () => {
212-
// esbuild converts calls to "require" to "__require"; this function
213-
// calls the real require if it exists, or throws if it does not (rather than
214-
// throwing an error like "require not defined"). But, since we want typescript
215-
// to be consumable by other bundlers, we need to convert these calls back to
216-
// require so our imports are visible again.
217-
//
218-
// The leading spaces are to keep the offsets the same within the files to keep
219-
// source maps working (though this only really matters for the line the require is on).
220-
//
221-
// See: https://github.com/evanw/esbuild/issues/1905
222-
let contents = await fs.promises.readFile(outfile, "utf-8");
223-
contents = contents.replace(/__require\(/g, " require(");
224-
await fs.promises.writeFile(outfile, contents);
225-
});
226-
},
227-
}
228-
]
229183
};
230184

231185
if (taskOptions.exportIsTsObject) {
@@ -235,14 +189,61 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
235189
options.globalName = "ts";
236190
// If we are in a CJS context, export the ts namespace.
237191
options.footer = { js: `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }` };
192+
193+
// esbuild converts calls to "require" to "__require"; this function
194+
// calls the real require if it exists, or throws if it does not (rather than
195+
// throwing an error like "require not defined"). But, since we want typescript
196+
// to be consumable by other bundlers, we need to convert these calls back to
197+
// require so our imports are visible again.
198+
//
199+
// The leading spaces are to keep the offsets the same within the files to keep
200+
// source maps working (though this only really matters for the line the require is on).
201+
//
202+
// See: https://github.com/evanw/esbuild/issues/1905
203+
options.define = { require: "$$require" };
204+
options.plugins = [
205+
{
206+
name: "fix-require",
207+
setup: (build) => {
208+
build.onEnd(async () => {
209+
let contents = await fs.promises.readFile(outfile, "utf-8");
210+
contents = contents.replace(/\$\$require/g, " require");
211+
await fs.promises.writeFile(outfile, contents);
212+
});
213+
},
214+
}
215+
];
238216
}
239217

240218
return options;
241219
});
242220

243221
return {
244222
build: async () => esbuild.build(await getOptions()),
245-
watch: async () => esbuild.build({ ...await getOptions(), watch: taskOptions.watchMode ?? true, logLevel: "info" }),
223+
watch: async () => {
224+
/** @type {esbuild.BuildOptions} */
225+
const options = { ...await getOptions(), logLevel: "info" };
226+
if (taskOptions.onWatchRebuild) {
227+
const onRebuild = taskOptions.onWatchRebuild;
228+
options.plugins = (options.plugins?.slice(0) ?? []).concat([{
229+
name: "watch",
230+
setup: (build) => {
231+
let firstBuild = true;
232+
build.onEnd(() => {
233+
if (firstBuild) {
234+
firstBuild = false;
235+
}
236+
else {
237+
onRebuild();
238+
}
239+
});
240+
}
241+
}]);
242+
}
243+
244+
const ctx = await esbuild.context(options);
245+
ctx.watch();
246+
},
246247
};
247248
}
248249

@@ -448,18 +449,8 @@ const { main: tests, watch: watchTests } = entrypointBuildTask({
448449
bundlerOptions: {
449450
// Ensure we never drop any dead code, which might be helpful while debugging.
450451
treeShaking: false,
451-
// These are directly imported via import statements and should not be bundled.
452-
external: [
453-
"chai",
454-
"del",
455-
"diff",
456-
"mocha",
457-
"ms",
458-
],
459-
watchMode: {
460-
onRebuild() {
461-
watchTestsEmitter.emit("rebuild");
462-
}
452+
onWatchRebuild() {
453+
watchTestsEmitter.emit("rebuild");
463454
}
464455
},
465456
});
@@ -524,6 +515,7 @@ const { main: watchGuard, watch: watchWatchGuard } = entrypointBuildTask({
524515
export const generateTypesMap = task({
525516
name: "generate-types-map",
526517
run: async () => {
518+
await fs.promises.mkdir("./built/local", { recursive: true });
527519
const source = "src/server/typesMap.json";
528520
const target = "built/local/typesMap.json";
529521
const contents = await fs.promises.readFile(source, "utf-8");
@@ -849,13 +841,6 @@ export const lkg = task({
849841
dependencies: [produceLKG],
850842
});
851843

852-
export const generateSpec = task({
853-
name: "generate-spec",
854-
description: "Generates a Markdown version of the Language Specification",
855-
hiddenFromTaskList: true,
856-
run: () => exec("cscript", ["//nologo", "scripts/word2md.mjs", path.resolve("doc/TypeScript Language Specification - ARCHIVED.docx"), path.resolve("doc/spec-ARCHIVED.md")]),
857-
});
858-
859844
export const cleanBuilt = task({
860845
name: "clean-built",
861846
hiddenFromTaskList: true,
@@ -892,3 +877,14 @@ export const help = task({
892877
hiddenFromTaskList: true,
893878
run: () => exec("hereby", ["--tasks"], { hidePrompt: true }),
894879
});
880+
881+
export const bumpLkgToNightly = task({
882+
name: "bump-lkg-to-nightly",
883+
description: "Bumps typescript in package.json to the latest nightly and copies it to LKG.",
884+
run: async () => {
885+
await exec("npm", ["install", "--save-dev", "--save-exact", "typescript@next"]);
886+
await fs.promises.rm("lib", { recursive: true, force: true });
887+
await fsExtra.copy("node_modules/typescript/lib", "lib");
888+
await fs.promises.writeFile("lib/.gitattributes", "* text eol=lf");
889+
}
890+
});

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ There are many ways to [contribute](https://github.com/microsoft/TypeScript/blob
3333
* Help each other in the [TypeScript Community Discord](https://discord.gg/typescript).
3434
* Join the [#typescript](https://twitter.com/search?q=%23TypeScript) discussion on Twitter.
3535
* [Contribute bug fixes](https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md).
36-
* Read the archived language specification ([docx](https://github.com/microsoft/TypeScript/blob/main/doc/TypeScript%20Language%20Specification%20-%20ARCHIVED.docx?raw=true),
37-
[pdf](https://github.com/microsoft/TypeScript/blob/main/doc/TypeScript%20Language%20Specification%20-%20ARCHIVED.pdf?raw=true), [md](https://github.com/microsoft/TypeScript/blob/main/doc/spec-ARCHIVED.md)).
3836

3937
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see
4038
the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)

0 commit comments

Comments
 (0)