Skip to content

Commit

Permalink
Fix rebuilds
Browse files Browse the repository at this point in the history
#90 introduced a bug that causes some rebuilds to not take effect.

The solution is not pretty, but it's what we need to do now to work around the weird data flow in latest ember-cli.

Fixes #99.
  • Loading branch information
ef4 committed Aug 15, 2018
1 parent e8a18e1 commit 58d8309
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"babylon": "^6.18.0",
"broccoli-concat": "^3.2.2",
"broccoli-debug": "^0.6.4",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^3.0.0",
"broccoli-plugin": "^1.3.0",
"debug": "^3.1.0",
Expand Down
5 changes: 4 additions & 1 deletion test-apps/sample-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

module.exports = {
name: 'sample-addon'
name: 'sample-addon',
isDevelopingAddon(){
return true;
}
};
30 changes: 26 additions & 4 deletions ts/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import Bundler from './bundler';
import Analyzer from './analyzer';
import Package from './package';
import { buildDebugCallback } from 'broccoli-debug';
import { bundles, bundleForPath } from './bundle-config';
import { bundles, bundleForPath, bundleEntrypoint } from './bundle-config';
import mergeTrees from 'broccoli-merge-trees';
import Funnel from 'broccoli-funnel';
import concat from 'broccoli-concat';

const debugTree = buildDebugCallback('ember-auto-import');
const protocol = '__ember_auto_import_protocol_v1__';
Expand Down Expand Up @@ -49,7 +51,7 @@ export default class AutoImport {
return analyzer;
}

addTo(allAppTree) {
makeBundler(allAppTree) {
// The Splitter takes the set of imports from the Analyzer and
// decides which ones to include in which bundles
let splitter = new Splitter({
Expand All @@ -60,14 +62,34 @@ export default class AutoImport {

// The Bundler asks the splitter for deps it should include and
// is responsible for packaging those deps up.
let bundler = new Bundler(allAppTree, {
return new Bundler(allAppTree, {
splitter,
environment: this.env,
packages: this.packages,
consoleWrite: this.consoleWrite
});
}

addTo(allAppTree) {
let bundler = debugTree(this.makeBundler(allAppTree), 'output');

let combinedEntrypoints = bundles.map(bundleName => {
let target = bundleEntrypoint(bundleName);
let original = new Funnel(allAppTree, {
include: [target, target.replace('.js', '.map')]
});
return concat(mergeTrees([original, bundler]), {
outputFile: target,
headerFiles: [target],
inputFiles: [`entrypoints/${bundleName}/*.js`]
});
});

let lazyChunks = new Funnel(bundler, {
include: ['assets/*']
});

return mergeTrees([allAppTree, debugTree(bundler, 'output')], {
return mergeTrees([allAppTree, lazyChunks, ...combinedEntrypoints], {
overwrite: true
});
}
Expand Down
30 changes: 11 additions & 19 deletions ts/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import WebpackBundler from './webpack';
import Splitter, { BundleDependencies } from './splitter';
import Package, { reloadDevPackages } from './package';
import { merge } from 'lodash';
import { bundles, bundleEntrypoint } from './bundle-config';
import { join, dirname } from 'path';
import { bundles } from './bundle-config';
import { join } from 'path';
import {
readFileSync,
writeFileSync,
ensureDirSync,
existsSync
emptyDirSync,
copySync,
} from 'fs-extra';

const debug = makeDebug('ember-auto-import:bundler');
Expand Down Expand Up @@ -93,29 +93,21 @@ export default class Bundler extends Plugin {
if (this.didEnsureDirs) {
return;
}
ensureDirSync(join(this.outputPath, 'assets'));
emptyDirSync(join(this.outputPath, 'assets'));
for (let bundle of bundles) {
ensureDirSync(dirname(join(this.outputPath, bundleEntrypoint(bundle))));
emptyDirSync(join(this.outputPath, 'entrypoints', bundle));
}
this.didEnsureDirs = true;
}

private addEntrypoints({ entrypoints, dir }) {
for (let bundle of bundles) {
if (entrypoints.has(bundle)) {
let target = bundleEntrypoint(bundle);
let inputTargetPath = join(this.inputPaths[0], target);
if (existsSync(inputTargetPath)) {
let sources = entrypoints
.get(bundle)
.map(asset => readFileSync(join(dir, asset), 'utf8'));
sources.unshift(readFileSync(inputTargetPath, 'utf8'));
writeFileSync(
join(this.outputPath, target),
sources.join('\n'),
'utf8'
);
}
entrypoints
.get(bundle)
.forEach(asset => {
copySync(join(dir, asset), join(this.outputPath, 'entrypoints', bundle, asset));
});
}
}
}
Expand Down

0 comments on commit 58d8309

Please sign in to comment.