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

[Monorepo] Adopt @glimmer/component and @glimmer/application #3

Merged
merged 346 commits into from
Aug 31, 2017

Conversation

tomdale
Copy link
Contributor

@tomdale tomdale commented Aug 15, 2017

This PR begins the process of turning this repo into a monorepo that contains "application-level" Glimmer packages (as opposed to "VM-level" packages in glimmer-vm).

To start, we import @glimmer/component and @glimmer/application. These are imported using the script in script/import-packages.sh which preserves each repository's git history.

Features

Lerna for managing dependencies

Each package can have its own dependencies; these are installed by running lerna bootstrap.

Single Root tsconfig.json

This prevents VS Code from getting confused when one package imports another across tsconfig.json boundaries, which may have different settings. The single tsconfig.json keeps VS Code happy and also keeps code quality consistent across subpackages.

Use paths for package resolution

We use tsconfig.json's paths setting to allow TypeScript to find local packages, even when imported via package name. This is preferable to symlinking into node_modules because relying on Node module resolution causes TypeScript to look at package.json, which points at .d.ts files instead of the actual TypeScript source. The implication of this is that when you command-click a symbol from another package in VS Code, you get taken to the actual source code instead of a generated .d.ts file, and cross-package changes are reflected in the editor immediately without waiting for a build step.

Unified build

Build and test all packages in the repository via a single Broccoli build script. The build infrastructure is very similar to the recent work for glimmer-vm with some tweaks:

  1. Work with existing repository layout, so we can import without major changes
  2. Run tests in ES6+ instead of transpiling ES5 as the VM does since we have less stringent compatibility constraints and this allows us to do things like use async functions in tests.

With this commit, tests import everything from the package's root `index.ts` file. This facilitates testing production builds of the package, where internal modules are hoisted and thus lost.
With this commit, tests import everything from the package's root `index.ts` file. This facilitates testing production builds of the package, where internal modules are hoisted and thus lost.
- rm files from correct directory
- fix glob for gitignore
- yarn install and lerna bootstrap after import
@dgeb dgeb self-requested a review August 17, 2017 16:08
Copy link
Member

@dgeb dgeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @tomdale!

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Need a build script (likely also as prepublish).

cache: yarn

addons:
firefox: "54.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update to use chrome with --headless instead (should be a follow up PR I believe).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

// Fail fast if we haven't done a build first.
assertDistExists();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think we should just always ember build -prod here instead of checking that dist exists. This same script exists in glimmer-vm and I have published old builds at least 5 times 🤦‍♂️ .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, sorry about that. I updated the script to eagerly perform a build always.

}

function assertGitIsClean() {
let status = execSync('git status').toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use --porcelain option (otherwise users git configs break this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, thank you

});

let glimmerVM = funnel('packages', {
include: ['@glimmer/*/node_modules/@glimmer/*/dist/amd/es5/*.js']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully grok what is happening here. What creates packages/@glimmer/<whatever>/node_modules/@glimmer/compiler? What prevents duplicates from being concatted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packages are installed here by Lerna during lerna bootstrap. Duplicates are indeed concatted, which is allowed by our AMD loader so long as it duplicates are registered before the module is reified. This is obviously not ideal, but requires a mechanism for having per-package dependencies in the tests. I wanted to get something working landed and then iterate on resolving that problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, mind creating an issue and linking to it from a comment? Just to make sure we don't lose track of the concern...

destDir: '/assets'
});

let qunit = funnel(path.join(require.resolve('qunitjs'), '..'), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to end up watching all of node_modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because:

> require.resolve('qunitjs')
'/Users/tomdale/Code/glimmer.js/node_modules/qunitjs/qunit/qunit.js'

So this resolves to node_modules/qunitjs/qunit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for confirming.

@@ -0,0 +1,50 @@
{
"name": "glimmer.js",
"version": "0.8.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to bump this here (others are on 0.7.x I believe)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we should synchronize versions here like we do with glimmer-vm since @glimmer/application and @glimmer/component are so coupled. They're on 0.7.2 and 0.6.0 respectively now so I think we'd need to bump to 0.8.0 if we want to sync versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agreed that we should synchronize, but what I was actually getting at was that the "bumping" of the version number should be done all at the same time with the publish script (the last time I ran the bin/publish in glimmer-vm where one package had a different version number I got an error)

name: 'symlink-dependencies',

preBuild() {
rimraf('dist/@glimmer/*/node_modules');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty weird: clearing dist/ when we may not even be building into dist/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is line 29 the best way to determine target output directory for the current build?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not really (it doesn't account for ember build --output-path=./some-path) but I don't think we can do better here without changes upstream.

I'd suggest we add a process.env.EMBER_CLI_BUILD_OUTPUT_PATH environment variable (or expose it via some specific API that addons have access to).

@@ -0,0 +1,66 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addon seems unused? Did you intend to add ember-addon: { paths: ['./build/symlink-dependencies']} to the package.json?

@chadhietala
Copy link
Member

chadhietala commented Aug 30, 2017

I'm going to block as there is a cycle.

Update
This dependency should not be an issue as the actual runtime code it just referring to interfaces and the tests are using concrete implementations. This seems "ok" for now.

⠋ BuildingWarning: cycle detected: @glimmer/component <- @glimmer/application <- @glimmer/component

@chadhietala chadhietala merged commit 4fe4bad into master Aug 31, 2017
chadhietala pushed a commit that referenced this pull request Aug 31, 2017
chadhietala pushed a commit that referenced this pull request Aug 31, 2017
Move Environment, DynamicScope, and Iterable modules to glimmer-application
@locks locks deleted the monorepo-infrastructure branch October 18, 2017 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet