Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test for #1696 #1711

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/addon-dev/src/rollup-addon-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const compilationModules = new Set(
templateCompilationModules.map((m) => m.module)
);

function resolvableDependencies() {
let deps = new Set();
function resolvableDependencies(): Set<string> {
let deps = new Set<string>();
let pkg = readJsonSync('package.json');
if (pkg.dependencies) {
for (let name of Object.keys(pkg.dependencies)) {
Expand All @@ -28,11 +28,16 @@ function resolvableDependencies() {
}

export default function emberExternals(): Plugin {
let deps = resolvableDependencies();
let deps: Set<string>;

return {
name: 'ember-externals',

buildStart() {
this.addWatchFile('package.json');
deps = resolvableDependencies();
},

async resolveId(source) {
let pkgName = packageName(source);
if (!pkgName) {
Expand Down
6 changes: 6 additions & 0 deletions packages/addon-dev/src/rollup-keep-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/addon-dev/src/rollup-public-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 2 additions & 0 deletions packages/addon-dev/src/rollup-public-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
Expand Down
30 changes: 30 additions & 0 deletions tests/scenarios/v2-addon-dev-watch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { baseV2Addon } from './scenarios';
import type { PreparedApp } from 'scenario-tester';
import { Scenarios } from 'scenario-tester';
import fs from 'fs/promises';
import { pathExists } from 'fs-extra';
import QUnit from 'qunit';
import merge from 'lodash/merge';
import { DevWatcher, becomesModified, isNotModified } from './helpers';
Expand Down Expand Up @@ -185,6 +186,35 @@ Scenarios.fromProject(() => baseV2Addon())
},
});
});

test('adding a new file triggers a re-build', async function (assert) {
watcher = new DevWatcher(addon);

await watcher.start();

const src = path.join(addon.dir, 'src/components/foo.js');
const dist = path.join(addon.dir, 'dist/components/foo.js');

assert.false(await pathExists(src), 'src/components/foo.js does not exist');
assert.false(await pathExists(dist), 'dist/components/foo.js does not exist');

await fs.writeFile(
src,
`
import Component from '@glimmer/component';
export default class FooComponent extends Component {}
`
);

assert.true(await pathExists(src), 'src/components/foo.js exists');

await watcher.nextBuild();

assert.true(
(await fs.readFile(dist)).includes('FooComponent'),
'dist/components/foo.js exists and has the right content'
);
});
});

test('the package.json *is* updated on a rebuild, since public assets changed', async function (assert) {
Expand Down