typescript-to-lua
Advanced tools
Comparing version 0.28.0 to 0.28.1
import * as ts from "typescript"; | ||
import { TranspileError } from "./TranspileError"; | ||
export declare const transpileError: (error: TranspileError) => ts.Diagnostic; | ||
export declare const tstlOptionsAreMovingToTheTstlObject: (tstl: Record<string, any>) => ts.Diagnostic; | ||
export declare const toLoadTransformerItShouldBeTranspiled: (transform: string) => ts.Diagnostic; | ||
@@ -9,11 +8,1 @@ export declare const couldNotResolveTransformerFrom: (transform: string, base: string) => ts.Diagnostic; | ||
export declare const transformerShouldBeATsTransformerFactory: (transform: string) => ts.Diagnostic; | ||
export declare const watchErrorSummary: (errorCount: number) => ts.Diagnostic; | ||
export declare const unknownCompilerOption: (name: string) => ts.Diagnostic; | ||
export declare const compilerOptionRequiresAValueOfType: (name: string, type: string) => ts.Diagnostic; | ||
export declare const optionProjectCannotBeMixedWithSourceFilesOnACommandLine: () => ts.Diagnostic; | ||
export declare const cannotFindATsconfigJsonAtTheSpecifiedDirectory: (dir: string) => ts.Diagnostic; | ||
export declare const theSpecifiedPathDoesNotExist: (dir: string) => ts.Diagnostic; | ||
export declare const compilerOptionExpectsAnArgument: (name: string) => ts.Diagnostic; | ||
export declare const argumentForOptionMustBe: (name: string, values: string) => ts.Diagnostic; | ||
export declare const optionCanOnlyBeSpecifiedInTsconfigJsonFile: (name: string) => ts.Diagnostic; | ||
export declare const optionBuildMustBeFirstCommandLineArgument: () => ts.Diagnostic; |
@@ -13,12 +13,2 @@ "use strict"; | ||
}); | ||
exports.tstlOptionsAreMovingToTheTstlObject = (tstl) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Warning, | ||
code: 0, | ||
source: "typescript-to-lua", | ||
messageText: 'TSTL options are moving to the "tstl" object. Adjust your tsconfig to look like\n' + | ||
`"tstl": ${JSON.stringify(tstl, undefined, 4)}`, | ||
}); | ||
exports.toLoadTransformerItShouldBeTranspiled = (transform) => ({ | ||
@@ -60,29 +50,2 @@ file: undefined, | ||
}); | ||
exports.watchErrorSummary = (errorCount) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Message, | ||
code: errorCount === 1 ? 6193 : 6194, | ||
messageText: errorCount === 1 | ||
? "Found 1 error. Watching for file changes." | ||
: `Found ${errorCount} errors. Watching for file changes.`, | ||
}); | ||
const createCommandLineError = (code, getMessage) => (...args) => ({ | ||
file: undefined, | ||
start: undefined, | ||
length: undefined, | ||
category: ts.DiagnosticCategory.Error, | ||
code, | ||
messageText: getMessage(...args), | ||
}); | ||
exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`); | ||
exports.compilerOptionRequiresAValueOfType = createCommandLineError(5024, (name, type) => `Compiler option '${name}' requires a value of type ${type}.`); | ||
exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError(5042, () => "Option 'project' cannot be mixed with source files on a command line."); | ||
exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = createCommandLineError(5057, (dir) => `Cannot find a tsconfig.json file at the specified directory: '${dir}'.`); | ||
exports.theSpecifiedPathDoesNotExist = createCommandLineError(5058, (dir) => `The specified path does not exist: '${dir}'.`); | ||
exports.compilerOptionExpectsAnArgument = createCommandLineError(6044, (name) => `Compiler option '${name}' expects an argument.`); | ||
exports.argumentForOptionMustBe = createCommandLineError(6046, (name, values) => `Argument for '${name}' option must be: ${values}.`); | ||
exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = createCommandLineError(6064, (name) => `Option '${name}' can only be specified in 'tsconfig.json' file.`); | ||
exports.optionBuildMustBeFirstCommandLineArgument = createCommandLineError(6369, () => "Option '--build' must be the first command line argument."); | ||
//# sourceMappingURL=diagnostics.js.map |
import { CompilerOptions } from "./CompilerOptions"; | ||
import { TranspiledFile, EmitHost } from "./Transpile"; | ||
import { EmitHost, TranspiledFile } from "./Transpile"; | ||
export interface OutputFile { | ||
@@ -4,0 +4,0 @@ name: string; |
@@ -6,4 +6,4 @@ "use strict"; | ||
const CompilerOptions_1 = require("./CompilerOptions"); | ||
const utils_1 = require("./utils"); | ||
const trimExt = (filePath) => filePath.slice(0, -path.extname(filePath).length); | ||
const normalizeSlashes = (filePath) => filePath.replace(/\\/g, "/"); | ||
let lualibContent; | ||
@@ -30,3 +30,3 @@ function emitTranspiledFiles(options, transpiledFiles, emitHost = ts.sys) { | ||
} | ||
outPath = normalizeSlashes(outPath); | ||
outPath = utils_1.normalizeSlashes(outPath); | ||
if (lua !== undefined) { | ||
@@ -59,3 +59,3 @@ files.push({ name: outPath, text: lua }); | ||
} | ||
files.push({ name: normalizeSlashes(outPath), text: lualibContent }); | ||
files.push({ name: utils_1.normalizeSlashes(outPath), text: lualibContent }); | ||
} | ||
@@ -62,0 +62,0 @@ return files; |
@@ -5,3 +5,5 @@ import * as ts from "typescript"; | ||
import { TranspiledFile, TranspileResult } from "./Transpile"; | ||
export { createDiagnosticReporter, parseCommandLine, ParsedCommandLine, updateParsedConfigFile, } from "./CommandLineParser"; | ||
export { version } from "./cli/information"; | ||
export { parseCommandLine, ParsedCommandLine, updateParsedConfigFile } from "./cli/parse"; | ||
export * from "./cli/report"; | ||
export * from "./CompilerOptions"; | ||
@@ -8,0 +10,0 @@ export * from "./Emit"; |
@@ -9,9 +9,11 @@ "use strict"; | ||
const ts = require("typescript"); | ||
const CommandLineParser_1 = require("./CommandLineParser"); | ||
const tsconfig_1 = require("./cli/tsconfig"); | ||
const Emit_1 = require("./Emit"); | ||
const Transpile_1 = require("./Transpile"); | ||
var CommandLineParser_2 = require("./CommandLineParser"); | ||
exports.createDiagnosticReporter = CommandLineParser_2.createDiagnosticReporter; | ||
exports.parseCommandLine = CommandLineParser_2.parseCommandLine; | ||
exports.updateParsedConfigFile = CommandLineParser_2.updateParsedConfigFile; | ||
var information_1 = require("./cli/information"); | ||
exports.version = information_1.version; | ||
var parse_1 = require("./cli/parse"); | ||
exports.parseCommandLine = parse_1.parseCommandLine; | ||
exports.updateParsedConfigFile = parse_1.updateParsedConfigFile; | ||
__export(require("./cli/report")); | ||
__export(require("./CompilerOptions")); | ||
@@ -38,3 +40,3 @@ __export(require("./Emit")); | ||
function transpileProject(configFileName, optionsToExtend) { | ||
const parseResult = CommandLineParser_1.parseConfigFileWithSystem(configFileName, optionsToExtend); | ||
const parseResult = tsconfig_1.parseConfigFileWithSystem(configFileName, optionsToExtend); | ||
if (parseResult.errors.length > 0) { | ||
@@ -41,0 +43,0 @@ return { diagnostics: parseResult.errors, emitResult: [] }; |
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const ts = require("typescript"); | ||
const tstl = require("."); | ||
const CommandLineParser = require("./CommandLineParser"); | ||
const diagnosticFactories = require("./diagnostics"); | ||
function createWatchStatusReporter(options) { | ||
return ts.createWatchStatusReporter(ts.sys, shouldBePretty(options)); | ||
} | ||
const cliDiagnostics = require("./cli/diagnostics"); | ||
const information_1 = require("./cli/information"); | ||
const parse_1 = require("./cli/parse"); | ||
const report_1 = require("./cli/report"); | ||
const tsconfig_1 = require("./cli/tsconfig"); | ||
function shouldBePretty(options) { | ||
@@ -17,43 +16,8 @@ return !options || options.pretty === undefined | ||
} | ||
let reportDiagnostic = tstl.createDiagnosticReporter(false); | ||
let reportDiagnostic = report_1.createDiagnosticReporter(false); | ||
function updateReportDiagnostic(options) { | ||
reportDiagnostic = tstl.createDiagnosticReporter(shouldBePretty(options)); | ||
reportDiagnostic = report_1.createDiagnosticReporter(shouldBePretty(options)); | ||
} | ||
function locateConfigFile(commandLine) { | ||
const { project } = commandLine.options; | ||
if (!project) { | ||
if (commandLine.fileNames.length === 0) { | ||
const searchPath = path.posix.normalize(ts.sys.getCurrentDirectory()); | ||
return ts.findConfigFile(searchPath, ts.sys.fileExists); | ||
} | ||
return; | ||
} | ||
if (commandLine.fileNames.length !== 0) { | ||
reportDiagnostic(diagnosticFactories.optionProjectCannotBeMixedWithSourceFilesOnACommandLine()); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
return; | ||
} | ||
let fileOrDirectory = path.posix.normalize(project); | ||
if (!path.isAbsolute(fileOrDirectory)) { | ||
fileOrDirectory = path.posix.join(ts.sys.getCurrentDirectory(), fileOrDirectory); | ||
} | ||
if (!fileOrDirectory || ts.sys.directoryExists(fileOrDirectory)) { | ||
const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json"); | ||
if (ts.sys.fileExists(configFileName)) { | ||
return configFileName; | ||
} | ||
else { | ||
reportDiagnostic(diagnosticFactories.cannotFindATsconfigJsonAtTheSpecifiedDirectory(project)); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
} | ||
} | ||
else { | ||
if (ts.sys.fileExists(fileOrDirectory)) { | ||
return fileOrDirectory; | ||
} | ||
else { | ||
reportDiagnostic(diagnosticFactories.theSpecifiedPathDoesNotExist(project)); | ||
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
} | ||
} | ||
function createWatchStatusReporter(options) { | ||
return ts.createWatchStatusReporter(ts.sys, shouldBePretty(options)); | ||
} | ||
@@ -67,5 +31,5 @@ function executeCommandLine(args) { | ||
} | ||
const commandLine = CommandLineParser.parseCommandLine(args); | ||
const commandLine = parse_1.parseCommandLine(args); | ||
if (commandLine.options.build) { | ||
reportDiagnostic(diagnosticFactories.optionBuildMustBeFirstCommandLineArgument()); | ||
reportDiagnostic(cliDiagnostics.optionBuildMustBeFirstCommandLineArgument()); | ||
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
@@ -80,14 +44,18 @@ } | ||
if (commandLine.options.version) { | ||
console.log(CommandLineParser.version); | ||
console.log(information_1.versionString); | ||
return ts.sys.exit(ts.ExitStatus.Success); | ||
} | ||
if (commandLine.options.help) { | ||
console.log(CommandLineParser.version); | ||
console.log(CommandLineParser.getHelpString()); | ||
console.log(information_1.versionString); | ||
console.log(information_1.getHelpString()); | ||
return ts.sys.exit(ts.ExitStatus.Success); | ||
} | ||
const configFileName = locateConfigFile(commandLine); | ||
const configFileName = tsconfig_1.locateConfigFile(commandLine); | ||
if (typeof configFileName === "object") { | ||
reportDiagnostic(configFileName); | ||
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); | ||
} | ||
const commandLineOptions = commandLine.options; | ||
if (configFileName) { | ||
const configParseResult = CommandLineParser.parseConfigFileWithSystem(configFileName, commandLineOptions); | ||
const configParseResult = tsconfig_1.parseConfigFileWithSystem(configFileName, commandLineOptions); | ||
updateReportDiagnostic(configParseResult.options); | ||
@@ -149,18 +117,7 @@ if (configParseResult.options.watch) { | ||
let fullRecompile = true; | ||
const configFileMap = new WeakMap(); | ||
const updateConfigFile = tsconfig_1.createConfigFileUpdater(optionsToExtend); | ||
host.afterProgramCreate = builderProgram => { | ||
const program = builderProgram.getProgram(); | ||
const options = builderProgram.getCompilerOptions(); | ||
let configFileParsingDiagnostics = []; | ||
const configFile = options.configFile; | ||
const configFilePath = options.configFilePath; | ||
if (configFile && configFilePath) { | ||
if (!configFileMap.has(configFile)) { | ||
const parsedConfigFile = CommandLineParser.updateParsedConfigFile(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath)); | ||
configFileMap.set(configFile, parsedConfigFile); | ||
} | ||
const parsedConfigFile = configFileMap.get(configFile); | ||
Object.assign(options, parsedConfigFile.options); | ||
configFileParsingDiagnostics = parsedConfigFile.errors; | ||
} | ||
const configFileParsingDiagnostics = updateConfigFile(options); | ||
let sourceFiles; | ||
@@ -196,8 +153,9 @@ if (!fullRecompile) { | ||
fullRecompile = errors.length > 0; | ||
host.onWatchStatusChange(diagnosticFactories.watchErrorSummary(errors.length), host.getNewLine(), options); | ||
host.onWatchStatusChange(cliDiagnostics.watchErrorSummary(errors.length), host.getNewLine(), options); | ||
}; | ||
} | ||
if (ts.sys.setBlocking) | ||
if (ts.sys.setBlocking) { | ||
ts.sys.setBlocking(); | ||
} | ||
executeCommandLine(ts.sys.args); | ||
//# sourceMappingURL=tstl.js.map |
@@ -17,2 +17,3 @@ "use strict"; | ||
const ts = require("typescript"); | ||
const cliDiagnostics = require("./cli/diagnostics"); | ||
const diagnosticFactories = require("./diagnostics"); | ||
@@ -86,3 +87,3 @@ const NoImplicitSelfTransformer_1 = require("./NoImplicitSelfTransformer"); | ||
const optionName = `${transformerOptionPath}.transform`; | ||
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "string") }; | ||
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "string") }; | ||
} | ||
@@ -138,3 +139,3 @@ let resolved; | ||
const optionName = `--${transformerOptionPath}.type`; | ||
return { error: diagnosticFactories.argumentForOptionMustBe(optionName, "program") }; | ||
return { error: cliDiagnostics.argumentForOptionMustBe(optionName, "program") }; | ||
} | ||
@@ -144,7 +145,7 @@ } | ||
const optionName = `${transformerOptionPath}.after`; | ||
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "boolean") }; | ||
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "boolean") }; | ||
} | ||
if (typeof afterDeclarations !== "boolean") { | ||
const optionName = `${transformerOptionPath}.afterDeclarations`; | ||
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "boolean") }; | ||
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "boolean") }; | ||
} | ||
@@ -151,0 +152,0 @@ if (typeof transformer === "function") { |
import * as ts from "typescript"; | ||
declare module "typescript" { | ||
function createDiagnosticReporter(system: ts.System, pretty?: boolean): ts.DiagnosticReporter; | ||
function createWatchStatusReporter(system: ts.System, pretty?: boolean): ts.WatchStatusReporter; | ||
interface System { | ||
setBlocking?(): void; | ||
} | ||
interface Statement { | ||
@@ -4,0 +9,0 @@ jsDoc?: ts.JSDoc[]; |
{ | ||
"name": "typescript-to-lua", | ||
"version": "0.28.0", | ||
"version": "0.28.1", | ||
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", | ||
@@ -47,2 +47,3 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", | ||
"devDependencies": { | ||
"@types/fs-extra": "^8.0.1", | ||
"@types/glob": "^7.1.1", | ||
@@ -53,2 +54,3 @@ "@types/jest": "^24.0.15", | ||
"fengari": "^0.1.4", | ||
"fs-extra": "^8.1.0", | ||
"javascript-stringify": "^2.0.0", | ||
@@ -55,0 +57,0 @@ "jest": "^24.8.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
610905
141
9719
14