Skip to content

Commit 3fe7aaf

Browse files
committed
Add a command for stripping the dependency down
1 parent 0da5415 commit 3fe7aaf

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

Gulpfile.js

+4
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ const configureExperimental = () => exec(process.execPath, ["scripts/configurePr
588588
task("configure-experimental", series(buildScripts, configureExperimental));
589589
task("configure-experimental").description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing";
590590

591+
const configureTSCOnly = () => exec(process.execPath, ["scripts/configureTSCBuild.js", "package.json", "src/compiler/core.ts"]);
592+
task("configure-tsc-only", series(buildScripts, configureNightly));
593+
task("configure-tsc-only").description = "Runs scripts/configureTSCOnly.ts to prepare a build for build which only has tsc ";
594+
591595
const publishNightly = () => exec("npm", ["publish", "--tag", "next"]);
592596
task("publish-nightly", series(task("clean"), task("LKG"), task("clean"), task("runtests-parallel"), publishNightly));
593597
task("publish-nightly").description = "Runs `npm publish --tag next` to create a new nightly build on npm";

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"scripts": {
105105
"prepare": "gulp build-eslint-rules",
106106
"pretest": "gulp tests",
107+
"postpublish": "gulp configure-tsc-only",
107108
"test": "gulp runtests-parallel --light=false",
108109
"test:eslint-rules": "gulp run-eslint-rules-tests",
109110
"build": "npm run build:compiler && npm run build:tests",

scripts/configureTSCBuild.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
exports.__esModule = true;
3+
/// <reference types="node"/>
4+
var path_1 = require("path");
5+
var fs_1 = require("fs");
6+
var assert = require("assert");
7+
var args = process.argv.slice(2);
8+
// function exec(path: string, args: string[] = []) {
9+
// const cmdLine = ["node", path, ...args].join(" ");
10+
// console.log(cmdLine);
11+
// execSync(cmdLine);
12+
// }
13+
function main() {
14+
if (args.length < 1) {
15+
console.log("Usage:");
16+
console.log("\tnode configureTSCBuild.js <package.json location>");
17+
return;
18+
}
19+
// Acquire the version from the package.json file and modify it appropriately.
20+
var packageJsonFilePath = path_1.normalize(args[0]);
21+
var packageJsonValue = JSON.parse(fs_1.readFileSync(packageJsonFilePath).toString());
22+
// Remove the bin section from the current package
23+
delete packageJsonValue.bin;
24+
// Set the new name
25+
packageJsonValue.name = "@orta/tsc";
26+
fs_1.writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4));
27+
// Remove the files which aren't use when just using the API
28+
var toRemove = [
29+
// JS Files
30+
"tsserver.js",
31+
"tsserverlibrary.js",
32+
"typescriptServices.js",
33+
"typingsInstaller.js",
34+
"tsc.js",
35+
// DTS files
36+
"typescriptServices.d.ts",
37+
"tsserverlibrary.d.ts"
38+
];
39+
// Get a link to the main dependency JS file, then remove the sibling JS files referenced above
40+
var lib = path_1.join(path_1.dirname(packageJsonFilePath), packageJsonValue.main);
41+
var libPath = path_1.dirname(lib);
42+
toRemove.forEach(function (file) {
43+
var path = path_1.join(libPath, file);
44+
if (fs_1.existsSync(path))
45+
fs_1.unlinkSync(path);
46+
});
47+
///////////////////////////////////
48+
// This section verifies that the build of TypeScript compiles and emits
49+
var ts = require("../" + lib);
50+
var source = "let x: string = 'string'";
51+
var results = ts.transpileModule(source, {
52+
compilerOptions: { module: ts.ModuleKind.CommonJS }
53+
});
54+
console.log(Object.keys(results));
55+
assert(results.outputText.trim() === "var x = 'string';", "Running typescript with " + packageJsonValue.name + " did not return the expected results, got: " + results.outputText);
56+
}
57+
main();

scripts/configureTSCBuild.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/// <reference types="node"/>
2+
import { normalize, dirname, join } from "path";
3+
import { readFileSync, writeFileSync, unlinkSync, existsSync } from "fs";
4+
import assert = require("assert");
5+
import { execSync } from "child_process";
6+
const args = process.argv.slice(2);
7+
8+
9+
10+
/**
11+
* A minimal description for a parsed package.json object.
12+
*/
13+
interface PackageJson {
14+
name: string;
15+
bin: {};
16+
main: string;
17+
}
18+
19+
// function exec(path: string, args: string[] = []) {
20+
// const cmdLine = ["node", path, ...args].join(" ");
21+
// console.log(cmdLine);
22+
// execSync(cmdLine);
23+
// }
24+
25+
function main(): void {
26+
if (args.length < 1) {
27+
console.log("Usage:");
28+
console.log("\tnode configureTSCBuild.js <package.json location>");
29+
return;
30+
}
31+
32+
// Acquire the version from the package.json file and modify it appropriately.
33+
const packageJsonFilePath = normalize(args[0]);
34+
const packageJsonValue: PackageJson = JSON.parse(readFileSync(packageJsonFilePath).toString());
35+
36+
// Remove the bin section from the current package
37+
delete packageJsonValue.bin;
38+
39+
// Set the new name
40+
packageJsonValue.name = "@orta/tsc";
41+
42+
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4));
43+
44+
// Remove the files which aren't use when just using the API
45+
const toRemove = [
46+
// JS Files
47+
"tsserver.js",
48+
"tsserverlibrary.js",
49+
"typescriptServices.js",
50+
"typingsInstaller.js",
51+
"tsc.js",
52+
// DTS files
53+
"typescriptServices.d.ts",
54+
"tsserverlibrary.d.ts"
55+
];
56+
57+
// Get a link to the main dependency JS file, then remove the sibling JS files referenced above
58+
const lib = join(dirname(packageJsonFilePath), packageJsonValue.main);
59+
const libPath = dirname(lib);
60+
toRemove.forEach(file => {
61+
const path = join(libPath, file);
62+
if (existsSync(path)) unlinkSync(path);
63+
});
64+
65+
///////////////////////////////////
66+
67+
// This section verifies that the build of TypeScript compiles and emits
68+
69+
const ts = require("../" + lib);
70+
const source = "let x: string = 'string'";
71+
72+
const results =ts.transpileModule(source, {
73+
compilerOptions: { module: ts.ModuleKind.CommonJS }
74+
});
75+
console.log(Object.keys(results));
76+
77+
assert(results.outputText.trim() === "var x = 'string';", `Running typescript with ${packageJsonValue.name} did not return the expected results, got: ${results.outputText}`);
78+
79+
80+
}
81+
82+
main();

0 commit comments

Comments
 (0)