mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-02 04:29:55 -06:00
* Revert "chore: simplify build script (#27547)" This reverts commit0a86ec686e. * Revert "chore: upgrade lerna to 6, cache build step (#26913)" This reverts commit9e60aeba8f. * [run ci] * chore: upgrade lerna to 6, cache build step (#26913) * chore: update build-npm-modules script * chore: update build-npm-modules script * chore: update build-npm-modules script * chore: update build-npm-modules script * chore: update lerna to 6 * [run ci] * try caching build step * we can't clean without building after * add dependencies on scripts for npm packages * update commands * add config for data-context build step * fix output configurations for npm packages, add gitignores * revert changes to config and data-context build steps * fix outputs * run with cache * fix outputs for cli * actually fix outputs * test with cache --------- Co-authored-by: astone123 <adams@cypress.io> * chore: simplify build script (#27547) * chore: simplify build script * update CI workflows * fix workflows * empty commit because Percy weirdness * chore: add driver, reporter, config as implicit dependencies for runner package (#27559) * run all workflows on branch * chore: parallelize test-binary-against-recipes CI step (#27570) * chore: fix some easy circular dependencies in dep graph (#27612) * chore: remove gulp tasks from postinstall (#27616) * empty commit * chore: minor improvements to node_modules_install (#27647) * chore: fix cypress:open and dev scripts * run with cache [run ci] * exclude mochaawesome assets from .yarnclean [run ci] * bump cache again [run ci] * run cached [run ci] * chore: do not cache cli build step [run ci] * update workflow command and docs for build-cli [run ci] * fix commands that use scope [run ci] * use different branch for publish repo [run ci] * percy weirdness? [run ci] * fix postbuild cli script [run ci] * try to remove typescript from production binary [run ci] * fix circular dependency [run ci] * try removing ts from node_modules [run ci] * remove typescript resolution [run ci] * remove redundant target scripts * update to lerna scoped commands * remove unneeded yarn in lerna command * try to fix Electron install in Windows workflow --------- Co-authored-by: Jordan <jordan@jpdesigning.com> Co-authored-by: Dave Kasper <dave.m.kasper@gmail.com>
154 lines
4.9 KiB
TypeScript
154 lines
4.9 KiB
TypeScript
// @ts-expect-error - no types
|
|
import rp from '@cypress/request-promise'
|
|
import path from 'path'
|
|
import pDefer from 'p-defer'
|
|
import chalk from 'chalk'
|
|
import fs from 'fs-extra'
|
|
import { buildSchema, extendSchema, GraphQLSchema, introspectionFromSchema, isObjectType, parse } from 'graphql'
|
|
import { minifyIntrospectionQuery } from '@urql/introspection'
|
|
|
|
import { nexusTypegen, watchNexusTypegen } from '../utils/nexusTypegenUtil'
|
|
import { monorepoPaths } from '../monorepoPaths'
|
|
import { spawned, universalSpawn } from '../utils/childProcessUtils'
|
|
import { DEFAULT_INTERNAL_CLOUD_ENV } from '../gulpConstants'
|
|
|
|
export async function nexusCodegen () {
|
|
return nexusTypegen({
|
|
cwd: monorepoPaths.pkgGraphql,
|
|
filePath: path.join(monorepoPaths.pkgGraphql, 'src/schema.ts'),
|
|
outputPath: path.join(monorepoPaths.pkgGraphql, 'src/gen/nxs.gen.ts'),
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Watches & regenerates the
|
|
*/
|
|
export async function nexusCodegenWatch () {
|
|
return watchNexusTypegen({
|
|
cwd: monorepoPaths.pkgGraphql,
|
|
watchPaths: [
|
|
'src/**/*.ts',
|
|
],
|
|
filePath: path.join(monorepoPaths.pkgGraphql, 'src/schema.ts'),
|
|
outputPath: path.join(monorepoPaths.pkgGraphql, 'src/gen/nxs.gen.ts'),
|
|
})
|
|
}
|
|
|
|
export async function graphqlCodegen () {
|
|
return spawned('gql-codegen', 'yarn graphql-codegen --config graphql-codegen.yml', {
|
|
cwd: monorepoPaths.pkgGraphql,
|
|
waitForExit: true,
|
|
})
|
|
}
|
|
|
|
export async function graphqlCodegenWatch () {
|
|
const spawned = universalSpawn('graphql-codegen', ['--watch', '--config', 'graphql-codegen.yml'], {
|
|
cwd: monorepoPaths.pkgGraphql,
|
|
})
|
|
const dfd = pDefer()
|
|
let hasResolved = false
|
|
|
|
spawned.stdout.on('data', (chunk) => {
|
|
const strs = `${chunk}`.split('\n').filter((f) => f)
|
|
const timestampRegex = /\[\d{2}:\d{2}:\d{2}\]/
|
|
const isFailureBlock = strs.some((s) => s.includes('[failed]'))
|
|
|
|
strs.forEach((str) => {
|
|
let codegenMsg = timestampRegex.test(str) ? str.slice(10) : str
|
|
|
|
if (codegenMsg.includes('Watching for changes') && !hasResolved) {
|
|
dfd.resolve({})
|
|
}
|
|
|
|
if (codegenMsg === str) {
|
|
process.stdout.write(
|
|
`${chalk.cyan('graphqlCodegen')}: ${chalk.gray(str)}\n`,
|
|
)
|
|
} else if (codegenMsg.startsWith(' Generate .') || isFailureBlock) {
|
|
codegenMsg = codegenMsg.includes('[failed]')
|
|
? chalk.red(codegenMsg)
|
|
: chalk.yellow(codegenMsg)
|
|
|
|
process.stdout.write(`${chalk.cyan('graphqlCodegen')}: ${codegenMsg}\n`)
|
|
}
|
|
})
|
|
})
|
|
|
|
spawned.stderr.on('data', (data) => {
|
|
console.error(chalk.red(String(data)))
|
|
})
|
|
|
|
return dfd.promise
|
|
}
|
|
|
|
const ENV_MAP = {
|
|
development: 'http://localhost:3000',
|
|
staging: 'https://cloud-staging.cypress.io',
|
|
production: 'https://cloud.cypress.io',
|
|
}
|
|
|
|
export async function syncRemoteGraphQL () {
|
|
if (!ENV_MAP[DEFAULT_INTERNAL_CLOUD_ENV]) {
|
|
throw new Error(`Expected --env to be one of ${Object.keys(ENV_MAP).join(', ')}`)
|
|
}
|
|
|
|
try {
|
|
const body = await rp.get(`${ENV_MAP[DEFAULT_INTERNAL_CLOUD_ENV]}/test-runner-graphql-schema`)
|
|
|
|
// TODO(tim): fix
|
|
await fs.ensureDir(path.join(monorepoPaths.pkgGraphql, 'src/gen'))
|
|
await fs.promises.writeFile(path.join(monorepoPaths.pkgGraphql, 'schemas/cloud.graphql'), body)
|
|
} catch (error) {
|
|
console.error('Could not sync remote GraphQL schema', error)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generates the schema so the urql GraphCache is
|
|
*/
|
|
export async function generateFrontendSchema () {
|
|
const schemaContents = await fs.promises.readFile(path.join(monorepoPaths.pkgGraphql, 'schemas/schema.graphql'), 'utf8')
|
|
const schema = buildSchema(schemaContents, { assumeValid: true })
|
|
const testExtensions = generateTestExtensions(schema)
|
|
const extendedSchema = extendSchema(schema, parse(testExtensions))
|
|
|
|
const URQL_INTROSPECTION_PATH = path.join(monorepoPaths.pkgDataContext, 'src/gen/urql-introspection.gen.ts')
|
|
|
|
await fs.ensureDir(path.dirname(URQL_INTROSPECTION_PATH))
|
|
await fs.ensureDir(path.join(monorepoPaths.pkgFrontendShared, 'src/generated'))
|
|
await fs.writeFile(path.join(monorepoPaths.pkgFrontendShared, 'src/generated/schema-for-tests.gen.json'), JSON.stringify(introspectionFromSchema(extendedSchema), null, 2))
|
|
|
|
await fs.promises.writeFile(
|
|
URQL_INTROSPECTION_PATH,
|
|
`/* eslint-disable */\nexport const urqlSchema = ${JSON.stringify(minifyIntrospectionQuery(introspectionFromSchema(schema)), null, 2)} as const`,
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Adds two fields to the GraphQL types specific to testing
|
|
*
|
|
* @param schema
|
|
* @returns
|
|
*/
|
|
function generateTestExtensions (schema: GraphQLSchema) {
|
|
const objects: string[] = []
|
|
const typesMap = schema.getTypeMap()
|
|
|
|
for (const [typeName, type] of Object.entries(typesMap)) {
|
|
if (!typeName.startsWith('__') && isObjectType(type)) {
|
|
if (isObjectType(type)) {
|
|
objects.push(typeName)
|
|
}
|
|
}
|
|
}
|
|
|
|
return `
|
|
union TestUnion = ${objects.join(' | ')}
|
|
|
|
extend type Query {
|
|
testFragmentMember: TestUnion!
|
|
testFragmentMemberList(count: Int = 2): [TestUnion!]!
|
|
}
|
|
`
|
|
}
|