@shopify/cli-hydrogen 0.31.0 → 0.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +1,18 @@
1
- import require$$0$5, { resolve } from 'path';
2
- import { C as Command, H as HelpfulError } from '../../Command-bded1434.js';
3
- import 'prettier';
4
1
  import { Request, MiniflareCore, CorePlugin } from '@miniflare/core';
5
- import { CachePlugin } from '@miniflare/cache';
6
- import { VMScriptRunner } from '@miniflare/runner-vm';
7
- import { Log, LogLevel } from '@miniflare/shared';
8
- import require$$3 from 'http';
9
- import require$$0$3 from 'fs';
10
- import require$$7, { URL } from 'url';
11
2
  import require$$0$1 from 'tty';
12
3
  import require$$0$2 from 'util';
4
+ import require$$0$3 from 'fs';
13
5
  import require$$4 from 'net';
14
6
  import require$$0$4 from 'events';
7
+ import require$$7 from 'url';
8
+ import require$$3 from 'http';
9
+ import { path, output, file, error } from '@shopify/cli-kit';
10
+ import { URL } from 'node:url';
15
11
  import { MemoryStorage } from '@miniflare/storage-memory';
16
- import '@oclif/core';
17
- import 'constants';
18
- import 'stream';
19
- import 'assert';
20
- import 'os';
21
- import 'readline';
22
- import 'buffer';
23
- import 'child_process';
24
- import 'string_decoder';
25
- import 'crypto';
26
- import '@shopify/cli-kit';
27
- import 'module';
28
- import 'vm';
29
- import 'v8';
12
+ import { CachePlugin } from '@miniflare/cache';
13
+ import { VMScriptRunner } from '@miniflare/runner-vm';
14
+ import { Log, LogLevel } from '@miniflare/shared';
15
+ import { Flags, Command } from '@oclif/core';
30
16
 
31
17
  /**
32
18
  * @param typeMap [Object] Map of MIME type -> Array[extensions]
@@ -3230,7 +3216,7 @@ function getProtohost(url) {
3230
3216
 
3231
3217
  function createAssetMiddleware(assets) {
3232
3218
  return (req, res, next) => {
3233
- const filePath = require$$0$5.join(process.cwd(), "./dist/client", req.url);
3219
+ const filePath = path.join(process.cwd(), "./dist/client", req.url);
3234
3220
  if (assets.includes(filePath)) {
3235
3221
  const rs = require$$0$3.createReadStream(filePath);
3236
3222
  const { size } = require$$0$3.statSync(filePath);
@@ -3238,7 +3224,7 @@ function createAssetMiddleware(assets) {
3238
3224
  res.setHeader("Content-Length", size);
3239
3225
  return rs.pipe(res);
3240
3226
  }
3241
- next();
3227
+ return next();
3242
3228
  };
3243
3229
  }
3244
3230
  function createRequestMiddleware(mf) {
@@ -3261,9 +3247,9 @@ function createRequestMiddleware(mf) {
3261
3247
  }
3262
3248
  }
3263
3249
  res.end();
3264
- } catch (e) {
3250
+ } catch (error) {
3265
3251
  res.writeHead(500, { "Content-Type": "text/plain; charset=UTF-8" });
3266
- res.end(e.stack, "utf8");
3252
+ res.end(error.stack, "utf8");
3267
3253
  }
3268
3254
  return response;
3269
3255
  };
@@ -3318,41 +3304,52 @@ const PLUGINS = {
3318
3304
  CachePlugin
3319
3305
  };
3320
3306
 
3321
- const port = 4e3;
3322
- class Preview extends Command {
3323
- async run() {
3324
- const hasWorkerBuild = await this.fs.hasFile("dist/worker/worker.js");
3325
- if (!hasWorkerBuild) {
3326
- throw new HelpfulError({
3327
- title: "worker.js not found",
3328
- content: "A worker build is required for this command.",
3329
- suggestion: () => `Run \`yarn run build\` to generate a worker build and try again.`
3330
- });
3331
- }
3332
- const files = await this.fs.glob("dist/client/**/*");
3333
- files.forEach((file) => {
3334
- this.interface.say(file);
3335
- });
3336
- const mf = new MiniOxygen({
3337
- buildCommand: "yarn build",
3338
- globals: { Oxygen: {} },
3339
- scriptPath: resolve(this.root, "dist/worker/worker.js"),
3340
- sitePath: resolve(this.root, "dist/client")
3341
- });
3342
- const app = await mf.createServer({ assets: files });
3343
- app.listen(port, () => {
3344
- this.interface.say(`
3307
+ async function preview({ directory, port }) {
3308
+ await runPreview({ directory, port });
3309
+ }
3310
+ async function runPreview({ directory, port }) {
3311
+ const files = await path.glob("dist/client/**/*");
3312
+ const mf = new MiniOxygen({
3313
+ buildCommand: "yarn build",
3314
+ globals: { Oxygen: {} },
3315
+ scriptPath: path.resolve(directory, "dist/worker/index.js"),
3316
+ sitePath: path.resolve(directory, "dist/client")
3317
+ });
3318
+ const app = await mf.createServer({ assets: files });
3319
+ app.listen(port, () => {
3320
+ output.info(`
3345
3321
  Started miniOxygen server. Listening at http://localhost:${port}
3346
3322
  `);
3347
- });
3348
- }
3323
+ });
3349
3324
  }
3350
- Preview.description = "Preview a hydrogen worker build in a worker environment.";
3351
- Preview.examples = [`$ shopify hydrogen preview`];
3325
+
3326
+ const _Preview = class extends Command {
3327
+ async run() {
3328
+ const { flags } = await this.parse(_Preview);
3329
+ const directory = flags.path ? path.resolve(flags.path) : process.cwd();
3330
+ const port = parseInt(flags.port, 10);
3331
+ if (!await file.exists(path.resolve(directory, "dist/worker"))) {
3332
+ throw new error.Abort(`Couldn't find worker build. Run "yarn build" in ${directory}, and try again.`);
3333
+ }
3334
+ await preview({ directory, port });
3335
+ }
3336
+ };
3337
+ let Preview = _Preview;
3338
+ Preview.description = "Run a Hydrogen storefront locally in a worker environment";
3352
3339
  Preview.flags = {
3353
- ...Command.flags
3340
+ path: Flags.string({
3341
+ hidden: true,
3342
+ description: "the path to your hydrogen storefront",
3343
+ env: "SHOPIFY_FLAG_PATH"
3344
+ }),
3345
+ port: Flags.string({
3346
+ char: "p",
3347
+ hidden: true,
3348
+ description: "the port to run the preview server on",
3349
+ default: "3000",
3350
+ env: "SHOPIFY_FLAG_PORT"
3351
+ })
3354
3352
  };
3355
- Preview.args = [];
3356
3353
 
3357
3354
  export { Preview as default };
3358
3355
  //# sourceMappingURL=preview.js.map