From 4fcdb2ded138131500c24f54443afac9cc3742db Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 4 Dec 2023 03:31:36 -0800 Subject: [PATCH] Use rollup's `addWatchFile` API to mark dependencies This solves a bunch of watch-mode (not) rebuilding issues; as a general rule everytime we probe or read from the file system we should at least consider whether such an annotation is needed. Unfortunately this package doesn't appear to be tested currently, but I have applied the same patch locally and it appears to be working fine. --- packages/addon-dev/src/rollup-addon-dependencies.ts | 11 ++++++++--- packages/addon-dev/src/rollup-keep-assets.ts | 6 ++++++ packages/addon-dev/src/rollup-public-assets.ts | 7 +++++++ packages/addon-dev/src/rollup-public-entrypoints.ts | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/addon-dev/src/rollup-addon-dependencies.ts b/packages/addon-dev/src/rollup-addon-dependencies.ts index 0f0172fdc..6fac8c628 100644 --- a/packages/addon-dev/src/rollup-addon-dependencies.ts +++ b/packages/addon-dev/src/rollup-addon-dependencies.ts @@ -11,8 +11,8 @@ const compilationModules = new Set( templateCompilationModules.map((m) => m.module) ); -function resolvableDependencies() { - let deps = new Set(); +function resolvableDependencies(): Set { + let deps = new Set(); let pkg = readJsonSync('package.json'); if (pkg.dependencies) { for (let name of Object.keys(pkg.dependencies)) { @@ -28,11 +28,16 @@ function resolvableDependencies() { } export default function emberExternals(): Plugin { - let deps = resolvableDependencies(); + let deps: Set; return { name: 'ember-externals', + buildStart() { + this.addWatchFile('package.json'); + deps = resolvableDependencies(); + }, + async resolveId(source) { let pkgName = packageName(source); if (!pkgName) { diff --git a/packages/addon-dev/src/rollup-keep-assets.ts b/packages/addon-dev/src/rollup-keep-assets.ts index 40de57188..fba42a421 100644 --- a/packages/addon-dev/src/rollup-keep-assets.ts +++ b/packages/addon-dev/src/rollup-keep-assets.ts @@ -14,6 +14,12 @@ export default function keepAssets({ return { name: 'copy-assets', + // Prior to https://github.com/rollup/rollup/pull/5270, we cannot call this + // from within `generateBundle` + buildStart() { + this.addWatchFile(from); + }, + // imports of assets should be left alone in the source code. This can cover // the case of .css as defined in the embroider v2 addon spec. async resolveId(source, importer, options) { diff --git a/packages/addon-dev/src/rollup-public-assets.ts b/packages/addon-dev/src/rollup-public-assets.ts index 80147ead8..156018524 100644 --- a/packages/addon-dev/src/rollup-public-assets.ts +++ b/packages/addon-dev/src/rollup-public-assets.ts @@ -11,6 +11,13 @@ export default function publicAssets( return { name: 'public-assets-bundler', + + // Prior to https://github.com/rollup/rollup/pull/5270, we cannot call this + // from within `generateBundle` + buildStart() { + this.addWatchFile(path); + }, + generateBundle() { let pkg = readJsonSync('package.json'); const filenames = walkSync(path, { diff --git a/packages/addon-dev/src/rollup-public-entrypoints.ts b/packages/addon-dev/src/rollup-public-entrypoints.ts index af7dcb5f9..29cc2a560 100644 --- a/packages/addon-dev/src/rollup-public-entrypoints.ts +++ b/packages/addon-dev/src/rollup-public-entrypoints.ts @@ -15,6 +15,8 @@ export default function publicEntrypoints(args: { return { name: 'addon-modules', async buildStart() { + this.addWatchFile(args.srcDir); + let matches = walkSync(args.srcDir, { globs: [...args.include, '**/*.hbs', '**/*.ts', '**/*.gts', '**/*.gjs'], });