From 3fe7aafb5bbb14da9ec20c7e5c01686e6f972eed Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 24 Sep 2019 13:11:08 -0400 Subject: [PATCH 1/5] Add a command for stripping the dependency down --- Gulpfile.js | 4 ++ package.json | 1 + scripts/configureTSCBuild.js | 57 +++++++++++++++++++++++++ scripts/configureTSCBuild.ts | 82 ++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 scripts/configureTSCBuild.js create mode 100644 scripts/configureTSCBuild.ts diff --git a/Gulpfile.js b/Gulpfile.js index 1f930e3b01967..7ed50e25beb56 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -588,6 +588,10 @@ const configureExperimental = () => exec(process.execPath, ["scripts/configurePr task("configure-experimental", series(buildScripts, configureExperimental)); task("configure-experimental").description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing"; +const configureTSCOnly = () => exec(process.execPath, ["scripts/configureTSCBuild.js", "package.json", "src/compiler/core.ts"]); +task("configure-tsc-only", series(buildScripts, configureNightly)); +task("configure-tsc-only").description = "Runs scripts/configureTSCOnly.ts to prepare a build for build which only has tsc "; + const publishNightly = () => exec("npm", ["publish", "--tag", "next"]); task("publish-nightly", series(task("clean"), task("LKG"), task("clean"), task("runtests-parallel"), publishNightly)); task("publish-nightly").description = "Runs `npm publish --tag next` to create a new nightly build on npm"; diff --git a/package.json b/package.json index 7a59b95a130f6..a61588734dba9 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "scripts": { "prepare": "gulp build-eslint-rules", "pretest": "gulp tests", + "postpublish": "gulp configure-tsc-only", "test": "gulp runtests-parallel --light=false", "test:eslint-rules": "gulp run-eslint-rules-tests", "build": "npm run build:compiler && npm run build:tests", diff --git a/scripts/configureTSCBuild.js b/scripts/configureTSCBuild.js new file mode 100644 index 0000000000000..3eb7e9ee93595 --- /dev/null +++ b/scripts/configureTSCBuild.js @@ -0,0 +1,57 @@ +"use strict"; +exports.__esModule = true; +/// +var path_1 = require("path"); +var fs_1 = require("fs"); +var assert = require("assert"); +var args = process.argv.slice(2); +// function exec(path: string, args: string[] = []) { +// const cmdLine = ["node", path, ...args].join(" "); +// console.log(cmdLine); +// execSync(cmdLine); +// } +function main() { + if (args.length < 1) { + console.log("Usage:"); + console.log("\tnode configureTSCBuild.js "); + return; + } + // Acquire the version from the package.json file and modify it appropriately. + var packageJsonFilePath = path_1.normalize(args[0]); + var packageJsonValue = JSON.parse(fs_1.readFileSync(packageJsonFilePath).toString()); + // Remove the bin section from the current package + delete packageJsonValue.bin; + // Set the new name + packageJsonValue.name = "@orta/tsc"; + fs_1.writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); + // Remove the files which aren't use when just using the API + var 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, then remove the sibling JS files referenced above + var lib = path_1.join(path_1.dirname(packageJsonFilePath), packageJsonValue.main); + var libPath = path_1.dirname(lib); + toRemove.forEach(function (file) { + var path = path_1.join(libPath, file); + if (fs_1.existsSync(path)) + fs_1.unlinkSync(path); + }); + /////////////////////////////////// + // This section verifies that the build of TypeScript compiles and emits + var ts = require("../" + lib); + var source = "let x: string = 'string'"; + var results = ts.transpileModule(source, { + compilerOptions: { module: ts.ModuleKind.CommonJS } + }); + console.log(Object.keys(results)); + assert(results.outputText.trim() === "var x = 'string';", "Running typescript with " + packageJsonValue.name + " did not return the expected results, got: " + results.outputText); +} +main(); diff --git a/scripts/configureTSCBuild.ts b/scripts/configureTSCBuild.ts new file mode 100644 index 0000000000000..8fd76eab1bb99 --- /dev/null +++ b/scripts/configureTSCBuild.ts @@ -0,0 +1,82 @@ +/// +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; +} + +// function exec(path: string, args: string[] = []) { +// const cmdLine = ["node", path, ...args].join(" "); +// console.log(cmdLine); +// execSync(cmdLine); +// } + +function main(): void { + if (args.length < 1) { + console.log("Usage:"); + console.log("\tnode configureTSCBuild.js "); + 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; + + // Set the new name + packageJsonValue.name = "@orta/tsc"; + + 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, then remove the sibling JS files referenced above + const lib = join(dirname(packageJsonFilePath), packageJsonValue.main); + const libPath = dirname(lib); + toRemove.forEach(file => { + const path = join(libPath, file); + if (existsSync(path)) unlinkSync(path); + }); + + /////////////////////////////////// + + // 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 } + }); + console.log(Object.keys(results)); + + assert(results.outputText.trim() === "var x = 'string';", `Running typescript with ${packageJsonValue.name} did not return the expected results, got: ${results.outputText}`); + + +} + +main(); From 63feabb920613738a1741b57d6a6e3f9e2198c03 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 24 Sep 2019 14:12:57 -0400 Subject: [PATCH 2/5] Improve the gitignore / npm ignore --- .gitignore | 3 ++- .npmignore | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index da24307954912..4177c0e99cae1 100644 --- a/.gitignore +++ b/.gitignore @@ -91,4 +91,5 @@ tests/cases/user/create-react-app/create-react-app tests/cases/user/webpack/webpack tests/cases/user/puppeteer/puppeteer tests/cases/user/axios-src/axios-src -tests/cases/user/prettier/prettier \ No newline at end of file +tests/cases/user/prettier/prettier +tmp diff --git a/.npmignore b/.npmignore index a0769e52a5444..7a8f8d5129113 100644 --- a/.npmignore +++ b/.npmignore @@ -31,4 +31,8 @@ yarn.lock CONTRIBUTING.md TEST-results.xml .dockerignore -Dockerfile \ No newline at end of file +Dockerfile +.DS_Store +.eslintrc.json +.yarnrc +tmp From 31c08b61913ef622a4a9afb56134567c6c1feb81 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 24 Sep 2019 14:26:35 -0400 Subject: [PATCH 3/5] More work on generating a small typescript build --- .dockerignore | 3 +- .gitignore | 1 + scripts/configureTSCBuild.js | 57 ------------------------------------ scripts/configureTSCBuild.ts | 31 ++++++++++++-------- 4 files changed, 21 insertions(+), 71 deletions(-) delete mode 100644 scripts/configureTSCBuild.js diff --git a/.dockerignore b/.dockerignore index 1f64bbcee3236..85c3bb869a73f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,6 +22,7 @@ scripts/buildProtocol.js scripts/ior.js scripts/authors.js scripts/configurePrerelease.js +scripts/configureTSCBuild.js scripts/open-user-pr.js scripts/open-cherry-pick-pr.js scripts/processDiagnosticMessages.d.ts @@ -45,4 +46,4 @@ TEST-results.xml package-lock.json tests .vscode -.git \ No newline at end of file +.git diff --git a/.gitignore b/.gitignore index 4177c0e99cae1..beeaeb200ad5e 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ scripts/buildProtocol.js scripts/ior.js scripts/authors.js scripts/configurePrerelease.js +scripts/configureTSCBuild.js scripts/open-user-pr.js scripts/open-cherry-pick-pr.js scripts/processDiagnosticMessages.d.ts diff --git a/scripts/configureTSCBuild.js b/scripts/configureTSCBuild.js deleted file mode 100644 index 3eb7e9ee93595..0000000000000 --- a/scripts/configureTSCBuild.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; -exports.__esModule = true; -/// -var path_1 = require("path"); -var fs_1 = require("fs"); -var assert = require("assert"); -var args = process.argv.slice(2); -// function exec(path: string, args: string[] = []) { -// const cmdLine = ["node", path, ...args].join(" "); -// console.log(cmdLine); -// execSync(cmdLine); -// } -function main() { - if (args.length < 1) { - console.log("Usage:"); - console.log("\tnode configureTSCBuild.js "); - return; - } - // Acquire the version from the package.json file and modify it appropriately. - var packageJsonFilePath = path_1.normalize(args[0]); - var packageJsonValue = JSON.parse(fs_1.readFileSync(packageJsonFilePath).toString()); - // Remove the bin section from the current package - delete packageJsonValue.bin; - // Set the new name - packageJsonValue.name = "@orta/tsc"; - fs_1.writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); - // Remove the files which aren't use when just using the API - var 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, then remove the sibling JS files referenced above - var lib = path_1.join(path_1.dirname(packageJsonFilePath), packageJsonValue.main); - var libPath = path_1.dirname(lib); - toRemove.forEach(function (file) { - var path = path_1.join(libPath, file); - if (fs_1.existsSync(path)) - fs_1.unlinkSync(path); - }); - /////////////////////////////////// - // This section verifies that the build of TypeScript compiles and emits - var ts = require("../" + lib); - var source = "let x: string = 'string'"; - var results = ts.transpileModule(source, { - compilerOptions: { module: ts.ModuleKind.CommonJS } - }); - console.log(Object.keys(results)); - assert(results.outputText.trim() === "var x = 'string';", "Running typescript with " + packageJsonValue.name + " did not return the expected results, got: " + results.outputText); -} -main(); diff --git a/scripts/configureTSCBuild.ts b/scripts/configureTSCBuild.ts index 8fd76eab1bb99..491784d9350df 100644 --- a/scripts/configureTSCBuild.ts +++ b/scripts/configureTSCBuild.ts @@ -5,8 +5,6 @@ import assert = require("assert"); import { execSync } from "child_process"; const args = process.argv.slice(2); - - /** * A minimal description for a parsed package.json object. */ @@ -14,14 +12,12 @@ interface PackageJson { name: string; bin: {}; main: string; + scripts: { + prepare: string + postpublish: string + } } -// function exec(path: string, args: string[] = []) { -// const cmdLine = ["node", path, ...args].join(" "); -// console.log(cmdLine); -// execSync(cmdLine); -// } - function main(): void { if (args.length < 1) { console.log("Usage:"); @@ -35,9 +31,13 @@ function main(): void { // 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 = "@orta/tsc"; + packageJsonValue.name = "@orta/language-services"; writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); @@ -54,14 +54,22 @@ function main(): void { "tsserverlibrary.d.ts" ]; - // Get a link to the main dependency JS file, then remove the sibling JS files referenced above + // 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 @@ -72,11 +80,8 @@ function main(): void { const results =ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }); - console.log(Object.keys(results)); assert(results.outputText.trim() === "var x = 'string';", `Running typescript with ${packageJsonValue.name} did not return the expected results, got: ${results.outputText}`); - - } main(); From 92b3266a9301d25f46678539b7a16d48fab80830 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 26 Sep 2019 13:23:19 -0400 Subject: [PATCH 4/5] Rename the smaller build to '@typescript/language-services' and have a separate build step for creating and publishing vs configuring the build --- .gitignore | 3 +- Gulpfile.js | 6 +-- package.json | 2 +- ...ld.ts => configureLanguageServiceBuild.ts} | 6 +-- scripts/createLanguageServiceBuild.ts | 46 +++++++++++++++++++ 5 files changed, 55 insertions(+), 8 deletions(-) rename scripts/{configureTSCBuild.ts => configureLanguageServiceBuild.ts} (92%) create mode 100644 scripts/createLanguageServiceBuild.ts diff --git a/.gitignore b/.gitignore index beeaeb200ad5e..087a32283bb1d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,8 @@ scripts/buildProtocol.js scripts/ior.js scripts/authors.js scripts/configurePrerelease.js -scripts/configureTSCBuild.js +scripts/configureLanguageServiceBuild.js +scripts/createLanguageServiceBuild.js scripts/open-user-pr.js scripts/open-cherry-pick-pr.js scripts/processDiagnosticMessages.d.ts diff --git a/Gulpfile.js b/Gulpfile.js index 7ed50e25beb56..7acc945550630 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -588,9 +588,9 @@ const configureExperimental = () => exec(process.execPath, ["scripts/configurePr task("configure-experimental", series(buildScripts, configureExperimental)); task("configure-experimental").description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing"; -const configureTSCOnly = () => exec(process.execPath, ["scripts/configureTSCBuild.js", "package.json", "src/compiler/core.ts"]); -task("configure-tsc-only", series(buildScripts, configureNightly)); -task("configure-tsc-only").description = "Runs scripts/configureTSCOnly.ts to prepare a build for build which only has tsc "; +const createLanguageServicesBuild = () => exec(process.execPath, ["scripts/createLanguageServicesBuild.js"]); +task("create-language-services-build", series(buildScripts, createLanguageServicesBuild)); +task("create-language-services-build").description = "Runs scripts/createLanguageServicesBuild.ts to prepare a build which only has the require('typescript') JS."; const publishNightly = () => exec("npm", ["publish", "--tag", "next"]); task("publish-nightly", series(task("clean"), task("LKG"), task("clean"), task("runtests-parallel"), publishNightly)); diff --git a/package.json b/package.json index a61588734dba9..cc42ddbdd0d1a 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "scripts": { "prepare": "gulp build-eslint-rules", "pretest": "gulp tests", - "postpublish": "gulp configure-tsc-only", + "postpublish": "gulp create-language-services-build", "test": "gulp runtests-parallel --light=false", "test:eslint-rules": "gulp run-eslint-rules-tests", "build": "npm run build:compiler && npm run build:tests", diff --git a/scripts/configureTSCBuild.ts b/scripts/configureLanguageServiceBuild.ts similarity index 92% rename from scripts/configureTSCBuild.ts rename to scripts/configureLanguageServiceBuild.ts index 491784d9350df..d61aeaeec35f3 100644 --- a/scripts/configureTSCBuild.ts +++ b/scripts/configureLanguageServiceBuild.ts @@ -37,7 +37,7 @@ function main(): void { delete packageJsonValue.scripts.postpublish; // Set the new name - packageJsonValue.name = "@orta/language-services"; + packageJsonValue.name = "@typescript/language-services"; writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); @@ -74,10 +74,10 @@ function main(): void { // This section verifies that the build of TypeScript compiles and emits - const ts = require("../" + lib); + const ts = require(lib); const source = "let x: string = 'string'"; - const results =ts.transpileModule(source, { + const results = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }); diff --git a/scripts/createLanguageServiceBuild.ts b/scripts/createLanguageServiceBuild.ts new file mode 100644 index 0000000000000..c870979eb1297 --- /dev/null +++ b/scripts/createLanguageServiceBuild.ts @@ -0,0 +1,46 @@ +/// +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(); From c64af5e50517eaac2160f28cb8f94e2daa491220 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 30 Sep 2019 08:29:16 -0400 Subject: [PATCH 5/5] Remove the post-publish script --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index cc42ddbdd0d1a..7a59b95a130f6 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,6 @@ "scripts": { "prepare": "gulp build-eslint-rules", "pretest": "gulp tests", - "postpublish": "gulp create-language-services-build", "test": "gulp runtests-parallel --light=false", "test:eslint-rules": "gulp run-eslint-rules-tests", "build": "npm run build:compiler && npm run build:tests",