Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into chore/vitepk…
Browse files Browse the repository at this point in the history
…g-dual

* 'main' of github.com:redwoodjs/redwood:
  fix(web): Re-add generating ESM types (redwoodjs#10952)
  chore(project-config): Verify package.json with publint and attw (redwoodjs#10951)
  chore(apollo client): Add types for cjs imports (redwoodjs#10949)
  chore(tsconfig.types-cjs): Specify tsBuildInfoFile location (redwoodjs#10950)
  • Loading branch information
dac09 committed Jul 16, 2024
2 parents 58d5bf7 + 7dde4dd commit d864fbf
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 28 deletions.
3 changes: 2 additions & 1 deletion packages/auth/tsconfig.types-cjs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs"
"outDir": "dist/cjs",
"tsBuildInfoFile": "./tsconfig.types-cjs.tsbuildinfo"
}
}
8 changes: 7 additions & 1 deletion packages/project-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"build:types": "tsc --build --verbose ./tsconfig.json ./tsconfig.types-cjs.json",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "vitest run",
"test": "concurrently npm:test:vitest npm:test:attw npm:test:publint",
"test:vitest": "vitest run",
"test:attw": "yarn attw -P",
"test:publint": "yarn publint",
"test:watch": "vitest watch"
},
"dependencies": {
Expand All @@ -40,7 +43,10 @@
"string-env-interpolation": "1.0.1"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.15.3",
"@redwoodjs/framework-tools": "workspace:*",
"concurrently": "8.2.2",
"publint": "0.2.8",
"rimraf": "5.0.7",
"tsx": "4.15.6",
"typescript": "5.4.5",
Expand Down
5 changes: 3 additions & 2 deletions packages/project-config/tsconfig.types-cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/cjs",
"tsBuildInfoFile": "tsconfig.types-cjs.tsbuildinfo",
"module": "commonjs",
"moduleResolution": "node",
},
"moduleResolution": "node"
}
}
31 changes: 31 additions & 0 deletions packages/web/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
declare module '@apollo/client/cache/cache.cjs' {
export * from '@apollo/client/cache'
}

declare module '@apollo/client/core/core.cjs' {
export * from '@apollo/client/core'
}

declare module '@apollo/client/link/context/context.cjs' {
export * from '@apollo/client/link/context'
}

declare module '@apollo/client/link/core/core.cjs' {
export * from '@apollo/client/link/core'
}

declare module '@apollo/client/link/http/http.cjs' {
export * from '@apollo/client/link/http'
}

declare module '@apollo/client/link/persisted-queries/persisted-queries.cjs' {
export * from '@apollo/client/link/persisted-queries'
}

declare module '@apollo/client/react/hooks/hooks.cjs' {
export * from '@apollo/client/react/hooks'
}

declare module '@apollo/client/utilities/utilities.cjs' {
export * from '@apollo/client/utilities'
}
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"scripts": {
"build": "tsx ./build.ts && yarn build:types",
"build:pack": "yarn pack -o redwoodjs-web.tgz",
"build:types": "tsc --build --verbose ./tsconfig.types-cjs.json",
"build:types": "tsc --build --verbose ./tsconfig.build.json ./tsconfig.types-cjs.json",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "concurrently npm:test:vitest npm:test:attw npm:test:publint",
Expand Down
2 changes: 0 additions & 2 deletions packages/web/src/apollo/fragmentRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as apolloClient from '@apollo/client'
import type { UseFragmentResult } from '@apollo/client'
// @ts-expect-error Force import cjs module
import { createFragmentRegistry } from '@apollo/client/cache/cache.cjs'
import type { FragmentRegistryAPI } from '@apollo/client/cache/index.js'
// @ts-expect-error Force import cjs module
import { getFragmentDefinitions } from '@apollo/client/utilities/utilities.cjs'
import type { DocumentNode } from 'graphql'

Expand Down
7 changes: 0 additions & 7 deletions packages/web/src/apollo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ import {
InMemoryCache,
split,
} from '@apollo/client'
// @ts-expect-error Force import cjs module
import { setLogVerbosity as apolloSetLogVerbosity } from '@apollo/client/core/core.cjs'
// @ts-expect-error Force import cjs module
import { setContext } from '@apollo/client/link/context/context.cjs'
// @ts-expect-error Force import cjs module
import { HttpLink } from '@apollo/client/link/http/http.cjs'
// @ts-expect-error Force import cjs module
import { createPersistedQueryLink } from '@apollo/client/link/persisted-queries/persisted-queries.cjs'
import {
useQuery,
Expand All @@ -30,9 +26,7 @@ import {
useBackgroundQuery,
useReadQuery,
useSuspenseQuery,
// @ts-expect-error Force import cjs module
} from '@apollo/client/react/hooks/hooks.cjs'
// @ts-expect-error Force import cjs module
import { getMainDefinition } from '@apollo/client/utilities/utilities.cjs'
import { fetch as crossFetch } from '@whatwg-node/fetch'
import { print } from 'graphql/language/printer.js'
Expand Down Expand Up @@ -246,7 +240,6 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
definition.operation === 'subscription'
)
},
// @ts-expect-error Due to CJS imports
new SSELink({
url: uri,
auth: { authProviderType, tokenFn: getToken },
Expand Down
4 changes: 1 addition & 3 deletions packages/web/src/apollo/sseLink.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { HttpOptions } from '@apollo/client'
import type { Operation, FetchResult } from '@apollo/client/core'
// @ts-expect-error Force import cjs module
import { ApolloLink } from '@apollo/client/link/core/core.cjs'
// @ts-expect-error Force import cjs module
import { Observable } from '@apollo/client/utilities/utilities.cjs'
import { print } from 'graphql'
import type { ClientOptions, Client, Sink } from 'graphql-sse'
Expand Down Expand Up @@ -95,7 +93,7 @@ class SSELink extends ApolloLink {
}

public request(operation: Operation): Observable<FetchResult> {
return new Observable((sink: Sink) => {
return new Observable<FetchResult>((sink: Sink) => {
return this.client.subscribe<FetchResult>(
{ ...operation, query: print(operation.query) },
{
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/apollo/useCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ApolloCache, Reference, StoreObject } from '@apollo/client'
import type { NormalizedCacheObject } from '@apollo/client/cache/inmemory/types.js'
import type { ApolloQueryResult } from '@apollo/client/core'
// @ts-expect-error Force import cjs module
import { useApolloClient } from '@apollo/client/react/hooks/hooks.cjs'

type useCacheType = {
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/components/cell/createSuspendingCell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Suspense } from 'react'

import type { OperationVariables, QueryReference } from '@apollo/client'
// @ts-expect-error Force import cjs module
import { useApolloClient } from '@apollo/client/react/hooks/hooks.cjs'

import { useBackgroundQuery, useReadQuery } from '../GraphQLHooksProvider.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/web/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"outDir": "dist",
"esModuleInterop": true,
"moduleResolution": "NodeNext",
"module": "NodeNext",
"module": "NodeNext"
},
"include": [
"./src/**/*",
"ambient.d.ts",
"modules.d.ts",
"testing-library.d.ts"
],
"references": [
Expand Down
3 changes: 1 addition & 2 deletions packages/web/tsconfig.types-cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs",
"module": "commonjs",
"moduleResolution": "node"
"tsBuildInfoFile": "tsconfig.types-cjs.tsbuildinfo"
}
}
4 changes: 4 additions & 0 deletions tasks/clean.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ await rimraf('packages/**/tsconfig.tsbuildinfo', {
await rimraf('packages/**/tsconfig.build.tsbuildinfo', {
glob: true,
})

await rimraf('packages/**/tsconfig.types-cjs.tsbuildinfo', {
glob: true,
})
22 changes: 16 additions & 6 deletions tasks/framework-tools/frameworkSyncToProject.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ignored = [

/tsconfig.tsbuildinfo/,
/tsconfig.build.tsbuildinfo/,
/tsconfig.types-cjs.tsbuildinfo/,

(filePath) => IGNORE_EXTENSIONS.some((ext) => filePath.endsWith(ext)),
]
Expand Down Expand Up @@ -124,7 +125,7 @@ async function main() {
c.bgYellow(c.black('Heads up ')),
'',
"If this failed because Nx couldn't find its package.json file in node_modules, it's a known issue. The workaround is just trying again.",
].join('\n')
].join('\n'),
)
return
}
Expand All @@ -140,11 +141,11 @@ async function main() {
// Save the project's package.json so that we can restore it when this process exits.
const redwoodProjectPackageJsonPath = path.join(
redwoodProjectPath,
'package.json'
'package.json',
)
const redwoodProjectPackageJson = fs.readFileSync(
redwoodProjectPackageJsonPath,
'utf-8'
'utf-8',
)

const viteConfigPath = resolveViteConfigPath(redwoodProjectPath)
Expand Down Expand Up @@ -243,7 +244,7 @@ async function main() {
`${c.red('Warning:')} You modified a package.json file.`,
`If you've modified the ${c.underline('dependencies')}`,
`then you must run ${c.underline('yarn rwfw project:sync')} again.`,
].join(' ')
].join(' '),
)
}

Expand All @@ -256,7 +257,16 @@ async function main() {
logStatus(`Cleaning ${c.magenta(packageName)}...`)
await rimraf(path.join(path.dirname(packageJsonPath), 'dist'))
await rimraf(
path.join(path.dirname(packageJsonPath), 'tsconfig.tsbuildinfo')
path.join(path.dirname(packageJsonPath), 'tsconfig.tsbuildinfo'),
)
await rimraf(
path.join(path.dirname(packageJsonPath), 'tsconfig.build.tsbuildinfo'),
)
await rimraf(
path.join(
path.dirname(packageJsonPath),
'tsconfig.types-cjs.tsbuildinfo',
),
)

logStatus(`Building ${c.magenta(packageName)}...`)
Expand Down Expand Up @@ -324,7 +334,7 @@ function createCleanUp({
"- remove your project's node_modules directory",
"- run 'yarn install'",
'',
].join('\n')
].join('\n'),
)

cleanedUp = true
Expand Down
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8513,9 +8513,12 @@ __metadata:
version: 0.0.0-use.local
resolution: "@redwoodjs/project-config@workspace:packages/project-config"
dependencies:
"@arethetypeswrong/cli": "npm:0.15.3"
"@redwoodjs/framework-tools": "workspace:*"
concurrently: "npm:8.2.2"
deepmerge: "npm:4.3.1"
fast-glob: "npm:3.3.2"
publint: "npm:0.2.8"
rimraf: "npm:5.0.7"
smol-toml: "npm:1.2.2"
string-env-interpolation: "npm:1.0.1"
Expand Down

0 comments on commit d864fbf

Please sign in to comment.