@torpor/adapter-cloudflare 0.0.9 → 0.0.11

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,18 @@
1
1
  # @torpor/adapter-cloudflare
2
2
 
3
+ ## 0.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 3ed8a23: Chore: specify exports in packages
8
+
9
+ ## 0.0.10
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [8de094b]
14
+ - @torpor/build@0.1.12
15
+
3
16
  ## 0.0.9
4
17
 
5
18
  ### Patch Changes
@@ -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// 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;AACnD,QAAM,aAAa,iBAAAA,QAAK,KAAK,YAAY,MAAM;AAC/C,QAAM,mBAAmB,iBAAAA,QAAK,KAAK,YAAY,YAAY;AAG3D,QAAM,iBAAiB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,mCAAmC;AAClF,QAAM,mBAAmB,iBAAAA,QA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AM,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"]}
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],\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): 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;AAC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iB;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.d.cts CHANGED
@@ -1,10 +1,5 @@
1
- import { Site } from '@torpor/build';
1
+ import { Adapter } from '@torpor/build';
2
2
 
3
- declare const _default: {
4
- postbuild: typeof postbuild;
5
- serve: () => void;
6
- };
7
-
8
- declare function postbuild(site: Site): Promise<void>;
3
+ declare const _default: Adapter;
9
4
 
10
5
  export { _default as cloudflare };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,5 @@
1
- import { Site } from '@torpor/build';
1
+ import { Adapter } from '@torpor/build';
2
2
 
3
- declare const _default: {
4
- postbuild: typeof postbuild;
5
- serve: () => void;
6
- };
7
-
8
- declare function postbuild(site: Site): Promise<void>;
3
+ declare const _default: Adapter;
9
4
 
10
5
  export { _default as cloudflare };
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// 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,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,KAAK,QAAQ,KAAK,MAAM,MAAM;AACjD,QAAM,eAAe,KAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,eAAe,KAAK,KAAK,YAAY,QAAQ;AACnD,Q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GR,eAAe;AAAA,MAChB;AAAA,IACD,CAAC;AAAA,EACF;AAGA,WAAS,QAAQ,MAAM,GAAG,QAAQ,gBAAgB,GAAG;AACpD,QAAI,KAAK,WAAW,SAAS,GAAG;AAC/B,UAAI,IAAI,MAAM,GAAG,SAAS,KAAK,KAAK,kBAAkB,IAAI,GAAG,OAAO;AACpE,UAAI,EAAE,SAAS,qBAAqB,GAAG;AACtC,YAAI,EAAE;AAAA,UACL;AAAA,UACA;AAAA,QACD;AACA,cAAM,GAAG,UAAU,KAAK,KAAK,kBAAkB,IAAI,GAAG,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,EACD;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 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],\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): 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,IAAI,WAAW,YAAY,KAAK;AACnD;;;ADbA,IAAO,kBAAQ;AAAA,EACd;AAAA,EACA,OAAO,MAAqC;AAC3C,YAAQ,IAAI,MAAM;AAAA,EACnB;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AA,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,WAAS,QAAQ,MAAM,GAAG,QAAQ,gBAAgB,GAAG;AACpD,QAAI,KAAK,WAAW,SAAS,GAAG;AAC/B,UAAI,IAAI,MAAM,GAAG,SAAS,KAAK,KAAK,kBAAkB,IAAI,GAAG,OAAO;AACpE,UAAI,EAAE,SAAS,qBAAqB,GAAG;AACtC,YAAI,EAAE;AAAA,UACL;AAAA,UACA;AAAA,QACD;AACA,cAAM,GAAG,UAAU,KAAK,KAAK,kBAAkB,IAAI,GAAG,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,EACD;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 +1 @@
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
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":4061,"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":8307},"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":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}}}
1
+ {"inputs":{"src/prepareTemplate.ts":{"bytes":809,"imports":[],"format":"esm"},"src/adapter.ts":{"bytes":4061,"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":7953},"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,11 +1,16 @@
1
1
  {
2
2
  "name": "@torpor/adapter-cloudflare",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A @torpor/build adapter for deploying to Cloudflare Pages",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "exports": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
@@ -13,18 +18,18 @@
13
18
  "author": "",
14
19
  "license": "ISC",
15
20
  "dependencies": {
16
- "vite": "^6.2.6",
17
- "@torpor/build": "^0.1.11"
21
+ "vite": "^6.3.3",
22
+ "@torpor/build": "^0.1.12"
18
23
  },
19
24
  "devDependencies": {
20
25
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
21
26
  "tsup": "^8.4.0",
22
- "tsx": "^4.19.3",
27
+ "tsx": "^4.19.4",
23
28
  "typescript": "^5.8.3",
24
- "vitest": "^3.1.1"
29
+ "vitest": "^3.1.2"
25
30
  },
26
31
  "scripts": {
27
- "build": "tsup",
32
+ "build": "tsc --noEmit && tsup",
28
33
  "build:watch": "tsup --watch",
29
34
  "check": "tsc --noEmit",
30
35
  "test": "vitest"
package/src/_worker.ts CHANGED
@@ -25,7 +25,7 @@ server.add("*", async (ev: any) => {
25
25
  });
26
26
 
27
27
  export default {
28
- async fetch(request: Request, env: any) {
28
+ async fetch(request: Request, env: any): Promise<any> {
29
29
  // Put adapter-specific functionality in the `adapter` property of globalThis
30
30
  // @ts-ignore
31
31
  globalThis.adapter = { env };
package/src/adapter.ts CHANGED
@@ -9,9 +9,9 @@ export default {
9
9
  serve: (/* server: Server, site: Site*/) => {
10
10
  console.log("TODO");
11
11
  },
12
- } satisfies Adapter;
12
+ } satisfies Adapter as Adapter;
13
13
 
14
- async function postbuild(site: Site) {
14
+ async function postbuild(site: Site): Promise<void> {
15
15
  // Build _worker.js as per
16
16
  // https://developers.cloudflare.com/pages/functions/advanced-mode/
17
17
 
@@ -1,4 +1,4 @@
1
- export default function prepareTemplate(template: string, clientScript: string) {
1
+ export default function prepareTemplate(template: string, clientScript: string): string {
2
2
  let contentStart = regexIndexOf(template, /\<div\s+id=("app"|'app'|app)\s+/);
3
3
  contentStart = template.indexOf(">", contentStart) + 1;
4
4
  let contentEnd = template.indexOf("</div>", contentStart);
package/tsup.config.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { defineConfig } from "tsup";
1
+ import { type Options, defineConfig } from "tsup";
2
+
3
+ type Config =
4
+ | Options
5
+ | Options[]
6
+ | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
2
7
 
3
8
  export default defineConfig({
4
9
  entry: ["src/index.ts"],
@@ -7,4 +12,4 @@ export default defineConfig({
7
12
  clean: true,
8
13
  metafile: true,
9
14
  sourcemap: true,
10
- });
15
+ }) satisfies Config as Config;
package/vitest.config.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { defineConfig } from "vitest/config";
1
+ import { type UserConfigFnObject, defineConfig } from "vitest/config";
2
2
 
3
- export default defineConfig(() => ({}));
3
+ export default defineConfig(() => ({})) satisfies UserConfigFnObject as UserConfigFnObject;