Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): Move more repetitive code into framework-tools #11320

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions packages/auth-providers/dbAuth/middleware/build.mts
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { buildExternalCjs, buildExternalEsm } from '@redwoodjs/framework-tools'
import {
generateTypesCjs,
generateTypesEsm,
insertCommonJsPackageJson,
} from '@redwoodjs/framework-tools/generateTypes'

// ESM build
await build({
buildOptions: {
...defaultBuildOptions,
format: 'esm',
packages: 'external',
},
})
await buildExternalEsm()
await generateTypesEsm()

// CJS build
await build({
buildOptions: {
...defaultBuildOptions,
outdir: 'dist/cjs',
packages: 'external',
},
})
await buildExternalCjs()
await generateTypesCjs()
await insertCommonJsPackageJson({
buildFileUrl: import.meta.url,
cjsDir: 'dist/cjs',
})

await insertCommonJsPackageJson({ buildFileUrl: import.meta.url })
2 changes: 1 addition & 1 deletion packages/auth-providers/dbAuth/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"scripts": {
"build": "tsx ./build.mts",
"build:pack": "yarn pack -o redwoodjs-auth-dbauth-middleware.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"build:types-cjs": "tsc --build --verbose tsconfig.cjs.json",
"check:attw": "yarn attw -P",
"check:package": "concurrently npm:check:attw yarn:publint",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { defaultGetRoles } from '../defaultGetRoles'
import { defaultGetRoles } from '../defaultGetRoles.js'

describe('dbAuth: defaultGetRoles', () => {
it('returns an empty array if no roles are present', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
MiddlewareResponse,
} from '@redwoodjs/web/middleware'

import { middlewareDefaultAuthProviderState } from '../../../../../auth/dist/AuthProvider/AuthProviderState'
import type { DbAuthMiddlewareOptions } from '../index'
import { initDbAuthMiddleware } from '../index'
import { middlewareDefaultAuthProviderState } from '../../../../../auth/dist/AuthProvider/AuthProviderState.js'
import type { DbAuthMiddlewareOptions } from '../index.js'
import { initDbAuthMiddleware } from '../index.js'

const FIXTURE_PATH = path.resolve(
__dirname,
'../../../../../../__fixtures__/example-todo-main',
Expand Down Expand Up @@ -39,6 +40,8 @@ beforeAll(() => {
mockedSession: 'this_is_the_only_correct_session',
}
}

return undefined
}),
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const defaultGetRoles = (decoded: Record<string, any>): string[] => {
export const defaultGetRoles = (
decoded: Record<string, any> | undefined | null,
): string[] => {
try {
const roles = decoded?.currentUser?.roles

Expand Down
16 changes: 16 additions & 0 deletions packages/auth-providers/dbAuth/middleware/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../../tsconfig.compilerOption.json",
"compilerOptions": {
"strict": true,
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo"
},
"include": ["src/**/*"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite/tsconfig.build.json" }
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs",
"tsBuildInfoFile": "./tsconfig.cjs.tsbuildinfo"
Expand Down
7 changes: 3 additions & 4 deletions packages/auth-providers/dbAuth/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"extends": "../../../../tsconfig.compilerOption.json",
"compilerOptions": {
"strict": true,
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
"moduleResolution": "Node16"
},
"include": ["src/**/*"],
"include": ["."],
"exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite/tsconfig.build.json" }
Expand Down
26 changes: 5 additions & 21 deletions packages/auth-providers/supabase/middleware/build.mts
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { buildExternalCjs, buildExternalEsm } from '@redwoodjs/framework-tools'
import {
generateTypesCjs,
generateTypesEsm,
insertCommonJsPackageJson,
} from '@redwoodjs/framework-tools/generateTypes'

// ESM build
await build({
buildOptions: {
...defaultBuildOptions,
format: 'esm',
packages: 'external',
},
})
await buildExternalEsm()
await generateTypesEsm()

// CJS build
await build({
buildOptions: {
...defaultBuildOptions,
outdir: 'dist/cjs',
packages: 'external',
},
})
await buildExternalCjs()
await generateTypesCjs()
await insertCommonJsPackageJson({
buildFileUrl: import.meta.url,
cjsDir: 'dist/cjs',
})

await insertCommonJsPackageJson({ buildFileUrl: import.meta.url })
2 changes: 1 addition & 1 deletion packages/auth-providers/supabase/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"build": "tsx ./build.mts",
"build:pack": "yarn pack -o redwoodjs-auth-supabase-middleware.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
"check:attw": "yarn attw -P",
"check:package": "concurrently npm:check:attw yarn:publint",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { defaultGetRoles } from '../defaultGetRoles'
import { defaultGetRoles } from '../defaultGetRoles.js'

describe('dbAuth: defaultGetRoles', () => {
it('returns an empty array if no roles are present', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
MiddlewareResponse,
} from '@redwoodjs/web/middleware'

import initSupabaseAuthMiddleware from '../index'
import type { SupabaseAuthMiddlewareOptions } from '../index'
import initSupabaseAuthMiddleware from '../index.js'
import type { SupabaseAuthMiddlewareOptions } from '../index.js'

const FIXTURE_PATH = path.resolve(
__dirname,
'../../../../../../__fixtures__/example-todo-main',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

interface PartialSupabaseDecoded {
app_metadata: {
roles?: string
[key: string]: unknown
roles?: string | undefined
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/auth-providers/supabase/middleware/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../../tsconfig.compilerOption.json",
"compilerOptions": {
"strict": true,
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo"
},
"include": ["src/**/*"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite/tsconfig.build.json" }
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs",
"tsBuildInfoFile": "./tsconfig.cjs.tsbuildinfo"
Expand Down
7 changes: 3 additions & 4 deletions packages/auth-providers/supabase/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"extends": "../../../../tsconfig.compilerOption.json",
"compilerOptions": {
"strict": true,
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
"moduleResolution": "Node16"
},
"include": ["src/**/*"],
"include": ["."],
"exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite/tsconfig.build.json" }
Expand Down
24 changes: 5 additions & 19 deletions packages/context/build.mts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { buildCjs, buildEsm } from '@redwoodjs/framework-tools'
import {
generateTypesCjs,
generateTypesEsm,
insertCommonJsPackageJson,
} from '@redwoodjs/framework-tools/generateTypes'

// ESM build and type generation
await build({
buildOptions: {
...defaultBuildOptions,
format: 'esm',
},
})
await buildEsm()
await generateTypesEsm()

// CJS build, type generation, and package.json insert
await build({
buildOptions: {
...defaultBuildOptions,
outdir: 'dist/cjs',
},
})
await buildCjs()
await generateTypesCjs()
await insertCommonJsPackageJson({
buildFileUrl: import.meta.url,
cjsDir: 'dist/cjs',
})

await insertCommonJsPackageJson({ buildFileUrl: import.meta.url })
2 changes: 1 addition & 1 deletion packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"scripts": {
"build": "tsx ./build.mts",
"build:pack": "yarn pack -o redwoodjs-context.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
"check:attw": "yarn attw -P",
Expand Down
11 changes: 11 additions & 0 deletions packages/context/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.compilerOption.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo"
},
"include": ["src"]
}
2 changes: 1 addition & 1 deletion packages/context/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs",
"tsBuildInfoFile": "./tsconfig.cjs.tsbuildinfo"
Expand Down
8 changes: 4 additions & 4 deletions packages/context/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "../../tsconfig.compilerOption.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16",
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
"moduleResolution": "Node16"
},
"include": ["src"]
"include": ["."],
"exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"],
"references": [{ "path": "../framework-tools" }]
}
42 changes: 42 additions & 0 deletions packages/framework-tools/src/buildDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,48 @@ export async function build({
}
}

export function buildCjs() {
return build({
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.cjs.json',
outdir: 'dist/cjs',
},
})
}

export function buildEsm() {
return build({
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.build.json',
format: 'esm',
},
})
}

export function buildExternalCjs() {
return build({
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.cjs.json',
outdir: 'dist/cjs',
packages: 'external',
},
})
}

export function buildExternalEsm() {
return build({
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.build.json',
format: 'esm',
packages: 'external',
},
})
}

interface CopyAssetsOptions {
buildFileUrl: string
patterns: string[]
Expand Down
Loading
Loading