Skip to content

Commit

Permalink
chore: move logging to after path normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee committed Nov 21, 2024
1 parent 424e6a0 commit 50f7656
Show file tree
Hide file tree
Showing 2 changed files with 585 additions and 780 deletions.
23 changes: 14 additions & 9 deletions cli/src/lib/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const {
createAppEntrypointWrapper,
createPluginEntrypointWrapper,
} = require('./entrypoints.js')
const { extensionPattern, normalizeExtension } = require('./extensionHelpers.js')
const {
extensionPattern,
normalizeExtension,
} = require('./extensionHelpers.js')

const watchFiles = ({ inputDir, outputDir, processFileCallback, watch }) => {
const compileFile = async (source) => {
const processFile = async (source) => {
const relative = path.relative(inputDir, source)
const destination = path.join(outputDir, relative)
reporter.debug(
`File ${relative} changed or added... dest: `,
path.relative(inputDir, destination)
)
reporter.debug(`File ${relative} changed or added...`)
await fs.ensureDir(path.dirname(destination))
await processFileCallback(source, destination)
}
Expand All @@ -43,8 +43,8 @@ const watchFiles = ({ inputDir, outputDir, processFileCallback, watch }) => {
}
resolve()
})
.on('add', compileFile)
.on('change', compileFile)
.on('add', processFile)
.on('change', processFile)
.on('unlink', removeFile)
.on('error', (error) => {
reporter.debugErr('Chokidar error:', error)
Expand Down Expand Up @@ -97,6 +97,7 @@ const compile = async ({
const babelConfig = makeBabelConfig({ moduleType, mode })

const copyFile = async (source, destination) => {
reporter.debug(`Copying ${source} to ${destination}`)
await fs.copy(source, destination)
}
const compileFile = async (source, destination) => {
Expand All @@ -106,10 +107,14 @@ const compile = async ({
source,
babelConfig
)

// Always write .js files
const jsDestination = normalizeExtension(destination)

reporter.debug(
`Compiled ${source} with Babel, saving to ${jsDestination}`
)

await fs.writeFile(jsDestination, result.code)
} catch (err) {
reporter.dumpErr(err)
Expand Down
Loading

0 comments on commit 50f7656

Please sign in to comment.