Skip to content

Commit

Permalink
fix: normalize to .js extensions when compiling libraries (#893)
Browse files Browse the repository at this point in the history
* fix: normalize to .js extensions when compiling libraries

* chore: move logging to after path normalization

* chore: log pretty-printed relative paths
  • Loading branch information
amcgee authored Nov 21, 2024
1 parent 6e90419 commit 58b33a8
Show file tree
Hide file tree
Showing 2 changed files with 597 additions and 780 deletions.
35 changes: 26 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 } = 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,11 @@ const compile = async ({
const babelConfig = makeBabelConfig({ moduleType, mode })

const copyFile = async (source, destination) => {
reporter.debug(
`Copying ${prettyPrint.relativePath(
source
)} to ${prettyPrint.relativePath(destination)}`
)
await fs.copy(source, destination)
}
const compileFile = async (source, destination) => {
Expand All @@ -106,7 +111,19 @@ const compile = async ({
source,
babelConfig
)
await fs.writeFile(destination, result.code)

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

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

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

0 comments on commit 58b33a8

Please sign in to comment.