Skip to content

Commit

Permalink
Define process so that React can load on mobile
Browse files Browse the repository at this point in the history
Signed-off-by: William So <polyipseity@gmail.com>
  • Loading branch information
polyipseity committed Aug 17, 2023
1 parent 5b10e71 commit a286c55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-pots-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"obsidian-modules": patch
---

Define `process` so that React can load on mobile.
10 changes: 7 additions & 3 deletions sources/require/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function createRequire(
})
}
preload(cleanup, rd, context)
new self0.Function("module", "exports", compiledSyncCode ??
new self0.Function("module", "exports", "process", compiledSyncCode ??
attachFunctionSourceMap(
self0.Function,
`${PRECOMPILE_SYNC_PREFIX}${code}`,
Expand All @@ -175,7 +175,10 @@ function createRequire(
file: id,
sourceRoot: `${sourceRoot}${sourceRoot && "/"}${id}`,
},
))(module, module.exports)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
))(module, module.exports, self0.process ??
// eslint-disable-next-line @typescript-eslint/naming-convention
{ env: { NODE_DEV: "production" } })
const { exports } = module
exports[Symbol.toStringTag] = "Module"
return exports
Expand Down Expand Up @@ -233,6 +236,7 @@ function createRequire(
? [
"export let module={exports:{[Symbol.toStringTag]:\"Module\"}}",
"let{exports}=module",
"let{process}=self;process??={env:{NODE_DEV:\"production\"}}",
"",
].join(";")
: "",
Expand Down Expand Up @@ -261,7 +265,7 @@ function createRequire(
? []
: [
(async (): Promise<never> => {
await sleep2(self, importTimeout)
await sleep2(self0, importTimeout)
throw new Error(id)
})(),
],
Expand Down

0 comments on commit a286c55

Please sign in to comment.