Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jul 11, 2024
1 parent f0d6cd8 commit 6135933
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 168 deletions.
6 changes: 3 additions & 3 deletions packages/addon-dev/src/rollup-hbs-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default function rollupHbsPlugin({
this.addWatchFile(hbsFilename);
}
if (hbsFilter(id)) {
let basename = id.replace(/\.\w{1,3}$/, '');
this.addWatchFile(basename + '.ts');
this.addWatchFile(basename + '.js');
// rollup looses watch of deleted files
// this.addWatchFile(id.replace(/\.hbs$/, '.js'));
// this.addWatchFile(id.replace(/\.hbs$/, '.ts'));
return {
code: hbsToJS(code),
};
Expand Down
43 changes: 9 additions & 34 deletions packages/addon-dev/src/rollup-incremental-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import walkSync from 'walk-sync';
import { rmSync } from 'fs';
import { join } from 'path';
import type { OutputAsset, Plugin } from 'rollup';
import type { Plugin } from 'rollup';
import { existsSync } from 'fs-extra';

export default function incremental(): Plugin {
const changed = new Set();
const generatedAssets = new Map();
const generatedFiles = new Set<string>();

Expand Down Expand Up @@ -47,48 +46,24 @@ export default function incremental(): Plugin {
}

function syncFiles(bundle: Record<string, any>) {
for (const key of Object.keys(bundle)) {
let checkKey = key;
if (key.endsWith('.js.map')) {
checkKey = key.replace('.js.map', '.js');
if (!bundle[checkKey]) {
delete bundle[key];
continue;
}
}
if (bundle[checkKey]?.type === 'asset') {
for (const checkKey of Object.keys(bundle)) {
if (bundle[checkKey]) {
let module = bundle[checkKey] as any;
let code = module.source || module.code;
if (
generatedAssets.has(checkKey) &&
isEqual(
(bundle[checkKey] as OutputAsset).source,
generatedAssets.get(checkKey)
)
isEqual(code, generatedAssets.get(checkKey))
) {
delete bundle[key];
continue;
delete bundle[checkKey];
} else {
generatedAssets.set(
checkKey,
(bundle[checkKey] as OutputAsset).source
);
generatedAssets.set(checkKey, code);
}
}
if (
(bundle[checkKey] as any)?.moduleIds?.every(
(m: string) => !changed.has(m)
)
) {
delete bundle[key];
}
}
changed.clear();
}

return {
name: 'clean',
transform(_code, id) {
changed.add(id);
},
name: 'incremental',
generateBundle(options, bundle) {
if (firstTime) {
firstTime = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/addon-dev/src/rollup-public-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function publicEntrypoints(args: {
}): Plugin {
return {
name: 'addon-modules',

async buildStart() {
let matches = walkSync(args.srcDir, {
globs: [...args.include, '**/*.hbs', '**/*.ts', '**/*.gts', '**/*.gjs'],
Expand All @@ -23,7 +24,6 @@ export default function publicEntrypoints(args: {

for (let name of matches) {
this.addWatchFile(path.join(args.srcDir, name));

// the matched file, but with the extension swapped with .js
let normalizedName = normalizeFileExt(name);

Expand Down
158 changes: 156 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/scenarios/helpers/v2-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class DevWatcher {
* NOTE: there is a bit of a delay between a file change and the next "START"
*/
this.#watcher.on('event', args => {
console.log('args', args);
switch (args.code) {
case 'START': {
this.#defer();
Expand Down
Loading

0 comments on commit 6135933

Please sign in to comment.