Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalize to .js extensions when compiling libraries #893

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
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
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
Loading