-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as go } from "./go/module.js"; | ||
export { default as python } from "./python/module.js"; | ||
export { default as ruby } from "./ruby/module.js"; | ||
export { default as typescript } from "./typescript/module.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import swc from "@swc/core"; | ||
|
||
const options = { | ||
jsc: { | ||
parser: { | ||
syntax: "typescript", | ||
}, | ||
target: "esnext", | ||
}, | ||
}; | ||
|
||
|
||
const transform = code => swc.transform(code, options); | ||
|
||
export default async code => (await transform(code)).code; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { filter } from "rcompat/object"; | ||
import { peers } from "../common/exports.js"; | ||
import depend from "../depend.js"; | ||
|
||
export default ({ | ||
extension = ".ts", | ||
} = {}) => { | ||
const name = "typescript"; | ||
const dependencies = ["@swc/core"]; | ||
const on = filter(peers, ([key]) => dependencies.includes(key)); | ||
let transpile; | ||
|
||
return { | ||
name: `primate:${name}`, | ||
async init(app, next) { | ||
await depend(on, `binding:${name}`); | ||
|
||
transpile = (await import("./imports.js")).default; | ||
|
||
return next(app); | ||
}, | ||
async stage(app, next) { | ||
app.register(extension, { | ||
route: async (directory, file) => { | ||
const path = directory.join(file); | ||
const base = path.directory; | ||
const js = path.base.concat(".js"); | ||
await base.join(js).write((await transpile(await path.text()))); | ||
}, | ||
}); | ||
return next(app); | ||
}, | ||
}; | ||
}; |