From 7d1a6dfef3eb0832189a136096fa09b7d8119aa9 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Mon, 19 Apr 2021 17:42:25 +0530 Subject: [PATCH 1/9] Initial commit for parcel v2 support --- package.json | 1 + src/lib/bundle-serve.js | 7 ++++--- src/lib/run-dev.js | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5f3f3ca4..ae3d5ede 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "ora": "^4.0.3", + "parcel": "^2.0.0-beta.2", "pure-http": "^2.0.3", "serve-static": "^1.14.1", "which": "^2.0.1", diff --git a/src/lib/bundle-serve.js b/src/lib/bundle-serve.js index 770185c7..bf7e1f37 100644 --- a/src/lib/bundle-serve.js +++ b/src/lib/bundle-serve.js @@ -36,11 +36,12 @@ module.exports = async (bundler, uiPort = SERVER_DEFAULT_PORT, options = {}, log aioLogger.debug(`bundle-serve uiPort: ${uiPort}`) aioLogger.debug(`bundle-serve options: ${JSON.stringify(options, null, 2)}`) - const uiServer = await bundler.serve(uiPort, options.https) - actualPort = uiServer.address().port + // const uiServer = await bundler.serve(uiPort, options.https) + const uiServer = await bundler.watch() + /* actualPort = uiServer.address().port const terminator = httpTerminator.createHttpTerminator({ server: uiServer - }) + }) */ if (actualPort !== uiPort) { log(`Could not use port:${uiPort}, using port:${actualPort} instead`) diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index dcb38a92..1be1bb60 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -100,7 +100,16 @@ async function runDev (config, options = {}, log = () => {}) { const script = await utils.runPackageScript('build-static') if (!script) { const entryFile = config.web.src + '/index.html' - bundleOptions.watch = true + // bundleOptions.watch = true + bundleOptions.serveOptions = { + distDir: config.web.distDev, + port: uiPort, + https: bundleOptions.https + } + bundleOptions.additionalReporters = [ + { packageName: '@parcel/reporter-cli', resolveFrom: __filename }, + { packageName: '@parcel/reporter-dev-server', resolveFrom: __filename } + ] const { bundler, cleanup: bundlerCleanup } = await bundle(entryFile, config.web.distDev, bundleOptions, log) defaultBundler = bundler cleanup.add(() => bundlerCleanup(), 'cleaning up bundle...') From 439462b32e7317c8efc0bdaa4847ce60bb185c86 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Tue, 20 Apr 2021 16:25:35 +0530 Subject: [PATCH 2/9] proper file paths --- src/commands/app/build.js | 2 +- src/lib/run-dev.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commands/app/build.js b/src/commands/app/build.js index 3d481faa..a6d791de 100644 --- a/src/commands/app/build.js +++ b/src/commands/app/build.js @@ -83,7 +83,7 @@ class Build extends BaseCommand { logLevel: flags.verbose ? 4 : 2 } const { bundler } = await bundle(entryFile, config.web.distProd, bundleOptions, onProgress) - await bundler.bundle() + await bundler.run() } spinner.succeed(chalk.green('Building web assets')) } catch (err) { diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 1be1bb60..0e7e6d5e 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -100,15 +100,13 @@ async function runDev (config, options = {}, log = () => {}) { const script = await utils.runPackageScript('build-static') if (!script) { const entryFile = config.web.src + '/index.html' - // bundleOptions.watch = true bundleOptions.serveOptions = { - distDir: config.web.distDev, port: uiPort, https: bundleOptions.https } bundleOptions.additionalReporters = [ - { packageName: '@parcel/reporter-cli', resolveFrom: __filename }, - { packageName: '@parcel/reporter-dev-server', resolveFrom: __filename } + { packageName: '@parcel/reporter-cli', resolveFrom: entryFile }, + { packageName: '@parcel/reporter-dev-server', resolveFrom: entryFile } ] const { bundler, cleanup: bundlerCleanup } = await bundle(entryFile, config.web.distDev, bundleOptions, log) defaultBundler = bundler From 1be3639a032ce2f822bdf699a3d12ba4b5eab747 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Wed, 21 Apr 2021 12:54:46 +0530 Subject: [PATCH 3/9] Find an available port automatically if given one is occupied --- src/lib/bundle-serve.js | 2 +- src/lib/run-dev.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/bundle-serve.js b/src/lib/bundle-serve.js index bf7e1f37..2c8597e8 100644 --- a/src/lib/bundle-serve.js +++ b/src/lib/bundle-serve.js @@ -52,7 +52,7 @@ module.exports = async (bundler, uiPort = SERVER_DEFAULT_PORT, options = {}, log const cleanup = async () => { aioLogger.debug('cleanup bundle-serve...') - await terminator.terminate() + // await terminator.terminate() } return { diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 0e7e6d5e..24fd47af 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -27,6 +27,7 @@ const actionsWatcher = require('./actions-watcher') const utils = require('./app-helper') const { run: logPoller } = require('./log-poller') +const getPort = require('get-port') /** @private */ async function runDev (config, options = {}, log = () => {}) { @@ -47,7 +48,7 @@ async function runDev (config, options = {}, log = () => {}) { const hasFrontend = config.app.hasFrontend const withBackend = config.app.hasBackend && !skipActions const isLocal = !options.devRemote // applies only for backend - const uiPort = parseInt(process.env.PORT) || SERVER_DEFAULT_PORT + const uiPort = parseInt(process.env.PORT) || (await getPort({ port: SERVER_DEFAULT_PORT })) aioLogger.debug(`hasFrontend ${hasFrontend}`) aioLogger.debug(`withBackend ${withBackend}`) From 5f00513ea9c53579c6b9bc57efefa90cac152fd7 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Sat, 24 Apr 2021 00:15:44 +0530 Subject: [PATCH 4/9] some refactoring and tests --- src/lib/bundle-serve.js | 23 +------- src/lib/run-dev.js | 9 ++- test/commands/app/build.test.js | 6 +- test/commands/lib/bundle-serve.test.js | 78 ++++++-------------------- test/commands/lib/run-dev.test.js | 15 +++++ 5 files changed, 44 insertions(+), 87 deletions(-) diff --git a/src/lib/bundle-serve.js b/src/lib/bundle-serve.js index 2c8597e8..3df158aa 100644 --- a/src/lib/bundle-serve.js +++ b/src/lib/bundle-serve.js @@ -11,8 +11,6 @@ governing permissions and limitations under the License. */ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:bundle-serve', { provider: 'debug' }) -const httpTerminator = require('http-terminator') -const { defaultHttpServerPort: SERVER_DEFAULT_PORT } = require('./defaults') /** * @typedef {object} BundleWebObject @@ -24,35 +22,20 @@ const { defaultHttpServerPort: SERVER_DEFAULT_PORT } = require('./defaults') * Serves the bundled web source via Parcel. * * @param {object} bundler the Parcel bundler object - * @param {number} uiPort the port number for the http server * @param {object} [options] the Parcel bundler options * @param {Function} [log] the app logger * @returns {BundleWebObject} the BundleWebObject */ -module.exports = async (bundler, uiPort = SERVER_DEFAULT_PORT, options = {}, log = () => {}) => { +module.exports = async (bundler, options, log = () => {}) => { log('serving front-end using bundler serve...') - let actualPort = uiPort - aioLogger.debug(`bundle-serve uiPort: ${uiPort}`) - aioLogger.debug(`bundle-serve options: ${JSON.stringify(options, null, 2)}`) + await bundler.watch() - // const uiServer = await bundler.serve(uiPort, options.https) - const uiServer = await bundler.watch() - /* actualPort = uiServer.address().port - const terminator = httpTerminator.createHttpTerminator({ - server: uiServer - }) */ - - if (actualPort !== uiPort) { - log(`Could not use port:${uiPort}, using port:${actualPort} instead`) - } - - const url = `${options.https ? 'https:' : 'http:'}//localhost:${actualPort}` + const url = `${options.serveOptions.https ? 'https:' : 'http:'}//localhost:${options.serveOptions.port}` log(`local frontend server running at ${url}`) const cleanup = async () => { aioLogger.debug('cleanup bundle-serve...') - // await terminator.terminate() } return { diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 24fd47af..8325d322 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -48,8 +48,11 @@ async function runDev (config, options = {}, log = () => {}) { const hasFrontend = config.app.hasFrontend const withBackend = config.app.hasBackend && !skipActions const isLocal = !options.devRemote // applies only for backend - const uiPort = parseInt(process.env.PORT) || (await getPort({ port: SERVER_DEFAULT_PORT })) - + const portToUse = parseInt(process.env.PORT) || SERVER_DEFAULT_PORT + const uiPort = await getPort({ port: portToUse }) + if (uiPort !== portToUse) { + log(`Could not use port:${portToUse}, using port:${uiPort} instead`) + } aioLogger.debug(`hasFrontend ${hasFrontend}`) aioLogger.debug(`withBackend ${withBackend}`) aioLogger.debug(`isLocal ${isLocal}`) @@ -129,7 +132,7 @@ async function runDev (config, options = {}, log = () => {}) { if (!script) { let result if (defaultBundler) { - result = await bundleServe(defaultBundler, uiPort, bundleOptions, log) + result = await bundleServe(defaultBundler, bundleOptions, log) } else { result = await serve(devConfig.web.distDev, uiPort, bundleOptions, log) } diff --git a/test/commands/app/build.test.js b/test/commands/app/build.test.js index 4cfc7f71..d3b41f05 100644 --- a/test/commands/app/build.test.js +++ b/test/commands/app/build.test.js @@ -127,7 +127,7 @@ beforeEach(() => { mockWebLib.deployWeb.mockReset() mockWebLib.bundle.mockReset() mockBundleFunc.mockReset() - mockWebLib.bundle.mockResolvedValue({ bundler: { bundle: mockBundleFunc } }) + mockWebLib.bundle.mockResolvedValue({ bundler: { run: mockBundleFunc } }) mockFS.existsSync.mockReset() helpers.writeConfig.mockReset() helpers.runPackageScript.mockReset() @@ -371,7 +371,7 @@ describe('run', () => { test('build (--skip-actions) calls provided log function', async () => { mockWebLib.bundle.mockImplementation((a, b, c, log) => { log('ok') - return { bundler: { bundle: mockBundleFunc } } + return { bundler: { run: mockBundleFunc } } }) const noScriptFound = undefined @@ -390,7 +390,7 @@ describe('run', () => { test('build (--skip-actions, --verbose) calls provided other log function', async () => { mockWebLib.bundle.mockImplementation((a, b, c, log) => { log('ok') - return { bundler: { bundle: mockBundleFunc } } + return { bundler: { run: mockBundleFunc } } }) const noScriptFound = undefined diff --git a/test/commands/lib/bundle-serve.test.js b/test/commands/lib/bundle-serve.test.js index b2b51f50..c6ba3545 100644 --- a/test/commands/lib/bundle-serve.test.js +++ b/test/commands/lib/bundle-serve.test.js @@ -11,88 +11,44 @@ governing permissions and limitations under the License. */ const bundleServe = require('../../../src/lib/bundle-serve') -const { defaultHttpServerPort: SERVER_DEFAULT_PORT } = require('../../../src/lib/defaults') -const httpTerminator = require('http-terminator') - -let SERVER_AVAILABLE_PORT - -jest.mock('http-terminator') - -const mockHttpsServerInstance = { - address: jest.fn(() => ({ - port: SERVER_AVAILABLE_PORT - })) -} - -const mockTerminatorInstance = { - terminate: jest.fn() -} const createBundler = () => { return { - serve: async () => mockHttpsServerInstance + watch: jest.fn() } } beforeEach(() => { - SERVER_AVAILABLE_PORT = SERVER_DEFAULT_PORT - mockTerminatorInstance.terminate.mockReset() - httpTerminator.createHttpTerminator.mockImplementation(() => mockTerminatorInstance) }) test('exports', () => { expect(typeof bundleServe).toEqual('function') }) -test('bundle-serve https (set port not available, use default', async () => { +test('bundle-serve', async () => { + const PORT = 8888 const options = { - https: { - cert: 'cert.cert', - key: 'key.key' + serveOptions: { + https: false, + port: PORT } } - - const requestedPort = 8888 - SERVER_AVAILABLE_PORT = 9099 - const { url } = await bundleServe(createBundler(), requestedPort, options) - + const { url, cleanup } = await bundleServe(createBundler(), options) + await cleanup() expect(typeof url).toEqual('string') - expect(url).toBe(`https://localhost:${SERVER_AVAILABLE_PORT}`) // specificPort not available + expect(url).toBe(`http://localhost:${PORT}`) // specificPort not available }) -test('bundle-serve https (set port available and used', async () => { +test('bundle-serve https', async () => { + const PORT = 8888 const options = { - https: { - cert: 'cert.cert', - key: 'key.key' + serveOptions: { + https: true, + port: PORT } } - - const requestedPort = 8888 - SERVER_AVAILABLE_PORT = requestedPort - const { url } = await bundleServe(createBundler(), requestedPort, options) - - expect(typeof url).toEqual('string') - expect(url).toBe(`https://localhost:${requestedPort}`) // requestedPort available -}) - -test('bundle-serve http (and use default port)', async () => { - const options = {} - const { url } = await bundleServe(createBundler(), undefined, options) - - expect(typeof url).toEqual('string') - expect(url).toBe(`http://localhost:${SERVER_DEFAULT_PORT}`) - delete process.env.PORT -}) - -test('bundle-serve cleanup', async () => { - const { cleanup } = await bundleServe(createBundler()) - - expect(typeof cleanup).toEqual('function') + const { url, cleanup } = await bundleServe(createBundler(), options) await cleanup() - - expect(mockTerminatorInstance.terminate).toBeCalledTimes(1) - expect(httpTerminator.createHttpTerminator).toHaveBeenCalledWith({ - server: mockHttpsServerInstance - }) + expect(typeof url).toEqual('string') + expect(url).toBe(`https://localhost:${PORT}`) // specificPort not available }) diff --git a/test/commands/lib/run-dev.test.js b/test/commands/lib/run-dev.test.js index a90e83e9..3ebec7e8 100644 --- a/test/commands/lib/run-dev.test.js +++ b/test/commands/lib/run-dev.test.js @@ -24,6 +24,7 @@ global.mockFs() const runDev = require('../../../src/lib/run-dev') const runLocalRuntime = require('../../../src/lib/run-local-runtime') const loadConfig = require('../../../src/lib/config-loader') +const defaults = require('../../../src/lib/defaults') const cloneDeep = require('lodash.clonedeep') const path = require('path') const mockAIOConfig = require('@adobe/aio-lib-core-config') @@ -42,6 +43,7 @@ const appHelper = require('../../../src/lib/app-helper') const execa = require('execa') const yeoman = require('yeoman-environment') const fs = require('fs-extra') +const getPort = require('get-port') const mockYeomanRegister = jest.fn() const mockYeomanRun = jest.fn() @@ -60,6 +62,10 @@ jest.mock('../../../src/lib/build-actions') jest.mock('../../../src/lib/deploy-actions') jest.mock('../../../src/lib/log-poller') jest.mock('@adobe/aio-lib-env') +jest.mock('get-port') +getPort.mockImplementation(() => { + return defaults.defaultHttpServerPort +}) jest.mock('../../../src/lib/app-helper', () => { const moduleMock = jest.requireActual('../../../src/lib/app-helper') @@ -520,6 +526,15 @@ function runCommonWithFrontendTests (ref) { expect(bundleServe).toHaveBeenCalled() }) + test('should start a ui server : find available port', async () => { + const options = { devRemote: ref.devRemote } + getPort.mockImplementationOnce(() => 12345) + await runDev(ref.config, options) + expect(serve).not.toHaveBeenCalled() + expect(bundleServe).toHaveBeenCalled() + expect(bundleServe).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ serveOptions: { https: undefined, port: 12345 } }), expect.anything()) + }) + test('should cleanup ui server on SIGINT', async () => { execa.mockImplementation(() => ({ kill: jest.fn() From 45d4c72deddcd3eda563b1d54a895bff8b561b06 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Wed, 5 May 2021 14:42:38 +0530 Subject: [PATCH 5/9] refactoring and minor fixes --- package.json | 1 - src/commands/app/build.js | 9 ++++----- src/lib/run-dev.js | 1 - test/commands/app/build.test.js | 6 +++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index a93b7bb4..1e26edb9 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "ora": "^4.0.3", - "parcel": "^2.0.0-beta.2", "pure-http": "^2.0.3", "serve-static": "^1.14.1", "which": "^2.0.1", diff --git a/src/commands/app/build.js b/src/commands/app/build.js index a6d791de..d5f3c1c4 100644 --- a/src/commands/app/build.js +++ b/src/commands/app/build.js @@ -76,11 +76,10 @@ class Build extends BaseCommand { if (!script) { const entryFile = config.web.src + '/index.html' const bundleOptions = { - cache: false, - contentHash: flags['content-hash'], - minify: false, - watch: false, - logLevel: flags.verbose ? 4 : 2 + shouldDisableCache: true, + shouldContentHash: flags['content-hash'], + shouldOptimize: false, + logLevel: flags.verbose ? 'verbose' : 'warn' } const { bundler } = await bundle(entryFile, config.web.distProd, bundleOptions, onProgress) await bundler.run() diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 8325d322..5cc75773 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -109,7 +109,6 @@ async function runDev (config, options = {}, log = () => {}) { https: bundleOptions.https } bundleOptions.additionalReporters = [ - { packageName: '@parcel/reporter-cli', resolveFrom: entryFile }, { packageName: '@parcel/reporter-dev-server', resolveFrom: entryFile } ] const { bundler, cleanup: bundlerCleanup } = await bundle(entryFile, config.web.distDev, bundleOptions, log) diff --git a/test/commands/app/build.test.js b/test/commands/app/build.test.js index d3b41f05..dca8ab61 100644 --- a/test/commands/app/build.test.js +++ b/test/commands/app/build.test.js @@ -200,7 +200,7 @@ describe('run', () => { expect(mockRuntimeLib.buildActions).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledWith('undefined/index.html', undefined, - expect.objectContaining({ cache: false, contentHash: true, logLevel: 2, minify: false, watch: false }), + expect.objectContaining({ shouldDisableCache: true, shouldContentHash: true, logLevel: 'warn', shouldOptimize: false }), expect.any(Function) ) expect(mockBundleFunc).toHaveBeenCalledTimes(1) @@ -213,7 +213,7 @@ describe('run', () => { expect(mockRuntimeLib.buildActions).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledWith('undefined/index.html', undefined, - expect.objectContaining({ cache: false, contentHash: false, logLevel: 2, minify: false, watch: false }), + expect.objectContaining({ shouldDisableCache: true, shouldContentHash: false, logLevel: 'warn', shouldOptimize: false }), expect.any(Function) ) expect(mockBundleFunc).toHaveBeenCalledTimes(1) @@ -226,7 +226,7 @@ describe('run', () => { expect(mockRuntimeLib.buildActions).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledTimes(1) expect(mockWebLib.bundle).toHaveBeenCalledWith('undefined/index.html', undefined, - expect.objectContaining({ cache: false, contentHash: false, logLevel: 4, minify: false, watch: false }), + expect.objectContaining({ shouldDisableCache: true, shouldContentHash: false, logLevel: 'verbose', shouldOptimize: false }), expect.any(Function) ) expect(mockBundleFunc).toHaveBeenCalledTimes(1) From 75ca458dd8dd78c25d7b9e2d76f655ed7c820d0c Mon Sep 17 00:00:00 2001 From: Himavanth Date: Thu, 6 May 2021 19:26:13 +0530 Subject: [PATCH 6/9] Adding parcel so linkages could work --- package.json | 1 + src/commands/app/run.js | 4 ++-- src/lib/run-dev.js | 9 ++++----- test/commands/app/run.test.js | 34 +++++++++++++++++----------------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 1e26edb9..a93b7bb4 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "ora": "^4.0.3", + "parcel": "^2.0.0-beta.2", "pure-http": "^2.0.3", "serve-static": "^1.14.1", "which": "^2.0.1", diff --git a/src/commands/app/run.js b/src/commands/app/run.js index 6037935b..4da20e1d 100644 --- a/src/commands/app/run.js +++ b/src/commands/app/run.js @@ -50,9 +50,9 @@ class Run extends BaseCommand { skipServe: !flags.serve, // todo: any other params we should add here? parcel: { - logLevel: flags.verbose ? 4 : 2, + logLevel: flags.verbose ? 'verbose' : 'warn', // always set to false on localhost to get debugging and hot reloading - contentHash: false + shouldContentHash: false }, fetchLogs: true, devRemote: !flags.local, diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 5cc75773..2c48f97e 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -33,10 +33,9 @@ const getPort = require('get-port') async function runDev (config, options = {}, log = () => {}) { /* parcel bundle options */ const bundleOptions = { - cache: false, - contentHash: true, - minify: false, - watch: false, + shouldDisableCache: true, + shouldContentHash: true, + shouldOptimize: false, ...options.parcel } /* skip actions */ @@ -109,7 +108,7 @@ async function runDev (config, options = {}, log = () => {}) { https: bundleOptions.https } bundleOptions.additionalReporters = [ - { packageName: '@parcel/reporter-dev-server', resolveFrom: entryFile } + { packageName: '@parcel/reporter-dev-server', resolveFrom: __filename } ] const { bundler, cleanup: bundlerCleanup } = await bundle(entryFile, config.web.distDev, bundleOptions, log) defaultBundler = bundler diff --git a/test/commands/app/run.test.js b/test/commands/app/run.test.js index ce4bdb31..55dbf99c 100644 --- a/test/commands/app/run.test.js +++ b/test/commands/app/run.test.js @@ -241,7 +241,7 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: expect.objectContaining({ - logLevel: 2 + logLevel: 'warn' }), devRemote: true }), expect.any(Function)) @@ -266,7 +266,7 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: expect.objectContaining({ - logLevel: 4 + logLevel: 'verbose' }), devRemote: true }), expect.any(Function)) @@ -293,7 +293,7 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: expect.objectContaining({ - logLevel: 4 + logLevel: 'verbose' }), devRemote: false }), expect.any(Function)) @@ -367,8 +367,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -388,8 +388,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -417,8 +417,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -453,8 +453,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -491,8 +491,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -527,8 +527,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH @@ -564,8 +564,8 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) expect(mockRunDev).toHaveBeenCalledWith(mockConfigData, expect.objectContaining({ parcel: { - contentHash: false, - logLevel: 2, + shouldContentHash: false, + logLevel: 'warn', https: { cert: PUB_CERT_PATH, key: PRIVATE_KEY_PATH From 7f9065705605546948e1fd291b903a1e427692d8 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Fri, 7 May 2021 15:03:21 +0530 Subject: [PATCH 7/9] cleanup --- src/commands/app/build.js | 2 +- src/lib/bundle-serve.js | 8 +++++-- src/lib/run-dev.js | 4 +--- test/commands/app/build.test.js | 6 +++--- test/commands/lib/bundle-serve.test.js | 13 +++++++++-- test/commands/lib/run-dev.test.js | 30 +++++++++++++------------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/commands/app/build.js b/src/commands/app/build.js index d5f3c1c4..1e68945b 100644 --- a/src/commands/app/build.js +++ b/src/commands/app/build.js @@ -81,7 +81,7 @@ class Build extends BaseCommand { shouldOptimize: false, logLevel: flags.verbose ? 'verbose' : 'warn' } - const { bundler } = await bundle(entryFile, config.web.distProd, bundleOptions, onProgress) + const bundler = await bundle(entryFile, config.web.distProd, bundleOptions, onProgress) await bundler.run() } spinner.succeed(chalk.green('Building web assets')) diff --git a/src/lib/bundle-serve.js b/src/lib/bundle-serve.js index 3df158aa..867dec59 100644 --- a/src/lib/bundle-serve.js +++ b/src/lib/bundle-serve.js @@ -29,13 +29,17 @@ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin- module.exports = async (bundler, options, log = () => {}) => { log('serving front-end using bundler serve...') - await bundler.watch() - + const { unsubscribe } = await bundler.watch((err) => { + if (err) { + log(err) + } + }) const url = `${options.serveOptions.https ? 'https:' : 'http:'}//localhost:${options.serveOptions.port}` log(`local frontend server running at ${url}`) const cleanup = async () => { aioLogger.debug('cleanup bundle-serve...') + await unsubscribe() } return { diff --git a/src/lib/run-dev.js b/src/lib/run-dev.js index 2c48f97e..275d04b1 100644 --- a/src/lib/run-dev.js +++ b/src/lib/run-dev.js @@ -110,9 +110,7 @@ async function runDev (config, options = {}, log = () => {}) { bundleOptions.additionalReporters = [ { packageName: '@parcel/reporter-dev-server', resolveFrom: __filename } ] - const { bundler, cleanup: bundlerCleanup } = await bundle(entryFile, config.web.distDev, bundleOptions, log) - defaultBundler = bundler - cleanup.add(() => bundlerCleanup(), 'cleaning up bundle...') + defaultBundler = await bundle(entryFile, config.web.distDev, bundleOptions, log) } } } diff --git a/test/commands/app/build.test.js b/test/commands/app/build.test.js index dca8ab61..ef355ea3 100644 --- a/test/commands/app/build.test.js +++ b/test/commands/app/build.test.js @@ -127,7 +127,7 @@ beforeEach(() => { mockWebLib.deployWeb.mockReset() mockWebLib.bundle.mockReset() mockBundleFunc.mockReset() - mockWebLib.bundle.mockResolvedValue({ bundler: { run: mockBundleFunc } }) + mockWebLib.bundle.mockResolvedValue({ run: mockBundleFunc }) mockFS.existsSync.mockReset() helpers.writeConfig.mockReset() helpers.runPackageScript.mockReset() @@ -371,7 +371,7 @@ describe('run', () => { test('build (--skip-actions) calls provided log function', async () => { mockWebLib.bundle.mockImplementation((a, b, c, log) => { log('ok') - return { bundler: { run: mockBundleFunc } } + return { run: mockBundleFunc } }) const noScriptFound = undefined @@ -390,7 +390,7 @@ describe('run', () => { test('build (--skip-actions, --verbose) calls provided other log function', async () => { mockWebLib.bundle.mockImplementation((a, b, c, log) => { log('ok') - return { bundler: { run: mockBundleFunc } } + return { run: mockBundleFunc } }) const noScriptFound = undefined diff --git a/test/commands/lib/bundle-serve.test.js b/test/commands/lib/bundle-serve.test.js index c6ba3545..c75cdc42 100644 --- a/test/commands/lib/bundle-serve.test.js +++ b/test/commands/lib/bundle-serve.test.js @@ -12,9 +12,9 @@ governing permissions and limitations under the License. const bundleServe = require('../../../src/lib/bundle-serve') -const createBundler = () => { +let createBundler = () => { return { - watch: jest.fn() + watch: jest.fn((cb) => { cb(); return { unsubscribe: jest.fn() } }) } } @@ -52,3 +52,12 @@ test('bundle-serve https', async () => { expect(typeof url).toEqual('string') expect(url).toBe(`https://localhost:${PORT}`) // specificPort not available }) + +test('watch error', async () => { + createBundler = () => { + return { + watch: jest.fn((cb) => cb(new Error())) + } + } + await expect(bundleServe(createBundler(), {})).rejects.toThrowError() +}) diff --git a/test/commands/lib/run-dev.test.js b/test/commands/lib/run-dev.test.js index 3ebec7e8..a3ba9b91 100644 --- a/test/commands/lib/run-dev.test.js +++ b/test/commands/lib/run-dev.test.js @@ -540,41 +540,41 @@ function runCommonWithFrontendTests (ref) { kill: jest.fn() })) - const mockBundlerCleanup = jest.fn() - bundle.mockImplementation(() => ({ - bundler: jest.fn(), - cleanup: mockBundlerCleanup + const mockServeCleanup = jest.fn() + bundleServe.mockImplementation(() => ({ + url: '', + cleanup: mockServeCleanup })) return new Promise(resolve => { testCleanupNoErrors(resolve, ref, () => { - expect(mockBundlerCleanup).toHaveBeenCalledTimes(1) + expect(mockServeCleanup).toHaveBeenCalledTimes(1) }) }) }) test('should cleanup ui server on error', async () => { - const mockBundlerCleanup = jest.fn() - bundle.mockImplementation(() => ({ - bundler: jest.fn(), - cleanup: mockBundlerCleanup + const mockServeCleanup = jest.fn() + bundleServe.mockImplementation(() => ({ + url: '', + cleanup: mockServeCleanup })) await testCleanupOnError(ref, () => { - expect(mockBundlerCleanup).toHaveBeenCalledTimes(1) + expect(mockServeCleanup).toHaveBeenCalledTimes(1) }) }) test('should exit with 1 if there is an error in cleanup', async () => { - const mockBundlerCleanup = jest.fn() - bundle.mockImplementation(() => ({ - bundler: jest.fn(), - cleanup: mockBundlerCleanup + const mockServeCleanup = jest.fn() + bundleServe.mockImplementation(() => ({ + url: '', + cleanup: mockServeCleanup })) return new Promise(resolve => { const theError = new Error('theerror') - mockBundlerCleanup.mockRejectedValue(theError) + mockServeCleanup.mockRejectedValue(theError) process.removeAllListeners('SIGINT') process.exit.mockImplementation(() => { expect(mockLogger.error).toHaveBeenCalledWith(theError) From 3f41087b30eeb7277a82aa49f2d6f954316d6b70 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Tue, 25 May 2021 00:59:02 +0530 Subject: [PATCH 8/9] parcel upgrade to beta.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56b4271c..f9c4ed0a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "ora": "^4.0.3", - "parcel": "^2.0.0-beta.2", + "parcel": "2.0.0-beta.3.1", "pure-http": "^2.0.3", "serve-static": "^1.14.1", "which": "^2.0.1", From 325c0c9d0a9eea4959566db4521a14c97865bba9 Mon Sep 17 00:00:00 2001 From: Himavanth Date: Wed, 26 May 2021 17:11:36 +0530 Subject: [PATCH 9/9] bump dependencies, remove parcel and fix babel-runtime dependency --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f9c4ed0a..2f44317a 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "@adobe/aio-lib-core-logging": "^1.1.0", "@adobe/aio-lib-env": "^1.0.0", "@adobe/aio-lib-ims": "^4.1.0", - "@adobe/aio-lib-runtime": "^1.5.0", - "@adobe/aio-lib-web": "^4.1.1", - "@adobe/generator-aio-app": "^1.9.0", + "@adobe/aio-lib-runtime": "^2.0.0", + "@adobe/aio-lib-web": "^5.0.0", + "@adobe/generator-aio-app": "^2.0.0", "@adobe/generator-aio-console": "^2.0.6", "@oclif/command": "^1.5.11", "@oclif/config": "^1.12.9", @@ -33,7 +33,6 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "ora": "^4.0.3", - "parcel": "2.0.0-beta.3.1", "pure-http": "^2.0.3", "serve-static": "^1.14.1", "which": "^2.0.1", @@ -43,6 +42,7 @@ "@adobe/eslint-config-aio-lib-config": "^1.2.0", "@oclif/dev-cli": "^1.21.3", "@types/jest": "^26.0.10", + "babel-runtime": "^6.26.0", "codecov": "^3.6.1", "eol": "^0.9.1", "eslint": "^6.0.0",