Skip to content

Commit

Permalink
Extract workerd logic in mini-oxygen package (#1891)
Browse files Browse the repository at this point in the history
* Move Node sandbox code

* Update imports

* Extract common headers

* Remove redundant values

* Change dependencies

* Extract workerd logic in MiniOxygen package

* Adjust e2e tests for workerd in MiniOxygen

* Fix sourcemaps

* Simplify reload usage

* Use @shopify/mini-oxygen in classic workerd dev process

* Only show errors in Node runtime

* Use @shopify/mini-oxygen in Vite dev process

* Extract compat flags

* Fix CLI deps

* Only find open ports when flags are not specified

* Move Node tests and avoid creating local folders

* Ensure only 1 instance of MiniOxygen is created

* Handle missing dependency better

* Adjust dependencies

* Make mini-oxygen an optional dep of CLI

* Fix preview command

* Make test more robust when running locally

* Minor log fixes

* Require direct mini-oxygen dependency in templates

* Update MiniOxygen readme

* Avoid depending on mini-oxygen directly from vite plugin

* Changesets

* Add dispatchFetch to Node sandbox runtime

* Add example for Node sandbox to readme

* Support wrappedBindings without compat flags

* Fix extra lines in banners

* Move unsafe outbound service condition to mini-oxygen

* Enable verbose logs based on DEBUG variable

* Fix TS auto-imports

* Move CAA schema patch for graphiql back to CLI
  • Loading branch information
frandiox committed Apr 1, 2024
1 parent 66e9e8b commit 140e476
Show file tree
Hide file tree
Showing 51 changed files with 1,369 additions and 1,098 deletions.
32 changes: 32 additions & 0 deletions .changeset/healthy-owls-lay.md
@@ -0,0 +1,32 @@
---
'@shopify/mini-oxygen': major
---

The main runtime exported from `@shopify/mini-oxygen` is now based on workerd.
The previous Node.js sandbox runtime has been moved to the `@shopify/mini-oxygen/node` export.

Example usage:

```js
import {createMiniOxygen} from '@shopify/mini-oxygen';

const miniOxygen = createMiniOxygen({
workers: [
{
name: 'main',
modules: true,
script: `export default {
async fetch() {
const response = await fetch("https://hydrogen.shopify.dev");
return response;
}
}`,
},
],
});

const response = await miniOxygen.dispatchFetch('http://placeholder');
console.log(await response.text());

await miniOxygen.dispose();
```
15 changes: 15 additions & 0 deletions .changeset/mean-pots-carry.md
@@ -0,0 +1,15 @@
---
'skeleton': patch
---

If you deploy to Oxygen, please add `@shopify/mini-oxygen` as a dev dependency in your project for local development:

```diff
"devDependencies": {
"@remix-run/dev": "^2.8.0",
"@remix-run/eslint-config": "^2.8.0",
+ "@shopify/mini-oxygen": "^3.0.0",
"@shopify/oxygen-workers-types": "^4.0.0",
...
},
```
7 changes: 7 additions & 0 deletions .changeset/quick-walls-smash.md
@@ -0,0 +1,7 @@
---
'@shopify/cli-hydrogen': major
---

Hydrogen CLI now requires `@shopify/mini-oxygen` to be installed separately as a dev dependency. It is still used automatically under the hood so there is no need to change your application code aside from installing the dependency.

Also, if a port provided via `--port` or `--inspector-port` flags is already in use, the CLI will now exit with an error message instead of finding a new open port. When the flags are not provided, the CLI will still find an open port.
1 change: 1 addition & 0 deletions examples/multipass/package.json
Expand Up @@ -28,6 +28,7 @@
"devDependencies": {
"@remix-run/dev": "^2.8.0",
"@remix-run/eslint-config": "^2.8.0",
"@shopify/mini-oxygen": "^2.2.5",
"@shopify/oxygen-workers-types": "^4.0.0",
"@shopify/prettier-config": "^1.1.2",
"@total-typescript/ts-reset": "^0.4.2",
Expand Down
1 change: 1 addition & 0 deletions examples/partytown/package.json
Expand Up @@ -29,6 +29,7 @@
"devDependencies": {
"@remix-run/dev": "^2.8.0",
"@remix-run/eslint-config": "^2.8.0",
"@shopify/mini-oxygen": "^2.2.5",
"@shopify/oxygen-workers-types": "^4.0.0",
"@shopify/prettier-config": "^1.1.2",
"@total-typescript/ts-reset": "^0.4.2",
Expand Down
1 change: 1 addition & 0 deletions examples/subscriptions/package.json
Expand Up @@ -26,6 +26,7 @@
"devDependencies": {
"@remix-run/dev": "^2.8.0",
"@remix-run/eslint-config": "^2.8.0",
"@shopify/mini-oxygen": "^2.2.5",
"@shopify/oxygen-workers-types": "^4.0.0",
"@shopify/prettier-config": "^1.1.2",
"@tailwindcss/forms": "^0.5.3",
Expand Down

0 comments on commit 140e476

Please sign in to comment.