Skip to content

Commit

Permalink
Consolidate Houdini modules under one package (#273)
Browse files Browse the repository at this point in the history
* add package emoji to changeset commit

* move packages to src dir and add esbuild for building

* fix import

* update package.json exports

* fix test path

* dry jest module name mapper

* reorganize imports

* fix type errors in tests

* got passed Array.flatMap

* more tests pass

* checkpoint

* attempt to synchronize main with branch

* most tests pass

* all tests pass 🎉

* update example

* generate typedefs when building

* cleanup package.json

* consolidate build script

* tests pass, runtime builds with typedefs

* add types to preprocessor dirs

* cmd is now generated as a commonjs module to avoid jest issues with import.meta.url

* use old rollup config to build packages

* isolate config class from runtime imports and dry up id computation

* fix adapter imports

* remove unused typescript config file

* export config types

* add shebang to cmd output

* add changeset

* remove dep and fix format script

* ran prettier

* missing dep

* configure ts-jest to use babel config

* update snapshots

* reuse default config value util

* only apply import.meta.url transform on tests
  • Loading branch information
AlecAivazis authored Apr 14, 2022
1 parent c5cce52 commit 2adabd7
Show file tree
Hide file tree
Showing 159 changed files with 4,330 additions and 22,866 deletions.
11 changes: 11 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
["@babel/preset-env", { "targets": { "node": "current" } }],
"@babel/preset-typescript"
],
"env": {
"test": {
"plugins": ["babel-plugin-transform-import-meta"]
}
}
}
1 change: 0 additions & 1 deletion .changeset/honest-actors-protect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
'houdini': patch
'houdini-common': patch
---

Added support for non-standard IDs and paginated fragment queries
5 changes: 5 additions & 0 deletions .changeset/shiny-falcons-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': minor
---

Consolidated all houdini packages under a single import. The preprocessor should now be imported from `houdini/preprocess`.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
version: yarn version
publish: yarn release
title: '📦 Version Update'
commit: '📦 v{VERSION}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ __tests__
example/.svelte-kit
example/functions
example/$houdini
packages/houdini/README.md

yarn-error.log

Expand Down
785 changes: 785 additions & 0 deletions .yarn/releases/yarn-3.2.0.cjs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
yarnPath: '.yarn/releases/yarn-berry.cjs'
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.0.cjs
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Changelog
# houdini

The CHANGELOG for a particular package can be found in `packages/<package name>/CHANGELOG.md`. For example, you will find the changelog for the houdini package at [`packages/houdini/CHANGELOG.md`](./packages/houdini/CHANGELOG.md).
## 0.13.10

### Patch Changes

- [#269](https://github.com/HoudiniGraphql/houdini/pull/269) [`bfcd003`](https://github.com/HoudiniGraphql/houdini/commit/bfcd00357e92b47caec988baa919c5c84ddcc333) Thanks [@fehnomenal](https://github.com/fehnomenal)! - Execute multiple queries in parallel

## 0.13.9

### Patch Changes

- [#266](https://github.com/HoudiniGraphql/houdini/pull/266) [`b26cb5e`](https://github.com/HoudiniGraphql/houdini/commit/b26cb5e032ffb87c40b3c43cef73c211cf2fd3de) Thanks [@fehnomenal](https://github.com/fehnomenal)! - Fix `afterLoad` data

## 0.13.8

### Patch Changes

- [#259](https://github.com/HoudiniGraphql/houdini/pull/259) [`d49c30a`](https://github.com/HoudiniGraphql/houdini/commit/d49c30a844228a6004f4590fd74355691f17095e) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - fixes an issue when resolving the first layer in the cache
5 changes: 0 additions & 5 deletions babel.config.cjs

This file was deleted.

1 change: 0 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"concurrently": "^6.2.1",
"graphql": "15.5.0",
"houdini": "^0.13.9",
"houdini-preprocess": "^0.13.9",
"svelte": "^3.38.2",
"svelte-preprocess": "^4.0.0",
"tslib": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion example/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import preprocess from 'svelte-preprocess'
import houdini from 'houdini-preprocess'
import houdini from 'houdini/preprocess'
import path from 'path'

/** @type {import('@sveltejs/kit').Config} */
Expand Down
14 changes: 11 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export default {
preset: 'ts-jest',
projects: ['<rootDir>/packages/*'],
preset: 'ts-jest', // or other ESM presets
moduleFileExtensions: ['js', 'ts'],
snapshotSerializers: ['ts-ast-serializer'],
setupFilesAfterEnv: ['./jest.setup.js'],

moduleNameMapper: {
'^~/(.*)$': '<rootDir>/src/$1',
},

globals: {
'ts-jest': {
babelConfig: true,
},
},
}
9 changes: 9 additions & 0 deletions jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
namespace jest {
interface Matchers<R> {
toMatchArtifactSnapshot(expected?: string): Promise<R>
}
}
}

export {}
51 changes: 35 additions & 16 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const recast = require('recast')
const graphql = require('graphql')
const { testConfig } = require('houdini-common')
const mockFs = require('mock-fs')
const path = require('path')
const { toMatchInlineSnapshot } = require('jest-snapshot')
Expand All @@ -9,9 +8,6 @@ const typeScriptParser = require('recast/parsers/typescript')

process.env.TEST = 'true'

// the config to use in tests
const config = testConfig()

expect.addSnapshotSerializer({
test: (val) => val && Object.keys(recast.types.namedTypes).includes(val.type),
serialize: (val) => {
Expand Down Expand Up @@ -41,9 +37,9 @@ expect.extend({

// assuming that the value we were given is a collected document, figure
// out the path holding the artifact
const path = config.artifactPath(value.document)
const artifactPath = path.join('$houdini/artifacts', documentName(value.document) + '.js')

const artifactContents = await fs.readFile(path, 'utf-8')
const artifactContents = await fs.readFile(artifactPath, 'utf-8')

// parse the contents
const parsed = recast.parse(artifactContents, {
Expand All @@ -56,20 +52,43 @@ expect.extend({

beforeEach(() => {
mockFs({
[path.relative(process.cwd(), config.rootDir)]: {
[path.relative(config.rootDir, config.artifactDirectory)]: {},
[path.relative(config.rootDir, config.runtimeDirectory)]: {},
$houdini: {
artifacts: {},
runtime: {},
},
// the runtime generator copies files relative to __dirname. we need our tests
// the runtime generator copies files relative to import.meta.url. we need our tests
// to point to the same filestructure that will exist
[`packages/houdini/build/runtime-esm`]: mockFs.load(
path.resolve(__dirname, 'packages', 'houdini', 'build', 'runtime-esm')
),
[`packages/houdini/build/runtime-cjs`]: mockFs.load(
path.resolve(__dirname, 'packages', 'houdini', 'build', 'runtime-cjs')
),
[`build/runtime-esm`]: mockFs.load(path.resolve('build', 'runtime-esm')),
[`build/runtime-cjs`]: mockFs.load(path.resolve('build', 'runtime-cjs')),
})
})

// make sure the runtime directory is clear before each test
afterEach(mockFs.restore)

function documentName(document) {
// if there is an operation in the document
const operation = document.definitions.find(({ kind }) => graphql.Kind.OPERATION_DEFINITION)
if (operation) {
// if the operation does not have a name
if (!operation.name) {
// we can't give them a file
throw new Error('encountered operation with no name: ' + graphql.print(document))
}

// use the operation name for the artifact
return operation.name.value
}

// look for a fragment definition
const fragmentDefinitions = document.definitions.filter(
({ kind }) => kind === graphql.Kind.FRAGMENT_DEFINITION
)
if (fragmentDefinitions.length) {
// join all of the fragment definitions into one
return fragmentDefinitions.map((fragment) => fragment.name).join('_')
}

// we don't know how to generate a name for this document
throw new Error('Could not generate artifact name for document: ' + graphql.print(document))
}
68 changes: 50 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
{
"name": "houdini-monorepo",
"private": true,
"name": "houdini",
"version": "0.13.10",
"description": "The disappearing graphql client for SvelteKit",
"workspaces": [
"example",
"packages/*"
"."
],
"type": "module",
"bin": "./build/cmd.js",
"exports": {
"./preprocess": {
"import": "./build/preprocess-esm/index.js",
"require": "./build/preprocess-cjs/index.js"
}
},
"scripts": {
"tests": "node --experimental-vm-modules node_modules/.bin/jest",
"tests": "NODE_ENV=test node --experimental-vm-modules node_modules/.bin/jest",
"tests:watch": "node --experimental-vm-modules node_modules/.bin/jest --watch",
"build": "yarn workspace houdini-common run build && yarn workspace houdini run build && yarn workspace houdini-preprocess run build ",
"clean": "rm -rf packages/*/build",
"format": "prettier \"packages/**/*.ts\"",
"build": "concurrently \"npm run build:runtime\" \"npm run build:cmd\" \"npm run build:preprocess\" && npm run build:typeModule",
"build:runtime": "concurrently \"npm run build:runtime:esm\" \"npm run build:runtime:cjs\"",
"build:runtime:cjs": "tsc --p tsconfig.runtime.cjs.json",
"build:runtime:esm": "tsc --p tsconfig.runtime.esm.json",
"build:preprocess": "concurrently \"npm run build:preprocess:esm\" \"npm run build:preprocess:cjs\"",
"build:preprocess:cjs": "TARGET=esm WHICH=preprocess rollup --config rollup.config.js",
"build:preprocess:esm": "TARGET=cjs WHICH=preprocess rollup --config rollup.config.js",
"build:cmd": "concurrently \"npm run build:cmd:esm\"",
"build:cmd:esm": "TARGET=esm WHICH=cmd rollup --config rollup.config.js",
"build:typeModule": "./typeModule.sh",
"format": "prettier \"src/**/*.ts\"",
"format:write": "npm run format -- -w",
"format:check": "npm run format -- --check",
"postinstall": "husky install",
Expand All @@ -26,33 +41,50 @@
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-typescript": "^7.16.7",
"@changesets/changelog-github": "^0.4.4",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-commonjs": "beta",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.2.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/inquirer": "^7.3.1",
"@types/jest": "^26.0.23",
"babel-jest": "^26.6.3",
"babel-plugin-transform-import-meta": "^2.0.0",
"graphql": "15.5.0",
"babel-plugin-transform-import-meta": "^2.1.1",
"concurrently": "^7.1.0",
"fs-extra": "^10.0.1",
"husky": "^6.0.0",
"install": "^0.13.0",
"jest": "^26.6.3",
"lerna": "^3.22.1",
"mock-fs": "^4.13.0",
"npm": "^8.6.0",
"prettier": "^2.0.5",
"pretty-quick": "^3.1.1",
"rollup": "^2.47.0",
"rollup": "2.68.0",
"rollup-plugin-typescript2": "^0.31.2",
"ts-ast-serializer": "^1.0.1",
"ts-jest": "next",
"ts-jest": "^26.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"typescript": "^4.6.3"
},
"dependencies": {
"@babel/parser": "^7.13.4",
"@changesets/changelog-git": "^0.1.11",
"@changesets/cli": "^2.22.0",
"@graphql-tools/schema": "^8.3.7",
"@types/mock-fs": "^4.13.0",
"babylon": "^7.0.0-beta.47",
"commander": "^7.1.0",
"estree-walker": "^2.0.2",
"glob": "^8.0.1",
"global": "^4.4.0",
"houdini": "^0.13.7-alpha.2",
"graphql": "^15.5.0",
"inquirer": "^8.2.2",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.1",
"recast": "^0.20.4",
"remove": "^0.1.5",
"rollup-plugin-typescript2": "^0.30.0"
"svelte": "^3.34.0"
}
}
11 changes: 0 additions & 11 deletions packages/houdini-common/CHANGELOG.md

This file was deleted.

35 changes: 0 additions & 35 deletions packages/houdini-common/package.json

This file was deleted.

23 changes: 0 additions & 23 deletions packages/houdini-common/rollup.config.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/houdini-common/tsconfig.json

This file was deleted.

Loading

0 comments on commit 2adabd7

Please sign in to comment.