Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh committed Mar 19, 2024
2 parents 39e42e4 + cc460dc commit 87cf4ad
Show file tree
Hide file tree
Showing 2,422 changed files with 50,696 additions and 46,561 deletions.
6 changes: 0 additions & 6 deletions .github/workflow-resources/.lsifrc.json

This file was deleted.

23 changes: 18 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ defaults:

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-14
node-version:
- '20'
- '18'
Expand All @@ -35,9 +37,15 @@ jobs:
- 'true'
include:
- node-version: '*'
bundle: 'false'
bundle: false
os: ubuntu-latest
exclude:
# No Node 14 on ARM macOS
- node-version: '14'
os: macos-14

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

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -49,9 +57,14 @@ jobs:
- run: npm ci

- name: Tests
id: test
# run tests, but lint separately
run: npm run test -- --no-lint --bundle=${{ matrix.bundle }}

- name: Print baseline diff on failure
if: ${{ failure() && steps.test.conclusion == 'failure' }}
run: git diff --diff-filter=AM --no-index -- ./tests/baselines/reference ./tests/baselines/local

lint:
runs-on: ubuntu-latest

Expand All @@ -77,7 +90,7 @@ jobs:
check-latest: true
- run: npm ci

- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
- uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
with:
path: ~/.cache/dprint
key: ${{ runner.os }}-dprint-${{ hashFiles('package-lock.json', '.dprint.jsonc') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

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

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

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
uses: github/codeql-action/analyze@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
47 changes: 47 additions & 0 deletions .github/workflows/lkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Update LKG

on:
workflow_dispatch:
inputs:
branch_name:
description: Release branch name to LKG
required: true
type: string

permissions:
contents: read

# Ensure scripts are run with pipefail. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
defaults:
run:
shell: bash

jobs:
build:
runs-on: ubuntu-latest
steps:
- run: |
if [[ ! "${{ inputs.branch_name }}" =~ ^release- ]]; then
echo "Branch name must start with 'release-'"
exit 1
fi
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ inputs.branch_name }}
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
- run: |
npm --version
# corepack enable npm
npm install -g $(jq -r '.packageManager' < package.json)
npm --version
- run: |
npm ci
npx hereby LKG
git add --force ./lib
git config user.email "typescriptbot@microsoft.com"
git config user.name "TypeScript Bot"
git commit -m 'Update LKG'
git push
40 changes: 0 additions & 40 deletions .github/workflows/rich-navigation.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: 'Upload to code-scanning'
uses: github/codeql-action/upload-sarif@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
uses: github/codeql-action/upload-sarif@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
with:
sarif_file: results.sarif
60 changes: 46 additions & 14 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
CancelToken,
} from "@esfx/canceltoken";
import assert from "assert";
import chalk from "chalk";
import chokidar from "chokidar";
import esbuild from "esbuild";
Expand Down Expand Up @@ -46,7 +47,7 @@ import {
void 0;

const copyrightFilename = "./scripts/CopyrightNotice.txt";
const copyright = memoize(async () => {
const getCopyrightHeader = memoize(async () => {
const contents = await fs.promises.readFile(copyrightFilename, "utf-8");
return contents.replace(/\r\n/g, "\n");
});
Expand Down Expand Up @@ -76,7 +77,7 @@ export const generateLibs = task({
run: async () => {
await fs.promises.mkdir("./built/local", { recursive: true });
for (const lib of libs()) {
let output = await copyright();
let output = await getCopyrightHeader();

for (const source of lib.sources) {
const contents = await fs.promises.readFile(source, "utf-8");
Expand Down Expand Up @@ -183,14 +184,18 @@ async function runDtsBundler(entrypoint, output) {
* @typedef BundlerTaskOptions
* @property {boolean} [exportIsTsObject]
* @property {boolean} [treeShaking]
* @property {boolean} [usePublicAPI]
* @property {() => void} [onWatchRebuild]
*/
function createBundler(entrypoint, outfile, taskOptions = {}) {
const getOptions = memoize(async () => {
const copyright = await getCopyrightHeader();
const banner = taskOptions.exportIsTsObject ? "var ts = {}; ((module) => {" : "";

/** @type {esbuild.BuildOptions} */
const options = {
entryPoints: [entrypoint],
banner: { js: await copyright() },
banner: { js: copyright + banner },
bundle: true,
outfile,
platform: "node",
Expand All @@ -204,13 +209,24 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
// legalComments: "none", // If we add copyright headers to the source files, uncomment.
};

if (taskOptions.usePublicAPI) {
options.external = ["./typescript.js"];
options.plugins = options.plugins || [];
options.plugins.push({
name: "remap-typescript-to-require",
setup(build) {
build.onLoad({ filter: /src[\\/]typescript[\\/]typescript\.ts$/ }, () => {
return { contents: `export * from "./typescript.js"` };
});
},
});
}

if (taskOptions.exportIsTsObject) {
// We use an IIFE so we can inject the footer, and so that "ts" is global if not loaded as a module.
options.format = "iife";
// Name the variable ts, matching our old big bundle and so we can use the code below.
options.globalName = "ts";
// If we are in a CJS context, export the ts namespace.
options.footer = { js: `\nif (typeof module !== "undefined" && module.exports) { module.exports = ts; }` };
// Monaco bundles us as ESM by wrapping our code with something that defines module.exports
// but then does not use it, instead using the `ts` variable. Ensure that if we think we're CJS
// that we still set `ts` to the module.exports object.
options.footer = { js: `})(typeof module !== "undefined" && module.exports ? module : { exports: ts });\nif (typeof module !== "undefined" && module.exports) { ts = module.exports; }` };

// esbuild converts calls to "require" to "__require"; this function
// calls the real require if it exists, or throws if it does not (rather than
Expand All @@ -227,18 +243,31 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
const fakeName = "Q".repeat(require.length);
const fakeNameRegExp = new RegExp(fakeName, "g");
options.define = { [require]: fakeName };
options.plugins = [

// For historical reasons, TypeScript does not set __esModule. Hack esbuild's __toCommonJS to be a noop.
// We reference `__copyProps` to ensure the final bundle doesn't have any unreferenced code.
const toCommonJsRegExp = /var __toCommonJS .*/;
const toCommonJsRegExpReplacement = "var __toCommonJS = (mod) => (__copyProps, mod); // Modified helper to skip setting __esModule.";

options.plugins = options.plugins || [];
options.plugins.push(
{
name: "fix-require",
name: "post-process",
setup: build => {
build.onEnd(async () => {
let contents = await fs.promises.readFile(outfile, "utf-8");
contents = contents.replace(fakeNameRegExp, require);
let matches = 0;
contents = contents.replace(toCommonJsRegExp, () => {
matches++;
return toCommonJsRegExpReplacement;
});
assert(matches === 1, "Expected exactly one match for __toCommonJS");
await fs.promises.writeFile(outfile, contents);
});
},
},
];
);
}

return options;
Expand Down Expand Up @@ -408,7 +437,8 @@ const { main: tsserver, watch: watchTsserver } = entrypointBuildTask({
srcEntrypoint: "./src/tsserver/server.ts",
builtEntrypoint: "./built/local/tsserver/server.js",
output: "./built/local/tsserver.js",
mainDeps: [generateLibs],
mainDeps: [generateLibs, services],
bundlerOptions: { usePublicAPI: true },
});
export { tsserver, watchTsserver };

Expand Down Expand Up @@ -450,7 +480,7 @@ export = ts;
* @param {string} contents
*/
async function fileContentsWithCopyright(contents) {
return await copyright() + contents.trim().replace(/\r\n/g, "\n") + "\n";
return await getCopyrightHeader() + contents.trim().replace(/\r\n/g, "\n") + "\n";
}

const lssl = task({
Expand Down Expand Up @@ -558,6 +588,8 @@ const { main: typingsInstaller, watch: watchTypingsInstaller } = entrypointBuild
srcEntrypoint: "./src/typingsInstaller/nodeTypingsInstaller.ts",
builtEntrypoint: "./built/local/typingsInstaller/nodeTypingsInstaller.js",
output: "./built/local/typingsInstaller.js",
mainDeps: [services],
bundlerOptions: { usePublicAPI: true },
});

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

0 comments on commit 87cf4ad

Please sign in to comment.