Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
87 lines (70 loc) · 2.8 KB

File metadata and controls

87 lines (70 loc) · 2.8 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.