@openworkers/adapter-static 0.1.1 → 0.1.3

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.
package/bin/cli.js CHANGED
File without changes
package/files/worker.js CHANGED
@@ -458,7 +458,7 @@ var Mime_default = Mime;
458
458
  var index_lite_default = new Mime_default(standard_default)._freeze();
459
459
 
460
460
  // src/worker.js
461
- import { routes } from "ROUTES";
461
+ import routes from "ROUTES";
462
462
  function isImmutable(pathname) {
463
463
  for (const pattern of routes.immutable) {
464
464
  if (pattern.endsWith("/*")) {
package/index.js CHANGED
@@ -29,13 +29,10 @@ export async function adapt(options = {}) {
29
29
  throw new Error(`Input directory not found: ${input}`);
30
30
  }
31
31
 
32
- const tmp = resolve(out, '.tmp');
33
-
34
32
  // Clean and create output directories
35
33
  rmSync(out, { recursive: true, force: true });
36
34
  mkdirSync(out, { recursive: true });
37
35
  mkdirSync(join(out, 'assets'), { recursive: true });
38
- mkdirSync(tmp, { recursive: true });
39
36
 
40
37
  // Copy all files to assets/
41
38
  cpSync(input, join(out, 'assets'), { recursive: true });
@@ -46,24 +43,35 @@ export async function adapt(options = {}) {
46
43
  // Detect immutable patterns
47
44
  const immutable = options.immutable ?? detectImmutable(join(out, 'assets'));
48
45
 
49
- // Generate routes config
50
- const routesConfig = {
46
+ // Generate _routes.json manifest for edge router
47
+ const allFiles = listFiles(join(out, 'assets'));
48
+ const staticFiles = allFiles.filter((f) => !isImmutablePath(f, immutable));
49
+
50
+ const manifest = {
51
51
  mode,
52
52
  fallback,
53
- immutable
53
+ immutable,
54
+ static: staticFiles.map((f) => '/' + f),
55
+ prerendered: [],
56
+ functions: [],
57
+ // If fallback is set, worker handles all unmatched routes (SPA mode)
58
+ ssr: fallback ? ['/*'] : []
54
59
  };
55
60
 
56
- writeFileSync(join(tmp, 'routes.js'), `export const routes = ${JSON.stringify(routesConfig, null, 2)};\n`);
61
+ writeFileSync(
62
+ join(out, '_routes.json'),
63
+ JSON.stringify(manifest, null, 2)
64
+ );
57
65
 
58
- // Bundle worker with esbuild
66
+ // Bundle worker with esbuild (use _routes.json for ROUTES alias)
59
67
  await build({
60
- entryPoints: [fileURLToPath(new URL('./src/worker.js', import.meta.url).href)],
68
+ entryPoints: [fileURLToPath(new URL('./files/worker.js', import.meta.url).href)],
61
69
  bundle: true,
62
70
  format: 'esm',
63
71
  platform: 'browser',
64
- outfile: resolve(out, 'worker.js'),
72
+ outfile: resolve(out, '_worker.js'),
65
73
  alias: {
66
- ROUTES: resolve(tmp, 'routes.js')
74
+ ROUTES: resolve(out, '_routes.json')
67
75
  },
68
76
  minify: false,
69
77
  banner: {
@@ -71,26 +79,6 @@ export async function adapt(options = {}) {
71
79
  }
72
80
  });
73
81
 
74
- // Generate routes.js manifest for edge router
75
- const allFiles = listFiles(join(out, 'assets'));
76
- const staticFiles = allFiles.filter((f) => !isImmutablePath(f, immutable));
77
-
78
- const manifest = {
79
- immutable,
80
- static: staticFiles.map((f) => '/' + f),
81
- fallback
82
- };
83
-
84
- writeFileSync(
85
- join(out, 'routes.js'),
86
- `// Generated by ${name} v${version}\n` +
87
- `// Used by OpenWorkers edge router for static content\n\n` +
88
- `export default ${JSON.stringify(manifest, null, '\t')};\n`
89
- );
90
-
91
- // Cleanup tmp
92
- rmSync(tmp, { recursive: true, force: true });
93
-
94
82
  console.log(`Built static site for OpenWorkers:`);
95
83
  console.log(` Input: ${input}`);
96
84
  console.log(` Output: ${out}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/adapter-static",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Static site adapter for OpenWorkers",
5
5
  "keywords": [
6
6
  "adapter",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "esbuild": "^0.27.2",
43
- "mime": "^4.0.0"
43
+ "mime": "^4.1.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@openworkers/workers-types": "^0.1.7",