@torpor/adapter-cloudflare 0.0.7 → 0.0.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @torpor/adapter-cloudflare
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 5df2010: Fix: force disabling Vite preload
8
+
3
9
  ## 0.0.7
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -112,6 +112,18 @@ async function postbuild(site) {
112
112
  }
113
113
  })
114
114
  );
115
+ for (let file of await import_node_fs.promises.readdir(cloudflareFolder)) {
116
+ if (file.startsWith("_worker")) {
117
+ let b = await import_node_fs.promises.readFile(import_node_path.default.join(cloudflareFolder, file), "utf-8");
118
+ if (b.includes("const __vitePreload")) {
119
+ b = b.replaceAll(
120
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) {",
121
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) { return baseModule();"
122
+ );
123
+ await import_node_fs.promises.writeFile(import_node_path.default.join(cloudflareFolder, file), b);
124
+ }
125
+ }
126
+ }
115
127
  await import_node_fs.promises.mkdir(import_node_path.default.join(cloudflareFolder, "assets"));
116
128
  for (let file of await import_node_fs.promises.readdir(import_node_path.default.join(clientFolder, "assets"))) {
117
129
  await import_node_fs.promises.copyFile(
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/prepareTemplate.ts"],"sourcesContent":["import cloudflare from \"./adapter\";\n\nexport { cloudflare };\n","import { type Adapter, Site } from \"@torpor/build\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport prepareTemplate from \"./prepareTemplate\";\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst buildSrcFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/\");\n\tconst adapterSrcFolder = path.resolve(\n\t\tsite.root,\n\t\t\"./node_modules/@torpor/adapter-cloudflare/src/\",\n\t);\n\n\t// Compile _worker.ts\n\tlet workerFile = path.join(adapterSrcFolder, \"_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.join(buildSrcFolder, \"server\", \"Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Copy the client assets into the Cloudflare folder\n\tawait fs.mkdir(path.join(cloudflareFolder, \"assets\"));\n\tfor (let file of await fs.readdir(path.join(clientFolder, \"assets\"))) {\n\t\tawait fs.copyFile(\n\t\t\tpath.join(clientFolder, \"assets\", file),\n\t\t\tpath.join(cloudflareFolder, \"assets\", file),\n\t\t);\n\t}\n\n\t// Build a wrangler.toml file for running with `wrangler dev`\n\tconst wranglerConfig = `\nname = \"torpor-miniflare\"\nmain = \"./cloudflare/_worker.js\"\ncompatibility_date = \"2025-01-01\"\n\n[assets]\ndirectory = \"./cloudflare\"\nbinding = \"ASSETS\"\n\t`;\n\tconst wranglerFile = path.join(distFolder, \"wrangler.toml\");\n\tawait fs.writeFile(wranglerFile, wranglerConfig);\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n","export default function prepareTemplate(template: string, clientScript: string) {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,qBAA+B;AAC/B,uBAAiB;AACjB,kBAAoC;;;ACHrB,SAAR,gBAAiC,UAAkB,cAAsB;AAC/E,MAAI,eAAe,aAAa,UAAU,iCAAiC;AAC3E,iBAAe,SAAS,QAAQ,KAAK,YAAY,IAAI;AACrD,MAAI,aAAa,SAAS,QAAQ,UAAU,YAAY;AACxD,MAAI,iBAAiB,MAAM,eAAe,IAAI;AAC7C,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACrD;AACA,SACC,SAAS,UAAU,GAAG,YAAY,IAClC,qBACA,SAAS,UAAU,UAAU,IAC7B,8BAA8B,YAAY;AAE5C;AAGA,SAAS,aAAa,QAAgB,OAAe,UAAmB;AACvE,MAAI,UAAU,OAAO,UAAU,YAAY,CAAC,EAAE,OAAO,KAAK;AAC1D,SAAO,WAAW,IAAI,WAAW,YAAY,KAAK;AACnD;;;ADbA,IAAO,kBAAQ;AAAA,EACd;AAAA,EACA,OAAO,MAAqC;AAC3C,YAAQ,IAAI,MAAM;AAAA,EACnB;AACD;AAEA,eAAe,UAAU,MAAY;AAIpC,QAAM,aAAa,iBAAAA,QAAK,QAAQ,KAAK,MAAM,MAAM;AACjD,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,aAAa,iBAAAA,QAAK,KAAK,YAAY,MAAM;AAC/C,QAAM,mBAAmB,iBAAAA,QAAK,KAAK,YAAY,YAAY;AAG3D,QAAM,iBAAiB,iBAAAA,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Ae;AAAA,MAChB;AAAA,IACD,CAAC;AAAA,EACF;AAGA,QAAM,eAAAA,SAAG,MAAM,iBAAAD,QAAK,KAAK,kBAAkB,QAAQ,CAAC;AACpD,WAAS,QAAQ,MAAM,eAAAC,SAAG,QAAQ,iBAAAD,QAAK,KAAK,cAAc,QAAQ,CAAC,GAAG;AACrE,UAAM,eAAAC,SAAG;AAAA,MACR,iBAAAD,QAAK,KAAK,cAAc,UAAU,IAAI;AAAA,MACtC,iBAAAA,QAAK,KAAK,kBAAkB,UAAU,IAAI;AAAA,IAC3C;AAAA,EACD;AAGA,QAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASvB,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,eAAe;AAC1D,QAAM,eAAAC,SAAG,UAAU,cAAc,cAAc;AAE/C,QAAM,eAAAA,SAAG,GAAG,YAAY,EAAE,WAAW,KAAK,CAAC;AAC5C;","names":["path","fs"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/prepareTemplate.ts"],"sourcesContent":["import cloudflare from \"./adapter\";\n\nexport { cloudflare };\n","import { type Adapter, Site } from \"@torpor/build\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport prepareTemplate from \"./prepareTemplate\";\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst buildSrcFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/\");\n\tconst adapterSrcFolder = path.resolve(\n\t\tsite.root,\n\t\t\"./node_modules/@torpor/adapter-cloudflare/src/\",\n\t);\n\n\t// Compile _worker.ts\n\tlet workerFile = path.join(adapterSrcFolder, \"_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.join(buildSrcFolder, \"server\", \"Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// HACK: Disabling preload doesn't work so we have to brute-force it???\n\tfor (let file of await fs.readdir(cloudflareFolder)) {\n\t\tif (file.startsWith(\"_worker\")) {\n\t\t\tlet b = await fs.readFile(path.join(cloudflareFolder, file), \"utf-8\");\n\t\t\tif (b.includes(\"const __vitePreload\")) {\n\t\t\t\tb = b.replaceAll(\n\t\t\t\t\t\"const __vitePreload = function preload(baseModule, deps, importerUrl) {\",\n\t\t\t\t\t\"const __vitePreload = function preload(baseModule, deps, importerUrl) { return baseModule();\",\n\t\t\t\t);\n\t\t\t\tawait fs.writeFile(path.join(cloudflareFolder, file), b);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Copy the client assets into the Cloudflare folder\n\tawait fs.mkdir(path.join(cloudflareFolder, \"assets\"));\n\tfor (let file of await fs.readdir(path.join(clientFolder, \"assets\"))) {\n\t\tawait fs.copyFile(\n\t\t\tpath.join(clientFolder, \"assets\", file),\n\t\t\tpath.join(cloudflareFolder, \"assets\", file),\n\t\t);\n\t}\n\n\t// Build a wrangler.toml file for running with `wrangler dev`\n\tconst wranglerConfig = `\nname = \"torpor-miniflare\"\nmain = \"./cloudflare/_worker.js\"\ncompatibility_date = \"2025-01-01\"\n\n[assets]\ndirectory = \"./cloudflare\"\nbinding = \"ASSETS\"\n\t`;\n\tconst wranglerFile = path.join(distFolder, \"wrangler.toml\");\n\tawait fs.writeFile(wranglerFile, wranglerConfig);\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n","export default function prepareTemplate(template: string, clientScript: string) {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,qBAA+B;AAC/B,uBAAiB;AACjB,kBAAoC;;;ACHrB,SAAR,gBAAiC,UAAkB,cAAsB;AAC/E,MAAI,eAAe,aAAa,UAAU,iCAAiC;AAC3E,iBAAe,SAAS,QAAQ,KAAK,YAAY,IAAI;AACrD,MAAI,aAAa,SAAS,QAAQ,UAAU,YAAY;AACxD,MAAI,iBAAiB,MAAM,eAAe,IAAI;AAC7C,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACrD;AACA,SACC,SAAS,UAAU,GAAG,YAAY,IAClC,qBACA,SAAS,UAAU,UAAU,IAC7B,8BAA8B,YAAY;AAE5C;AAGA,SAAS,aAAa,QAAgB,OAAe,UAAmB;AACvE,MAAI,UAAU,OAAO,UAAU,YAAY,CAAC,EAAE,OAAO,KAAK;AAC1D,SAAO,WAAW,IAAI,WAAW,YAAY,KAAK;AACnD;;;ADbA,IAAO,kBAAQ;AAAA,EACd;AAAA,EACA,OAAO,MAAqC;AAC3C,YAAQ,IAAI,MAAM;AAAA,EACnB;AACD;AAEA,eAAe,UAAU,MAAY;AAIpC,QAAM,aAAa,iBAAAA,QAAK,QAAQ,KAAK,MAAM,MAAM;AACjD,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,QAAQ;AAC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,gBAAgB;AAAA,YAChB,gBAAgB;AAAA,UACjB;AAAA,UACA,yBAAyB;AAAA,QAC1B;AAAA;AAAA;AAAA,QAGA,QAAQ;AAAA;AAAA;AAAA,QAGR,eAAe;AAAA,MAChB;AAAA,IACD,CAAC;AAAA,EACF;AAGA,WAAS,QAAQ,MAAM,eAAAA,SAAG,QAAQ,gBAAgB,GAAG;AACpD,QAAI,KAAK,WAAW,SAAS,GAAG;AAC/B,UAAI,IAAI,MAAM,eAAAA,SAAG,SAAS,iBAAAD,QAAK,KAAK,kBAAkB,IAAI,GAAG,OAAO;AACpE,UAAI,EAAE,SAAS,qBAAqB,GAAG;AACtC,YAAI,EAAE;AAAA,UACL;AAAA,UACA;AAAA,QACD;AACA,cAAM,eAAAC,SAAG,UAAU,iBAAAD,QAAK,KAAK,kBAAkB,IAAI,GAAG,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,EACD;AAGA,QAAM,eAAAC,SAAG,MAAM,iBAAAD,QAAK,KAAK,kBAAkB,QAAQ,CAAC;AACpD,WAAS,QAAQ,MAAM,eAAAC,SAAG,QAAQ,iBAAAD,QAAK,KAAK,cAAc,QAAQ,CAAC,GAAG;AACrE,UAAM,eAAAC,SAAG;AAAA,MACR,iBAAAD,QAAK,KAAK,cAAc,UAAU,IAAI;AAAA,MACtC,iBAAAA,QAAK,KAAK,kBAAkB,UAAU,IAAI;AAAA,IAC3C;AAAA,EACD;AAGA,QAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASvB,QAAM,eAAe,iBAAAA,QAAK,KAAK,YAAY,eAAe;AAC1D,QAAM,eAAAC,SAAG,UAAU,cAAc,cAAc;AAE/C,QAAM,eAAAA,SAAG,GAAG,YAAY,EAAE,WAAW,KAAK,CAAC;AAC5C;","names":["path","fs"]}
package/dist/index.js CHANGED
@@ -76,6 +76,18 @@ async function postbuild(site) {
76
76
  }
77
77
  })
78
78
  );
79
+ for (let file of await fs.readdir(cloudflareFolder)) {
80
+ if (file.startsWith("_worker")) {
81
+ let b = await fs.readFile(path.join(cloudflareFolder, file), "utf-8");
82
+ if (b.includes("const __vitePreload")) {
83
+ b = b.replaceAll(
84
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) {",
85
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) { return baseModule();"
86
+ );
87
+ await fs.writeFile(path.join(cloudflareFolder, file), b);
88
+ }
89
+ }
90
+ }
79
91
  await fs.mkdir(path.join(cloudflareFolder, "assets"));
80
92
  for (let file of await fs.readdir(path.join(clientFolder, "assets"))) {
81
93
  await fs.copyFile(
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter.ts","../src/prepareTemplate.ts"],"sourcesContent":["import { type Adapter, Site } from \"@torpor/build\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport prepareTemplate from \"./prepareTemplate\";\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst buildSrcFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/\");\n\tconst adapterSrcFolder = path.resolve(\n\t\tsite.root,\n\t\t\"./node_modules/@torpor/adapter-cloudflare/src/\",\n\t);\n\n\t// Compile _worker.ts\n\tlet workerFile = path.join(adapterSrcFolder, \"_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.join(buildSrcFolder, \"server\", \"Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Copy the client assets into the Cloudflare folder\n\tawait fs.mkdir(path.join(cloudflareFolder, \"assets\"));\n\tfor (let file of await fs.readdir(path.join(clientFolder, \"assets\"))) {\n\t\tawait fs.copyFile(\n\t\t\tpath.join(clientFolder, \"assets\", file),\n\t\t\tpath.join(cloudflareFolder, \"assets\", file),\n\t\t);\n\t}\n\n\t// Build a wrangler.toml file for running with `wrangler dev`\n\tconst wranglerConfig = `\nname = \"torpor-miniflare\"\nmain = \"./cloudflare/_worker.js\"\ncompatibility_date = \"2025-01-01\"\n\n[assets]\ndirectory = \"./cloudflare\"\nbinding = \"ASSETS\"\n\t`;\n\tconst wranglerFile = path.join(distFolder, \"wrangler.toml\");\n\tawait fs.writeFile(wranglerFile, wranglerConfig);\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n","export default function prepareTemplate(template: string, clientScript: string) {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n"],"mappings":";AACA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,OAAO,oBAAoB;;;ACHrB,SAAR,gBAAiC,UAAkB,cAAsB;AAC/E,MAAI,eAAe,aAAa,UAAU,iCAAiC;AAC3E,iBAAe,SAAS,QAAQ,KAAK,YAAY,IAAI;AACrD,MAAI,aAAa,SAAS,QAAQ,UAAU,YAAY;AACxD,MAAI,iBAAiB,MAAM,eAAe,IAAI;AAC7C,UAAM,IAAI,MAAM,oCAAoC;AAAA,E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KAAK,KAAK,cAAc,gBAAgB;AAG7D,iBAAe,aACb,QAAQ,kBAAkB,WAAW,EACrC,QAAQ,mBAAmB,YAAY,EACvC,QAAQ,mBAAmB,QAAQ;AAErC,eAAa,KAAK,KAAK,YAAY,YAAY;AAC/C,QAAM,GAAG,MAAM,UAAU;AACzB,QAAM,GAAG,UAAU,YAAY,YAAY;AAE3C,QAAM;AAAA,IACL,aAAa;AAAA,MACZ,OAAO;AAAA,QACN,QAAQ;AAAA,QACR,eAAe;AAAA,UACd,OAAO,CAAC,UAAU;AAAA,UAClB,QAAQ;AAAA,YACP,gBAAgB;AAAA,YAChB,gBAAgB;AAAA,YAChB,gBAAgB;AAAA,UACjB;AAAA,UACA,yBAAyB;AAAA,QAC1B;AAAA;AAAA;AAAA,QAGA,QAAQ;AAAA;AAAA;AAAA,QAGR,eAAe;AAAA,MAChB;AAAA,IACD,CAAC;AAAA,EACF;AAGA,QAAM,GAAG,MAAM,KAAK,KAAK,kBAAkB,QAAQ,CAAC;AACpD,WAAS,QAAQ,MAAM,GAAG,QAAQ,KAAK,KAAK,cAAc,QAAQ,CAAC,GAAG;AACrE,UAAM,GAAG;AAAA,MACR,KAAK,KAAK,cAAc,UAAU,IAAI;AAAA,MACtC,KAAK,KAAK,kBAAkB,UAAU,IAAI;AAAA,IAC3C;AAAA,EACD;AAGA,QAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASvB,QAAM,eAAe,KAAK,KAAK,YAAY,eAAe;AAC1D,QAAM,GAAG,UAAU,cAAc,cAAc;AAE/C,QAAM,GAAG,GAAG,YAAY,EAAE,WAAW,KAAK,CAAC;AAC5C;","names":[]}
1
+ {"version":3,"sources":["../src/adapter.ts","../src/prepareTemplate.ts"],"sourcesContent":["import { type Adapter, Site } from \"@torpor/build\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport prepareTemplate from \"./prepareTemplate\";\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst buildSrcFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/\");\n\tconst adapterSrcFolder = path.resolve(\n\t\tsite.root,\n\t\t\"./node_modules/@torpor/adapter-cloudflare/src/\",\n\t);\n\n\t// Compile _worker.ts\n\tlet workerFile = path.join(adapterSrcFolder, \"_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.join(buildSrcFolder, \"server\", \"Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// HACK: Disabling preload doesn't work so we have to brute-force it???\n\tfor (let file of await fs.readdir(cloudflareFolder)) {\n\t\tif (file.startsWith(\"_worker\")) {\n\t\t\tlet b = await fs.readFile(path.join(cloudflareFolder, file), \"utf-8\");\n\t\t\tif (b.includes(\"const __vitePreload\")) {\n\t\t\t\tb = b.replaceAll(\n\t\t\t\t\t\"const __vitePreload = function preload(baseModule, deps, importerUrl) {\",\n\t\t\t\t\t\"const __vitePreload = function preload(baseModule, deps, importerUrl) { return baseModule();\",\n\t\t\t\t);\n\t\t\t\tawait fs.writeFile(path.join(cloudflareFolder, file), b);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Copy the client assets into the Cloudflare folder\n\tawait fs.mkdir(path.join(cloudflareFolder, \"assets\"));\n\tfor (let file of await fs.readdir(path.join(clientFolder, \"assets\"))) {\n\t\tawait fs.copyFile(\n\t\t\tpath.join(clientFolder, \"assets\", file),\n\t\t\tpath.join(cloudflareFolder, \"assets\", file),\n\t\t);\n\t}\n\n\t// Build a wrangler.toml file for running with `wrangler dev`\n\tconst wranglerConfig = `\nname = \"torpor-miniflare\"\nmain = \"./cloudflare/_worker.js\"\ncompatibility_date = \"2025-01-01\"\n\n[assets]\ndirectory = \"./cloudflare\"\nbinding = \"ASSETS\"\n\t`;\n\tconst wranglerFile = path.join(distFolder, \"wrangler.toml\");\n\tawait fs.writeFile(wranglerFile, wranglerConfig);\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n","export default function prepareTemplate(template: string, clientScript: string) {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n"],"mappings":";AACA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,OAAO,oBAAoB;;;ACHrB,SAAR,gBAAiC,UAAkB,cAAsB;AAC/E,MAAI,eAAe,aAAa,UAAU,iCAAiC;AAC3E,iBAAe,SAAS,QAAQ,KAAK,YAAY,IAAI;AACrD,MAAI,aAAa,SAAS,QAAQ,UAAU,YAAY;AACxD,MAAI,iBAAiB,MAAM,eAAe,IAAI;AAC7C,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACrD;AACA,SACC,SAAS,UAAU,GAAG,YAAY,IAClC,qBACA,SAAS,UAAU,UAAU,IAC7B,8BAA8B,YAAY;AAE5C;AAGA,SAAS,aAAa,QAAgB,OAAe,UAAmB;AACvE,MAAI,UAAU,OAAO,UAAU,YAAY,CAAC,EAAE,OAAO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src/prepareTemplate.ts":{"bytes":801,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3467,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true},{"path":"src/prepareTemplate.ts","kind":"import-statement","original":"./prepareTemplate"}],"format":"esm"},"src/index.ts":{"bytes":60,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7312},"dist/index.cjs":{"imports":[{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"vite","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":136},"src/adapter.ts":{"bytesInOutput":3569},"src/prepareTemplate.ts":{"bytesInOutput":698}},"bytes":5985}}}
1
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":801,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":4035,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true},{"path":"src/prepareTemplate.ts","kind":"import-statement","original":"./prepareTemplate"}],"format":"esm"},"src/index.ts":{"bytes":60,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8272},"dist/index.cjs":{"imports":[{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"vite","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":136},"src/adapter.ts":{"bytesInOutput":4202},"src/prepareTemplate.ts":{"bytesInOutput":698}},"bytes":6618}}}
@@ -1 +1 @@
1
- {"inputs":{"src/prepareTemplate.ts":{"bytes":801,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3467,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true},{"path":"src/prepareTemplate.ts","kind":"import-statement","original":"./prepareTemplate"}],"format":"esm"},"src/index.ts":{"bytes":60,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6990},"dist/index.js":{"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true}],"exports":["cloudflare"],"entryPoint":"src/index.ts","inputs":{"src/adapter.ts":{"bytesInOutput":2958},"src/prepareTemplate.ts":{"bytesInOutput":698},"src/index.ts":{"bytesInOutput":0}},"bytes":3764}}}
1
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":801,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":4035,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true},{"path":"src/prepareTemplate.ts","kind":"import-statement","original":"./prepareTemplate"}],"format":"esm"},"src/index.ts":{"bytes":60,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":7918},"dist/index.js":{"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true}],"exports":["cloudflare"],"entryPoint":"src/index.ts","inputs":{"src/adapter.ts":{"bytesInOutput":3488},"src/prepareTemplate.ts":{"bytesInOutput":698},"src/index.ts":{"bytesInOutput":0}},"bytes":4294}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/adapter-cloudflare",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A @torpor/build adapter for deploying to Cloudflare Pages",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/adapter.ts CHANGED
@@ -82,6 +82,20 @@ async function postbuild(site: Site) {
82
82
  }),
83
83
  );
84
84
 
85
+ // HACK: Disabling preload doesn't work so we have to brute-force it???
86
+ for (let file of await fs.readdir(cloudflareFolder)) {
87
+ if (file.startsWith("_worker")) {
88
+ let b = await fs.readFile(path.join(cloudflareFolder, file), "utf-8");
89
+ if (b.includes("const __vitePreload")) {
90
+ b = b.replaceAll(
91
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) {",
92
+ "const __vitePreload = function preload(baseModule, deps, importerUrl) { return baseModule();",
93
+ );
94
+ await fs.writeFile(path.join(cloudflareFolder, file), b);
95
+ }
96
+ }
97
+ }
98
+
85
99
  // Copy the client assets into the Cloudflare folder
86
100
  await fs.mkdir(path.join(cloudflareFolder, "assets"));
87
101
  for (let file of await fs.readdir(path.join(clientFolder, "assets"))) {