MCPcopy Create free account
hub / github.com/stenciljs/core / createNodeSys

Function createNodeSys

src/sys/node/node-sys.ts:37–674  ·  view source on GitHub ↗
(c: { process?: any; logger?: Logger } = {})

Source from the content-addressed store, hash-verified

35 * @returns a node.js `CompilerSystem` object
36 */
37export function createNodeSys(c: { process?: any; logger?: Logger } = {}): CompilerSystem {
38 const prcs: NodeJS.Process = c?.process ?? global.process;
39 const logger: Logger | undefined = c?.logger;
40 const destroys = new Set<() => Promise<void> | void>();
41 const onInterruptsCallbacks: (() => void)[] = [];
42
43 const sysCpus = cpus();
44 const hardwareConcurrency = sysCpus.length;
45 const osPlatform = platform();
46
47 const compilerExecutingPath = path.join(__dirname, '..', '..', 'compiler', 'stencil.js');
48 const devServerExecutingPath = path.join(__dirname, '..', '..', 'dev-server', 'index.js');
49
50 const runInterruptsCallbacks = () => {
51 const returnValues: Promise<any>[] = [];
52 let cb: () => any;
53 while (isFunction((cb = onInterruptsCallbacks.pop()))) {
54 try {
55 const rtn = cb();
56 returnValues.push(rtn);
57 } catch (e) {}
58 }
59 return Promise.all(returnValues).then(() => {});
60 };
61
62 const sys: CompilerSystem = {
63 name: 'node',
64 version: prcs.versions.node,
65 access(p) {
66 return new Promise((resolve) => {
67 fs.access(p, (err) => resolve(!err));
68 });
69 },
70 accessSync(p) {
71 let hasAccess = false;
72 try {
73 fs.accessSync(p);
74 hasAccess = true;
75 } catch (e) {}
76 return hasAccess;
77 },
78 addDestroy(cb) {
79 destroys.add(cb);
80 },
81 removeDestroy(cb) {
82 destroys.delete(cb);
83 },
84 applyPrerenderGlobalPatch(opts) {
85 if (typeof global.fetch !== 'function') {
86 const nodeFetch = require(path.join(__dirname, 'node-fetch.js'));
87
88 global.fetch = (input: any, init: any) => {
89 if (typeof input === 'string') {
90 // fetch(url) w/ url string
91 const urlStr = new URL(input, opts.devServerHostUrl).href;
92 return nodeFetch.fetch(urlStr, init);
93 } else {
94 // fetch(Request) w/ request object

Callers 3

startServerFunction · 0.85
loadConfigFunction · 0.85
validateConfigFunction · 0.85

Calls 6

runInterruptsCallbacksFunction · 0.85
releaseFunction · 0.85
joinMethod · 0.80
pushMethod · 0.80
onMethod · 0.80
fetchMethod · 0.65

Tested by

no test coverage detected