-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23893 from Microsoft/libReference
Adds 'lib' reference directives
- Loading branch information
Showing
1,559 changed files
with
9,716 additions
and
9,288 deletions.
There are no files selected for viewing
This file contains 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 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,88 @@ | ||
// @ts-check | ||
const path = require("path"); | ||
const child_process = require("child_process"); | ||
const tsc = require("gulp-typescript"); | ||
const Vinyl = require("vinyl"); | ||
const { Duplex, Readable } = require("stream"); | ||
|
||
/** | ||
* @param {string} tsConfigFileName | ||
* @param {tsc.Settings} settings | ||
* @param {Object} options | ||
* @param {string} [options.typescript] | ||
*/ | ||
function createProject(tsConfigFileName, settings, options) { | ||
settings = { ...settings }; | ||
options = { ...options }; | ||
if (settings.typescript) throw new Error(); | ||
|
||
const localSettings = { ...settings }; | ||
if (options.typescript) { | ||
options.typescript = path.resolve(options.typescript); | ||
localSettings.typescript = require(options.typescript); | ||
} | ||
|
||
const project = tsc.createProject(tsConfigFileName, localSettings); | ||
const wrappedProject = /** @type {tsc.Project} */(() => { | ||
const proc = child_process.fork(require.resolve("./main.js")); | ||
/** @type {Duplex & { js?: Readable, dts?: Readable }} */ | ||
const compileStream = new Duplex({ | ||
objectMode: true, | ||
read() {}, | ||
/** @param {*} file */ | ||
write(file, encoding, callback) { | ||
proc.send({ method: "write", params: { path: file.path, cwd: file.cwd, base: file.base }}); | ||
callback(); | ||
}, | ||
final(callback) { | ||
proc.send({ method: "final" }); | ||
callback(); | ||
} | ||
}); | ||
const jsStream = compileStream.js = new Readable({ | ||
objectMode: true, | ||
read() {} | ||
}); | ||
const dtsStream = compileStream.dts = new Readable({ | ||
objectMode: true, | ||
read() {} | ||
}); | ||
proc.send({ method: "createProject", params: { tsConfigFileName, settings, options } }); | ||
proc.on("message", ({ method, params }) => { | ||
if (method === "write") { | ||
const file = new Vinyl({ | ||
path: params.path, | ||
cwd: params.cwd, | ||
base: params.base, | ||
contents: Buffer.from(params.contents, "utf8") | ||
}); | ||
if (params.sourceMap) file.sourceMap = params.sourceMap | ||
compileStream.push(file);; | ||
if (file.path.endsWith(".d.ts")) { | ||
dtsStream.push(file); | ||
} | ||
else { | ||
jsStream.push(file); | ||
} | ||
} | ||
else if (method === "final") { | ||
compileStream.push(null); | ||
jsStream.push(null); | ||
dtsStream.push(null); | ||
proc.kill(); | ||
} | ||
else if (method === "error") { | ||
const error = new Error(); | ||
error.name = params.name; | ||
error.message = params.message; | ||
error.stack = params.stack; | ||
compileStream.emit("error", error); | ||
proc.kill(); | ||
} | ||
}); | ||
return /** @type {*} */(compileStream); | ||
}); | ||
return Object.assign(wrappedProject, project); | ||
} | ||
|
||
exports.createProject = createProject; |
This file contains 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,91 @@ | ||
// @ts-check | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const tsc = require("gulp-typescript"); | ||
const Vinyl = require("vinyl"); | ||
const { Readable, Writable } = require("stream"); | ||
|
||
/** @type {tsc.Project} */ | ||
let project; | ||
|
||
/** @type {Readable} */ | ||
let inputStream; | ||
|
||
/** @type {Writable} */ | ||
let outputStream; | ||
|
||
/** @type {tsc.CompileStream} */ | ||
let compileStream; | ||
|
||
process.on("message", ({ method, params }) => { | ||
try { | ||
if (method === "createProject") { | ||
const { tsConfigFileName, settings, options } = params; | ||
if (options.typescript) { | ||
settings.typescript = require(options.typescript); | ||
} | ||
project = tsc.createProject(tsConfigFileName, settings); | ||
inputStream = new Readable({ | ||
objectMode: true, | ||
read() {} | ||
}); | ||
outputStream = new Writable({ | ||
objectMode: true, | ||
/** | ||
* @param {*} file | ||
*/ | ||
write(file, encoding, callback) { | ||
process.send({ | ||
method: "write", | ||
params: { | ||
path: file.path, | ||
cwd: file.cwd, | ||
base: file.base, | ||
contents: file.contents.toString(), | ||
sourceMap: file.sourceMap | ||
} | ||
}); | ||
callback(); | ||
}, | ||
final(callback) { | ||
process.send({ method: "final" }); | ||
callback(); | ||
} | ||
}); | ||
outputStream.on("error", error => { | ||
process.send({ | ||
method: "error", | ||
params: { | ||
name: error.name, | ||
message: error.message, | ||
stack: error.stack | ||
} | ||
}); | ||
}); | ||
compileStream = project(); | ||
inputStream.pipe(compileStream).pipe(outputStream); | ||
} | ||
else if (method === "write") { | ||
const file = new Vinyl({ | ||
path: params.path, | ||
cwd: params.cwd, | ||
base: params.base | ||
}); | ||
file.contents = fs.readFileSync(file.path); | ||
inputStream.push(/** @type {*} */(file)); | ||
} | ||
else if (method === "final") { | ||
inputStream.push(null); | ||
} | ||
} | ||
catch (e) { | ||
process.send({ | ||
method: "error", | ||
params: { | ||
name: e.name, | ||
message: e.message, | ||
stack: e.stack | ||
} | ||
}); | ||
} | ||
}); |
This file contains 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
Oops, something went wrong.