-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup_piglet.mjs
29 lines (25 loc) · 973 Bytes
/
rollup_piglet.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {createFilter} from '@rollup/pluginutils'
import * as path from 'node:path'
import * as url from "node:url"
import {intern, symbol, qsym, module_registry} from "./lib/piglet/lang.mjs"
import {PIGLET_PKG} from "./lib/piglet/lang/util.mjs"
import NodeCompiler from './lib/piglet/node/NodeCompiler.mjs'
const compiler = new NodeCompiler()
global.$piglet$ = module_registry.index
const PIGLET_PACKAGE_PATH = path.join(url.fileURLToPath(import.meta.url), "../packages/piglet")
await compiler.load_package(PIGLET_PACKAGE_PATH);
intern(symbol('piglet:lang:*compiler*'), compiler)
export default function(options) {
return {
transform: async function(code, id) {
let out = ""
compiler.hooks.js = (s) => out+=(s+";")
await compiler.load(qsym(`${PIGLET_PKG}:lang`))
await compiler.load_file(id)
return {
code: out,
map: {mappings: ''}
};
}
}
}