Skip to content

Import not generated #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oleersoy opened this issue Jul 7, 2019 · 15 comments · Fixed by #61
Closed

Import not generated #24

oleersoy opened this issue Jul 7, 2019 · 15 comments · Fixed by #61
Labels
Bug Something isn't working

Comments

@oleersoy
Copy link

oleersoy commented Jul 7, 2019

ObjectErrors import ValidationError.

When the projects build is run, the import is not generated. I think it's because ObjectErrors and ValidationError both reside in the same directory.

If I do not use a paths import, but instead switch it to a relative import, then the build generates the import.

To see the current behavior:

git clone [email protected]:fireflysemantics/validator.git
npm run dist

Look at dist/container/error/ObjectErrors.d.ts. It will be missing the ValidationError import.

@oleersoy
Copy link
Author

oleersoy commented Jul 7, 2019

Found another one. Inisde the ValidatorError the ValidationContext import is not being generated:

https://github.com/fireflysemantics/validator/blob/master/src/container/error/ValidationError.ts

@oleersoy
Copy link
Author

oleersoy commented Jul 7, 2019

I'm finding more now. Looks like a lot of imports are not being generated in general.

@oleersoy
Copy link
Author

oleersoy commented Jul 7, 2019

Before switching over to this plugin I was using a pretty simple script to perform the path translations:

const fs = require("fs");
const globby = require("globby");
const cpy = require("cpy"); 
require("mkdirp").sync("dist");
cpy("package.json", "dist");
cpy("README.md", "dist");
cpy("src/index.ts", "dist");
const options = { overwrite: true };
const rc = require("recursive-copy");
rc("target/src/", "dist", options).then(() => {
  globby("./dist/**/*.js")
    .then(paths => {
      paths.forEach(update);
    })
    .catch(e => console.log(e));

    globby("./dist/**/*.d.ts")
    .then(paths => {
      paths.forEach(update);
    })
    .catch(e => console.log(e));   
});

function update(path) {
  count = (path.match(/\//g) || []).length;
  let replacement = "";
  if (count == 2) {
    replacement = "./";
  } else if (count > 2) {
    const size = count - 2;
    replacement = Array(size)
      .fill("../")
      .join("");
  } else {
    throw new Error("Invalid / count in path of file");
  }
  let js = fs.readFileSync(path, "utf8");
  js = js.replace(/@fs\//g, replacement);
  fs.writeFileSync(path, js);
}

I worked perfectly. Perhaps the algorithm could be incorporated here.

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

I'm going to change the paths that are not being generated back to relative paths. This is the commit ID for the build that has the errors:

fireflysemantics/validator@24e5eee

It's corresponds to package version 1.18. The new release will have version 1.19.

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

I noticed that for these imports:

import { ValidationContext } from "./";
import { getPropertyKey } from "../../utilities/utilities";
import { isDefined } from "@fireflysemantics/is";
import { MetaClass } from "@fs/container/validation";

The imports IsDefined and MetaClass are not imported. That's OK because they are not part of the .d.ts type information. So I wonder if the plugin is confused WRT which nodes are part of the .d.ts type information and which ones are not.

@danielpza danielpza added the Bug Something isn't working label Jul 9, 2019
danielpza added a commit that referenced this issue Jul 9, 2019
@danielpza
Copy link
Member

A fix is up with v1.1.5, please upgrade. It should also fix #23 and #22.

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

Awesome - Will try it out ASAP!! THANKS!!

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

OK - Hopefully just one weird bug left. In src/container/validation/index.ts I have the following exports:

export { MetaClass } from "@fs/container/validation/MetaClass";
export { ValidationContainer } from "@fs/container/validation/ValidationContainer";
export { ValidationContext } from "@fs/container/validation/ValidationContext";
export { ValidationOptions } from "@fs/container/validation/ValidationOptions";

When the build runs the corresponding index.d.ts file has these exports:

export { MetaClass } from "./MetaClass";
export { ValidationContainer } from "./ValidationContainer";
export { ValidationContext } from "./ValidationContext";

So it left off the

export { ValidationOptions } from "@fs/container/validation/ValidationOptions";

Export. Thoughts?

@danielpza
Copy link
Member

I added a regression test and a fix in 0263f06, could you test it and see if there's any other issues before deploying a new version?, is fine either way

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

Sure - I'm cloning it right now.

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

I just tested it with the cloned install, and it looks like the ValidationOptions export is still missing.

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

Actually - Hold on - I think maybe the install of the clone did not go right. Looking at it now.

@danielpza
Copy link
Member

nvm, cool, if you find any other issue let me know. Thanks a lot for the feedback

@oleersoy
Copy link
Author

oleersoy commented Jul 9, 2019

OK - Just tested it - And it's looking good! Thanks again! You rock!

@danielpza
Copy link
Member

v1.1.6 is up

danielpza pushed a commit that referenced this issue Jul 30, 2020
* Multiple Issue Fixes

- Allow more than one path routing (fixes #60)
- Remove implicit extensions from output (fixes #24)
- Properly implemented isTypeOnly (fixes #48)
- Corrected errors in tests due to TS changing logic for type only star exports
- Bonus: Made package zero-dependency

* Removed accidental dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants