Skip to content

Conversation

@jtenner
Copy link
Contributor

@jtenner jtenner commented Aug 27, 2019

Todo:

  • Testing
  • Document code
  • Readme
  • package.json

Currently the algorithm is functional but could be optimized.

Supports async package resolution for ide plugins and eventually the compiler too.

const fileRelativePath = this.file;
const packageJsonPath = path.join(moduleFolder, "package.json");
const pkg = readFileSync(packageJsonPath);
let ascFolder = "assembly";
Copy link
Member

@MaxGraey MaxGraey Aug 27, 2019

Choose a reason for hiding this comment

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

I guess better move "assembly" out to top level const and call something like const ASC_DEFAULT_FOLDER = "assembly", and here use let ascFolder = ASC_DEFAULT_FOLDER

Copy link
Contributor Author

@jtenner jtenner Aug 27, 2019

Choose a reason for hiding this comment

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

We aren't satisfied with any of the implementation. This will likely change. Considder my pull request a draft.

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 also appears that @willemneal is porting this whole algorithm to TypeScript. Should be able to generate the Types and portable es5 js.

Copy link
Contributor Author

@jtenner jtenner left a comment

Choose a reason for hiding this comment

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

These changes I've submitted are todos. Feel free to comment @dcodeIO and @MaxGraey

Package = 2,
}

export function resolve(fromSourcePath, toSourcePath, args, sourcePathType = SourceType.Local) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing about the lib folders in the args object is that it should be an array of absolute paths. Perhaps we should name the parameters this:

export function resolve(absoluteFromSource: string, relativeToSource: string, absoluteLibFolders: string[] = [], pathFolders: string[] = [], fromSourceType: SourceType): Entry[];

Also, what should we name the Entry class? It represents a potential module resolution point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe Address? Also how about args as an interfaces { lib: string[]; path: string[]} so we can just pass that in from the compiler as is?

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 lib folders work if they are relative to cwd?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they have to be relative to baseDir. So we could just turn them into absolute paths, or pass a baseDir.

: string = null;
url: url.UrlWithStringQuery = null;

constructor(public file: string = null, public type: SourceType = SourceType.Local, packageFolder = "") {
Copy link
Contributor Author

@jtenner jtenner Aug 27, 2019

Choose a reason for hiding this comment

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

We need to comment this constructor function way better.

const packageFolder = path.join(fromSourceFolder, moduleFolder, toSourceStart);

// create two entries and assume file.ts first over file/index.ts
if (toSourceEnd !== "") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why this if exists is because the first entry assumes that the package folder is toSourceEntries.join(path.sep) in totality. The only thing it could possibly be at this point is {package}/assembly/index.ts. Perhaps we should remove this if statement and copy the second push out of the loop, starting said loop with i = 1.

function resolveFromUrl(fromSourcePath: string, toSourcePath: string, args: any): Entry[] {
const isRelativePath = toSourcePath.startsWith(".");
if (isRelativePath) {
const resolved = url.resolve(fromSourcePath, toSourcePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if this works completely. We should look into url joining algorithms :)

#!/usr/bin/env node
const { resolve, SourceType } = require("./index");
const { deepEqual } = require("assert");
const snapshots = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Write all the tests here. All we care about is the fact that it generates every possibility correctly, In the case of Assembly folder determination using ascMain, that is done in the resolveSync() function. All we care is that each of the data properties are generated correctly. We could even do JSON.stringify(result, null, 2) and use the diff package do show the difference between the snapshots at test time.

@@ -0,0 +1,20 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might like to regenerate this with tsc --init. Modify the tsc values there.

@jtenner
Copy link
Contributor Author

jtenner commented Mar 31, 2020

This should be closed :).

@jtenner jtenner closed this Mar 31, 2020
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.

3 participants