-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
transform: remove ".ts" extension in output #5395
Comments
Hi Luke, are we talking about a feature request for the up coming transformer https://www.npmjs.com/package/oxc-transform or something else? |
Hey -- Yes, I'm using that package, but it's currently a bug and not a feature request. When transforming TS source to JS, the generated JS still has imports referencing |
For reproduction: import { transform } from "oxc-transform";
let sourceText = `
import { join } from 'node:path';
import * as walk from './walk.ts';
import type { Options } from './walk.ts';
export type { Options };
export function up(name: string, options?: Options): string | undefined {
// ...
}
`
console.log(transform("asdf.ts", sourceText, {
typescript: {
onlyRemoveTypeImports: true,
declaration: true,
}
}))
|
(On an unrelated note, |
@Dunqing apparently we need to port https://babel.dev/docs/babel-preset-typescript#rewriteimportextensions import { transformSync } from "@babel/core";
let sourceText = `
import { join } from 'node:path';
import * as walk from './walk.ts';
import type { Options } from './walk.ts';
export type { Options };
export function up(name: string, options?: Options): string | undefined {
// ...
}
`
console.log(
transformSync(sourceText, {
presets: [["@babel/preset-typescript", { onlyRemoveTypeImports:true, rewriteImportExtensions:true }]],
filename: 'script.ts',
})
)
|
We'll align everything with babel. |
That |
Interesting, I suppose we need to change the API to allow removal. I see people had to come up with more plugins to fix this problem https://www.npmjs.com/package/babel-plugin-replace-import-extension?activeTab=readme 🤯 |
|
Well, babel predates TS and export conditions, which are the two main players in affecting path resolution. Babel also positions itself & wants to be the be-all, end-all... AKA, it assumes it's always the final build. I didn't know that OXC is aligning with Babel. NGL that makes me really nervous |
Our goal is not 100% compat, but we are currently aligning with Babel 8 to bootstrap ourself, otherwise we'll never ship. (Babel 8 is never going to be shipped isn't it ...) We can always bend the API to allow current and future use cases. |
The latest oxc-transform@v0.26.0 includes the option In: let ret = transform("asdf.ts", sourceText, {
typescript: {
onlyRemoveTypeImports: true,
rewriteImportExtensions: 'remove',
declaration: true,
}
});
console.log('Transformed:')
console.log(ret.code);
console.log('Declaration:')
console.log(ret.declaration); Out:
|
Declarations shouldn't remove extensions right? Otherwise type resolution will fail. |
They should be removed. If only publishing a build/ directory with the JS and DTS, the dts points to nothing if retains the *.ts import |
I don't fully understand why we need to remove them, I have tried the above example in We are looking at your build script https://github.com/lukeed/empathic/blob/efc67f9c7fc5d2b0a6d748eeabc8a45d35c0a799/scripts/build.ts Updated: After looking at your script, I thought I knew why you needed to remove them; The transformed .d.ts file is named *.d.mts. So those .d.ts files don't exist anymore. |
Given that this is typically used for library/bundler transformations, the generated output shouldn't contain extensions in the output.
I suppose the jury can still be out in regards to JS extensions, but TS extensions should definitely not be there.
Input
Output
Desired
Because this particular case is a library,
./walk
will be re-resolved to the correct"exports"
condition when needed.And arguably, any bundler (or even runtime) contexts that ingest an extension-less import will still be able to resolve the local file sibling.
The text was updated successfully, but these errors were encountered: