Skip to content

Commit

Permalink
New emit pipeline and API/CLI refactor (#511)
Browse files Browse the repository at this point in the history
* New emit pipeline and API/CLI refactor

* Move high-level API to index file

* Extract multi-file `transpileString`  input to `transpileVirtualProgram`

* Return an results from emitTranspiledFiles instead of a using a callback

* Refactor CommandLineParser and further CLI refactor

* Fix strict issues

* Fix rootDir and outDir defaults always being used

* Remove failing test

* Remove command line parser tests that test standard TS parser features

* Use tsconfig source file during parse to get better diagnostics

* Parse command line options more similar to typescript

* Refactor commandLineParser tests

* Rename transpileVirtualProgram to transpileVirtualProject

* Remove export from CLI

* Add expect(received).toHaveDiagnostics() matcher

* Parse command line options case-insensitively

* Disallow unknown options in "tstl" config object

* Rename compiler tests to CLI tests

* Refactor CLI tests

* Add transpile tests

* Fix invalid behavior with relative outFile and outDir

* Rename getTranspileOutput to getTranspilationResult

* Remove `options` argument from `getTranspilationResult`

* Rename getTranspilationResult to transpile

* Extract luaLibImport to a variable

* Add command line parsing integration tests

* Make diagnostics use node's source file instead of transformed one

* Cast getCompilerOptions calls to custom compiler options

* Export TranspileError and all LuaTransformer exports from package index

* Remove options argument from LuaTransformer

* Rename sourceFile variable

* Set printer default during destructuring

* Rename

* Use emitTranspiledFiles in transpileFiles and transpileProject

* Use transpileFiles in transpile tests runner

* Fix typos

* Deprecate root-level options

* Move TranspileError diagnostic to diagnostics.ts

* Add source to custom diagnostics

* Show custom diagnostics as `TSTL<code>` in CLI

* Fix quotes

* Always import tstl as a namespace in tests

* Simplify tstl object formatting in deprecation warning

* Add Lua AST to TranspiledFile interface
  • Loading branch information
ark120202 authored and Perryvw committed May 2, 2019
1 parent 247ceba commit 5d4ed09
Show file tree
Hide file tree
Showing 67 changed files with 1,747 additions and 1,616 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/dist
/coverage
/test/compiler/testfiles/invalid_syntax.ts
/test/translation/transformation/characterEscapeSequence.ts

/src
Expand Down
43 changes: 18 additions & 25 deletions build_lualib.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
import * as fs from "fs";
import * as glob from "glob";
import { compile } from "./src/Compiler";
import { LuaLib as luaLib, LuaLibFeature } from "./src/LuaLib";
import * as path from "path";
import * as ts from "typescript";
import * as tstl from "./src";
import { LuaLib } from "./src/LuaLib";

const bundlePath = "./dist/lualib/lualib_bundle.lua";
const options: tstl.CompilerOptions = {
skipLibCheck: true,
types: [],
luaLibImport: tstl.LuaLibImportKind.None,
luaTarget: tstl.LuaTarget.Lua51,
noHeader: true,
outDir: path.join(__dirname, "./dist/lualib"),
rootDir: path.join(__dirname, "./src/lualib"),
};

compile([
"--skipLibCheck",
"--types",
"node",
"--luaLibImport",
"none",
"--luaTarget",
"5.1",
"--noHeader",
"--outDir",
"./dist/lualib",
"--rootDir",
"./src/lualib",
"--noHeader",
"true",
...glob.sync("./src/lualib/**/*.ts"),
]);
// TODO: Check diagnostics
const { emitResult } = tstl.transpileFiles(glob.sync("./src/lualib/**/*.ts"), options);
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));

const bundlePath = path.join(__dirname, "./dist/lualib/lualib_bundle.lua");
if (fs.existsSync(bundlePath)) {
fs.unlinkSync(bundlePath);
}

const features = Object.keys(LuaLibFeature).map(
lib => LuaLibFeature[lib as keyof typeof LuaLibFeature],
);
const bundle = luaLib.loadFeatures(features);
fs.writeFileSync(bundlePath, bundle);
fs.writeFileSync(bundlePath, LuaLib.loadFeatures(Object.values(tstl.LuaLibFeature)));
10 changes: 8 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ const isCI = require("is-ci");
/** @type {Partial<import("@jest/types").Config.DefaultOptions>} */
module.exports = {
testMatch: ["**/test/**/*.spec.ts"],
collectCoverageFrom: ["<rootDir>/src/**/*", "!<rootDir>/src/lualib/**/*"],
watchPathIgnorePatterns: ["/watch\\.ts$"],
collectCoverageFrom: [
"<rootDir>/src/**/*",
"!<rootDir>/src/lualib/**/*",
// https://github.com/facebook/jest/issues/5274
"!<rootDir>/src/tstl.ts",
],
watchPathIgnorePatterns: ["cli/watch/[^/]+$"],

setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
testEnvironment: "node",
testRunner: "jest-circus/runner",
preset: "ts-jest",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@types/glob": "^5.0.35",
"@types/jest": "^24.0.11",
"@types/node": "^9.6.23",
"@types/node": "^11.13.0",
"fengari": "^0.1.2",
"glob": "^7.1.2",
"jest": "^24.5.0",
Expand Down

0 comments on commit 5d4ed09

Please sign in to comment.