Skip to content

Commit

Permalink
handle cases where manifest specifies action dir, and it changes duri…
Browse files Browse the repository at this point in the history
…ng run
  • Loading branch information
purplecabbage committed Sep 12, 2024
1 parent 1abf545 commit b1619c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/commands/app/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class Run extends BaseCommand {
}

const verboseOutput = flags.verbose || flags.local || headlessApp
// we should evaluate this, a lot of output just disappears in the spinner text and
// using verbose dumps ALL of parcel's output, so this become unreadable
// we need a middle ground. -jm
const onProgress = !verboseOutput
? info => {
spinner.text = info
Expand Down
16 changes: 14 additions & 2 deletions src/lib/actions-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const deployActions = require('./deploy-actions')
module.exports = async (watcherOptions) => {
const { config, log } = watcherOptions

log(`watching action files at ${config.actions.src}...`)
log(`watching action files at ${config.actions.src} ...`)
const watcher = chokidar.watch(config.actions.src)

watcher.on('change', createChangeHandler({ ...watcherOptions, watcher }))
Expand Down Expand Up @@ -91,6 +91,8 @@ function createChangeHandler (watcherOptions) {
try {
aioLogger.debug(`${filePath} has changed. Redeploying actions.`)
const filterActions = getActionNameFromPath(filePath, watcherOptions)
// this is happening, but its not showing up because verbose is usually off
// this might be more important and worthy of signalling to the user
if (!filterActions.length) {
log(' -> A non-action file was changed, restart is required to deploy...')
} else {
Expand Down Expand Up @@ -119,14 +121,24 @@ function createChangeHandler (watcherOptions) {
* @returns {Array<string>} All of the actions which match the modified path
*/
function getActionNameFromPath (filePath, watcherOptions) {
// note: this check only happens during aio app run
// before the watcher is started, all actions are built and deployed and hashes updated
// this code is missing 2 cases:
// 1. if the action is a folder with a package.json and the changed file is in the folder
// 2. if the changed file is in the folder with the action, but not the action file itself
// we need to be careful with these cases, because we could cause a recursive loop
// for now we continue to error on the cautious side, and output a message suggesting a restart
const actionNames = []
const unixFilePath = upath.toUnix(filePath)
const { config } = watcherOptions
Object.entries(config.manifest.full.packages).forEach(([, pkg]) => {
if (pkg.actions) {
Object.entries(pkg.actions).forEach(([actionName, action]) => {
const unixActionFunction = upath.toUnix(action.function)
if (unixActionFunction.includes(unixFilePath)) {
// since action could be a folder, and changed file could be in the folder
// we need to compare both ways
// there are 2 additional cases listed above
if (unixActionFunction.includes(unixFilePath) || unixFilePath.includes(unixActionFunction)) {
actionNames.push(actionName)
}
})
Expand Down
16 changes: 11 additions & 5 deletions src/lib/run-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function runDev (config, dataDir, options = {}, log = () => {}, inprocHook
// build and deploy actions
log('building actions..')
await buildActions(devConfig, null, false /* force build */)

console.log('log = ', log('boo'))
const { cleanup: watcherCleanup } = await actionsWatcher({ config: devConfig, isLocal, log, inprocHook })
cleanup.add(() => watcherCleanup(), 'stopping action watcher...')
}
Expand Down Expand Up @@ -152,10 +152,16 @@ async function runDev (config, dataDir, options = {}, log = () => {}, inprocHook
devConfig.app.hasFrontend = false
}

log('setting up vscode debug configuration files...')
const vscodeConfig = vscode(devConfig)
await vscodeConfig.update({ frontEndUrl })
cleanup.add(() => vscodeConfig.cleanup(), 'cleaning up vscode debug configuration files...')
// todo: remove vscode config swapping, dev command uses a persistent file so we don't need this.
// also there was a latent issue with projects that defined an action src as a folder with an index.js file.
// it looks explicitly for package.json and fails if it does not find it.
// regarless, we don't need it, and when we actually remove --local we can be rid of this.
if (isLocal) {
log('setting up vscode debug configuration files...')
const vscodeConfig = vscode(devConfig)
await vscodeConfig.update({ frontEndUrl })
cleanup.add(() => vscodeConfig.cleanup(), 'cleaning up vscode debug configuration files...')
}

// automatically fetch logs if there are actions
if (config.app.hasBackend && fetchLogs) {
Expand Down

0 comments on commit b1619c3

Please sign in to comment.