From bb71394d39f10298171630c15c07e128f3e7d88f Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 22 Apr 2020 23:55:33 +0200 Subject: [PATCH] packages/cli: call watchDeps before plugin:serve and update path resolutions --- .../cli/src/commands/plugin/serve/index.ts | 6 ++++ .../cli/src/commands/plugin/serve/paths.ts | 34 ++++++++----------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/cli/src/commands/plugin/serve/index.ts b/packages/cli/src/commands/plugin/serve/index.ts index de6f871b0e..00c7728b63 100644 --- a/packages/cli/src/commands/plugin/serve/index.ts +++ b/packages/cli/src/commands/plugin/serve/index.ts @@ -15,7 +15,13 @@ */ import { startDevServer } from './server'; +import { watchDeps } from 'lib/watchDeps'; export default async () => { + await watchDeps({ build: true }); + await startDevServer(); + + // Wait for interrupt signal + await new Promise(() => {}); }; diff --git a/packages/cli/src/commands/plugin/serve/paths.ts b/packages/cli/src/commands/plugin/serve/paths.ts index 732efc46f1..8d7dd2273c 100644 --- a/packages/cli/src/commands/plugin/serve/paths.ts +++ b/packages/cli/src/commands/plugin/serve/paths.ts @@ -14,39 +14,35 @@ * limitations under the License. */ -import { resolve as resolvePath } from 'path'; -import { existsSync, realpathSync } from 'fs'; +import { existsSync } from 'fs'; +import { paths } from 'lib/paths'; export function getPaths() { - const appDir = realpathSync(process.cwd()); - - const resolveApp = (path: string) => resolvePath(appDir, path); - const resolveOwn = (path: string) => resolvePath(__dirname, '..', path); - const resolveAppModule = (path: string) => { + const resolveTargetModule = (path: string) => { for (const ext of ['mjs', 'js', 'ts', 'tsx', 'jsx']) { - const filePath = resolveApp(`${path}.${ext}`); + const filePath = paths.resolveTarget(`${path}.${ext}`); if (existsSync(filePath)) { return filePath; } } - return resolveApp(`${path}.js`); + return paths.resolveTarget(`${path}.js`); }; - let appHtml = resolveApp('dev/index.html'); + let appHtml = paths.resolveTarget('dev/index.html'); if (!existsSync(appHtml)) { - appHtml = resolveOwn('../../templates/serve_index.html'); + appHtml = paths.resolveOwn('templates/serve_index.html'); } return { appHtml, - appPath: resolveApp('.'), - appAssets: resolveApp('assets'), - appSrc: resolveApp('src'), - appDev: resolveApp('dev'), - appDevEntry: resolveAppModule('dev/index'), - appTsConfig: resolveApp('tsconfig.json'), - appNodeModules: resolveApp('node_modules'), - appPackageJson: resolveApp('package.json'), + appPath: paths.resolveTarget('.'), + appAssets: paths.resolveTarget('assets'), + appSrc: paths.resolveTarget('src'), + appDev: paths.resolveTarget('dev'), + appDevEntry: resolveTargetModule('dev/index'), + appTsConfig: paths.resolveTarget('tsconfig.json'), + appNodeModules: paths.resolveTarget('node_modules'), + appPackageJson: paths.resolveTarget('package.json'), }; }