A bit of context: to facilitate the consumption of @useoptic/optic, we package it using pkg to make it an executable.
If I run the diff command using native TypeScript compilers such as ts-node, I have no issue because the final HTML file resolves to a local file in my filesystem, for example, file:///Users/xxxxxxx/work/tools/tool-api-standards/node_modules/@useoptic/optic/web/build/index.html#W0cZF0U
During packaging process pkg collects project files and places them into executable. It is called a snapshot. At run time the packaged application has access to snapshot filesystem where all that files reside.
Packaged files have /snapshot/ prefix in their paths (or C:\snapshot\ in Windows). If you used pkg /path/app.js command line, then filename value will be likely /snapshot/path/app.js at run time. dirname will be /snapshot/path as well.
I think it is caused by maybeChangelogUrl found in the following line in combination with our use of pkg to make executables: maybeChangelogUrl
pkg recommends to use process.cwd() instead of __dirname
On the other hand, to access a real file system at run time (pick up a user’s external javascript plugin, JSON configuration or even get a list of the user’s directory) you should take process.cwd() or path.dirname(process.execPath)
One can assert the following is true: (process.execPath) === __dirname === true
🍗 Description
What does this PR do? Anything folks should know?
A bit of context: to facilitate the consumption of
@useoptic/optic
, we package it using pkg to make it an executable.If I run the diff command using native TypeScript compilers such as ts-node, I have no issue because the final HTML file resolves to a local file in my filesystem, for example,
file:///Users/xxxxxxx/work/tools/tool-api-standards/node_modules/@useoptic/optic/web/build/index.html#W0cZF0U
But because we package using pkg, it prefixes the local file path with snapshot, so it becomes:
file:///snapshot/tool-api-standards/node_modules/@useoptic/optic/web/build/index.html#W0cZF0U
I think it is caused by
maybeChangelogUrl
found in the following line in combination with our use of pkg to make executables: maybeChangelogUrlpkg recommends to use
process.cwd()
instead of__dirname
One can assert the following is true:
(process.execPath) === __dirname === true
đź“š References
Links to relevant docs (Notion, Twist, GH issues, etc.), if applicable. https://www.npmjs.com/package/pkg#snapshot-filesystem https://www.npmjs.com/package/ts-node
đź‘ą QA
How can other humans verify that this PR is correct?
When running
diff
with the--web
flag, it should open a browser window with the results.