Skip to content

Conversation

@ark120202
Copy link
Contributor

@ark120202 ark120202 commented Jul 27, 2020

Closes #432.

  • This PR implements node-like resolution within rootDir. For example, now "./foo" may resolve to "./foo.ts" and "./foo/index.ts". Resolution that goes into node_modules out of project root is not implemented yet.
  • Failure to resolve an imported file now adds an error diagnostic. Modules that are provided by environment should be marked with a @noResolve annotation, or should imported with non-esm syntax (i.e. using require)
  • Imports that resolve to .lua files now would be included in the Transpiler output.

@ark120202 ark120202 force-pushed the node-module-resolution branch 4 times, most recently from 3fc08f9 to dd66b88 Compare October 19, 2020 14:36
@ark120202 ark120202 force-pushed the node-module-resolution branch from dd66b88 to 260c71d Compare October 20, 2020 06:21
"ts-node": "^8.6.2"
},
"peerDependencies": {
"ts-node": "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this as peer dependency? isn't the regular dev dependency enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optional peer dependency. It is required for Yarn 2, since it doesn't allow importing unreferenced packages

{
name: "mode",
description:
'In "lib" mode, imported modules are emitted without being resolved. Visit https://typescripttolua.github.io/docs/TODO for more details.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Make sure documentation link leads somewhere.

import { Chunk } from ".";
import { CompilerOptions } from "../../CompilerOptions";

export function chunkToAssets(chunk: Chunk, options: CompilerOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the 'Assets' name (also for the file name), it's too generic. What does this mean? Maybe we can come up with a more descriptive name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ts.createProgram(Object.keys(input), options, compilerHost);
}

export interface TranspiledFile {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be in utils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't generic utils, but utils for managed-api (they are in a separate file because we import them in tests). TranspiledFile is the result of createEmitOutputCollector defined below


const srcFilePath = path.resolve(__dirname, "errors", "error.ts");
const outFilePath = path.resolve(__dirname, "errors", "error.lua");
const srcFilePath = resolveFixture("errors/error.ts");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these paths normalized to work on windows too? Thoughts about making resolveFixture (...parts: string[]) => path.resolve(__dirname, "__fixtures__", ...parts);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally TypeScript normalizes user-supplied paths to /, so mixed ones are fine too. I don't mind making these platform-specifc if you'd like though


test("resolve relative module paths", () => {
const result = loadConfigImport("test", "test", resolveFixture("load-config-import"), "./ts.ts");
expect(result).toMatchObject({ result: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the only thing we can assert here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestions? loadConfigImport returns whatever is exported by specified file

@Zamiell
Copy link
Contributor

Zamiell commented Apr 17, 2021

Would love to see this merged, what is the status of this PR?

@Perryvw
Copy link
Member

Perryvw commented Apr 18, 2021

Would love to see this merged, what is the status of this PR?

We still want this functionality, but this PR is stale and not ready. This will most likely not be merged, but parts of it will end up in other changes as we add this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New module resolution and Compilation structure

3 participants