Skip to content
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

scripts: Add script for changing all abs paths #402

Merged
merged 1 commit into from
Dec 16, 2023
Merged

Conversation

johannes-wolf
Copy link
Member

@johannes-wolf johannes-wolf commented Dec 13, 2023

This allows installing cetz with all paths in all *.typ files changed to relative ones.
@Andrew15-5: Please test this via just package <your-directory> --relative-paths.

As soon as Typst supports changing the package path, this cursed script must get removed.

@Andrew15-5
Copy link
Contributor

BTW, it's not great when you import the same published package multiple times. I had an issue (with cetz) where I thought I've changed the version, but actually I imported the same old version in different files. So I advise you to import external libraries somewhere once and then import that local file everywhere where you need external library API.

You can very easily forget to update all files that import the same package.

src/anchor.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

src/draw/grouping.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

src/coordinate.typ
3:#import "@preview/oxifmt:0.2.0": strfmt

src/util.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

@Andrew15-5
Copy link
Contributor

I test some basic stuff, and it works:

#import "./cetz/0.2.0/src/lib.typ" as cetz

#cetz.canvas({
  import cetz.draw: *
  circle(())
})

#cetz.canvas({
  import cetz.draw: *
  import cetz.plot
  plot.plot(size: (5, 5), {
    plot.add(domain: (-10, 10), x => x * x)
  })
})

#367 (comment):

I think Typst checks/imports everything first, before compiling, so the test is just "does it compile a document?" Although I'm not sure.

Indeed, it checks for everything, therefore if there is an invalid import, then the error must show up. So any "import cetz and compile" test should prevent any relative path bugs.

@Andrew15-5
Copy link
Contributor

Note this:

So the only thing that won't be noticed right away [by the compiler] is if if statement block isn't run or loop isn't run or a function isn't called, but all root imports/includes will 100% be checked.

@johannes-wolf
Copy link
Member Author

johannes-wolf commented Dec 13, 2023

Note this:

So the only thing that won't be noticed right away [by the compiler] is if if statement block isn't run or loop isn't run or a function isn't called, but all root imports/includes will 100% be checked.

So what? Test cases run all code (I guess). Imports in functions or ifs are fine.

@Andrew15-5
Copy link
Contributor

So what? Test cases run all code (I guess). Imports in functions or ifs are fine.

Then we are golden (good to go). If you run your regular tests after applying relative paths and before publishing the package, then no additional tests are necessary.

@johannes-wolf johannes-wolf merged commit a2dc617 into 0.2.0 Dec 16, 2023
2 checks passed
@johannes-wolf johannes-wolf deleted the relpaths branch December 16, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎁 Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants