Skip to content

Commit 960a4fd

Browse files
authored
fix: ACNA-3942 - error when running project with no actions (#156)
1 parent 32dbd50 commit 960a4fd

6 files changed

Lines changed: 108 additions & 75 deletions

File tree

src/BaseCommand.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class BaseCommand extends Command {
2727
async catch (error) {
2828
const { flags } = await this.parse(this.prototype)
2929
if (flags.verbose) {
30-
aioLogger.error(error)
30+
if (error.diagnostics) {
31+
aioLogger.error(JSON.stringify(error.diagnostics, null, 2))
32+
} else {
33+
aioLogger.error(error)
34+
}
3135
}
3236
this.handleError(error, flags.verbose)
3337
}

src/commands/app/dev/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ class Dev extends BaseCommand {
102102
* @param {object} config the config for the app
103103
*/
104104
async verifyActionConfig (config) {
105-
const actionConfig = config.manifest.full.packages
105+
const actionConfig = config.manifest?.full?.packages
106106
const errors = []
107107

108+
// there might not be a runtime manifest, that's ok
109+
if (!actionConfig) {
110+
return
111+
}
112+
108113
// 1. all actions in sequences must exist
109114
Object.entries(actionConfig).forEach(([_, pkg]) => { // iterate through each package
110115
const sequences = pkg?.sequences || {}
@@ -140,7 +145,9 @@ class Dev extends BaseCommand {
140145

141146
async runAppBuild (extensionConfig) {
142147
this.log('Building the app...')
143-
await buildActions(extensionConfig, null /* filterActions[] */, false /* skipCheck */)
148+
if (extensionConfig.app.hasBackend) {
149+
await buildActions(extensionConfig, null /* filterActions[] */, false /* skipCheck */)
150+
}
144151
}
145152

146153
async runOneExtensionPoint (name, config, flags) {
@@ -204,12 +211,11 @@ class Dev extends BaseCommand {
204211
}
205212
if (hasBackend) {
206213
this.displayActionUrls(actionUrls)
214+
const { watcherCleanup } = await createWatcher({ config, isLocal: true, inprocHook })
215+
cleanup.add(() => watcherCleanup(), 'cleaning up action watcher...')
216+
cleanup.wait()
207217
}
208218
this.log('press CTRL+C to terminate the dev environment')
209-
210-
const { watcherCleanup } = await createWatcher({ config, isLocal: true, inprocHook })
211-
cleanup.add(() => watcherCleanup(), 'cleaning up action watcher...')
212-
cleanup.wait()
213219
}
214220

215221
async getOrGenerateCertificates ({ pubCertPath, privateKeyPath, devKeysDir, devKeysConfigKey, maxWaitTimeSeconds = 20 }) {

src/lib/run-dev.js

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ async function runDev (runOptions, config, _inprocHookRunner) {
6666
const distFolder = devConfig.actions.dist
6767

6868
const serveLogger = coreLogger('serve', { level: process.env.LOG_LEVEL, provider: 'winston' })
69-
serveLogger.debug('config.manifest is', JSON.stringify(devConfig.manifest.full.packages, null, 2))
69+
serveLogger.debug('config.manifest is', JSON.stringify(devConfig.manifest?.full?.packages, null, 2))
7070

71-
const actionConfig = devConfig.manifest.full.packages
71+
const actionConfig = devConfig.manifest?.full?.packages
7272
const hasFrontend = devConfig.app.hasFrontend
7373
const hasBackend = devConfig.app.hasBackend
7474
const httpsSettings = runOptions?.parcel?.https
@@ -117,55 +117,51 @@ async function runDev (runOptions, config, _inprocHookRunner) {
117117
if (hasFrontend) {
118118
const liveReloadServer = livereload.createServer({ https: serverOptions })
119119
liveReloadServer.watch(devConfig.web.distDev)
120+
serveLogger.info(`Watching web folder ${devConfig.web.distDev}...`)
120121
liveReloadServer.server.once('connection', () => {
121122
setTimeout(() => {
122123
liveReloadServer.refresh('/')
123124
}, 100)
124125
})
125126

126-
try {
127-
utils.writeConfig(devConfig.web.injectedConfig, actionUrls)
127+
utils.writeConfig(devConfig.web.injectedConfig, actionUrls)
128128

129-
const bundlerPortToUse = parseInt(process.env.BUNDLER_PORT) || BUNDLER_DEFAULT_PORT
130-
const bundlerPort = await getPort({ port: bundlerPortToUse })
129+
const bundlerPortToUse = parseInt(process.env.BUNDLER_PORT) || BUNDLER_DEFAULT_PORT
130+
const bundlerPort = await getPort({ port: bundlerPortToUse })
131131

132-
if (bundlerPort !== bundlerPortToUse) {
133-
serveLogger.info(`Could not use bundler port ${bundlerPortToUse}, using port ${bundlerPort} instead`)
134-
}
132+
if (bundlerPort !== bundlerPortToUse) {
133+
serveLogger.info(`Could not use bundler port ${bundlerPortToUse}, using port ${bundlerPort} instead`)
134+
}
135135

136-
const entries = devConfig.web.src + '/**/*.html'
137-
bundleOptions.serveOptions = {
138-
port: bundlerPort,
139-
https: httpsSettings
140-
}
136+
const entries = devConfig.web.src + '/**/*.html'
137+
bundleOptions.serveOptions = {
138+
port: bundlerPort,
139+
https: httpsSettings
140+
}
141141

142-
const bundler = await bundle(entries, devConfig.web.distDev, bundleOptions, serveLogger.debug.bind(serveLogger))
143-
await bundler.run() // run it once
142+
const bundler = await bundle(entries, devConfig.web.distDev, bundleOptions, serveLogger.debug.bind(serveLogger))
143+
await bundler.run() // run it once
144144

145-
subscription = await bundler.watch((err, event) => {
146-
if (err) {
147-
// fatal error
148-
throw err
149-
}
145+
subscription = await bundler.watch((err, event) => {
146+
if (err) {
147+
// fatal error
148+
throw err
149+
}
150150

151-
serveLogger.info(`${event.changedAssets.size} static asset(s) changed`)
152-
const limit = runOptions.verbose ? Infinity : CHANGED_ASSETS_PRINT_LIMIT
153-
if (event.changedAssets.size <= limit) {
154-
event.changedAssets.forEach((value, key, map) => {
155-
serveLogger.info('\t-->', value)
156-
})
157-
}
158-
if (event.type === 'buildSuccess') {
159-
const bundles = event.bundleGraph.getBundles()
160-
serveLogger.info(`✨ Built ${bundles.length} bundles in ${event.buildTime}ms!`)
161-
} else if (event.type === 'buildFailure') {
162-
serveLogger.error(event.diagnostics)
163-
}
164-
})
165-
} catch (err) {
166-
console.error(err)
167-
serveLogger.error(err.diagnostics)
168-
}
151+
serveLogger.info(`${event.changedAssets.size} static asset(s) changed`)
152+
const limit = runOptions.verbose ? Infinity : CHANGED_ASSETS_PRINT_LIMIT
153+
if (event.changedAssets.size <= limit) {
154+
event.changedAssets.forEach((value, key, map) => {
155+
serveLogger.info('\t-->', value)
156+
})
157+
}
158+
if (event.type === 'buildSuccess') {
159+
const bundles = event.bundleGraph.getBundles()
160+
serveLogger.info(`✨ Built ${bundles.length} bundles in ${event.buildTime}ms!`)
161+
} else if (event.type === 'buildFailure') {
162+
serveLogger.error(event.diagnostics)
163+
}
164+
})
169165
}
170166

171167
const app = express()

test/BaseCommand.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ describe('catch', () => {
182182
expect(command.error).toHaveBeenCalledWith(expect.stringContaining(errorList.join('\n')))
183183
})
184184

185+
test('will handle errors with diagnostics property when using --verbose flag', async () => {
186+
command.argv = ['--verbose']
187+
const errorWithDiagnostics = new Error('fake error')
188+
errorWithDiagnostics.diagnostics = { some: 'property ' }
189+
await command.catch(errorWithDiagnostics)
190+
191+
expect(command.error).toHaveBeenCalledWith(expect.stringContaining('fake error'))
192+
})
193+
185194
test('will handle errors without stack traces when using --verbose flag', async () => {
186195
command.argv = ['--verbose']
187196
const errorWithoutStack = new Error('fake error')

test/commands/app/dev/index.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ describe('run', () => {
169169
}
170170

171171
command.getAppExtConfigs.mockResolvedValueOnce({ myextension: appConfig })
172-
const serverCleanup = () => console.log('server cleanup')
173172
mockRunDev.mockResolvedValue({
174173
frontEndUrl: 'https://localhost:9080',
175174
actionUrls: {
@@ -235,7 +234,6 @@ describe('run', () => {
235234
test('run, no flags, has frontend, no backend', async () => {
236235
command.argv = []
237236
const appConfig = {
238-
manifest: { full: { packages: {} } },
239237
hooks: {
240238
},
241239
app: {

test/lib/run-dev.test.js

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,23 +1449,22 @@ describe('runDev', () => {
14491449
}
14501450
})
14511451

1452-
test('has front end, has back end, bundler watch error', async () => {
1453-
const actionPath = fixturePath('actions/successNoReturnAction.js')
1454-
const config = createConfig({
1455-
hasFrontend: true,
1456-
hasBackend: true,
1457-
packageName: 'mypackage',
1458-
actions: {
1459-
myaction: {
1460-
function: actionPath
1452+
describe('has front end, has back end, bundler errors', () => {
1453+
test('bundler watch error', async () => {
1454+
const actionPath = fixturePath('actions/successNoReturnAction.js')
1455+
const config = createConfig({
1456+
hasFrontend: true,
1457+
hasBackend: true,
1458+
packageName: 'mypackage',
1459+
actions: {
1460+
myaction: {
1461+
function: actionPath
1462+
}
14611463
}
1462-
}
1463-
})
1464-
const runOptions = createRunOptions({ cert: 'my-cert', key: 'my-key' })
1465-
const hookRunner = () => {}
1464+
})
1465+
const runOptions = createRunOptions({ cert: 'my-cert', key: 'my-key' })
1466+
const hookRunner = () => {}
14661467

1467-
// 1. error in bundle.watch
1468-
{
14691468
const bundleEvent = createBundlerEvent()
14701469
const bundleErr = { diagnostics: 'something went wrong' }
14711470
mockLibWeb.bundle.mockResolvedValue({
@@ -1475,16 +1474,24 @@ describe('runDev', () => {
14751474
}
14761475
})
14771476

1478-
const { frontendUrl, actionUrls, serverCleanup } = await runDev(runOptions, config, hookRunner)
1479-
await serverCleanup()
1477+
await expect(runDev(runOptions, config, hookRunner)).rejects.toEqual(bundleErr)
1478+
})
14801479

1481-
expect(frontendUrl).toBeDefined()
1482-
expect(Object.keys(actionUrls).length).toBeGreaterThan(0)
1483-
expect(mockLogger.error).toHaveBeenCalledWith(bundleErr.diagnostics)
1484-
}
1480+
test('bundler build error', async () => {
1481+
const actionPath = fixturePath('actions/successNoReturnAction.js')
1482+
const config = createConfig({
1483+
hasFrontend: true,
1484+
hasBackend: true,
1485+
packageName: 'mypackage',
1486+
actions: {
1487+
myaction: {
1488+
function: actionPath
1489+
}
1490+
}
1491+
})
1492+
const runOptions = createRunOptions({ cert: 'my-cert', key: 'my-key' })
1493+
const hookRunner = () => {}
14851494

1486-
// 2. error in bundle build
1487-
{
14881495
const bundlerEventParams = { type: 'buildFailure', diagnostics: 'something went wrong' }
14891496
const bundleEvent = createBundlerEvent(bundlerEventParams)
14901497
mockLibWeb.bundle.mockResolvedValue({
@@ -1500,10 +1507,23 @@ describe('runDev', () => {
15001507
expect(frontendUrl).toBeDefined()
15011508
expect(Object.keys(actionUrls).length).toBeGreaterThan(0)
15021509
expect(mockLogger.error).toHaveBeenCalledWith(bundlerEventParams.diagnostics)
1503-
}
1510+
})
1511+
1512+
test('unknown build event type', async () => {
1513+
const actionPath = fixturePath('actions/successNoReturnAction.js')
1514+
const config = createConfig({
1515+
hasFrontend: true,
1516+
hasBackend: true,
1517+
packageName: 'mypackage',
1518+
actions: {
1519+
myaction: {
1520+
function: actionPath
1521+
}
1522+
}
1523+
})
1524+
const runOptions = createRunOptions({ cert: 'my-cert', key: 'my-key' })
1525+
const hookRunner = () => {}
15041526

1505-
// 2. unknown buildEvent type
1506-
{
15071527
const bundlerEventParams = { type: 'unknown_event_type', diagnostics: 'something went wrong 2' }
15081528
const bundleEvent = createBundlerEvent(bundlerEventParams)
15091529
mockLibWeb.bundle.mockResolvedValue({
@@ -1518,7 +1538,7 @@ describe('runDev', () => {
15181538

15191539
expect(frontendUrl).toBeDefined()
15201540
expect(Object.keys(actionUrls).length).toBeGreaterThan(0)
1521-
}
1541+
})
15221542
})
15231543
})
15241544

0 commit comments

Comments
 (0)