Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
package.json
is a useful to be able to read inside the source code. This is because it contains version information that we often need to provide in our own program.There are 2 ways of acquiring the
package.json
:The former is using ES6 imports, and will trigger typescript to resolve and compile it.
TSC will ask for
resolveJsonModule: true
option intsconfig.json
. However if we enable it to be true, then thepackage.json
file will be copied in thedist/
directory.At this point in time, we don't really want this, although we could adapt by changing the
main
andtypes
path inpackage.json
.Ideally TSC will just not copy
package.json
, but there's only 2 ways to do this.First way is to remove
resolveJsonModule: true
so that it's not resolved. Then make tsc ignore the error:Then when compiling it works.
Second way, just use
require
, and tsc will ignore it.The second way is not as good idea if we want to later move to ES6 style imports/exports as in #32.
The first way has one limitation, the
resolveJsonModule
must be false. This means we are making TSC not check/resolve the json module at all and therefore there's no type information. This means we cannot use import json module anywhere, and TSC won't have any type information about JSON that is imported.This can be a problem, and then JSON would have to be considered non-source code, but instead static assets that should be acquired elsewhere.
An alternative to this solution is https://stackoverflow.com/a/61467483/582917 and https://stackoverflow.com/a/61467483/582917. These suggest creating a
tsconfig.json
undersrc
as well astsconfig.json
in the root.In our PK code, we have to use
resolveJsonModule: true
(due to our json schema), so our only option is to userequire
right now. We must continue this PR to try the other solutions so that #32 can be used.Tasks
require
method@ts-ignore
methodFinal checklist