-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Feature: Append file extension based on runtime #936
base: main
Are you sure you want to change the base?
Changes from all commits
a193017
a7cc9f4
9e3408f
06a4b95
3092cf0
1f04b9b
8512ed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// global.d.ts | ||
|
||
declare const Deno: | ||
| { | ||
version: { deno: string; typescript: string; v8: string }; | ||
// Add more Deno-specific properties here if needed | ||
} | ||
| undefined; | ||
|
||
declare const Bun: | ||
| { | ||
version: string; | ||
// Add more Bun-specific properties here if needed | ||
} | ||
| undefined; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ import { createRequire } from 'node:module'; | |
import path from 'node:path'; | ||
|
||
import { getConfig, isStandaloneClient } from '../utils/config'; | ||
import { appendExt } from '../utils/extension'; | ||
import { ensureDirSync } from './utils'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
export const clientModulePath = () => { | ||
const config = getConfig(); | ||
return config.client.bundle ? './client' : config.client.name; | ||
|
||
return appendExt(config.client.bundle ? './client' : config.client.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add extension to node_modules imports too? This may generate code like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, only for relative/absolute paths or importing specific files. I see, Id have to check then how to differentiate if its coming from core or an external package... |
||
}; | ||
|
||
export const clientOptionsTypeName = () => 'Options'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isDenoRuntime } from './runtime'; | ||
|
||
/** | ||
* Appends the file extension to a file name based on the current runtime | ||
* | ||
* Some TS runtimes require using the complete path for import/export, | ||
* including the extension | ||
*/ | ||
export const appendExt = (fileName: string): string => { | ||
if (isDenoRuntime()) { | ||
return `${fileName}.ts`; | ||
} | ||
return fileName; | ||
}; | ||
|
||
/** | ||
* Returns the file extension based on the current runtime | ||
*/ | ||
export const getExt = (): string => appendExt(''); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Runtime detection functions | ||
|
||
export const isNodeRuntime = (): boolean => | ||
typeof process !== 'undefined' && | ||
typeof process.versions !== 'undefined' && | ||
typeof process.versions.node !== 'undefined'; | ||
|
||
export const isDenoRuntime = (): boolean => | ||
typeof Deno !== 'undefined' && typeof Deno.version !== 'undefined'; | ||
|
||
export const isBunRuntime = (): boolean => | ||
typeof Bun !== 'undefined' && typeof Bun.version !== 'undefined'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,10 @@ | |
}, | ||
"exclude": ["node_modules", "**/__mocks__"], | ||
"files": ["./src/types/hbs.d.ts"], | ||
"include": ["./src/**/*.ts", "rollup.config.ts", "rollup.dts.config.ts"] | ||
"include": [ | ||
"global.d.ts", | ||
"./src/**/*.ts", | ||
"rollup.config.ts", | ||
"rollup.dts.config.ts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to add this file? |
||
] | ||
} |
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.
Is this file for the utils/runtime module?
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.
Yes, if not TypeScript (node) thinks it is an undeclared type since it is not aware of Deno and Bun (rightfully so)