Skip to content

Commit

Permalink
Merge pull request #625 from embroider-build/broccoli-updates
Browse files Browse the repository at this point in the history
Switching to broccoli-node-api types
  • Loading branch information
ef4 authored Nov 23, 2020
2 parents 7caf7ae + ecab833 commit 4256159
Show file tree
Hide file tree
Showing 42 changed files with 195 additions and 225 deletions.
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"private": true,
"workspaces": [
"packages/*",
"test-packages/*",
"test-packages/@embroider/*",
"types/babel-core",
"types/@babel__traverse"
],
"workspaces": {
"packages": [
"packages/*",
"test-packages/*",
"test-packages/@embroider/*",
"types/babel-core",
"types/@babel__traverse",
"types/broccoli-funnel",
"types/broccoli-concat",
"types/ember-cli-htmlbars"
],
"nohoist": [
"**/@types/broccoli-plugin"
]
},
"scripts": {
"clean": "git clean -x -f",
"compile": "tsc",
Expand Down
6 changes: 3 additions & 3 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"broccoli-file-creator": "^2.1.1",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^3.0.0",
"broccoli-persistent-filter": "^2.3.1",
"broccoli-plugin": "^1.3.0",
"broccoli-source": "^1.1.0",
"broccoli-persistent-filter": "^3.1.2",
"broccoli-plugin": "^4.0.0",
"broccoli-source": "^3.0.0",
"chalk": "^4.1.0",
"debug": "^3.1.0",
"ember-cli-htmlbars": "^4.0.9",
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/add-to-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import Funnel from 'broccoli-funnel';

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

export default function cachedBuildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Tree {
export default function cachedBuildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Node {
let tree = buildCompatAddon(originalPackage, v1Cache);
if (!originalPackage.mayRebuild) {
tree = new OneShot(tree);
}
return tree;
}

function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Tree {
function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Node {
if (originalPackage.isV2Addon()) {
// this case is needed when a native-v2 addon depends on a
// non-native-v2 addon. (The non-native one will get rewritten and
Expand Down Expand Up @@ -49,7 +49,7 @@ function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): T
}
}

function withoutNodeModules(root: string): Tree {
function withoutNodeModules(root: string): Node {
return new Funnel(new UnwatchedDir(root), {
exclude: ['node_modules'],
});
Expand Down
5 changes: 3 additions & 2 deletions packages/compat/src/compat-adapters/ember-cli-fastboot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import V1Addon from '../v1-addon';
import Plugin, { Tree } from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { readJSONSync, outputJSONSync } from 'fs-extra';
import { join } from 'path';
import writeFile from 'broccoli-file-creator';
Expand Down Expand Up @@ -96,7 +97,7 @@ export default class EmberCliFastboot extends V1Addon {
}

class RewriteManifest extends Plugin {
constructor(tree: Tree, private scriptFilter: (file: string) => boolean, private extraAppFiles: string[]) {
constructor(tree: Node, private scriptFilter: (file: string) => boolean, private extraAppFiles: string[]) {
super([tree], { annotation: 'embroider-compat-adapter-ember-cli-fastboot' });
}
build() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import V1Addon from '../v1-addon';
import { join } from 'path';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { readdirSync, writeFileSync, readFileSync } from 'fs';
import { pathExistsSync, removeSync } from 'fs-extra';
import Funnel from 'broccoli-funnel';
import { transform } from '@babel/core';
import { stripBadReexportsPlugin } from '../compat-utils';

export default class extends V1Addon {
get v2Tree(): Tree {
get v2Tree(): Node {
// workaround for https://github.com/DockYard/ember-composable-helpers/issues/308
// and https://github.com/DockYard/ember-composable-helpers/pull/302
// and https://github.com/DockYard/ember-composable-helpers/pull/307
Expand All @@ -17,7 +17,7 @@ export default class extends V1Addon {
}

class MatchHelpers extends Funnel {
constructor(inputTree: Tree) {
constructor(inputTree: Node) {
super(inputTree, {});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path';
import { Memoize } from 'typescript-memoize';
import cloneDeep from 'lodash/cloneDeep';
import { AddonMeta } from '@embroider/core';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { sync as resolveSync } from 'resolve';

export default class EmberData extends V1Addon {
Expand All @@ -17,7 +17,7 @@ export default class EmberData extends V1Addon {
// ember-data needs its dynamically generated version module.
@Memoize()
get v2Trees() {
let versionTree: () => Tree;
let versionTree: () => Node;
try {
// ember-data 3.10 and earlier kept the version module here.
// eslint-disable-next-line @typescript-eslint/no-require-imports
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-inflector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import AddToTree from '../add-to-tree';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { removeSync } from 'fs-extra';
Expand All @@ -18,7 +18,7 @@ if (Ember.ENV.EXTEND_PROTOTYPES === true || Ember.ENV.EXTEND_PROTOTYPES.String)
const patch = `import './make-configurable';`;

export default class extends V1Addon {
get v2Tree(): Tree {
get v2Tree(): Node {
return new AddToTree(super.v2Tree, outputDir => {
let target = join(outputDir, 'index.js');
let source = readFileSync(target);
Expand Down
6 changes: 3 additions & 3 deletions packages/compat/src/compat-addons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { join, relative, dirname } from 'path';
import { emptyDirSync, ensureSymlinkSync, ensureDirSync, realpathSync, copySync, writeJSONSync } from 'fs-extra';
import { Stage, Package, PackageCache, WaitForTrees, mangledEngineRoot } from '@embroider/core';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class CompatAddons implements Stage {
this.v1Cache = v1Cache;
}

get tree(): Tree {
get tree(): Node {
let movedAddons = [...this.packageCache.moved.keys()].map(oldPkg => buildCompatAddon(oldPkg, this.v1Cache));
let { synthVendor, synthStyles } = this.getSyntheticPackages(this.v1Cache.app, movedAddons);
return new WaitForTrees(
Expand Down Expand Up @@ -188,7 +188,7 @@ export default class CompatAddons implements Stage {
}
}

private getSyntheticPackages(v1App: V1App, movedAddons: Tree[]): { synthVendor: Tree; synthStyles: Tree } {
private getSyntheticPackages(v1App: V1App, movedAddons: Node[]): { synthVendor: Node; synthStyles: Node } {
let index = 0;
let upgradedAddonTrees = [];
for (let [oldPkg] of this.packageCache.moved.entries()) {
Expand Down
12 changes: 6 additions & 6 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from 'broccoli-plugin';
import { Node as BroccoliNode } from 'broccoli-node-api';
import mergeTrees from 'broccoli-merge-trees';
import {
Stage,
Expand Down Expand Up @@ -37,10 +37,10 @@ import { tmpdir } from 'os';
import { Options as AdjustImportsOptions } from '@embroider/core/src/babel-plugin-adjust-imports';

interface TreeNames {
appJS: Tree;
htmlTree: Tree;
publicTree: Tree | undefined;
configTree: Tree;
appJS: BroccoliNode;
htmlTree: BroccoliNode;
publicTree: BroccoliNode | undefined;
configTree: BroccoliNode;
}

// This runs at broccoli-pipeline-construction time, whereas our actual
Expand All @@ -56,7 +56,7 @@ function setup(legacyEmberAppInstance: object, options: Required<Options>) {
let appBootTree = oldPackage.appBoot;

if (options.extraPublicTrees.length > 0) {
publicTree = mergeTrees([publicTree, ...options.extraPublicTrees].filter(Boolean) as Tree[]);
publicTree = mergeTrees([publicTree, ...options.extraPublicTrees].filter(Boolean) as BroccoliNode[]);
}

let inTrees = {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, Addons as CompatAddons, Options, PrebuiltAddons } from '.';
import { toBroccoliPlugin, Packager, Variant } from '@embroider/core';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import writeFile from 'broccoli-file-creator';
import mergeTrees from 'broccoli-merge-trees';

Expand All @@ -14,7 +14,7 @@ export default function defaultPipeline<PackagerOptions>(
emberApp: object,
packager: Packager<PackagerOptions>,
options?: PipelineOptions<PackagerOptions>
): Tree {
): Node {
let outputPath: string;
let addons;
if (process.env.REUSE_WORKSPACE) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/modules-compat.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Funnel from 'broccoli-funnel';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import mergeTrees from 'broccoli-merge-trees';

// there is a weirder, older behavior where addons wrapped their addon tree
// output in a `modules` folder. This strips that level off if it exists,
// without discarding any other content that was not inside `modules`.

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

export default class ObserveTree extends Funnel {
constructor(combinedVendor: Tree, private hook: (outputPath: string) => Promise<void> | void) {
constructor(combinedVendor: Node, private hook: (outputPath: string) => Promise<void> | void) {
super(combinedVendor, {
annotation: '@embroider/compat/observe-tree',
});
Expand Down
5 changes: 3 additions & 2 deletions packages/compat/src/one-shot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Plugin, { Tree } from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { Builder } from 'broccoli';
import { copySync } from 'fs-extra';

Expand All @@ -8,7 +9,7 @@ export default class OneShot extends Plugin {
private builder: Builder;
private didBuild = false;

constructor(originalTree: Tree) {
constructor(originalTree: Node) {
// from broccoli's perspective, we don't depend on any input trees!
super([], {
persistentOutput: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { V1AddonConstructor } from './v1-addon';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { Options as CoreOptions, optionsWithDefaults as coreWithDefaults } from '@embroider/core';
import { PackageRules } from './dependency-rules';

Expand Down Expand Up @@ -67,7 +67,7 @@ export default interface Options extends CoreOptions {
// optional list of additional broccoli trees that should be incorporated into
// the final build. This exists because the classic `app.toTree()` method
// accepts an optional tree argument that has the same purpose.
extraPublicTrees?: Tree[];
extraPublicTrees?: Node[];

// Allows you to tell Embroider about otherwise dynamic dependencies within
// your app and addons that it can't figure out on its own. These are combined
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/prebuilt-addons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Stage, Package, PackageCache } from '@embroider/core';
import { realpathSync, readJSONSync } from 'fs-extra';
import { UnwatchedDir } from 'broccoli-source';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { join } from 'path';
import Options, { optionsWithDefaults } from './options';
import V1InstanceCache from './v1-instance-cache';
Expand All @@ -10,7 +10,7 @@ export default class PrebuiltAddons implements Stage {
private packageCache: PackageCache;
private appDestDir: string;
readonly inputPath: string;
readonly tree: Tree;
readonly tree: Node;

constructor(legacyEmberAppInstance: object, maybeOptions: Options | undefined, workspaceDir: string) {
let options = optionsWithDefaults(maybeOptions);
Expand Down
6 changes: 3 additions & 3 deletions packages/compat/src/rewrite-addon-tree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Funnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import Snitch from './snitch';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { AddonMeta } from '@embroider/core';
import AddToTree from './add-to-tree';
import { moveSync, readdirSync, statSync } from 'fs-extra';
Expand Down Expand Up @@ -43,10 +43,10 @@ import { join, basename } from 'path';
type GetMeta = () => Partial<AddonMeta>;

export default function rewriteAddonTree(
tree: Tree,
tree: Node,
name: string,
moduleName: string
): { tree: Tree; getMeta: GetMeta } {
): { tree: Node; getMeta: GetMeta } {
let renamed: { [name: string]: string } = {};

tree = new AddToTree(tree, outputPath => {
Expand Down
5 changes: 3 additions & 2 deletions packages/compat/src/rewrite-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Plugin, { Tree } from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { writeFileSync } from 'fs';
import { join } from 'path';
import { AddonMeta } from '@embroider/core';

type GetMeta = () => Partial<AddonMeta>;

export default class RewritePackageJSON extends Plugin {
constructor(inputTree: Tree, private getMeta: GetMeta, private originalPackageJSON: any) {
constructor(inputTree: Node, private getMeta: GetMeta, private originalPackageJSON: any) {
super([inputTree], {
annotation: 'embroider:core:rewrite-package-json',
});
Expand Down
5 changes: 3 additions & 2 deletions packages/compat/src/smoosh-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Plugin, { Tree } from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { mergeWithUniq } from './merges';

export default class SmooshPackageJSON extends Plugin {
constructor(inputTrees: Tree[]) {
constructor(inputTrees: Node[]) {
super(inputTrees, {
annotation: 'embroider:core:smoosh-package-json',
});
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/snitch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Funnel, { Options as FunnelOptions } from 'broccoli-funnel';
import walkSync from 'walk-sync';
import { Tree } from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';

/*
This is used to monitor when addons are emitting badly-behaved broccoli
Expand All @@ -16,7 +16,7 @@ export default class Snitch extends Funnel {
private mustCheck = true;

constructor(
inputTree: Tree,
inputTree: Node,
snitchOptions: { allowedPaths: RegExp; foundBadPaths: Function },
funnelOptions: FunnelOptions
) {
Expand Down
5 changes: 3 additions & 2 deletions packages/compat/src/synthesize-template-only-components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Plugin, { Tree } from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import { join, basename } from 'path';
import walkSync from 'walk-sync';
import { remove, outputFileSync, pathExistsSync } from 'fs-extra';
Expand All @@ -15,7 +16,7 @@ const jsExtension = '.js';
export default class SynthesizeTemplateOnlyComponents extends Plugin {
private emitted = new Set() as Set<string>;

constructor(tree: Tree, private allowedPaths: string[]) {
constructor(tree: Node, private allowedPaths: string[]) {
super([tree], {
annotation: `synthesize-template-only-components:${allowedPaths.join(':')}`,
persistentOutput: true,
Expand Down
Loading

0 comments on commit 4256159

Please sign in to comment.