Skip to content

Commit

Permalink
Remove lib folder (LKG) and use node_modules for building (#52226)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Mar 7, 2023
1 parent 2f229ab commit 3f4d16a
Show file tree
Hide file tree
Showing 105 changed files with 51 additions and 763,515 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ jobs:
with:
node-version: "*"
check-latest: true

# Pre-build the base branch so we can check lib folder size changes.
# Note that github.sha points to a merge commit, meaning we're testing
# the base branch versus the base branch with the PR applied.
- if: github.event_name == 'pull_request'
run: |
if [ ! -d lib ]; then
git fetch origin ${{ github.base_ref }}
git checkout ${{ github.base_ref }}
npm ci
npx hereby lkg
mkdir /tmp/lkg
mv lib /tmp/lkg/
git restore lib
git clean -fdx lib
git checkout ${{ github.sha }}
rm -rf lib
mv /tmp/lkg/lib .
fi
- run: npm ci

- run: npx hereby lkg
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ TEST-results.xml
package-lock.json
.eslintcache
*v8.log
lib/
3 changes: 0 additions & 3 deletions .vscode/settings.template.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Rename this file 'settings.json' or merge its
// contents into your existing settings.
{
// To use the last-known-good (LKG) compiler version:
// "typescript.tsdk": "lib"

// To use the locally built compiler, after 'npm run build':
// "typescript.tsdk": "built/local"

Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"label": "tsc: watch ./src",
"type": "shell",
"command": "node",
"args": ["${workspaceFolder}/lib/tsc.js", "--build", "${workspaceFolder}/src", "--watch"],
"args": ["${workspaceFolder}/node_modules/tsc.js", "--build", "${workspaceFolder}/src", "--watch"],
"group": "build",
"isBackground": true,
"problemMatcher": [
Expand Down
28 changes: 12 additions & 16 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import del from "del";
import esbuild from "esbuild";
import { EventEmitter } from "events";
import fs from "fs";
import fsExtra from "fs-extra";
import _glob from "glob";
import { task } from "hereby";
import path from "path";
Expand Down Expand Up @@ -833,11 +832,19 @@ export const produceLKG = task({
if (missingFiles.length > 0) {
throw new Error("Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n" + missingFiles.join("\n"));
}
const sizeBefore = getDirSize("lib");

/** @type {number | undefined} */
let sizeBefore;
if (fs.existsSync("lib")) {
sizeBefore = getDirSize("lib");
}
await exec(process.execPath, ["scripts/produceLKG.mjs"]);
const sizeAfter = getDirSize("lib");
if (sizeAfter > (sizeBefore * 1.10)) {
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");

if (sizeBefore !== undefined) {
const sizeAfter = getDirSize("lib");
if (sizeAfter > (sizeBefore * 1.10)) {
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
}
}
}
});
Expand Down Expand Up @@ -884,14 +891,3 @@ export const help = task({
hiddenFromTaskList: true,
run: () => exec("hereby", ["--tasks"], { hidePrompt: true }),
});

export const bumpLkgToNightly = task({
name: "bump-lkg-to-nightly",
description: "Bumps typescript in package.json to the latest nightly and copies it to LKG.",
run: async () => {
await exec("npm", ["install", "--save-dev", "--save-exact", "typescript@next"]);
await fs.promises.rm("lib", { recursive: true, force: true });
await fsExtra.copy("node_modules/typescript/lib", "lib");
await fs.promises.writeFile("lib/.gitattributes", "* text eol=lf");
}
});
1 change: 0 additions & 1 deletion lib/.gitattributes

This file was deleted.

5 changes: 0 additions & 5 deletions lib/README.md

This file was deleted.

91 changes: 0 additions & 91 deletions lib/cancellationToken.js

This file was deleted.

Loading

2 comments on commit 3f4d16a

@meszaros-lajos-gyorgy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any alternatives for this? I was using this url to quickly load a typescript compiler in the browser: https://rawgit.com/microsoft/TypeScript/main/lib/typescript.js

@RyanCavanaugh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpkg should work just as well

Please sign in to comment.