Skip to content

Commit

Permalink
portable paths for dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Walker-GM committed Aug 23, 2024
1 parent 60b0c98 commit 65437b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tasks/e2e-background-jobs/run.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
SAMPLE_JOB_PERFORM_ARGS,
SAMPLE_JOB_PERFORM_BODY,
} from './fixtures.mjs'
import { projectDirectoryExists, projectFileExists } from './util.mjs'
import {
makeFilePath,
projectDirectoryExists,
projectFileExists,
} from './util.mjs'

$.env.DATABASE_URL = 'file:./dev.db'

Expand Down Expand Up @@ -65,7 +69,7 @@ async function main() {

// Confirm jobs dependency in api package.json
const apiPackageJson = await import(
path.join(projectPath, 'api/package.json')
makeFilePath(path.join(projectPath, 'api/package.json'))
)
if (!apiPackageJson.dependencies['@redwoodjs/jobs']) {
console.error(
Expand All @@ -91,7 +95,9 @@ async function main() {

// Confirm the prisma model exists
await $`yarn rw build api`
const { db } = await import(path.join(projectPath, 'api/dist/lib/db.js'))
const { db } = await import(
makeFilePath(path.join(projectPath, 'api/dist/lib/db.js'))
)
const model = db['BackgroundJob']
if (model?.name !== 'BackgroundJob') {
console.error("Expected database model 'BackgroundJob' not found")
Expand Down
6 changes: 6 additions & 0 deletions tasks/e2e-background-jobs/util.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToFileURL } from 'node:url'

import { fs, path } from 'zx'

export function projectFileExists({
Expand Down Expand Up @@ -27,3 +29,7 @@ export function projectDirectoryExists({
}
return fs.statSync(path.join(projectPath, directoryPath)).isDirectory()
}

export function makeFilePath(path: string) {
return pathToFileURL(path).href
}

0 comments on commit 65437b7

Please sign in to comment.