How to get the file-path of the currently executing javascript code

Within the script: var scripts = document.getElementsByTagName(“script”), src = scripts[scripts.length-1].src; This works because the browser loads and executes scripts in order, so while your script is executing, the document it was included in is sure to have your script element as the last one on the page. This code of course must be ‘global’ to … Read more

How to eliminate absolute path in zip archive if absolute paths for files are provided?

The zipfile write() method supports an extra argument (arcname) which is the archive name to be stored in the zip file, so you would only need to change your code with: from os.path import basename … zip.write(first_path, basename(first_path)) zip.write(second_path, basename(second_path)) zip.close() When you have some spare time reading the documentation for zipfile will be helpful.

How to avoid using relative path imports (/../../../redux/action/action1) in create-react-app

Create a file called .env in the project root and write there: NODE_PATH=src Then restart the development server. You should be able to import anything inside src without relative paths. Note I would not recommend calling your folder src/redux because now it is confusing whether redux import refers to your app or the library. Instead … Read more

Expand a possible relative path in bash

MY_PATH=$(readlink -f $YOUR_ARG) will resolve relative paths like “./” and “../” Consider this as well (source): #!/bin/bash dir_resolve() { cd “$1” 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status echo “`pwd -P`” # output full, link-resolved path } # sample usage if abs_path=”`dir_resolve \”$1\”`” … Read more

What’s a “canonical path”?

The whole point of making anything “canonical” is so that you can compare two things. For example, both ../../here/bar/x and ./test/../../bar/x may refer to the same location, but you can’t do a textual comparison on the two paths. However, if you turn them into their canonical representation, they both become ../bar/x, and we see that … Read more

Jest + Typescript + Absolute paths (baseUrl) gives error: Cannot find module

I was struggling with the same problem and actually it turns out that a simple change seems to do the trick. I just updated the moduleDirectories field in jest.config.js. Before moduleDirectories: [‘node_modules’] After moduleDirectories: [‘node_modules’, ‘src’] Hope it helps.