shiply-cli 0.18.0 → 0.18.1

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.
Files changed (2) hide show
  1. package/dist/bundle.js +39 -38
  2. package/package.json +1 -1
package/dist/bundle.js CHANGED
@@ -1,58 +1,59 @@
1
1
  import { cp, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
2
2
  import { tmpdir } from 'node:os';
3
- import { dirname, join } from 'node:path';
3
+ import { join } from 'node:path';
4
4
  import { build } from 'esbuild';
5
5
  const BUNDLE_COMPAT_DATE = '2025-05-05';
6
- /** Stage a temp publish dir: static assets at root, worker modules under
7
- * `.shiply/bundle/`, plus `.shiply/bundle.json`. Returns the dir; the caller
8
- * removes it after publish. The existing publish pipeline handles the rest. */
6
+ /** Cloudflare runtime built-ins (`cloudflare:workers`, …) and `node:*` (provided
7
+ * by `nodejs_compat`) resolve at the edge they must stay external. Everything
8
+ * else, including the framework server code that an adapter's `_worker.js`
9
+ * imports from OUTSIDE its output dir, gets inlined. */
10
+ const WORKER_EXTERNALS = ['cloudflare:*', 'node:*'];
11
+ /** esbuild-bundle a worker entry into one self-contained ESM module. */
12
+ async function bundleWorker(entryAbs) {
13
+ const result = await build({
14
+ entryPoints: [entryAbs],
15
+ bundle: true,
16
+ format: 'esm',
17
+ platform: 'neutral',
18
+ target: 'es2022',
19
+ external: WORKER_EXTERNALS,
20
+ write: false,
21
+ logLevel: 'silent',
22
+ });
23
+ return result.outputFiles[0].text;
24
+ }
25
+ /** Stage a temp publish dir: a single bundled worker under `.shiply/bundle/`,
26
+ * static assets at the root, plus `.shiply/bundle.json`. Returns the dir; the
27
+ * caller removes it after publish. The existing publish pipeline handles the rest.
28
+ *
29
+ * BOTH tiers esbuild-bundle the entry. Adapter output (SvelteKit, Astro) is NOT
30
+ * self-contained — `_worker.js` imports server code from sibling dirs
31
+ * (`../output/server`, `../cloudflare-tmp`) — so we bundle it exactly as
32
+ * `wrangler deploy` would, rather than upload it as-is. */
9
33
  export async function prepareBundle(sourceDir, ssr) {
10
34
  const out = await mkdtemp(join(tmpdir(), 'shiply-bundle-'));
11
35
  const bundleDir = join(out, '.shiply', 'bundle');
12
36
  await mkdir(bundleDir, { recursive: true });
13
37
  if (ssr.tier0) {
14
- // Tier 0: esbuild-bundle the worker entry into one ESM module.
15
- const result = await build({
16
- entryPoints: [join(ssr.assetsDir, ssr.workerMain)],
17
- bundle: true,
18
- format: 'esm',
19
- platform: 'neutral',
20
- target: 'es2022',
21
- write: false,
22
- logLevel: 'silent',
23
- });
24
- await writeFile(join(bundleDir, 'index.js'), result.outputFiles[0].text);
38
+ // Tier 0: bundle the wrangler `main` entry; optional static assets dir.
39
+ await writeFile(join(bundleDir, 'index.js'), await bundleWorker(join(ssr.assetsDir, ssr.workerMain)));
25
40
  if (ssr.staticDir) {
26
41
  await cp(join(sourceDir, ssr.staticDir), out, { recursive: true });
27
42
  }
28
- await writeManifest(out, {
29
- framework: ssr.framework,
30
- entry: 'index.js',
31
- modules: ['index.js'],
32
- compatibilityDate: ssr.compatibilityDate ?? BUNDLE_COMPAT_DATE,
33
- compatibilityFlags: ssr.compatibilityFlags,
34
- });
35
- return out;
36
- }
37
- // Tier 1: copy the whole assets dir, then RELOCATE worker modules into
38
- // .shiply/bundle/ so they aren't double-served as static assets.
39
- await cp(ssr.assetsDir, out, { recursive: true });
40
- for (const m of ssr.modules) {
41
- const from = join(out, m);
42
- const to = join(bundleDir, m);
43
- await mkdir(dirname(to), { recursive: true });
44
- await cp(from, to, { recursive: true });
45
- await rm(from, { recursive: true, force: true });
46
43
  }
47
- // If the entry lived in a worker subdir (Astro's _worker.js/), drop the
48
- // original subdir entirely so no leftover files are served as assets.
49
- if (ssr.entry.includes('/')) {
44
+ else {
45
+ // Tier 1: bundle the adapter's worker entry into one module, then copy the
46
+ // rest of the output dir as static assets (minus the now-bundled entry).
47
+ await writeFile(join(bundleDir, 'index.js'), await bundleWorker(join(ssr.assetsDir, ssr.entry)));
48
+ await cp(ssr.assetsDir, out, { recursive: true });
49
+ // Drop the original worker entry (file, or Astro's `_worker.js/` dir) so it
50
+ // isn't double-served as a static asset.
50
51
  await rm(join(out, ssr.entry.split('/')[0]), { recursive: true, force: true });
51
52
  }
52
53
  await writeManifest(out, {
53
54
  framework: ssr.framework,
54
- entry: ssr.entry,
55
- modules: ssr.modules,
55
+ entry: 'index.js',
56
+ modules: ['index.js'],
56
57
  compatibilityDate: ssr.compatibilityDate ?? BUNDLE_COMPAT_DATE,
57
58
  compatibilityFlags: ssr.compatibilityFlags,
58
59
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shiply-cli",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Publish static sites to shiply.now from the command line — instant web hosting for agents.",
5
5
  "license": "MIT",
6
6
  "type": "module",