Skip to content

Commit b2f8d3c

Browse files
authored
Add support for .luau (roblox-ts#2802)
Depends on: - roblox-ts/path-translator#2 - roblox-ts/rojo-resolver#496 Allows for both emitting .luau files to `outDir` and importing packages contain `.luau` files (or `.lua` for backwards compatibility). Unit tests pass with the above two PR branches installed locally.
1 parent e6a6b3b commit b2f8d3c

10 files changed

+28
-19
lines changed

package-lock.json

+11-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"license": "MIT",
5050
"dependencies": {
5151
"@roblox-ts/luau-ast": "=2.0.0",
52-
"@roblox-ts/path-translator": "=1.0.0",
53-
"@roblox-ts/rojo-resolver": "=1.0.7",
52+
"@roblox-ts/path-translator": "^1.1.0",
53+
"@roblox-ts/rojo-resolver": "^1.1.0",
5454
"chokidar": "^3.6.0",
5555
"fs-extra": "^11.2.0",
5656
"kleur": "^4.1.5",

src/CLI/commands/build.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ export = ts.identity<yargs.CommandModule<object, BuildFlags & Partial<ProjectOpt
111111
.option("allowCommentDirectives", {
112112
boolean: true,
113113
hidden: true,
114+
})
115+
.option("luau", {
116+
boolean: true,
117+
describe: "emit files with .luau extension",
114118
}),
115119

116120
handler: async argv => {
@@ -134,7 +138,7 @@ export = ts.identity<yargs.CommandModule<object, BuildFlags & Partial<ProjectOpt
134138
setupProjectWatchProgram(data, projectOptions.usePolling);
135139
} else {
136140
const program = createProjectProgram(data);
137-
const pathTranslator = createPathTranslator(program);
141+
const pathTranslator = createPathTranslator(program, data);
138142
cleanup(pathTranslator);
139143
copyInclude(data);
140144
copyFiles(data, pathTranslator, new Set(getRootDirs(program.getCompilerOptions())));

src/CLI/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("should compile tests project", () => {
2727
}),
2828
);
2929
const program = createProjectProgram(data);
30-
const pathTranslator = createPathTranslator(program);
30+
const pathTranslator = createPathTranslator(program, data);
3131

3232
// clean outDir between test runs
3333
fs.removeSync(program.getCompilerOptions().outDir!);

src/Project/classes/VirtualProject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class VirtualProject {
110110
this.typeChecker = this.program.getTypeChecker();
111111

112112
const services = createTransformServices(this.typeChecker);
113-
const pathTranslator = new PathTranslator(ROOT_DIR, OUT_DIR, undefined, false);
113+
const pathTranslator = new PathTranslator(ROOT_DIR, OUT_DIR, undefined, false, this.data.projectOptions.luau);
114114

115115
const sourceFile = this.program.getSourceFile(PLAYGROUND_PATH);
116116
assert(sourceFile);
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { PathTranslator } from "@roblox-ts/path-translator";
22
import path from "path";
3+
import { ProjectData } from "Shared/types";
34
import { findAncestorDir } from "Shared/util/findAncestorDir";
45
import { getRootDirs } from "Shared/util/getRootDirs";
56
import ts from "typescript";
67

7-
export function createPathTranslator(program: ts.BuilderProgram) {
8+
export function createPathTranslator(program: ts.BuilderProgram, data: ProjectData) {
89
const compilerOptions = program.getCompilerOptions();
910
const rootDir = findAncestorDir([program.getProgram().getCommonSourceDirectory(), ...getRootDirs(compilerOptions)]);
1011
const outDir = compilerOptions.outDir!;
@@ -13,5 +14,5 @@ export function createPathTranslator(program: ts.BuilderProgram) {
1314
buildInfoPath = path.normalize(buildInfoPath);
1415
}
1516
const declaration = compilerOptions.declaration === true;
16-
return new PathTranslator(rootDir, outDir, buildInfoPath, declaration);
17+
return new PathTranslator(rootDir, outDir, buildInfoPath, declaration, data.projectOptions.luau);
1718
}

src/Project/functions/setupProjectWatchProgram.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function setupProjectWatchProgram(data: ProjectData, usePolling: boolean)
7575
const createProgram = createProgramFactory(data, options);
7676
function refreshProgram() {
7777
program = createProgram([...fileNamesSet], options);
78-
pathTranslator = createPathTranslator(program);
78+
pathTranslator = createPathTranslator(program, data);
7979
}
8080

8181
function runInitialCompile() {

src/Shared/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ export const DEFAULT_PROJECT_OPTIONS: ProjectOptions = {
5151
writeTransformedFiles: false,
5252
optimizedLoops: true,
5353
allowCommentDirectives: false,
54+
luau: true,
5455
};

src/Shared/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ProjectOptions {
1414
writeTransformedFiles: boolean;
1515
optimizedLoops: boolean;
1616
allowCommentDirectives: boolean;
17+
luau: boolean;
1718
}
1819

1920
export interface ProjectData {

tests/default.project.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ServerScriptService": {
1919
"$className": "ServerScriptService",
2020
"main": {
21-
"$path": "out/main.server.lua"
21+
"$path": "out/main.server.luau"
2222
},
2323
"tests": {
2424
"$path": "out/tests"
@@ -36,7 +36,7 @@
3636
"StarterGui": {
3737
"$className": "StarterGui",
3838
"isolated": {
39-
"$path": "out/helpers/rojo/isolated.lua"
39+
"$path": "out/helpers/rojo/isolated.luau"
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)