Skip to content

Commit

Permalink
Merge branch 'master' into the-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Mar 28, 2021
2 parents d889a36 + a22223d commit 1619275
Show file tree
Hide file tree
Showing 97 changed files with 3,797 additions and 3,258 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/packages/core/**/*.js
/packages/core/**/*.d.ts
/packages/shared-internals/**/*.js
/packages/shared-internals/**/*.d.ts
/packages/compat/**/*.js
/packages/compat/**/*.d.ts
/packages/macros/**/*.js
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v1
- uses: rwjblue/setup-volta@v1
with:
node-version: '12'
- uses: volta-cli/action@v1
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -43,9 +41,7 @@ jobs:
matrix: ${{fromJson(needs.discover_matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v1
- uses: rwjblue/setup-volta@v1
with:
node-version: '12'
- uses: volta-cli/action@v1
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
23 changes: 15 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
"name": "Run tests",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"cwd": "${workspaceFolder}/packages/core",
"args": [
"--runInBand",
"--testPathPattern",
"tests/portable-babel-config.test.js",
"--test-name-pattern",
"undefined"
],
"args": ["--runInBand", "--testPathPattern", "tests/import-adder.test.js"],
"outputCapture": "std"
},
{
Expand Down Expand Up @@ -62,6 +56,18 @@
},
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
"name": "Build fastboot-app",
"program": "/Users/edward/hacking/sample/node_modules/.bin/ember",
"cwd": "${workspaceFolder}/test-packages/fastboot-app",
"args": ["build"],
"env": {
"JOBS": "1"
},
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
Expand Down Expand Up @@ -143,7 +149,8 @@
"cwd": "${workspaceFolder}/packages/util",
"args": ["build"],
"env": {
"JOBS": "1"
"JOBS": "1",
"EMBROIDER_TEST_SETUP_FORCE": "embroider"
},
"outputCapture": "std"
},
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Embroider: a modern build system for EmberJS apps
# Embroider: translating existing Ember code into spec-compliant modern JavaScript

[![GitHub Actions CI][github-actions-badge]][github-actions-ci-url]

Expand Down Expand Up @@ -31,16 +31,13 @@ You can read more about the motivation and key ideas in the [intro to the SPEC](

## Status / Should I Use It?

This is beta-quality software. Teams are encouraged to test their apps and
addons using Embroider and report bugs. We need more real-world testing before
we can hit stable 1.0 and integrate into ember-cli as the default build
pipeline.

The main risks to be aware of if you choose to use Embroider in production are:
We are rapidly nearing a 1.0 release, and several large, heavily-tested Ember apps are shipping to production with Embroider. So if you are excited to adopt Embroider, it is a reasonable choice. The main risks to be aware of if you choose to use Embroider in production are:

- you're likely to discover some Ember addons don't work or break your build
- Embroider's own configuration options are subject to change, so you'll need
to read the CHANGELOG.md when updating the Embroider packages.

Alternatively, it is totally safe to stick with the traditional build pipeline and wait for the official cutover point when EmberCLI starts generating new apps with Embroider by default.

## For Addon Authors

Expand Down Expand Up @@ -101,6 +98,20 @@ The recommended steps when introducing Embroider into an existing app are:
4. Enable `staticComponents`, and work to eliminate any resulting build warnings about dynamic component invocation. You may need to add `packageRules` that declare where invocations like `{{component someComponent}}` are getting `someComponent` from.
5. Once your app is working with all of the above, you can enable `splitAtRoutes` and add the `@embroider/router` and code splitting should work.

## Configuring asset URLs

If you are serving your assets from a different origin (like a CDN) from where your index.html content will
be served from, you can use the publicAssetURL option to specify the base URL. In pre-Embroider Ember apps,
this was accomplished by configuring the `fingerprint: { prepend: ... }` option handled by broccoli-asset-rev.

```js
return require('@embroider/compat').compatBuild(app, Webpack, {
packagerOptions: {
publicAssetURL: 'https://your-cdn-here.com/', // This should be a URL ending in "/"
},
});
```

## Analyzing Bundles

see [`ANALYZING.md`](ANALYZING.md)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
},
"resolutions": {
"**/browserslist": "^4.14.0",
"**/fastboot": "^3.1.0"
"**/fastboot": "^3.1.0",
"**/qunit": "^2.14.1"
},
"devDependencies": {
"@types/jest": "^24.0.11",
Expand Down Expand Up @@ -81,7 +82,7 @@
},
"volta": {
"node": "12.16.1",
"yarn": "1.17.3"
"yarn": "1.22.5"
},
"version": "0.37.0"
}
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-engines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import Filter from 'broccoli-persistent-filter';
import { AddonMeta } from '@embroider/core/src/metadata';
import { AddonMeta } from '@embroider/core';

class Awk extends Filter {
search: string;
Expand Down
75 changes: 73 additions & 2 deletions packages/compat/src/compat-adapters/ember-source.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import Funnel from 'broccoli-funnel';
import broccoliMergeTrees from 'broccoli-merge-trees';
import V1Addon from '../v1-addon';
import Funnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import AddToTree from '../add-to-tree';
import { outputFileSync, unlinkSync } from 'fs-extra';
import { join } from 'path';
import semver from 'semver';

export default class extends V1Addon {
private useRealModules = semver.satisfies(this.packageJSON.version, '>=3.27.0', { includePrerelease: true });

get newPackageJSON() {
let extra = {
'./dist/ember-template-compiler': './dist/ember-template-compiler.js',
Expand All @@ -21,4 +27,69 @@ export default class extends V1Addon {
new Funnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] }),
]);
}

// when using real modules, we're replacing treeForAddon and treeForVendor
customizes(treeName: string) {
return (
(this.useRealModules && (treeName === 'treeForAddon' || treeName === 'treeForVendor')) ||
super.customizes(treeName)
);
}

invokeOriginalTreeFor(name: string, opts: { neuterPreprocessors: boolean } = { neuterPreprocessors: false }) {
if (this.useRealModules) {
if (name === 'addon') {
return this.customAddonTree();
}
if (name === 'vendor') {
return this.customVendorTree();
}
}
return super.invokeOriginalTreeFor(name, opts);
}

// Our addon tree is all of the "packages" we share. @embroider/compat already
// supports that pattern of emitting modules into other package's namespaces.
private customAddonTree() {
return mergeTrees([
new Funnel(this.rootTree, {
srcDir: 'dist/packages',
}),
new Funnel(this.rootTree, {
srcDir: 'dist/dependencies',
}),
]);
}

// We're zeroing out these files in vendor rather than deleting them, because
// we can't easily intercept the `app.import` that presumably exists for them,
// so rather than error they will just be empty.
//
// The reason we're zeroing these out is that we're going to consume all our
// modules directly out of treeForAddon instead, as real modules that webpack
// can see.
private customVendorTree() {
return new AddToTree(this.addonInstance._treeFor('vendor'), outputPath => {
unlinkSync(join(outputPath, 'ember', 'ember.js'));
outputFileSync(join(outputPath, 'ember', 'ember.js'), '');
unlinkSync(join(outputPath, 'ember', 'ember-testing.js'));
outputFileSync(join(outputPath, 'ember', 'ember-testing.js'), '');
});
}

get packageMeta() {
let meta = super.packageMeta;
if (this.useRealModules) {
if (!meta['implicit-modules']) {
meta['implicit-modules'] = [];
}
meta['implicit-modules'].push('./ember/index.js');

if (!meta['implicit-test-modules']) {
meta['implicit-test-modules'] = [];
}
meta['implicit-test-modules'].push('./ember-testing/index.js');
}
return meta;
}
}
5 changes: 5 additions & 0 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import bind from 'bind-decorator';
import { pathExistsSync } from 'fs-extra';
import { tmpdir } from 'os';
import { Options as AdjustImportsOptions } from '@embroider/core/src/babel-plugin-adjust-imports';
import semver from 'semver';

interface TreeNames {
appJS: BroccoliNode;
Expand Down Expand Up @@ -359,6 +360,9 @@ class CompatAppAdapter implements AppAdapter<TreeNames> {
activeAddons[addon.name] = addon.root;
}

let emberSource = this.activeAddonChildren().find(a => a.name === 'ember-source')!;
let emberNeedsModulesPolyfill = semver.satisfies(emberSource.version, '<3.27.0', { includePrerelease: true });

return {
activeAddons,
renameModules,
Expand All @@ -374,6 +378,7 @@ class CompatAppAdapter implements AppAdapter<TreeNames> {
// up as a side-effect of babel transpilation, and babel is subject to
// persistent caching.
externalsDir: join(tmpdir(), 'embroider', 'externals'),
emberNeedsModulesPolyfill,
};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Node } from 'broccoli-node-api';
import writeFile from 'broccoli-file-creator';
import mergeTrees from 'broccoli-merge-trees';

interface PipelineOptions<PackagerOptions> extends Options {
export interface PipelineOptions<PackagerOptions> extends Options {
packagerOptions?: PackagerOptions;
onOutputPath?: (outputPath: string) => void;
variants?: Variant[];
}

export default function defaultPipeline<PackagerOptions>(
emberApp: object,
packager: Packager<PackagerOptions>,
packager?: Packager<PackagerOptions>,
options?: PipelineOptions<PackagerOptions>
): Node {
let outputPath: string;
Expand Down Expand Up @@ -43,7 +43,7 @@ export default function defaultPipeline<PackagerOptions>(

let embroiderApp = new App(emberApp, addons, options);

if (process.env.STAGE2_ONLY) {
if (process.env.STAGE2_ONLY || !packager) {
return mergeTrees([embroiderApp.tree, writeFile('.stage2-output', () => outputPath)]);
}

Expand Down
37 changes: 37 additions & 0 deletions packages/compat/src/detect-babel-plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { PluginItem } from '@babel/core';

export function isEmberAutoImportDynamic(item: PluginItem): boolean {
let pluginPath: string;
if (typeof item === 'string') {
pluginPath = item;
} else if (Array.isArray(item) && item.length > 0 && typeof item[0] === 'string') {
pluginPath = item[0];
} else {
return false;
}
return /(^|\/)ember-auto-import\//.test(pluginPath);
}

export function isCompactReexports(item: PluginItem): boolean {
let pluginPath: string;
if (typeof item === 'string') {
pluginPath = item;
} else if (Array.isArray(item) && item.length > 0 && typeof item[0] === 'string') {
pluginPath = item[0];
} else {
return false;
}
return /(^|\/)babel-plugin-compact-reexports\//.test(pluginPath);
}

export function isColocationPlugin(item: PluginItem): boolean {
let pluginPath: string;
if (typeof item === 'string') {
pluginPath = item;
} else if (Array.isArray(item) && item.length > 0 && typeof item[0] === 'string') {
pluginPath = item[0];
} else {
return false;
}
return /(^|\/)ember-cli-htmlbars\/lib\/colocated-babel-plugin/.test(pluginPath);
}
13 changes: 0 additions & 13 deletions packages/compat/src/detect-ember-auto-import.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export { default as Addons } from './compat-addons';
export { default as PrebuiltAddons } from './prebuilt-addons';
export { default as Options, recommendedOptions } from './options';
export { default as V1Addon } from './v1-addon';
export { default as compatBuild } from './default-pipeline';
export { default as compatBuild, PipelineOptions } from './default-pipeline';
export { PackageRules, ModuleRules } from './dependency-rules';
4 changes: 4 additions & 0 deletions packages/compat/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ export default class CompatResolver implements Resolver {
return null;
}

get adjustImportsOptions() {
return this.params.adjustImportsOptions;
}

@Memoize()
private get appPackage(): AppPackagePlaceholder {
return { root: this.params.root, name: this.params.modulePrefix };
Expand Down
3 changes: 2 additions & 1 deletion packages/compat/src/synthesize-template-only-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { join, basename } from 'path';
import walkSync from 'walk-sync';
import { remove, outputFileSync, pathExistsSync } from 'fs-extra';

const source = `export default Ember._templateOnlyComponent();`;
const source = `import templateOnlyComponent from '@ember/component/template-only';
export default templateOnlyComponent();`;

const templateExtension = '.hbs';

Expand Down
Loading

0 comments on commit 1619275

Please sign in to comment.