This commit is contained in:
zino
2021-03-02 00:06:38 +01:00
parent 3a8aab0e9a
commit eeb745b013
3567 changed files with 1234741 additions and 0 deletions

28
client/node_modules/tsify/lib/CompileError.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
'use strict';
var os = require('os');
module.exports = function (ts) {
function CompileError(diagnostic) {
SyntaxError.call(this);
this.message = '';
if (diagnostic.file) {
var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
this.fileName = diagnostic.file.fileName;
this.line = loc.line + 1;
this.column = loc.character + 1;
this.message += this.fileName + '(' + this.line + ',' + this.column + '): ';
}
var category = ts.DiagnosticCategory[diagnostic.category];
this.name = 'TypeScript error';
this.message += category + ' TS' + diagnostic.code + ': ' +
ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL);
}
CompileError.prototype = Object.create(SyntaxError.prototype);
return CompileError;
};

294
client/node_modules/tsify/lib/Host.js generated vendored Normal file
View File

@@ -0,0 +1,294 @@
'use strict';
var events = require('events');
var fs = require('fs');
var realpath = require('fs.realpath');
var log = require('util').debuglog(require('../package').name);
var trace = require('util').debuglog(require('../package').name + '-trace');
var os = require('os');
var path = require('path');
var util = require('util');
var semver = require('semver');
module.exports = function (ts) {
var isCaseSensitiveFileSystem;
try {
fs.accessSync(path.join(__dirname, path.basename(__filename).toUpperCase()), fs.constants.R_OK);
isCaseSensitiveFileSystem = false;
} catch (error) {
trace('Case sensitive detection error: %s', error);
isCaseSensitiveFileSystem = true;
}
log('Detected case %s file system', isCaseSensitiveFileSystem ? 'sensitive' : 'insensitive');
function Host(currentDirectory, opts) {
this.isCaseSensitive = !!opts.forceConsistentCasingInFileNames || isCaseSensitiveFileSystem;
this.currentDirectory = this.getCanonicalFileName(path.resolve(currentDirectory));
this.outputDirectory = this.getCanonicalFileName(path.resolve(opts.outDir));
this.rootDirectory = this.getCanonicalFileName(path.resolve(opts.rootDir));
this.languageVersion = opts.target;
this.files = {};
this.previousFiles = {};
this.output = {};
this.version = 0;
this.error = false;
}
util.inherits(Host, events.EventEmitter);
Host.prototype._reset = function () {
this.previousFiles = this.files;
this.files = {};
this.output = {};
this.error = false;
++this.version;
log('Resetting (version %d)', this.version);
};
Host.prototype._addFile = function (filename, root) {
// Ensure that the relative file name is what's passed to
// 'createSourceFile', as that's the name that will be used in error
// messages, etc.
var relative = ts.normalizeSlashes(path.relative(
this.currentDirectory,
this.getCanonicalFileName(path.resolve(this.currentDirectory, filename))
));
var canonical = this._canonical(filename);
trace('Parsing %s', canonical);
var text;
try {
text = fs.readFileSync(filename, 'utf-8');
} catch (ex) {
return;
}
var file;
var current = this.files[canonical];
var previous = this.previousFiles[canonical];
var version;
if (current && current.contents === text) {
file = current.ts;
version = current.version;
trace('Reused current file %s (version %d)', canonical, version);
} else if (previous && previous.contents === text) {
file = previous.ts;
version = previous.version;
trace('Reused previous file %s (version %d)', canonical, version);
} else {
file = ts.createSourceFile(relative, text, this.languageVersion, true);
version = this.version;
trace('New version of source file %s (version %d)', canonical, version);
}
this.files[canonical] = {
filename: relative,
contents: text,
ts: file,
root: root,
version: version,
nodeModule: /\/node_modules\//i.test(canonical) && !/\.d\.ts$/i.test(canonical)
};
this.emit('file', canonical, relative);
return file;
};
Host.prototype.getSourceFile = function (filename) {
if (filename === '__lib.d.ts') {
return this.libDefault;
}
var canonical = this._canonical(filename);
if (this.files[canonical]) {
return this.files[canonical].ts;
}
return this._addFile(filename, false);
};
Host.prototype.getDefaultLibFileName = function () {
var libPath = path.dirname(ts.sys.getExecutingFilePath());
var libFile = ts.getDefaultLibFileName({ target: this.languageVersion });
return ts.normalizeSlashes(path.join(libPath, libFile));
};
Host.prototype.writeFile = function (filename, data) {
var outputCanonical = this._canonical(filename);
log('Cache write %s', outputCanonical);
this.output[outputCanonical] = data;
var sourceCanonical = this._inferSourceCanonical(outputCanonical);
var sourceFollowed = this._follow(path.dirname(sourceCanonical)) + '/' + path.basename(sourceCanonical);
if (sourceFollowed !== sourceCanonical) {
outputCanonical = this._inferOutputCanonical(sourceFollowed);
log('Cache write (followed) %s', outputCanonical);
this.output[outputCanonical] = data;
}
};
Host.prototype.getCurrentDirectory = function () {
return this.currentDirectory;
};
Host._getCanonicalFileName = function (filename) {
return ts.normalizeSlashes(isCaseSensitiveFileSystem ? filename : filename.toLowerCase());
}
Host.prototype.getCanonicalFileName = function (filename) {
return ts.normalizeSlashes(this.isCaseSensitive ? filename : filename.toLowerCase());
};
Host.prototype.useCaseSensitiveFileNames = function () {
return this.isCaseSensitive;
};
Host.prototype.getNewLine = function () {
return os.EOL;
};
Host.prototype.fileExists = function (filename) {
return ts.sys.fileExists(filename);
};
Host.prototype.readFile = function (filename) {
return ts.sys.readFile(filename);
};
Host.prototype.directoryExists = function (dirname) {
return ts.sys.directoryExists(dirname);
};
Host.prototype.getDirectories = function (dirname) {
return ts.sys.getDirectories(dirname);
};
Host.prototype.getEnvironmentVariable = function (name) {
return ts.sys.getEnvironmentVariable(name);
};
Host.prototype.realpath = function (name) {
return realpath.realpathSync(name);
};
Host.prototype.trace = function (message) {
ts.sys.write(message + this.getNewLine());
};
Host.prototype._rootFilenames = function () {
var rootFilenames = [];
for (var filename in this.files) {
if (!Object.hasOwnProperty.call(this.files, filename)) continue;
if (!this.files[filename].root) continue;
rootFilenames.push(filename);
}
return rootFilenames;
}
Host.prototype._nodeModuleFilenames = function () {
var nodeModuleFilenames = [];
for (var filename in this.files) {
if (!Object.hasOwnProperty.call(this.files, filename)) continue;
if (!this.files[filename].nodeModule) continue;
nodeModuleFilenames.push(filename);
}
return nodeModuleFilenames;
}
Host.prototype._compile = function (opts) {
var rootFilenames = this._rootFilenames();
var nodeModuleFilenames = [];
log('Compiling files:');
rootFilenames.forEach(function (file) { log(' %s', file); });
if (semver.gte(ts.version, '2.0.0')) {
ts.createProgram(rootFilenames, opts, this);
nodeModuleFilenames = this._nodeModuleFilenames();
log(' + %d file(s) found in node_modules', nodeModuleFilenames.length);
}
return ts.createProgram(rootFilenames.concat(nodeModuleFilenames), opts, this);
}
Host.prototype._output = function (filename) {
var outputCanonical = this._inferOutputCanonical(filename);
log('Cache read %s', outputCanonical);
var output = this.output[outputCanonical];
if (!output) {
log('Cache miss on %s', outputCanonical);
}
return output;
}
Host.prototype._canonical = function (filename) {
return this.getCanonicalFileName(path.resolve(
this.currentDirectory,
filename
));
}
Host.prototype._inferOutputCanonical = function (filename) {
var sourceCanonical = this._canonical(filename);
var outputRelative = path.relative(
this.rootDirectory,
sourceCanonical
);
var outputCanonical = this.getCanonicalFileName(path.resolve(
this.outputDirectory,
outputRelative
));
return outputCanonical;
}
Host.prototype._inferSourceCanonical = function (filename) {
var outputCanonical = this._canonical(filename);
var outputRelative = path.relative(
this.outputDirectory,
outputCanonical
);
var sourceCanonical = this.getCanonicalFileName(path.resolve(
this.rootDirectory,
outputRelative
));
return sourceCanonical;
}
Host.prototype._follow = function (filename) {
filename = this._canonical(filename);
var basename;
var parts = [];
do {
var stats = fs.lstatSync(filename);
if (stats.isSymbolicLink()) {
filename = realpath.realpathSync(filename);
} else {
basename = path.basename(filename);
if (basename) {
parts.unshift(basename);
filename = path.dirname(filename);
}
}
} while (basename);
return ts.normalizeSlashes(filename + parts.join('/'));
};
return Host;
};

344
client/node_modules/tsify/lib/Tsifier.js generated vendored Normal file
View File

@@ -0,0 +1,344 @@
'use strict';
var convert = require('convert-source-map');
var events = require('events');
var extend = require('util')._extend;
var fs = require('fs');
var realpath = require('fs.realpath');
var log = require('util').debuglog(require('../package').name);
var trace = require('util').debuglog(require('../package').name + '-trace');
var path = require('path');
var through = require('through2');
var time = require('./time');
var tsconfig = require('tsconfig');
var util = require('util');
var assign = require('object-assign');
module.exports = function (ts) {
var CompileError = require('./CompileError')(ts);
var Host = require('./Host')(ts);
var currentDirectory = ts.normalizeSlashes(realpath.realpathSync(process.cwd()));
var parseJsonConfigFileContent = ts.parseJsonConfigFileContent || ts.parseConfigFile;
function isTypescript(file) {
return (/\.tsx?$/i).test(file);
}
function isTsx(file) {
return (/\.tsx$/i).test(file);
}
function isJavascript(file) {
return (/\.jsx?$/i).test(file);
}
function isTypescriptDeclaration(file) {
return (/\.d\.ts$/i).test(file);
}
function replaceFileExtension(file, extension) {
return file.replace(/\.\w+$/i, extension);
}
function fileExists(file) {
try {
var stats = fs.lstatSync(file);
return stats.isFile();
} catch (e) {
return false;
}
}
function parseOptions(opts, bopts) {
// Expand any short-name, command-line options
var expanded = {};
if (opts.m) { expanded.module = opts.m; }
if (opts.p) { expanded.project = opts.p; }
if (opts.t) { expanded.target = opts.t; }
opts = assign(expanded, opts);
var config;
var configFile;
if (typeof opts.project === "object"){
log('Using inline tsconfig');
config = JSON.parse(JSON.stringify(opts.project));
config.compilerOptions = config.compilerOptions || {};
extend(config.compilerOptions, opts);
} else {
if (fileExists(opts.project)) {
configFile = opts.project;
} else {
configFile = ts.findConfigFile(
ts.normalizeSlashes(opts.project || bopts.basedir || currentDirectory),
fileExists
);
}
if (configFile) {
log('Using tsconfig file at %s', configFile);
config = tsconfig.readFileSync(configFile);
config.compilerOptions = config.compilerOptions || {};
extend(config.compilerOptions, opts);
} else {
config = {
files: [],
compilerOptions: opts
};
}
}
// Note that subarg parses command line arrays in its own peculiar way:
// https://github.com/substack/subarg
if (opts.exclude) {
config.exclude = opts.exclude._ || opts.exclude;
}
if (opts.files) {
config.files = opts.files._ || opts.files;
}
if (opts.include) {
config.include = opts.include._ || opts.include;
}
var parsed = parseJsonConfigFileContent(
config,
ts.sys,
configFile ? ts.normalizeSlashes(path.resolve(path.dirname(configFile))) : currentDirectory,
null,
configFile ? ts.normalizeSlashes(path.resolve(configFile)) : undefined
);
// Generate inline sourcemaps if Browserify's --debug option is set
parsed.options.sourceMap = false;
parsed.options.inlineSourceMap = bopts.debug;
parsed.options.inlineSources = bopts.debug;
// Default to CommonJS module mode
parsed.options.module = parsed.options.module || ts.ModuleKind.CommonJS;
// Blacklist --out/--outFile/--noEmit; these should definitely not be set, since we are doing
// concatenation with Browserify instead
delete parsed.options.out;
delete parsed.options.outFile;
delete parsed.options.noEmit;
// Set rootDir and outDir so we know exactly where the TS compiler will be trying to
// write files; the filenames will end up being the keys into our in-memory store.
// The output directory needs to be distinct from the input directory to prevent the TS
// compiler from thinking that it might accidentally overwrite source files, which would
// prevent it from outputting e.g. the results of transpiling ES6 JS files with --allowJs.
parsed.options.rootDir = path.relative('.', '/');
parsed.options.outDir = ts.normalizeSlashes(path.resolve('/__tsify__'));
log('Files from tsconfig parse:');
parsed.fileNames.forEach(function (filename) { log(' %s', filename); });
var result = {
options: parsed.options,
fileNames: parsed.fileNames
};
return result;
}
function Tsifier(opts, bopts) {
var self = this;
var parsedOptions = parseOptions(opts, bopts);
self.opts = parsedOptions.options;
self.files = parsedOptions.fileNames;
self.ignoredFiles = [];
self.bopts = bopts;
self.host = new Host(currentDirectory, self.opts);
self.host.on('file', function (file, id) {
self.emit('file', file, id);
});
}
util.inherits(Tsifier, events.EventEmitter);
Tsifier.prototype.reset = function () {
var self = this;
self.ignoredFiles = [];
self.host._reset();
self.addFiles(self.files);
};
Tsifier.prototype.generateCache = function (files, ignoredFiles) {
if (ignoredFiles) {
this.ignoredFiles = ignoredFiles;
}
this.addFiles(files);
this.compile();
};
Tsifier.prototype.addFiles = function (files) {
var self = this;
files.forEach(function (file) {
self.host._addFile(file, true);
});
};
Tsifier.prototype.compile = function () {
var self = this;
var createProgram_t0 = time.start();
var program = self.host._compile(self.opts);
time.stop(createProgram_t0, 'createProgram');
var syntaxDiagnostics = self.checkSyntax(program);
if (syntaxDiagnostics.length) {
log('Compilation encountered fatal syntax errors');
return;
}
var semanticDiagnostics = self.checkSemantics(program);
if (semanticDiagnostics.length && self.opts.noEmitOnError) {
log('Compilation encountered fatal semantic errors');
return;
}
var emit_t0 = time.start();
var emitOutput = program.emit();
time.stop(emit_t0, 'emit program');
var emittedDiagnostics = self.checkEmittedOutput(emitOutput);
if (emittedDiagnostics.length && self.opts.noEmitOnError) {
log('Compilation encountered fatal errors during emit');
return;
}
log('Compilation completed without errors');
};
Tsifier.prototype.checkSyntax = function (program) {
var self = this;
var syntaxCheck_t0 = time.start();
var syntaxDiagnostics = program.getSyntacticDiagnostics();
time.stop(syntaxCheck_t0, 'syntax checking');
syntaxDiagnostics.forEach(function (error) {
self.emit('error', new CompileError(error));
});
if (syntaxDiagnostics.length) {
self.host.error = true;
}
return syntaxDiagnostics;
};
Tsifier.prototype.checkSemantics = function (program) {
var self = this;
var semanticDiagnostics_t0 = time.start();
var semanticDiagnostics = program.getGlobalDiagnostics();
if (semanticDiagnostics.length === 0) {
semanticDiagnostics = program.getSemanticDiagnostics();
}
time.stop(semanticDiagnostics_t0, 'semantic checking');
semanticDiagnostics.forEach(function (error) {
self.emit('error', new CompileError(error));
});
if (semanticDiagnostics.length && self.opts.noEmitOnError) {
self.host.error = true;
}
return semanticDiagnostics;
};
Tsifier.prototype.checkEmittedOutput = function (emitOutput) {
var self = this;
var emittedDiagnostics = emitOutput.diagnostics;
emittedDiagnostics.forEach(function (error) {
self.emit('error', new CompileError(error));
});
if (emittedDiagnostics.length && self.opts.noEmitOnError) {
self.host.error = true;
}
return emittedDiagnostics;
};
Tsifier.prototype.transform = function (file) {
var self = this;
trace('Transforming %s', file);
if (self.ignoredFiles.indexOf(file) !== -1) {
return through();
}
if (isTypescriptDeclaration(file)) {
return through(transform);
}
if (isTypescript(file) || (isJavascript(file) && self.opts.allowJs)) {
return through(transform, flush);
}
return through();
function transform(chunk, enc, next) {
next();
}
function flush(next) {
if (self.host.error) {
next();
return;
}
var compiled = self.getCompiledFile(file);
if (compiled) {
this.push(compiled);
}
this.push(null);
next();
}
};
Tsifier.prototype.getCompiledFile = function (inputFile, alreadyMissedCache) {
var self = this;
var outputExtension = (ts.JsxEmit && self.opts.jsx === ts.JsxEmit.Preserve && isTsx(inputFile)) ? '.jsx' : '.js';
var output = self.host._output(replaceFileExtension(inputFile, outputExtension));
if (output === undefined) {
if (alreadyMissedCache) {
self.emit('error', new Error('tsify: no compiled file for ' + inputFile));
return;
}
self.generateCache([inputFile]);
if (self.host.error)
return;
return self.getCompiledFile(inputFile, true);
}
if (self.opts.inlineSourceMap) {
output = self.setSourcePathInSourcemap(output, inputFile);
}
return output;
};
Tsifier.prototype.setSourcePathInSourcemap = function (output, inputFile) {
var self = this;
var normalized = ts.normalizePath(path.relative(
self.bopts.basedir || currentDirectory,
inputFile
));
var sourcemap = convert.fromComment(output);
sourcemap.setProperty('sources', [normalized]);
return output.replace(convert.commentRegex, sourcemap.toComment());
}
var result = Tsifier;
result.isTypescript = isTypescript;
result.isTypescriptDeclaration = isTypescriptDeclaration;
return result;
};

13
client/node_modules/tsify/lib/time.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
'use strict';
var log = require('util').debuglog(require('../package').name);
function start() {
return process.hrtime();
}
function stop(t0, message) {
var tDiff = process.hrtime(t0);
log('%d sec -- %s', (tDiff[0] + (tDiff[1] / 1000000000)).toFixed(4), message);
}
module.exports = { start: start, stop: stop };