slint/api/sixtyfps-node/loader.mjs
Olivier Goffart 13c7e0dec8 Begin working on a Node API
Currently, the followinf command in the example/nodetest directory works:
    npm install ../../api/sixtyfps-node && node main.js
2020-06-03 17:33:05 +02:00

39 lines
No EOL
1.1 KiB
JavaScript

import { URL, pathToFileURL } from 'url';
const extensionsRegex = /\.60$/;
const baseURL = pathToFileURL(`${process.cwd()}/`).href;
export function resolve(specifier, context, defaultResolve) {
const { parentURL = baseURL } = context;
if (extensionsRegex.test(specifier)) {
return { url: new URL(specifier, parentURL).href };
}
return defaultResolve(specifier, context, defaultResolve);
}
export function getFormat(url, context, defaultGetFormat) {
if (extensionsRegex.test(url)) {
return {
format: 'module'
};
}
return defaultGetFormat(url, context, defaultGetFormat);
}
export function transformSource(source, context, defaultTransformSource) {
const { url, format } = context;
if (extensionsRegex.test(url)) {
console.log(`This is where one can compile ${url}`)
return {
source: "console.log('Hey'); export function foo(x) { return x + 55 }"
};
}
// Let Node.js handle all other sources.
return defaultTransformSource(source, context, defaultTransformSource);
}