Skip to content
Merged
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
22 changes: 13 additions & 9 deletions packages/vite-plugin-tanstack-start/test/support/netlify-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec as originalExec } from 'node:child_process'
import { writeFile, readFile, readdir } from 'node:fs/promises'
import { writeFile, readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { URL } from 'node:url'
import { promisify } from 'node:util'
Expand All @@ -8,6 +8,8 @@ import normalizePackageData, { type Package } from 'normalize-package-data'

const exec = promisify(originalExec)

type MonorepoPackage = Package & { workspaces?: string[] }

// https://app.netlify.com/sites/tanstack-start-e2e-tests
const SITE_ID = process.env.NETLIFY_SITE_ID ?? 'cd4e45ce-895c-432b-af6d-61e10ad1d125'

Expand All @@ -17,13 +19,15 @@ export interface Deploy {
logs: string
}

const packagesRootDir = join(import.meta.dirname, '../../../')
const packageDirs = await readdir(packagesRootDir)
const repoRoot = join(import.meta.dirname, '../../../../')
const workspaces =
(JSON.parse(await readFile(join(repoRoot, 'package.json'), 'utf-8')) as MonorepoPackage).workspaces ?? []

const packages = await Promise.all(
packageDirs.map(async (dirName) => {
const packageJsonPath = join(packagesRootDir, dirName, 'package.json')
workspaces.map(async (packageDir) => {
const packageJsonPath = join(repoRoot, packageDir, 'package.json')
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as Package
return { name: packageJson.name, dirName }
return { name: packageJson.name, packageDir }
}),
)

Expand All @@ -33,7 +37,7 @@ const packages = await Promise.all(
* We can't use a simpler approach like a monorepo workspace or `npm link` because the fixture site
* needs to be self-contained to be deployable to Netlify (i.e. it can't have symlinks).
*/
const prepareDeps = async (cwd: string, packagesAbsoluteDir: string): Promise<void> => {
const prepareDeps = async (cwd: string): Promise<void> => {
const packageJson = JSON.parse(await readFile(`${cwd}/package.json`, 'utf-8')) as Package & {
overrides?: Record<string, string>
}
Expand All @@ -45,7 +49,7 @@ const prepareDeps = async (cwd: string, packagesAbsoluteDir: string): Promise<vo
const isDevDep = pkg.name in devDependencies
console.log(`💉 Injecting local ${pkg.name} ${isDevDep ? 'dev ' : ''}dependency`)
const { stdout } = await exec(`npm pack --json --ignore-scripts --pack-destination ${cwd}`, {
cwd: join(packagesAbsoluteDir, pkg.dirName),
cwd: join(repoRoot, pkg.packageDir),
})
const [{ filename }] = JSON.parse(stdout) as { filename: string }[]
if (isDep) {
Expand All @@ -64,7 +68,7 @@ const prepareDeps = async (cwd: string, packagesAbsoluteDir: string): Promise<vo
}

export const deploySite = async (projectDir: string): Promise<Deploy> => {
await prepareDeps(projectDir, join(import.meta.dirname, '../../../'))
await prepareDeps(projectDir)

console.log(`🚀 Building and deploying site...`)
try {
Expand Down
Loading