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

Add Embroider support #486

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
lint:
name: Linting
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v1
Expand All @@ -23,6 +24,7 @@ jobs:
test-ember:
name: Tests / Ember
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v1
Expand All @@ -34,6 +36,7 @@ jobs:
test-node:
name: Tests / Node
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v1
Expand All @@ -49,6 +52,7 @@ jobs:
test-float:
name: Tests / floating dependencies
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v1
Expand All @@ -61,6 +65,7 @@ jobs:
name: Tests / ${{ matrix.ember-try-scenario }}
runs-on: ubuntu-latest
needs: [lint, test-ember]
timeout-minutes: 15

strategy:
matrix:
Expand All @@ -72,6 +77,8 @@ jobs:
- ember-canary
- ember-default-with-jquery
- ember-classic
- embroider-safe
# - embroider-optimized

steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 3 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');

module.exports = async function () {
return {
Expand Down Expand Up @@ -77,6 +78,8 @@ module.exports = async function () {
},
},
},
embroiderSafe(),
embroiderOptimized(),
],
};
};
6 changes: 5 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const { maybeEmbroider } = require('@embroider/test-setup');
const { treeForManifest } = require('./index');

module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
Expand All @@ -14,5 +16,7 @@ module.exports = function (defaults) {
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
return maybeEmbroider(app, {
extraPublicTrees: [treeForManifest(app)],
});
};
30 changes: 20 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const BroccoliMergeTrees = require('broccoli-merge-trees');
const Manifest = require('./lib/manifest');
const Browserconfig = require('./lib/browserconfig');
const tags = require('./lib/tags');
const pkg = require('./package');

module.exports = {
name: require('./package').name,
name: pkg.name,

shouldIncludeChildAddon(childAddon) {
if (childAddon.name === 'broccoli-asset-rev') {
Expand All @@ -17,6 +18,15 @@ module.exports = {

included(app) {
this.app = app;
},

treeForPublic() {
if (!this.manifest) {
return this._treeForManifest(this.app);
}
},

_treeForManifest(app) {
app.options = app.options || {};
app.options[this.name] = app.options[this.name] || {};

Expand All @@ -26,19 +36,19 @@ module.exports = {
this.manifest.configureFingerprint();
this.browserconfig.configureFingerprint();

this._super.included.apply(this, arguments);
},

treeForPublic() {
let manifest = this.manifest.toTree();
let browserconfig = this.browserconfig.toTree();

return new BroccoliMergeTrees([manifest, browserconfig]);
return new BroccoliMergeTrees([
this.manifest.toTree(),
this.browserconfig.toTree(),
]);
},

contentFor(section) {
if (section === 'head') {
if (this.manifest && section === 'head') {
return tags(this.manifest.configuration);
}
},
};

module.exports.treeForManifest = function treeForManifest(app) {
return app.project.findAddonByName(pkg.name)._treeForManifest(app);
};
16 changes: 4 additions & 12 deletions node-tests/blueprints/ember-web-app-test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
'use strict';
const { expect } = require('ember-cli-blueprint-test-helpers/chai');

const {
setupTestHooks,
emberNew,
emberGenerate,
emberGenerateDestroy,
emberDestroy,
} = require('ember-cli-blueprint-test-helpers/helpers');

describe('Blueprints', function () {
setupTestHooks(this);

describe('ember generate', function () {
it('generates config/manifest.js file', function () {
it('generates files', function () {
let args = ['ember-web-app', 'foo'];

return emberNew().then(() =>
emberGenerateDestroy(args, (file) => {
emberGenerate(args, (file) => {
expect(file('config/manifest.js'))
.to.contain('name: "my-app"')
.to.contain('short_name: "my-app"')
.to.contain('display: "standalone"');
})
);
});

it('adds manifest link & browserconfig meta into app/index.html file', function () {
let args = ['ember-web-app', 'foo'];

return emberNew().then(() =>
emberGenerate(args, (file) => {
expect(file('app/index.html'))
.to.contain(
'<link rel="manifest" src="{{rootURL}}manifest.webmanifest">'
'<link rel="manifest" href="{{rootURL}}manifest.webmanifest">'
)
.to.contain(
'<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml">'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"release": "release-it",
"changelog": "lerna-changelog",
"fast-test": "SKIP_ACCEPTANCE=true yarn node-test",
"node-test": "nyc --reporter=lcov mocha --recursive node-tests",
"node-test": "nyc --reporter=lcov mocha --recursive node-tests/**/*-test.js",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"lint:hbs": "ember-template-lint .",
Expand All @@ -50,6 +50,7 @@
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.5.0",
"@embroider/test-setup": "^0.47.0",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"babel-eslint": "^10.1.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/dummy/app/templates/docs/advanced/fingerprinting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ The following example prepends with a custom domain and adds fingerprint checksu
```javascript
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const broccoliAssetRevDefaults = require('broccoli-asset-rev/lib/default-options');
const { extensions } = require('broccoli-asset-rev/lib/default-options');

module.exports = function(defaults) {
module.exports = function (defaults) {
let options = {
fingerprint: {
extensions: broccoliAssetRevDefaults.extensions.concat(['webmanifest']),
extensions: [...extensions, 'webmanifest'],
prepend: 'https://www.example.com/',
},
};
Expand Down
7 changes: 4 additions & 3 deletions tests/dummy/app/templates/docs/advanced/generating-icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ If your `config/manifest.js` looks like this and needs a `192px` and a `512px` i
```javascript
'use strict';

module.exports = function() {
module.exports = function () {
return {
icons: [
{
src: '/assets/icons/appicon-32.png',
sizes: '32x32',
targets: ['favicon'],
},
...[192, 280, 512].map(size => ({
...[192, 280, 512].map((size) => ({
src: `/assets/icons/appicon-${size}.png`,
sizes: `${size}x${size}`,
})),
Expand All @@ -28,8 +28,9 @@ You can start with a base `brand-icon.svg` image and automatically build the `19

```javascript
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
module.exports = function (defaults) {
let options = {
'ember-cli-image-transformer': {
images: [
Expand Down
26 changes: 24 additions & 2 deletions tests/dummy/app/templates/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,32 @@ ember install ember-web-app
Ember should install the addon, add a `config/manifest.js` file, and insert HTML tags for `manifest.webmanifest` and `browserconfig.xml` into `app/index.html` file.

```html
<!-- app/index.html -->
<head>
<link rel="manifest" href="{{rootURL}}manifest.webmanifest">
<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml">
<link rel="manifest" href="{{rootURL}}manifest.webmanifest" />
<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml" />
</head>
```

Check out the {{docs-link "upgrade guide" "docs.getting-started.upgrade-guide"}} if you're coming from a previous version of Web App.

## Embroider

When application uses Embroider, then pass manifest tree into `extraPublicTrees` configuration property.

```javascript
// ember-cli-build.js
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {});

const { Webpack } = require('@embroider/webpack');
return require('@embroider/compat').compatBuild(app, Webpack, {
extraPublicTrees: [treeForManifest(app)],
});
};
```
4 changes: 2 additions & 2 deletions tests/dummy/app/templates/docs/getting-started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ From [MDN](https://developer.mozilla.org/en-US/docs/Web/Manifest)
The generated `manifest.webmanifest` file is linked to the application using `link` tag in `app/index.html` file.

```html
<link rel="manifest" src="{{rootURL}}manifest.webmanifest">
<link rel="manifest" href="{{rootURL}}manifest.webmanifest" />
```

_The generated manifest is validated using `web-app-manifest-validator` package._
Expand All @@ -28,7 +28,7 @@ From [Microsoft](https://msdn.microsoft.com/en-us/library/dn320426%28v=vs.85%29.
The generated `browserconfig.xml` file is linked to the application using `meta` tag in `app/index.html` file.

```html
<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml">
<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml" />
```

_You can skip generating of `browserconfig.xml` file by removing the `meta` tag from the `app/index.html` file._
Expand Down
Loading