-
Notifications
You must be signed in to change notification settings - Fork 566
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
feat(typescript/combine-json): add .ts file processing if runtime sup… #1392
Conversation
This pull request is automatically being deployed by Amplify Hosting (learn more). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few notes, but overall I like adding support for "native" TS token files.
- can you add a changeset with
npx changeset
locally, probably a minor bump for this - I wonder if it would be possible to create a test for this feature that we only run in the CI workflow for node version which supports the strip types experimental flag, and run Node in the CI with that flag. The test would have to run conditionally based on whether the flag is active, maybe with some kind of environment variable
For reference here is the example log output for running Could not import TypeScript file: ./tokens/token.ts
Executing typescript files during runtime is only possible via
- 'node >= 22.6.0' with '--experimental-strip-types'
Alternatively by using 'deno' or 'bun'
If you are not able to satisfy the above requirements, consider transpiling the TypeScript file to plain JavaScript before running the Style Dictionary build process.
node:internal/modules/esm/get_format:218
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Failed to load or parse JSON or JS Object: Failed to load or parse JSON or JS Object: Unknown file extension ".ts" for ./tokens/token.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:218:9)
at defaultGetFormat (node:internal/modules/esm/get_format:244:36)
at defaultLoad (node:internal/modules/esm/load:122:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:570:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:443:45)
at async ModuleJob._link (node:internal/modules/esm/module_job:106:19) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Node.js v22.9.0 |
6f13a1c
to
98e58f3
Compare
f29c831
to
dbd368d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started adding some more tests and realised we would probably want to support TS configs as well, we had some duplicate code going on. So I extracted the file loading stuff into its own util, with its own tests. It's much cleaner now I think.
I also made it a minor bump since this new feature is pretty significant.
@dbanksdesign needs your review since I now co-authored this PR instead of only reviewing.
Any updates on this? |
Rebased & fixed one failing test, just waiting now for approval by Amazon, imo this should be in next release indeed, but depends a bit on @dbanksdesign 's availability as for when that happens, we have quite a few other ready PRs that I also wanna include that need approval as well. 4.3.0 will be a big one :) |
As described in #1391 many runtimes implement support for executing
.ts
files without any need for transpilation.It seems the only problem is that
style-dictionary
tries to parse.ts
files withJSON5.parse
rather than just importing the file like the regular.js
files.I've tested the changes with:
deno
v2.0.0
node --experimental-strip-types
v22.9.0
bun
v1.1.29
closes #1391
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.