Download web/scripts/node_register.cjs from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/f694a2bb8305731dbfb36abe080ff76fe2b3a6c4/web/scripts/node_register.cjs
- Command line
-
hf download hf://spaces/fsanyoto/loopable@f694a2bb8305731dbfb36abe080ff76fe2b3a6c4/web/scripts/node_register.cjs
-
curl -L -o node_register.cjs https://huggingface.co/spaces/fsanyoto/loopable/resolve/f694a2bb8305731dbfb36abe080ff76fe2b3a6c4/web/scripts/node_register.cjs
2.15 kB
| // The ONE CommonJS register for a node test that loads app source (W-8547). | |
| // node -r ./scripts/node_register.cjs <runner.cjs> or require("./scripts/node_register.cjs") | |
| // A bare node loads no `src/customer-grid/*.tsx`. This makes three things loadable: | |
| // .ts/.tsx transpiled by the project's own typescript (react-jsx, CommonJS); `import.meta` gets the | |
| // D-312 stand-in, or node re-reads the module as ESM ("exports is not defined"). | |
| // .css an empty module: Vite bundles stylesheets, and node parses one as JavaScript. | |
| // cjs .js a dependency that ships its CommonJS build as `.js` in a "type": "module" package | |
| // (glide-data-grid `dist/cjs/`, phosphor-icons `dist/index.cjs.js`): node reads that build | |
| // as ESM ("exports is not defined in ES module scope"). It is compiled as CommonJS. | |
| // Proved by `python aios-web/web/_gate_node.py --selftest`. | |
| ; | |
| const fs = require("fs"); | |
| const Module = require("module"); | |
| const META_STANDIN = '({ env: { BASE_URL: "/", MODE: "test", DEV: false, PROD: true, SSR: true }, ' | |
| + 'url: require("url").pathToFileURL(__filename).href, glob: () => ({}) })'; // glob: a Vite build feature | |
| const CJS_AS_JS = /[\\/]node_modules[\\/](?:.*[\\/]cjs[\\/].*|.*\.cjs)\.js$/; | |
| let ts = null; | |
| function transpile(source, filename) { | |
| ts = ts || require("typescript"); // lazy: a runner that loads no .ts needs no node_modules | |
| const out = ts.transpileModule(source, { fileName: filename, compilerOptions: { | |
| module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.ReactJSX, | |
| esModuleInterop: true } }).outputText; | |
| return out.replace(/\bimport\.meta\b/g, META_STANDIN); | |
| } | |
| for (const ext of [".ts", ".tsx"]) { | |
| Module._extensions[ext] = (mod, filename) => | |
| mod._compile(transpile(fs.readFileSync(filename, "utf8"), filename), filename, "commonjs"); | |
| } | |
| Module._extensions[".css"] = () => {}; | |
| const loadJs = Module._extensions[".js"]; | |
| Module._extensions[".js"] = (mod, filename) => CJS_AS_JS.test(filename) | |
| ? mod._compile(fs.readFileSync(filename, "utf8"), filename, "commonjs") | |
| : loadJs(mod, filename); | |