-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add back TypeScript version for -v flag using package.json info #1676
Conversation
@@ -129,6 +129,11 @@ deno_cargo_info = exec_script("build_extra/rust/get_cargo_info.py", | |||
[ rebase_path("Cargo.toml", root_build_dir) ], | |||
"json") | |||
|
|||
# Reads the typescript info from package.json | |||
deno_ts_info = exec_script("build_extra/rust/get_ts_info.py", |
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.
Hrm. This works, but it's kinda ad hoc... We have a similar situation with deno.platform
where we need to inject some information into the build. It's done using rollup here:
Lines 92 to 124 in 748b0f9
/** Inject deno.platform.arch and deno.platform.os | |
* @param {any} param0 | |
*/ | |
function platform({ include, exclude } = {}) { | |
if (!include) { | |
throw new Error("include option must be passed"); | |
} | |
const filter = createFilter(include, exclude); | |
return { | |
name: "platform", | |
/** | |
* @param {any} _code | |
* @param {string} id | |
*/ | |
transform(_code, id) { | |
if (filter(id)) { | |
// Adapted from https://github.com/rollup/rollup-plugin-inject/blob/master/src/index.js | |
const arch = archNodeToDeno[process.arch]; | |
const os = osNodeToDeno[process.platform]; | |
// We do not have to worry about the interface here, because this is just to generate | |
// the actual runtime code, not any type information integrated into Deno | |
const magicString = new MagicString(` | |
export const platform = { arch: "${arch}", os:"${os}" };`); | |
return { | |
code: magicString.toString(), | |
map: magicString.generateMap() | |
}; | |
} | |
} | |
}; | |
} |
What do you think about doing something similar for the TS version?
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.
Yeah, I think that makes much more sense, though it sort of would be great not to have to go to JavaScript at all, the other two strings exist in Rust already and we pass it to JS to just print it out.
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.
Yeah it should also work (this platform injection was also done by me quite a while ago). Probably we can centralize all the injected variables during build in a single file (to avoid being too messy in the future when we possibly also inject other stuff)? I'll go and work on that if sound okay.
Another problem I realized with GN injection is that it would not work with cargo build
, unless specially handled in build.rs
...
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.
though it sort of would be great not to have to go to JavaScript at all
I don't think that's worth optimizing for.
Another problem I realized with GN injection is that it would not work with
cargo build
, unless specially handled inbuild.rs
...
Good point
It would be good to have access to the versions in the runtime environment - maybe that can be done as part of this work... deno.version.v8
for example would be nice to have.
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.
How about using rollup-plugin-replace for embedding the version number in script? The plugin can replace certain types of symbols in scripts with the supplied values.
I did a simple experiment using rollup-plugin-replace on my fork. It seems working and this looks a little simpler than this patch (the diff is +11,-2). @kevinkassimo @ry |
@kt3k SGTM. I'll close this once you have your PR set up. |
Closed in favor of #1788 |
Similar to the way we pass
deno
crate version