Skip to content

Commit

Permalink
More work on generating a small typescript build
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Sep 24, 2019
1 parent 63feabb commit 31c08b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,4 +46,4 @@ TEST-results.xml
package-lock.json
tests
.vscode
.git
.git
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 0 additions & 57 deletions scripts/configureTSCBuild.js

This file was deleted.

31 changes: 18 additions & 13 deletions scripts/configureTSCBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ 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 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:");
Expand All @@ -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));

Expand All @@ -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
Expand All @@ -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();

0 comments on commit 31c08b6

Please sign in to comment.