Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Feb 22, 2023
1 parent 096674f commit cd49f30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
28 changes: 27 additions & 1 deletion packages/internal/src/__tests__/build_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import path from 'path'
import * as babel from '@babel/core'
import compat from 'core-js-compat'

import { cleanApiBuild, prebuildApiFiles } from '../build/api'
import { cleanApiBuild } from '../build/api'
import { prebuildApiFile } from '../build/babel/api'
import {
getApiSideBabelConfigPath,
getApiSideBabelPlugins,
Expand All @@ -20,6 +21,31 @@ const FIXTURE_PATH = path.resolve(
'../../../../__fixtures__/example-todo-main'
)

export const prebuildApiFiles = (srcFiles: string[]) => {
const rwjsPaths = getPaths()
const plugins = getApiSideBabelPlugins()

return srcFiles.map((srcPath) => {
const relativePathFromSrc = path.relative(rwjsPaths.base, srcPath)
const dstPath = path
.join(rwjsPaths.generated.prebuild, relativePathFromSrc)
.replace(/\.(ts)$/, '.js')

const result = prebuildApiFile(srcPath, dstPath, plugins)
if (!result?.code) {
// TODO: Figure out a better way to return these programatically.
console.warn('Error:', srcPath, 'could not prebuilt.')

return undefined
}

fs.mkdirSync(path.dirname(dstPath), { recursive: true })
fs.writeFileSync(dstPath, result.code)

return dstPath
})
}

const cleanPaths = (p) => {
return ensurePosixPath(path.relative(FIXTURE_PATH, p))
}
Expand Down
1 change: 0 additions & 1 deletion packages/internal/src/build/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs'
import path from 'path'

import { build } from 'esbuild'
Expand Down

0 comments on commit cd49f30

Please sign in to comment.