Skip to content

Commit 5d4ed09

Browse files
ark120202Perryvw
authored andcommitted
New emit pipeline and API/CLI refactor (#511)
* 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
1 parent 247ceba commit 5d4ed09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1747
-1616
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/dist
22
/coverage
3-
/test/compiler/testfiles/invalid_syntax.ts
43
/test/translation/transformation/characterEscapeSequence.ts
54

65
/src

build_lualib.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
import * as fs from "fs";
22
import * as glob from "glob";
3-
import { compile } from "./src/Compiler";
4-
import { LuaLib as luaLib, LuaLibFeature } from "./src/LuaLib";
3+
import * as path from "path";
4+
import * as ts from "typescript";
5+
import * as tstl from "./src";
6+
import { LuaLib } from "./src/LuaLib";
57

6-
const bundlePath = "./dist/lualib/lualib_bundle.lua";
8+
const options: tstl.CompilerOptions = {
9+
skipLibCheck: true,
10+
types: [],
11+
luaLibImport: tstl.LuaLibImportKind.None,
12+
luaTarget: tstl.LuaTarget.Lua51,
13+
noHeader: true,
14+
outDir: path.join(__dirname, "./dist/lualib"),
15+
rootDir: path.join(__dirname, "./src/lualib"),
16+
};
717

8-
compile([
9-
"--skipLibCheck",
10-
"--types",
11-
"node",
12-
"--luaLibImport",
13-
"none",
14-
"--luaTarget",
15-
"5.1",
16-
"--noHeader",
17-
"--outDir",
18-
"./dist/lualib",
19-
"--rootDir",
20-
"./src/lualib",
21-
"--noHeader",
22-
"true",
23-
...glob.sync("./src/lualib/**/*.ts"),
24-
]);
18+
// TODO: Check diagnostics
19+
const { emitResult } = tstl.transpileFiles(glob.sync("./src/lualib/**/*.ts"), options);
20+
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
2521

22+
const bundlePath = path.join(__dirname, "./dist/lualib/lualib_bundle.lua");
2623
if (fs.existsSync(bundlePath)) {
2724
fs.unlinkSync(bundlePath);
2825
}
2926

30-
const features = Object.keys(LuaLibFeature).map(
31-
lib => LuaLibFeature[lib as keyof typeof LuaLibFeature],
32-
);
33-
const bundle = luaLib.loadFeatures(features);
34-
fs.writeFileSync(bundlePath, bundle);
27+
fs.writeFileSync(bundlePath, LuaLib.loadFeatures(Object.values(tstl.LuaLibFeature)));

jest.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ const isCI = require("is-ci");
33
/** @type {Partial<import("@jest/types").Config.DefaultOptions>} */
44
module.exports = {
55
testMatch: ["**/test/**/*.spec.ts"],
6-
collectCoverageFrom: ["<rootDir>/src/**/*", "!<rootDir>/src/lualib/**/*"],
7-
watchPathIgnorePatterns: ["/watch\\.ts$"],
6+
collectCoverageFrom: [
7+
"<rootDir>/src/**/*",
8+
"!<rootDir>/src/lualib/**/*",
9+
// https://github.com/facebook/jest/issues/5274
10+
"!<rootDir>/src/tstl.ts",
11+
],
12+
watchPathIgnorePatterns: ["cli/watch/[^/]+$"],
813

14+
setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
915
testEnvironment: "node",
1016
testRunner: "jest-circus/runner",
1117
preset: "ts-jest",

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"devDependencies": {
4646
"@types/glob": "^5.0.35",
4747
"@types/jest": "^24.0.11",
48-
"@types/node": "^9.6.23",
48+
"@types/node": "^11.13.0",
4949
"fengari": "^0.1.2",
5050
"glob": "^7.1.2",
5151
"jest": "^24.5.0",

0 commit comments

Comments
 (0)