-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95a0707
commit f824df7
Showing
21 changed files
with
334 additions
and
143 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 @@ | ||
--- | ||
'houdini-adapter-auto': patch | ||
--- | ||
|
||
Add smart adapter |
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 @@ | ||
--- | ||
'houdini-adapter-node': patch | ||
--- | ||
|
||
Add adapter for node |
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 |
---|---|---|
|
@@ -142,62 +142,6 @@ jobs: | |
|
||
- name: Run init | ||
run: cd project && node ../houdini/packages/houdini/build/cmd-esm/index.js init -y | ||
|
||
verify_create: | ||
name: Verify Create | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
template: [react, react-typescript, sveltekit-demo] | ||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref }} | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.17.1 | ||
|
||
- uses: pnpm/[email protected] | ||
name: Install pnpm | ||
id: pnpm-install | ||
with: | ||
version: 8 | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache | ||
run: | | ||
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: cd packages/create-houdini && pnpm install | ||
|
||
- name: Create template (local) | ||
if: matrix.template != 'sveltekit-demo' | ||
run: cd packages/create-houdini && pnpm dev test-${{ matrix.template }} -t ${{ matrix.template }} -s local | ||
|
||
- name: Create template (not local) | ||
if: matrix.template == 'sveltekit-demo' | ||
run: cd packages/create-houdini && pnpm dev test-${{ matrix.template }} -t ${{ matrix.template }} | ||
|
||
- run: cd packages/create-houdini/test-${{ matrix.template }} && npx playwright install | ||
|
||
- name: e2e install | ||
run: cd packages/create-houdini/test-${{ matrix.template }} && npm i | ||
|
||
- name: e2e tests | ||
if: matrix.template == 'sveltekit-demo' | ||
run: cd packages/create-houdini/test-${{ matrix.template }} && npm run test:integration | ||
|
||
e2e_tests: | ||
name: End-to-End Tests | ||
|
@@ -314,4 +258,4 @@ jobs: | |
run: pnpm --filter e2e-kit run lint | ||
|
||
- name: End-to-End check | ||
run: pnpm --filter e2e-kit run check | ||
run: pnpm --filter e2e-kit run check |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "houdini-adapter-auto", | ||
"version": "1.2.27", | ||
"description": "An adapter for deploying your Houdini application according to the build environment ", | ||
"keywords": [ | ||
"houdini", | ||
"adpter", | ||
"cloudflare", | ||
"workers", | ||
"node" | ||
], | ||
"homepage": "https://github.com/HoudiniGraphql/houdini", | ||
"funding": "https://github.com/sponsors/HoudiniGraphql", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/HoudiniGraphql/houdini.git" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsup src/* --format esm,cjs --external vite --minify --dts --clean --out-dir build", | ||
"build:": "cd ../../ && ((run build && cd -) || (cd - && exit 1))", | ||
"build:build": "pnpm build: && pnpm build" | ||
}, | ||
"devDependencies": { | ||
"scripts": "workspace:^", | ||
"tsup": "^7.2.0" | ||
}, | ||
"dependencies": { | ||
"houdini": "workspace:^", | ||
"import-meta-resolve": "^3.0.0" | ||
}, | ||
"files": [ | ||
"build" | ||
], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": "./build/index.js", | ||
"require": "./build/index.cjs" | ||
}, | ||
"./app": { | ||
"import": "./build/app.js", | ||
"require": "./build/app.cjs" | ||
} | ||
}, | ||
"types": "./build/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"app": [ | ||
"build/app.d.ts" | ||
] | ||
} | ||
} | ||
} |
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,106 @@ | ||
import { type Adapter, detectTools } from 'houdini' | ||
import { resolve } from 'import-meta-resolve' | ||
import { execSync } from 'node:child_process' | ||
import { pathToFileURL } from 'node:url' | ||
|
||
const adapters = [ | ||
{ | ||
name: 'CloudFlare Pages', | ||
test: () => Boolean(process.env.CF_PAGES), | ||
module: 'houdini-adapter-cloudflare', | ||
}, | ||
{ | ||
name: 'HoudiniCloud', | ||
test: () => Boolean(process.env.HOUDINI_CLOUD), | ||
module: 'houdini-cloud-adapter', | ||
}, | ||
// putting this at the bottom makes it will be the default | ||
{ | ||
name: 'Node', | ||
test: () => true, | ||
module: 'houdini-adapter-node', | ||
}, | ||
] | ||
|
||
const adapter: Adapter = async (ctx) => { | ||
// find the matching adapter | ||
let match: (typeof adapters)[number] | undefined | ||
for (const adapter of adapters) { | ||
if (adapter.test()) { | ||
match = adapter | ||
break | ||
} | ||
} | ||
|
||
// make typescript happy even tho we have a default | ||
if (!match) throw new Error('Could not identify environment') | ||
|
||
// tell the user what we found | ||
console.log(`🎩 Identified environment: ${match.name}`) | ||
|
||
// load the adapter | ||
const nextAdapter = await loadAdapter(match) | ||
|
||
// run the adapter | ||
return nextAdapter(ctx) | ||
} | ||
|
||
async function loadAdapter({ module }: { module: string }): Promise<Adapter> { | ||
// if we have the required module loaded, we're good | ||
try { | ||
return (await importFromCwd(module)) as Adapter | ||
} catch (err) { | ||
// if the error indicates we were missing the module, let's keep going | ||
const error = err as Error & { code: string } | ||
if ( | ||
error.code !== 'ERR_MODULE_NOT_FOUND' || | ||
!error.message.startsWith(`Cannot find package '${module}'`) | ||
) { | ||
throw err | ||
} | ||
} | ||
|
||
// if we didn't have the module loaded we can try installing it with the users package manager | ||
const { package_manager } = await detectTools() | ||
|
||
// the command to run to install the adapter | ||
const installCmds = { | ||
yarn: 'add -D', | ||
npm: 'install -D', | ||
pnpm: 'add -D', | ||
} | ||
|
||
// something might go wrong during installation | ||
try { | ||
// install the pacakge we need to | ||
execSync(`${package_manager} ${installCmds[package_manager]} ${module}`, { | ||
stdio: 'inherit', | ||
env: { | ||
...process.env, | ||
NODE_ENV: undefined, | ||
}, | ||
}) | ||
|
||
console.log(`Successfully installed ${module}!`) | ||
console.warn( | ||
`If you plan on staying in this environment, consider adding ${module} to your project so you don't have to install it every time you build your application.` | ||
) | ||
|
||
// we should be able to import it now | ||
return (await importFromCwd(module)) as Adapter | ||
} catch (err) { | ||
throw new Error( | ||
`Could not install package ${module}. Please install it manually or maybe consider replacing houdini-adapter-auto with ${module}.` + | ||
`\n${(err as Error).message}` | ||
) | ||
} | ||
} | ||
|
||
async function importFromCwd(name: string) { | ||
const cwd = pathToFileURL(process.cwd()).href | ||
const url = resolve(name, cwd + '/x.js') | ||
|
||
return (await import(url)).default | ||
} | ||
|
||
export default adapter |
File renamed without changes.
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
File renamed without changes.
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,48 @@ | ||
{ | ||
"name": "houdini-adapter-node", | ||
"version": "1.2.27", | ||
"description": "The adapter for deploying your Houdini application as a standalone node server", | ||
"keywords": [ | ||
"houdini", | ||
"adpter", | ||
"node" | ||
], | ||
"homepage": "https://github.com/HoudiniGraphql/houdini", | ||
"funding": "https://github.com/sponsors/HoudiniGraphql", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/HoudiniGraphql/houdini.git" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsup src/index.ts src/app.ts --format esm,cjs --minify --dts --clean --out-dir build", | ||
"build:": "cd ../../ && ((run build && cd -) || (cd - && exit 1))", | ||
"build:build": "pnpm build: && pnpm build" | ||
}, | ||
"devDependencies": { | ||
"scripts": "workspace:^", | ||
"tsup": "^7.2.0" | ||
}, | ||
"dependencies": { | ||
"houdini": "workspace:^" | ||
}, | ||
"files": [ | ||
"build" | ||
], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": "./build/index.js", | ||
"require": "./build/index.cjs" | ||
} | ||
}, | ||
"types": "./build/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"app": [ | ||
"build/app.d.ts" | ||
] | ||
} | ||
} | ||
} |
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,14 @@ | ||
import { createServerAdapter } from 'houdini/adapter' | ||
import { createServer } from 'node:http' | ||
|
||
// create the production server adapter | ||
const serverAdapter = createServerAdapter({ | ||
production: true, | ||
assetPrefix: '/assets', | ||
}) | ||
|
||
// wrap the server adapter in a node http server | ||
const nodeServer = createServer(serverAdapter) | ||
|
||
// start listening on the designated port | ||
nodeServer.listen(process.env.PORT ?? 3000) |
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,16 @@ | ||
import { type Adapter, fs, path } from 'houdini' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
const adapter: Adapter = async ({ outDir, adapterPath }) => { | ||
// read the contents of the app file | ||
let workerContents = (await fs.readFile( | ||
fileURLToPath(new URL('./app.js', import.meta.url).href) | ||
))! | ||
|
||
// make sure that the adapter module imports from the correct path | ||
workerContents = workerContents.replaceAll('houdini/adapter', adapterPath) | ||
|
||
await fs.writeFile(path.join(outDir, 'index.js'), workerContents!) | ||
} | ||
|
||
export default adapter |
Oops, something went wrong.