-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Creates a smaller build of TypeScript which just has the language services #33584
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3fe7aaf
Add a command for stripping the dependency down
orta 63feabb
Improve the gitignore / npm ignore
orta 31c08b6
More work on generating a small typescript build
orta 92b3266
Rename the smaller build to '@typescript/language-services' and have …
orta 392af2b
Merge branch 'master' of https://github.com/microsoft/TypeScript into…
orta 40ceb4f
Merge branch 'master' into small_ts
c64af5e
Remove the post-publish script
orta 4c4a683
Merge branch 'small_ts' of https://github.com/orta/TypeScript into sm…
orta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/// <reference types="node"/> | ||
import { normalize, dirname, join } from "path"; | ||
import { readFileSync, writeFileSync, unlinkSync, existsSync } from "fs"; | ||
import assert = require("assert"); | ||
import { execSync } from "child_process"; | ||
const args = process.argv.slice(2); | ||
|
||
/** | ||
* A minimal description for a parsed package.json object. | ||
*/ | ||
interface PackageJson { | ||
name: string; | ||
bin: {}; | ||
main: string; | ||
scripts: { | ||
prepare: string | ||
postpublish: string | ||
} | ||
} | ||
|
||
function main(): void { | ||
if (args.length < 1) { | ||
console.log("Usage:"); | ||
console.log("\tnode configureTSCBuild.js <package.json location>"); | ||
return; | ||
} | ||
|
||
// Acquire the version from the package.json file and modify it appropriately. | ||
const packageJsonFilePath = normalize(args[0]); | ||
const packageJsonValue: PackageJson = JSON.parse(readFileSync(packageJsonFilePath).toString()); | ||
|
||
// Remove the bin section from the current package | ||
delete packageJsonValue.bin; | ||
// We won't be running eslint which would run before publishing | ||
delete packageJsonValue.scripts.prepare; | ||
// No infinite loops | ||
delete packageJsonValue.scripts.postpublish; | ||
|
||
// Set the new name | ||
packageJsonValue.name = "@typescript/language-services"; | ||
|
||
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); | ||
|
||
// Remove the files which aren't use when just using the API | ||
const toRemove = [ | ||
// JS Files | ||
"tsserver.js", | ||
"tsserverlibrary.js", | ||
"typescriptServices.js", | ||
"typingsInstaller.js", | ||
"tsc.js", | ||
// DTS files | ||
"typescriptServices.d.ts", | ||
"tsserverlibrary.d.ts" | ||
]; | ||
|
||
// Get a link to the main dependency JS file | ||
const lib = join(dirname(packageJsonFilePath), packageJsonValue.main); | ||
const libPath = dirname(lib); | ||
|
||
// Remove the sibling JS large files referenced above | ||
toRemove.forEach(file => { | ||
const path = join(libPath, file); | ||
if (existsSync(path)) unlinkSync(path); | ||
}); | ||
|
||
// Remove VS-specific localization keys | ||
execSync("rm -rf loc", { cwd: dirname(packageJsonFilePath) }); | ||
|
||
// Remove runnable file reference | ||
execSync("rm -rf bin", { cwd: dirname(packageJsonFilePath) }); | ||
|
||
/////////////////////////////////// | ||
|
||
// This section verifies that the build of TypeScript compiles and emits | ||
|
||
const ts = require(lib); | ||
const source = "let x: string = 'string'"; | ||
|
||
const results = ts.transpileModule(source, { | ||
compilerOptions: { module: ts.ModuleKind.CommonJS } | ||
}); | ||
|
||
assert(results.outputText.trim() === "var x = 'string';", `Running typescript with ${packageJsonValue.name} did not return the expected results, got: ${results.outputText}`); | ||
} | ||
|
||
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// <reference types="node"/> | ||
import { join } from "path"; | ||
import { readFileSync, unlinkSync } from "fs"; | ||
import { tmpdir } from "os"; | ||
import { execSync, ExecSyncOptions } from "child_process"; | ||
import chalk from "chalk"; | ||
|
||
interface PackageJson { | ||
name: string; | ||
version: string | ||
} | ||
|
||
const exec = (cmd: string, opts?: ExecSyncOptions) => { | ||
console.log(chalk.gray(`> ${cmd} ${opts ? JSON.stringify(opts) : ""}`)); | ||
execSync(cmd, opts); | ||
}; | ||
|
||
const step = (msg: string) => { | ||
console.log("\n\n" + chalk.bold("- ") + msg); | ||
}; | ||
|
||
function main(): void { | ||
console.log(chalk.bold("## Creating the language services build of TypeScript")); | ||
process.stdout.write(chalk.grey("> node /scripts/createLanguageServiceBuild.ts")); | ||
|
||
// Create a tarball of the current version | ||
step("Packing the current TypeScript via npm."); | ||
exec("npm pack"); | ||
|
||
const packageJsonValue: PackageJson = JSON.parse(readFileSync("package.json", "utf8")); | ||
const tarballFileName = `${packageJsonValue.name}-${packageJsonValue.version}.tgz`; | ||
|
||
const unzipDir = tmpdir(); | ||
step(`Extracting the built version into a temporary folder. ${unzipDir}/package`); | ||
exec(`tar -xvzf ${tarballFileName} -C ${unzipDir}`); | ||
unlinkSync(tarballFileName); | ||
|
||
step(`Updating the build metadata`); | ||
const packagePath = join(unzipDir, "package"); | ||
exec(`node scripts/configureLanguageServiceBuild.js ${join(packagePath, "package.json")}`); | ||
|
||
step(`Deploying the language service`); | ||
exec("npm publish --access public", { cwd: packagePath }); | ||
} | ||
|
||
main(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any other scripts that auto-publish? I don’t know what our publish process is like, but I assume it runs in CI. I would lean toward adding automation there rather than scripted into
postpublish
, as principle of least surprise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOW, the code seems fine (but I’ve never looked at our packing process before either, so I’m not the best one to review), but I’m skeptical of the trigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it doesn't happen on CI (I am happy to move it to a new step in there) and/or look at moving to deploy on CI ( e.g microsoft/types-publisher#659 ) and all we do is ship a tag to indicate we want a release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh really? I figured we publish from here: https://dev.azure.com/typescript/TypeScript/_release?definitionId=1&view=mine&_a=releases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do! It definitely happens on CI! Anyone caught not publishing on CI will be [redacted]!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, we publish a prepared tarball directly, using
npm publish $(System.ArtifactsDirectory)/typescript.tgz --tag $(PUBLISH_TAG)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So a
postpublish
script is actually wholly nonfunctional, since we don't even publish in a clone of our repo 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! OK cool, perfect!
I'll that and add the extra step on CI 👯♂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool - updated the deployment docs, and removed the auto-publish. Will give this a few hours for last feedback and merge today. Then once that's in I'll add the step to the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is not executable in the release pipeline, as far as I'm aware. Releases are not executed within the context of the repo. (There's good reason for this, too, it means at no point does potentially malicious code get a chance to execute in a context where we have our publishing key set!) The code in the repo does not exist in the release pipeline. To publish a second package, you would need to publish a second pipeline artifact with the secondary tarball (which is just done with a few commands in the build pipeline, but I imagine you'll need to add a call to the
configure
script in addition to replicating those), and publish in a similar way as we do the first (with thenpm publish
release pipeline task).