Spaces:
Paused
Paused
Download node_modules/esrun/plugins/fileConstants.js from no1b4me/hytranslator: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/no1b4me/hytranslator/resolve/main/node_modules/esrun/plugins/fileConstants.js
- Command line
-
hf download hf://spaces/no1b4me/hytranslator/node_modules/esrun/plugins/fileConstants.js
-
curl -L -o fileConstants.js https://huggingface.co/spaces/no1b4me/hytranslator/resolve/main/node_modules/esrun/plugins/fileConstants.js
1.07 kB
| import { posix } from "path"; | |
| import process from "process"; | |
| import fs from "fs"; | |
| import { grub } from "@digitak/grubber"; | |
| export const fileConstantsPlugin = (options = {}) => ({ | |
| name: "fileConstants", | |
| setup(build) { | |
| build.onLoad({ filter: /.\.(c|m)?(js|ts)x?$/, namespace: "file" }, async (options) => { | |
| const isWindows = /^win/.test(process.platform); | |
| const escapeBackslashes = (path) => isWindows ? path.replace(/\\/g, "/") : path; | |
| const filename = escapeBackslashes(options.path); | |
| const dirname = posix.dirname(options.path); | |
| const fileContent = fs.readFileSync(options.path, "utf8"); | |
| const contents = grub(fileContent).replace({ from: "__dirname", to: `"${dirname}"` }, { from: "__filename", to: `"${filename}"` }); | |
| let loader = posix.extname(options.path).slice(1); | |
| if (["m", "c"].includes(loader[0])) | |
| loader = loader.slice(1); | |
| return { | |
| contents, | |
| loader, | |
| }; | |
| }); | |
| }, | |
| }); | |