Skip to content

Commit

Permalink
Avoid bundling vite (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Sep 23, 2023
1 parent 493ed2b commit 8741ff3
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-rings-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Fix bug in init causing it to always crash
54 changes: 52 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,56 @@ jobs:
- name: Tests
run: pnpm run tests

verify_create:
name: Verify Create
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
path: houdini

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16.17.0

- 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 houdini && pnpm install

- name: Build packages
run: cd houdini && pnpm run compile

- name: Checkout template
uses: actions/checkout@v4
with:
repository: sveltejs/kit
path: kit

- name: Extract Template
run: mv kit/packages/create-svelte/templates/default project

- name: Run init
run: cd project && node ../houdini/packages/houdini/build/cmd-esm/index.js init -y

e2e_tests:
name: End-to-End Tests
strategy:
Expand Down Expand Up @@ -135,7 +185,7 @@ jobs:
run: pnpm install

# Playwright

# Use Playwright version as part of the cache key
# AFAIK this is a x-platform way to get your installed Playwright version.
# Be sure to be diligent in specifying ^, ~, or locked versions.
Expand Down Expand Up @@ -206,4 +256,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
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/build/**
README.md
.github/**
.github/
packages/*/package.json

packages/houdini-svelte/src/runtime/index.ts
Expand Down
10 changes: 8 additions & 2 deletions packages/_scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async function ({ plugin }) {
// cmd needs to be bundled and set as the project's bin
else if (dirname === 'cmd') {
package_json.bin = './build/cmd-esm/index.js'
await build({ package_json, source: dir, plugin, cmd: true })
await build({ package_json, source: dir, plugin, bundle: true, cmd: true })
}

// its not a special directory, treat it as a sub module
Expand Down Expand Up @@ -108,12 +108,18 @@ async function build({ package_json, source, bundle = true, plugin, cmd }) {
}
}

// compute the appropriate external dependencies based on what we are bundling
let external = []
if (bundle) {
external.push('vite', 'graphql', 'HOUDINI_CLIENT_PATH')
}

// the esbuild config
const config = {
bundle,
platform: 'node',
format: which,
external: bundle ? ['vite', 'HOUDINI_CLIENT_PATH', 'graphql'] : [],
external,
banner: {
js: header,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
},
"main": "./build/plugin-cjs/index.js",
"types": "./build/plugin/index.d.ts"
}
}
5 changes: 2 additions & 3 deletions packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
get_session,
handle_request,
localApiSessionKeys,
isViteSchemaBuild,
isSecondaryBuild,
} from 'houdini'
import type { renderToStream as streamingRender } from 'react-streaming/server'
import { InputOption } from 'rollup'
import type { BuildOptions, Connect, ViteDevServer } from 'vite'

import { setManifest } from '.'
Expand Down Expand Up @@ -50,7 +49,7 @@ export default {
}

// build up the list of entries that we need vite to bundle
if (!isViteSchemaBuild()) {
if (!isSecondaryBuild()) {
rollupConfig.outDir = config.compiledAssetsDir
rollupConfig.rollupOptions!.input = {}

Expand Down
10 changes: 1 addition & 9 deletions packages/houdini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
"import": "./build/lib-esm/index.js",
"require": "./build/lib-cjs/index.js"
},
"./router": {
"types": "./build/router/index.d.ts",
"import": "./build/router-esm/index.js",
"require": "./build/router-cjs/index.js"
},
"./test": {
"types": "./build/test/index.d.ts",
"import": "./build/test-esm/index.js",
Expand All @@ -94,9 +89,6 @@
"codegen": [
"build/codegen/index.d.ts"
],
"router": [
"build/router/index.d.ts"
],
"test": [
"build/test/index.d.ts"
],
Expand All @@ -108,4 +100,4 @@
"bin": "./build/cmd-esm/index.js",
"main": "./build/lib-cjs/index.js",
"types": "./build/lib/index.d.ts"
}
}
1 change: 1 addition & 0 deletions packages/houdini/src/cmd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ program
'-h, --headers <headers...>',
'header to use when pulling your schema. Should be passed as KEY=VALUE'
)
.option('-y, --yes', 'dont prompt for input. uses default values or empty strings')
.action(init)

// register the pull schema command
Expand Down
48 changes: 27 additions & 21 deletions packages/houdini/src/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function init(
_path: string | undefined,
args: {
headers?: string[]
yes?: boolean
}
): Promise<void> {
p.intro('🎩 Welcome to Houdini!')
Expand Down Expand Up @@ -84,23 +85,28 @@ export async function init(

// Questions...
let url = 'http://localhost:5173/api/graphql'
const { is_remote_endpoint } = await p.group(
{
is_remote_endpoint: () =>
p.confirm({
message: 'Will you use a remote GraphQL API?',
initialValue: true,
}),
},
{
onCancel: () => pCancel(),
}
)
let is_remote_endpoint = true
if (!args.yes) {
is_remote_endpoint = (
await p.group(
{
is_remote_endpoint: () =>
p.confirm({
message: 'Will you use a remote GraphQL API?',
initialValue: true,
}),
},
{
onCancel: () => pCancel(),
}
)
).is_remote_endpoint
}

let schemaPath = is_remote_endpoint ? './schema.graphql' : 'path/to/src/lib/**/*.graphql'

let pullSchema_content: string | null = null
if (is_remote_endpoint) {
if (is_remote_endpoint && !args.yes) {
let number_of_round = 0
let url_and_headers = ''
while (pullSchema_content === null && number_of_round < 10) {
Expand Down Expand Up @@ -160,7 +166,7 @@ export async function init(
if (pullSchema_content === null) {
pCancel("We couldn't pull the schema. Please check your URL/headers and try again.")
}
} else {
} else if (!args.yes) {
// the schema is local so ask them for the path
const answers = await p.group(
{
Expand Down Expand Up @@ -288,13 +294,13 @@ export function finale_logs(package_manager: 'npm' | 'yarn' | 'pnpm') {
/******************************/
/* Houdini's files */
/******************************/
const houdiniConfig = async (
async function houdiniConfig(
configPath: string,
schemaPath: string,
module: 'esm' | 'commonjs',
frameworkInfo: HoudiniFrameworkInfo,
url: string | null
): Promise<boolean> => {
): Promise<boolean> {
const config: ConfigFile = {}

// if we have no url, we are using a local schema
Expand Down Expand Up @@ -352,12 +358,12 @@ module.exports = config
return false
}

const houdiniClient = async (
async function houdiniClient(
targetPath: string,
typescript: boolean,
frameworkInfo: HoudiniFrameworkInfo,
url: string
) => {
) {
// where we put the houdiniClient
const houdiniClientExt = typescript ? `ts` : `js`
const houdiniClientPath = path.join(targetPath, `client.${houdiniClientExt}`)
Expand All @@ -369,8 +375,8 @@ export default new HoudiniClient({
// uncomment this to configure the network call (for things like authentication)
// for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
// fetchParams({ session }) {
// return {
// fetchParams({ session }) {
// return {
// headers: {
// Authentication: \`Bearer \${session.token}\`,
// }
Expand Down Expand Up @@ -496,7 +502,7 @@ export default defineConfig({
$houdini: path.resolve('$houdini'),
},
},
})
})
`
} else if (frameworkInfo.framework === 'kit') {
content = `import { sveltekit } from '@sveltejs/kit/vite'
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export type { EmbeddedGraphqlDocument } from './walk'

export * as fs from './fs'
export * as path from './path'
export * from '../router'
export * from './router'

export { Cache } from '../runtime/cache/cache'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { path, fs, type Config } from '../lib'
import { path, fs, type Config } from '..'

/** The location of the project's router */
export function router_path(config: Config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './manifest'
export * from './types'
export * from './server'

export { handle_request, get_session } from '../runtime/router/server'
export { handle_request, get_session } from '../../runtime/router/server'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, describe } from 'vitest'

import { fs } from '../lib'
import { testConfig, clearMock } from '../test'
import { fs } from '..'
import { testConfig, clearMock } from '../../test'
import { load_manifest, extractQueries } from './manifest'

test('empty routes dir generates empty manifest', async function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as t from '@babel/types'
import * as graphql from 'graphql'

import { path, fs, parseJS, type Config } from '../lib'
import type { ProjectManifest, PageManifest, QueryManifest } from '../runtime/lib/types'
import { path, fs, parseJS, type Config } from '..'
import type { ProjectManifest, PageManifest, QueryManifest } from '../../runtime/lib/types'
import {
read_layoutQuery,
read_layoutView,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type * as graphql from 'graphql'
import path from 'node:path'
import { build } from 'vite'

import type { Config } from '../lib/config'
import type { Config } from '../config'

export function isViteSchemaBuild() {
export function isSecondaryBuild() {
return process.env.HOUDINI_SCHEMA_BUILD === 'true'
}

export async function loadLocalSchema(config: Config): Promise<graphql.GraphQLSchema> {
// load the current version of vite
const { build } = await import('vite')

process.env.HOUDINI_SCHEMA_BUILD = 'true'

// build the schema somewhere we can import from
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProjectManifest, routerConventions } from '.'
import type { Config } from '../lib/config'
import type { Config } from '../config'

export type Adapter = (args: {
config: Config
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
} from 'rollup'
import type { ConfigEnv, ResolvedConfig, UserConfig, ViteDevServer } from 'vite'

import type { Adapter } from '../router'
import type { ConfigFile } from '../runtime/lib/config'
import type {
ArtifactKinds,
Expand All @@ -24,6 +23,7 @@ import type {
} from '../runtime/lib/types'
import type { TransformPage } from '../vite/houdini'
import type { Config } from './config'
import type { Adapter } from './router'

type Program = recast.types.namedTypes.Program

Expand Down
Loading

0 comments on commit 8741ff3

Please sign in to comment.