-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudflare-pages): generate
_routes.json
(#121)
* feat(cloudflare-pages): detect static files automatically * add changeset * Update packages/cloudflare-pages/src/cloudflare-pages.ts Co-authored-by: ryu <[email protected]> * `readdir` in the `writeBundle` * add `serveStaticDir` option and fixed the order * don't set `serveStatc()` and fixed the order for `_routes.json` --------- Co-authored-by: yudai-nkt <[email protected]> Co-authored-by: ryu <[email protected]>
- Loading branch information
1 parent
9bed7aa
commit cf3afbf
Showing
8 changed files
with
78 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hono/vite-cloudflare-pages': minor | ||
--- | ||
|
||
feat: detect static files automatically |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { cloudflarePagesPlugin } from './cloudflare-pages.js' | ||
import { cloudflarePagesPlugin, defaultOptions } from './cloudflare-pages.js' | ||
export { defaultOptions } | ||
export default cloudflarePagesPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,70 @@ | ||
import * as fs from 'node:fs' | ||
import path from 'path' | ||
import { build } from 'vite' | ||
import { describe, it, expect, beforeAll, afterAll } from 'vitest' | ||
import { describe, it, expect, afterAll } from 'vitest' | ||
import cloudflarePagesPlugin from '../src/index' | ||
|
||
describe('cloudflarePagesPlugin', () => { | ||
const testDir = './test-project' | ||
const testDir = './test/project' | ||
const entryFile = `${testDir}/app/server.ts` | ||
|
||
beforeAll(() => { | ||
fs.mkdirSync(path.dirname(entryFile), { recursive: true }) | ||
fs.writeFileSync(entryFile, 'export default { fetch: () => new Response("Hello World") }') | ||
}) | ||
|
||
afterAll(() => { | ||
fs.rmSync(testDir, { recursive: true, force: true }) | ||
fs.rmSync(`${testDir}/dist`, { recursive: true, force: true }) | ||
}) | ||
|
||
it('Should build the project correctly with the plugin', async () => { | ||
const outputFile = `${testDir}/dist/_worker.js` | ||
const routesFile = `${testDir}/dist/_routes.json` | ||
|
||
expect(fs.existsSync(entryFile)).toBe(true) | ||
|
||
await build({ | ||
root: testDir, | ||
plugins: [cloudflarePagesPlugin()], | ||
build: { | ||
emptyOutDir: true, | ||
}, | ||
}) | ||
|
||
expect(fs.existsSync(outputFile)).toBe(true) | ||
expect(fs.existsSync(routesFile)).toBe(true) | ||
|
||
const output = fs.readFileSync(outputFile, 'utf-8') | ||
expect(output).toContain('Hello World') | ||
|
||
const routes = fs.readFileSync(routesFile, 'utf-8') | ||
expect(routes).toContain( | ||
'{"version":1,"include":["/*"],"exclude":["/favicon.ico","/static/*"]}' | ||
) | ||
}) | ||
|
||
it('Should build the project correctly with custom output directory', async () => { | ||
const outputFile = `${testDir}/customDir/_worker.js` | ||
const routesFile = `${testDir}/customDir/_routes.json` | ||
|
||
afterAll(() => { | ||
fs.rmSync(`${testDir}/customDir/`, { recursive: true, force: true }) | ||
}) | ||
|
||
expect(fs.existsSync(entryFile)).toBe(true) | ||
|
||
await build({ | ||
root: testDir, | ||
plugins: [cloudflarePagesPlugin({ | ||
outputDir: 'customDir', | ||
})], | ||
plugins: [ | ||
cloudflarePagesPlugin({ | ||
outputDir: 'customDir', | ||
}), | ||
], | ||
build: { | ||
emptyOutDir: true, | ||
}, | ||
}) | ||
|
||
expect(fs.existsSync(outputFile)).toBe(true) | ||
expect(fs.existsSync(routesFile)).toBe(true) | ||
|
||
const output = fs.readFileSync(outputFile, 'utf-8') | ||
expect(output).toContain('Hello World') | ||
|
||
const routes = fs.readFileSync(routesFile, 'utf-8') | ||
expect(routes).toContain( | ||
'{"version":1,"include":["/*"],"exclude":["/favicon.ico","/static/*"]}' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
fetch: () => new Response('Hello World'), | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |