Skip to content

Commit

Permalink
Update all internal broccoli-funnel usage to new APIs
Browse files Browse the repository at this point in the history
The 3.x era changed how to instantiate / consume broccoli-funnels, this
updates to that newer API style.
  • Loading branch information
rwjblue committed May 6, 2021
1 parent 9f3459e commit 7902490
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 57 deletions.
6 changes: 3 additions & 3 deletions packages/addon-shim/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AddonInstance,
isDeepAddonInstance,
} from '@embroider/shared-internals';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import type { Node } from 'broccoli-node-api';
import { satisfies } from 'semver';

Expand Down Expand Up @@ -88,7 +88,7 @@ export function addonV1Shim(directory: string, options: ShimOptions = {}) {
let maybeAppJS = meta['app-js'];
if (maybeAppJS) {
const appJS = maybeAppJS;
return new Funnel(rootTree(this), {
return buildFunnel(rootTree(this), {
files: Object.values(appJS),
getDestinationPath(relativePath: string): string {
for (let [exteriorName, interiorName] of Object.entries(appJS)) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export function addonV1Shim(directory: string, options: ShimOptions = {}) {
let maybeAssets = meta['public-assets'];
if (maybeAssets) {
const assets = maybeAssets;
return new Funnel(rootTree(this), {
return buildFunnel(rootTree(this), {
files: Object.keys(assets),
getDestinationPath(relativePath: string): string {
for (let [interiorName, exteriorName] of Object.entries(assets)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/add-to-tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from 'broccoli-node-api';
import Funnel from 'broccoli-funnel';
import { Funnel } from 'broccoli-funnel';

export default class AddToTree extends Funnel {
constructor(combinedVendor: Node, private hook: (outputPath: string) => Promise<void> | void) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/build-compat-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SmooshPackageJSON from './smoosh-package-json';
import broccoliMergeTrees from 'broccoli-merge-trees';
import { Node } from 'broccoli-node-api';
import OneShot from './one-shot';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import { UnwatchedDir, WatchedDir } from 'broccoli-source';
import EmptyPackageTree from './empty-package-tree';

Expand Down Expand Up @@ -51,7 +51,7 @@ function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): N

function withoutNodeModules(originalPackage: Package): Node {
let Klass = originalPackage.mayRebuild ? WatchedDir : UnwatchedDir;
return new Funnel(new Klass(originalPackage.root), {
return buildFunnel(new Klass(originalPackage.root), {
exclude: ['node_modules'],
});
}
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-asset-loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import V1Addon from '../v1-addon';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import cloneDeep from 'lodash/cloneDeep';

// ember-asset-loader's ManifestGenerator (which is used as the Addon base class
Expand All @@ -14,7 +14,7 @@ import cloneDeep from 'lodash/cloneDeep';
// loading is a thing that is natively handled by embroider.
export default class extends V1Addon {
get v2Tree() {
return new Funnel(super.v2Tree, {
return buildFunnel(super.v2Tree, {
exclude: ['_app_/config/asset-manifest.js', '_app_/instance-initializers/load-asset-manifest.js'],
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-cli-clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import V1Addon from '../v1-addon';
import { Memoize } from 'typescript-memoize';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';

export default class EmberCLIClipboard extends V1Addon {
@Memoize()
get v2Tree() {
let tree = super.v2Tree;
return new Funnel(tree, {
return buildFunnel(tree, {
// ember-cli-clipboard is wrapping *everything* in its vendor tree inside
// a fastboot guard, including a package.json file. The presence a file
// named "package.json" that isn't actually valid JSON makes packagers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join, dirname } from 'path';
import { UnwatchedDir } from 'broccoli-source';
import resolve from 'resolve';
import { Memoize } from 'typescript-memoize';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';

export default class extends V1Addon {
@Memoize()
Expand All @@ -18,7 +18,7 @@ export default class extends V1Addon {
let polyfillDir = dirname(
resolve.sync('ember-debug-handlers-polyfill/package.json', { basedir: this.addonInstance.root })
);
let tree = new Funnel(new UnwatchedDir(join(polyfillDir, 'vendor')), {
let tree = buildFunnel(new UnwatchedDir(join(polyfillDir, 'vendor')), {
destDir: 'vendor',
});
let trees = super.v2Trees;
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-cli-mirage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import V1Addon from '../v1-addon';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import { AddonMeta } from '@embroider/core';

export default class extends V1Addon {
Expand All @@ -19,7 +19,7 @@ export default class extends V1Addon {
if (this.addonInstance._shouldIncludeFiles()) {
return tree;
}
return new Funnel(tree, {
return buildFunnel(tree, {
include: ['package.json'],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path';
import { Node } from 'broccoli-node-api';
import { readdirSync, writeFileSync, readFileSync } from 'fs';
import { pathExistsSync, removeSync } from 'fs-extra';
import Funnel from 'broccoli-funnel';
import { Funnel } from 'broccoli-funnel';
import { transform } from '@babel/core';
import { stripBadReexportsPlugin } from '../compat-utils';

Expand Down
8 changes: 4 additions & 4 deletions packages/compat/src/compat-adapters/ember-source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import V1Addon from '../v1-addon';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import AddToTree from '../add-to-tree';
import { outputFileSync, unlinkSync } from 'fs-extra';
Expand All @@ -10,7 +10,7 @@ export default class extends V1Addon {
private useRealModules = semver.satisfies(this.packageJSON.version, '>=3.27.0-beta.0', { includePrerelease: true });

get v2Tree() {
return mergeTrees([super.v2Tree, new Funnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]);
return mergeTrees([super.v2Tree, buildFunnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]);
}

// when using real modules, we're replacing treeForAddon and treeForVendor
Expand All @@ -37,10 +37,10 @@ export default class extends V1Addon {
// supports that pattern of emitting modules into other package's namespaces.
private customAddonTree() {
return mergeTrees([
new Funnel(this.rootTree, {
buildFunnel(this.rootTree, {
srcDir: 'dist/packages',
}),
new Funnel(this.rootTree, {
buildFunnel(this.rootTree, {
srcDir: 'dist/dependencies',
}),
]);
Expand Down
6 changes: 3 additions & 3 deletions packages/compat/src/modules-compat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import { Node } from 'broccoli-node-api';
import mergeTrees from 'broccoli-merge-trees';

Expand All @@ -8,7 +8,7 @@ import mergeTrees from 'broccoli-merge-trees';

export default function modulesCompat(tree: Node) {
return mergeTrees([
new Funnel(tree, { exclude: ['modules'] }),
new Funnel(tree, { srcDir: 'modules', allowEmpty: true }),
buildFunnel(tree, { exclude: ['modules'] }),
buildFunnel(tree, { srcDir: 'modules', allowEmpty: true }),
]);
}
2 changes: 1 addition & 1 deletion packages/compat/src/observe-tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from 'broccoli-node-api';
import Funnel from 'broccoli-funnel';
import { Funnel } from 'broccoli-funnel';

export default class ObserveTree extends Funnel {
constructor(combinedVendor: Node, private hook: (outputPath: string) => Promise<void> | void) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/rewrite-addon-tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import Snitch from './snitch';
import { Node } from 'broccoli-node-api';
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function rewriteAddonTree(
allowEmpty: true,
}
);
let badParts = new Funnel(tree, {
let badParts = buildFunnel(tree, {
exclude: [`${moduleName}/**`],
});
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/snitch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Funnel, { Options as FunnelOptions } from 'broccoli-funnel';
import { Funnel, Options as FunnelOptions } from 'broccoli-funnel';
import walkSync from 'walk-sync';
import { Node } from 'broccoli-node-api';

Expand Down
22 changes: 11 additions & 11 deletions packages/compat/src/v1-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Memoize } from 'typescript-memoize';
import { dirname, isAbsolute, join, relative } from 'path';
import { sync as pkgUpSync } from 'pkg-up';
import { existsSync, pathExistsSync } from 'fs-extra';
import Funnel, { Options as FunnelOptions } from 'broccoli-funnel';
import buildFunnel, { Options as FunnelOptions } from 'broccoli-funnel';
import { UnwatchedDir, WatchedDir } from 'broccoli-source';
import RewritePackageJSON from './rewrite-package-json';
import { todo, unsupported } from '@embroider/core/src/messages';
Expand Down Expand Up @@ -422,7 +422,7 @@ export default class V1Addon {
// legacy root
let srcDir = relative(this.root, join(this.addonInstance.root, this.addonInstance.treePaths[treeName]));
let opts = Object.assign({ srcDir }, this.stockTreeFunnelOptions(treeName));
return new Funnel(this.rootTree, opts);
return buildFunnel(this.rootTree, opts);
})!;
}

Expand Down Expand Up @@ -686,7 +686,7 @@ export default class V1Addon {
// this one doesn't go through transpile yet because it gets handled as
// part of the consuming app. For example, imports should be relative to
// the consuming app, not our own package.
return new Funnel(this.stockTree('test-support'), {
return buildFunnel(this.stockTree('test-support'), {
destDir: `${appPublicationDir}/tests`,
});
}
Expand Down Expand Up @@ -745,7 +745,7 @@ export default class V1Addon {
// around, which is actually what we want
tree = this.invokeOriginalTreeFor('styles');
if (tree) {
tree = new Funnel(tree, {
tree = buildFunnel(tree, {
destDir: '_app_styles_',
getDestinationPath(path) {
return path.replace(/^app\/styles\//, '');
Expand Down Expand Up @@ -818,7 +818,7 @@ export default class V1Addon {
if (this.customizes('treeForApp', 'treeForTemplates')) {
let original = this.invokeOriginalTreeFor('app');
if (original) {
appTree = new Funnel(original, {
appTree = buildFunnel(original, {
destDir: appPublicationDir,
});
}
Expand All @@ -842,7 +842,7 @@ export default class V1Addon {
if (hintTree) {
hintTree = this.maybeSetDirectoryMeta(
built,
new Funnel(hintTree, { destDir: appPublicationDir }),
buildFunnel(hintTree, { destDir: appPublicationDir }),
appPublicationDir,
'app-js'
);
Expand All @@ -866,15 +866,15 @@ export default class V1Addon {
// concept of "fastboot directory" because they can use the macro system to
// conditionally import some things only in fastboot.)
if (pathExistsSync(join(this.root, 'fastboot'))) {
tree = new Funnel(this.rootTree, { srcDir: 'fastboot' });
tree = buildFunnel(this.rootTree, { srcDir: 'fastboot' });
}
tree = this.addonInstance.treeForFastBoot(tree);
if (tree) {
tree = new Funnel(tree, { destDir: fastbootPublicationDir });
tree = buildFunnel(tree, { destDir: fastbootPublicationDir });
}
} else {
if (pathExistsSync(join(this.root, 'fastboot'))) {
tree = new Funnel(this.rootTree, { srcDir: 'fastboot', destDir: fastbootPublicationDir });
tree = buildFunnel(this.rootTree, { srcDir: 'fastboot', destDir: fastbootPublicationDir });
}
}

Expand All @@ -894,7 +894,7 @@ export default class V1Addon {
if (this.customizes('treeForPublic') && !this.isEngine()) {
let original = this.invokeOriginalTreeFor('public');
if (original) {
publicTree = new Funnel(original, {
publicTree = buildFunnel(original, {
destDir: 'public',
});
}
Expand Down Expand Up @@ -924,7 +924,7 @@ export default class V1Addon {
let tree = this.invokeOriginalTreeFor('vendor');
if (tree) {
built.trees.push(
new Funnel(tree, {
buildFunnel(tree, {
destDir: 'vendor',
})
);
Expand Down
29 changes: 14 additions & 15 deletions packages/compat/src/v1-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Memoize } from 'typescript-memoize';
import { sync as pkgUpSync } from 'pkg-up';
import { join, dirname, isAbsolute } from 'path';
import Funnel from 'broccoli-funnel';
import buildFunnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import { WatchedDir } from 'broccoli-source';
import resolve from 'resolve';
Expand Down Expand Up @@ -187,7 +187,7 @@ export default class V1App {

private get indexTree() {
let indexFilePath = this.app.options.outputPaths.app.html;
let index = new Funnel(this.app.trees.app, {
let index = buildFunnel(this.app.trees.app, {
allowEmpty: true,
include: [`index.html`],
getDestinationPath: () => indexFilePath,
Expand All @@ -202,7 +202,7 @@ export default class V1App {
}

private get testIndexTree() {
let index = new Funnel(this.app.trees.tests, {
let index = buildFunnel(this.app.trees.tests, {
allowEmpty: true,
include: [`index.html`],
destDir: 'tests',
Expand Down Expand Up @@ -327,15 +327,15 @@ export default class V1App {
private combinedVendor(addonTrees: Node[]): Node {
let trees = addonTrees.map(
tree =>
new Funnel(tree, {
buildFunnel(tree, {
allowEmpty: true,
srcDir: 'vendor',
destDir: 'vendor',
})
);
if (this.vendorTree) {
trees.push(
new Funnel(this.vendorTree, {
buildFunnel(this.vendorTree, {
destDir: 'vendor',
})
);
Expand Down Expand Up @@ -444,12 +444,11 @@ export default class V1App {
}

private combinedStyles(addonTrees: Node[]): Node {
let trees: Node[] = addonTrees.map(
tree =>
new Funnel(tree, {
allowEmpty: true,
srcDir: '_app_styles_',
})
let trees: Node[] = addonTrees.map(tree =>
buildFunnel(tree, {
allowEmpty: true,
srcDir: '_app_styles_',
})
);
let appStyles = this.app.trees.styles as Node | undefined;
if (appStyles) {
Expand Down Expand Up @@ -478,7 +477,7 @@ export default class V1App {
minifyCSS: this.app.options.minifyCSS.options,
};

let nestedInput = new Funnel(this.combinedStyles(addonTrees), { destDir: 'app/styles' });
let nestedInput = buildFunnel(this.combinedStyles(addonTrees), { destDir: 'app/styles' });
let styles = this.preprocessors.preprocessCss(nestedInput, 'app/styles', '/assets', options);

return new AddToTree(styles, outputPath => {
Expand Down Expand Up @@ -509,7 +508,7 @@ export default class V1App {
let transformName = customTransformEntry[0];
let transformConfig = customTransformEntry[1];

let transformTree = new Funnel(externalTree, {
let transformTree = buildFunnel(externalTree, {
files: transformConfig.files,
annotation: `Funnel (custom transform: ${transformName})`,
});
Expand Down Expand Up @@ -587,7 +586,7 @@ export default class V1App {
// from all addons too.
private get appTree(): Node {
return this.preprocessJS(
new Funnel(this.app.trees.app, {
buildFunnel(this.app.trees.app, {
exclude: ['styles/**', '*.html'],
})
);
Expand All @@ -596,7 +595,7 @@ export default class V1App {
private get testsTree(): Node | undefined {
if (this.shouldBuildTests && this.app.trees.tests) {
return this.preprocessJS(
new Funnel(this.app.trees.tests, {
buildFunnel(this.app.trees.tests, {
destDir: 'tests',
})
);
Expand Down
Loading

0 comments on commit 7902490

Please sign in to comment.