MCPcopy
hub / github.com/QwikDev/qwik / getSystem

Function getSystem

packages/qwik/src/optimizer/src/platform.ts:11–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import { versions } from './versions';
10
11export async function getSystem() {
12 const sysEnv = getEnv();
13
14 const sys: OptimizerSystem = {
15 dynamicImport: (path) => {
16 throw new Error(
17 `Qwik Optimizer sys.dynamicImport() not implemented, trying to import: "${path}"`
18 );
19 },
20 strictDynamicImport: (path) => {
21 throw new Error(
22 `Qwik Optimizer sys.strictDynamicImport() not implemented, trying to import: "${path}"`
23 );
24 },
25 path: null as any,
26 cwd: () => '/',
27 os: 'unknown',
28 env: sysEnv,
29 };
30
31 sys.path = createPath(sys);
32
33 if (globalThis.IS_ESM) {
34 sys.strictDynamicImport = sys.dynamicImport = (path) => import(path);
35 }
36
37 if (globalThis.IS_CJS) {
38 if (sysEnv === 'node' || sysEnv === 'bun') {
39 // using this api object as a way to ensure bundlers
40 // do not try to inline or rewrite require()
41 sys.dynamicImport = (path) => require(path);
42 sys.strictDynamicImport = (path) => import(path);
43
44 if (typeof TextEncoder === 'undefined') {
45 // TextEncoder/TextDecoder needs to be on the global scope for the WASM file
46 // https://nodejs.org/api/util.html#class-utiltextdecoder
47 const nodeUtil: typeof import('util') = await sys.dynamicImport('node:util');
48 globalThis.TextEncoder = nodeUtil.TextEncoder;
49 globalThis.TextDecoder = nodeUtil.TextDecoder;
50 }
51 } else if (sysEnv === 'webworker' || sysEnv === 'browsermain') {
52 sys.strictDynamicImport = (path) => import(path);
53 sys.dynamicImport = async (path: string) => {
54 const cjsRsp = await fetch(path);
55 const cjsCode = await cjsRsp.text();
56 const cjsModule: any = { exports: {} };
57 // eslint-disable-next-line no-new-func
58 const cjsRun = new Function('module', 'exports', cjsCode);
59 cjsRun(cjsModule, cjsModule.exports);
60 return cjsModule.exports;
61 };
62 }
63 }
64 if (sysEnv !== 'webworker' && sysEnv !== 'browsermain') {
65 try {
66 sys.path = await sys.dynamicImport('node:path');
67 sys.cwd = () => process.cwd();
68 sys.os = process.platform;

Callers 1

createOptimizerFunction · 0.90

Calls 4

createPathFunction · 0.90
getEnvFunction · 0.85
requireFunction · 0.85
fetchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…