@torpor/adapter-cloudflare 0.0.23 → 0.0.24

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,13 @@
1
1
  # @torpor/adapter-cloudflare
2
2
 
3
+ ## 0.0.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 22f62d4: Fix: Site.viteConfig settings
8
+ - Updated dependencies [22f62d4]
9
+ - @torpor/build@0.1.23
10
+
3
11
  ## 0.0.23
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -90,27 +90,20 @@ async function postbuild(site) {
90
90
  workerFile = import_node_path.default.join(tempFolder, "_worker.ts");
91
91
  await import_node_fs.promises.mkdir(tempFolder);
92
92
  await import_node_fs.promises.writeFile(workerFile, workerSource);
93
- await (0, import_vite.build)(
94
- (0, import_vite.defineConfig)({
95
- build: {
96
- outDir: cloudflareFolder,
97
- rollupOptions: {
98
- input: [workerFile, ...site.inputs],
99
- output: {
100
- entryFileNames: `[name].js`,
101
- chunkFileNames: `[name].js`,
102
- assetFileNames: `[name].[ext]`
103
- },
104
- preserveEntrySignatures: "strict"
105
- },
106
- // HACK: We don't need to minify as the worker isn't downloaded?
107
- // And it makes debugging easier
108
- minify: false,
109
- // HACK: Build for SSR so we don't get document and window references
110
- ssr: true
111
- }
112
- })
113
- );
93
+ const cloudflareConfig = structuredClone(site.viteConfig ?? {});
94
+ cloudflareConfig.build ??= {};
95
+ cloudflareConfig.build.outDir = cloudflareFolder;
96
+ cloudflareConfig.build.rollupOptions ??= {};
97
+ cloudflareConfig.build.rollupOptions.input = [workerFile, ...site.inputs];
98
+ cloudflareConfig.build.rollupOptions.output = {
99
+ entryFileNames: `[name].js`,
100
+ chunkFileNames: `[name].js`,
101
+ assetFileNames: `[name].[ext]`
102
+ };
103
+ cloudflareConfig.build.rollupOptions.preserveEntrySignatures = "strict";
104
+ cloudflareConfig.build.minify = false;
105
+ cloudflareConfig.build.ssr = true;
106
+ await (0, import_vite.build)((0, import_vite.defineConfig)(cloudflareConfig));
114
107
  await import_node_fs.promises.mkdir(import_node_path.default.join(cloudflareFolder, "assets"));
115
108
  for (let file of await import_node_fs.promises.readdir(import_node_path.default.join(clientFolder, "assets"))) {
116
109
  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 as Adapter;\n\nasync function postbuild(site: Site): Promise<void> {\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, ...site.inputs],\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: Build for SSR so we don't get document and window references\n\t\t\t\tssr: true,\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): 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,cAA8B;AACvF,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,a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"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 as Adapter;\n\nasync function postbuild(site: Site): Promise<void> {\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\tconst cloudflareConfig = structuredClone(site.viteConfig ?? {});\n\tcloudflareConfig.build ??= {};\n\tcloudflareConfig.build.outDir = cloudflareFolder;\n\tcloudflareConfig.build.rollupOptions ??= {};\n\tcloudflareConfig.build.rollupOptions.input = [workerFile, ...site.inputs];\n\tcloudflareConfig.build.rollupOptions.output = {\n\t\tentryFileNames: `[name].js`,\n\t\tchunkFileNames: `[name].js`,\n\t\tassetFileNames: `[name].[ext]`,\n\t};\n\tcloudflareConfig.build.rollupOptions.preserveEntrySignatures = \"strict\";\n\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t// And it makes debugging easier\n\tcloudflareConfig.build.minify = false;\n\t// HACK: Build for SSR so we don't get document and window references\n\tcloudflareConfig.build.ssr = true;\n\tawait build(defineConfig(cloudflareConfig));\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): 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,cAA8B;AACvF,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,MAA2B;AA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AE3C,QAAM,mBAAmB,gBAAgB,KAAK,cAAc,CAAC,CAAC;AAC9D,mBAAiB,UAAU,CAAC;AAC5B,mBAAiB,MAAM,SAAS;AAChC,mBAAiB,MAAM,kBAAkB,CAAC;AAC1C,mBAAiB,MAAM,cAAc,QAAQ,CAAC,YAAY,GAAG,KAAK,MAAM;AACxE,mBAAiB,MAAM,cAAc,SAAS;AAAA,IAC7C,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EACjB;AACA,mBAAiB,MAAM,cAAc,0BAA0B;AAG/D,mBAAiB,MAAM,SAAS;AAEhC,mBAAiB,MAAM,MAAM;AAC7B,YAAM,uBAAM,0BAAa,gBAAgB,CAAC;AAG1C,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"]}
package/dist/index.js CHANGED
@@ -54,27 +54,20 @@ async function postbuild(site) {
54
54
  workerFile = path.join(tempFolder, "_worker.ts");
55
55
  await fs.mkdir(tempFolder);
56
56
  await fs.writeFile(workerFile, workerSource);
57
- await build(
58
- defineConfig({
59
- build: {
60
- outDir: cloudflareFolder,
61
- rollupOptions: {
62
- input: [workerFile, ...site.inputs],
63
- output: {
64
- entryFileNames: `[name].js`,
65
- chunkFileNames: `[name].js`,
66
- assetFileNames: `[name].[ext]`
67
- },
68
- preserveEntrySignatures: "strict"
69
- },
70
- // HACK: We don't need to minify as the worker isn't downloaded?
71
- // And it makes debugging easier
72
- minify: false,
73
- // HACK: Build for SSR so we don't get document and window references
74
- ssr: true
75
- }
76
- })
77
- );
57
+ const cloudflareConfig = structuredClone(site.viteConfig ?? {});
58
+ cloudflareConfig.build ??= {};
59
+ cloudflareConfig.build.outDir = cloudflareFolder;
60
+ cloudflareConfig.build.rollupOptions ??= {};
61
+ cloudflareConfig.build.rollupOptions.input = [workerFile, ...site.inputs];
62
+ cloudflareConfig.build.rollupOptions.output = {
63
+ entryFileNames: `[name].js`,
64
+ chunkFileNames: `[name].js`,
65
+ assetFileNames: `[name].[ext]`
66
+ };
67
+ cloudflareConfig.build.rollupOptions.preserveEntrySignatures = "strict";
68
+ cloudflareConfig.build.minify = false;
69
+ cloudflareConfig.build.ssr = true;
70
+ await build(defineConfig(cloudflareConfig));
78
71
  await fs.mkdir(path.join(cloudflareFolder, "assets"));
79
72
  for (let file of await fs.readdir(path.join(clientFolder, "assets"))) {
80
73
  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 as Adapter;\n\nasync function postbuild(site: Site): Promise<void> {\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, ...site.inputs],\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: Build for SSR so we don't get document and window references\n\t\t\t\tssr: true,\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): 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\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A;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 as Adapter;\n\nasync function postbuild(site: Site): Promise<void> {\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\tconst cloudflareConfig = structuredClone(site.viteConfig ?? {});\n\tcloudflareConfig.build ??= {};\n\tcloudflareConfig.build.outDir = cloudflareFolder;\n\tcloudflareConfig.build.rollupOptions ??= {};\n\tcloudflareConfig.build.rollupOptions.input = [workerFile, ...site.inputs];\n\tcloudflareConfig.build.rollupOptions.output = {\n\t\tentryFileNames: `[name].js`,\n\t\tchunkFileNames: `[name].js`,\n\t\tassetFileNames: `[name].[ext]`,\n\t};\n\tcloudflareConfig.build.rollupOptions.preserveEntrySignatures = \"strict\";\n\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t// And it makes debugging easier\n\tcloudflareConfig.build.minify = false;\n\t// HACK: Build for SSR so we don't get document and window references\n\tcloudflareConfig.build.ssr = true;\n\tawait build(defineConfig(cloudflareConfig));\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): 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,cAA8B;AACvF,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,IA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AY,YAAY;AAE3C,QAAM,mBAAmB,gBAAgB,KAAK,cAAc,CAAC,CAAC;AAC9D,mBAAiB,UAAU,CAAC;AAC5B,mBAAiB,MAAM,SAAS;AAChC,mBAAiB,MAAM,kBAAkB,CAAC;AAC1C,mBAAiB,MAAM,cAAc,QAAQ,CAAC,YAAY,GAAG,KAAK,MAAM;AACxE,mBAAiB,MAAM,cAAc,SAAS;AAAA,IAC7C,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EACjB;AACA,mBAAiB,MAAM,cAAc,0BAA0B;AAG/D,mBAAiB,MAAM,SAAS;AAEhC,mBAAiB,MAAM,MAAM;AAC7B,QAAM,MAAM,aAAa,gBAAgB,CAAC;AAG1C,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 +1 @@
1
- {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3434,"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":7292},"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":3506},"src/prepareTemplate.ts":{"bytesInOutput":698}},"bytes":5922}}}
1
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3677,"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":7547},"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":3517},"src/prepareTemplate.ts":{"bytesInOutput":698}},"bytes":5933}}}
@@ -1 +1 @@
1
- {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3434,"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.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6970},"dist/index.js":{"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true}],"exports":["cloudflare"],"entryPoint":"src/index.ts","inputs":{"src/adapter.ts":{"bytesInOutput":2885},"src/prepareTemplate.ts":{"bytesInOutput":698},"src/index.ts":{"bytesInOutput":0}},"bytes":3691}}}
1
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":3677,"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.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":7224},"dist/index.js":{"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"vite","kind":"import-statement","external":true}],"exports":["cloudflare"],"entryPoint":"src/index.ts","inputs":{"src/adapter.ts":{"bytesInOutput":2896},"src/prepareTemplate.ts":{"bytesInOutput":698},"src/index.ts":{"bytesInOutput":0}},"bytes":3702}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/adapter-cloudflare",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "A @torpor/build adapter for deploying to Cloudflare Pages",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -19,7 +19,7 @@
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
21
  "vite": "^6.3.5",
22
- "@torpor/build": "^0.1.22"
22
+ "@torpor/build": "^0.1.23"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
package/src/adapter.ts CHANGED
@@ -59,27 +59,23 @@ async function postbuild(site: Site): Promise<void> {
59
59
  await fs.mkdir(tempFolder);
60
60
  await fs.writeFile(workerFile, workerSource);
61
61
 
62
- await build(
63
- defineConfig({
64
- build: {
65
- outDir: cloudflareFolder,
66
- rollupOptions: {
67
- input: [workerFile, ...site.inputs],
68
- output: {
69
- entryFileNames: `[name].js`,
70
- chunkFileNames: `[name].js`,
71
- assetFileNames: `[name].[ext]`,
72
- },
73
- preserveEntrySignatures: "strict",
74
- },
75
- // HACK: We don't need to minify as the worker isn't downloaded?
76
- // And it makes debugging easier
77
- minify: false,
78
- // HACK: Build for SSR so we don't get document and window references
79
- ssr: true,
80
- },
81
- }),
82
- );
62
+ const cloudflareConfig = structuredClone(site.viteConfig ?? {});
63
+ cloudflareConfig.build ??= {};
64
+ cloudflareConfig.build.outDir = cloudflareFolder;
65
+ cloudflareConfig.build.rollupOptions ??= {};
66
+ cloudflareConfig.build.rollupOptions.input = [workerFile, ...site.inputs];
67
+ cloudflareConfig.build.rollupOptions.output = {
68
+ entryFileNames: `[name].js`,
69
+ chunkFileNames: `[name].js`,
70
+ assetFileNames: `[name].[ext]`,
71
+ };
72
+ cloudflareConfig.build.rollupOptions.preserveEntrySignatures = "strict";
73
+ // HACK: We don't need to minify as the worker isn't downloaded?
74
+ // And it makes debugging easier
75
+ cloudflareConfig.build.minify = false;
76
+ // HACK: Build for SSR so we don't get document and window references
77
+ cloudflareConfig.build.ssr = true;
78
+ await build(defineConfig(cloudflareConfig));
83
79
 
84
80
  // Copy the client assets into the Cloudflare folder
85
81
  await fs.mkdir(path.join(cloudflareFolder, "assets"));