Skip to content

Commit

Permalink
Merge pull request #1917 from embroider-build/merge-stable
Browse files Browse the repository at this point in the history
Merge stable into main
  • Loading branch information
mansona committed May 15, 2024
2 parents efd6c9a + 4da7279 commit 706d56f
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 152 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Embroider Changelog

## Release (2024-05-08)

@embroider/addon-shim 1.8.8 (patch)
@embroider/compat 3.5.0 (minor)
@embroider/router 2.1.7 (patch)

#### :rocket: Enhancement
* `@embroider/compat`
* [#1907](https://github.com/embroider-build/embroider/pull/1907) Make ember-source compat adapter tolerant of upcoming ember-source changes ([@ef4](https://github.com/ef4))

#### :bug: Bug Fix
* `@embroider/router`
* [#1904](https://github.com/embroider-build/embroider/pull/1904) Fix getRoute override ([@jembezmamy](https://github.com/jembezmamy))
* `@embroider/addon-shim`
* [#1901](https://github.com/embroider-build/embroider/pull/1901) [addon-shim]: Narrowed down broccoli trees for optimized file watching ([@simonihmig](https://github.com/simonihmig))

#### :house: Internal
* `@embroider/test-scenarios`
* [#1908](https://github.com/embroider-build/embroider/pull/1908) update tests to follow newer babel-plugin-ember-template-compiilation ([@ef4](https://github.com/ef4))

#### Committers: 3
- Edward Faulkner ([@ef4](https://github.com/ef4))
- Paweł Bator ([@jembezmamy](https://github.com/jembezmamy))
- Simon Ihmig ([@simonihmig](https://github.com/simonihmig))

## Release (2024-04-30)

@embroider/compat 3.4.9 (patch)
@embroider/core 3.4.9 (patch)
@embroider/macros 1.16.1 (patch)
@embroider/util 1.13.1 (patch)

#### :bug: Bug Fix
* `@embroider/macros`, `@embroider/util`
* [#1891](https://github.com/embroider-build/embroider/pull/1891) Revert "Update to `ember-cli-babel` v8" ([@mansona](https://github.com/mansona))

#### Committers: 1
- Chris Manson ([@mansona](https://github.com/mansona))

## Release (2024-04-18)

@embroider/compat 3.4.8 (patch)
Expand Down
4 changes: 3 additions & 1 deletion packages/addon-shim/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/addon-shim",
"version": "1.8.7",
"version": "1.8.8",
"description": "Make v2 addons work in non-Embroider apps.",
"keywords": [],
"main": "./src/index.js",
Expand All @@ -19,9 +19,11 @@
"dependencies": {
"@embroider/shared-internals": "workspace:^",
"broccoli-funnel": "^3.0.8",
"common-ancestor-path": "^1.0.1",
"semver": "^7.3.8"
},
"devDependencies": {
"@types/common-ancestor-path": "^1.0.2",
"@types/semver": "^7.3.6",
"broccoli-node-api": "^1.7.0",
"typescript": "^5.4.5",
Expand Down
89 changes: 45 additions & 44 deletions packages/addon-shim/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { resolve, relative, isAbsolute } from 'path';
import { readFileSync } from 'fs';
import {
AddonMeta,
AddonInstance,
isDeepAddonInstance,
AddonMeta,
PackageInfo,
isDeepAddonInstance,
} from '@embroider/shared-internals';
import buildFunnel from 'broccoli-funnel';
import type { Node } from 'broccoli-node-api';
import commonAncestorPath from 'common-ancestor-path';
import { readFileSync } from 'fs';
import { dirname, isAbsolute, join, normalize, relative, resolve } from 'path';
import { satisfies } from 'semver';

export interface ShimOptions {
Expand All @@ -29,15 +29,46 @@ export function addonV1Shim(directory: string, options: ShimOptions = {}) {

let meta = addonMeta(pkg);
let disabled = false;
const rootTrees = new WeakMap<AddonInstance, Node>();

function rootTree(addonInstance: AddonInstance): Node {
let tree = rootTrees.get(addonInstance);
if (!tree) {
tree = addonInstance.treeGenerator(directory);
rootTrees.set(addonInstance, tree);
function treeFor(
addonInstance: AddonInstance,
resourceMap: Record<string, string>,
// default expectation is for resourceMap to map from interior to exterior, swap if needed
swapInteriorExterior = false
) {
const absoluteInteriorPaths = Object[
swapInteriorExterior ? 'values' : 'keys'
](resourceMap).map((internalPath) => join(directory, internalPath));

if (absoluteInteriorPaths.length === 0) {
return;
}
return tree;

const ancestorPath =
commonAncestorPath(...absoluteInteriorPaths.map(dirname)) ?? directory;
const ancestorPathRel = relative(directory, ancestorPath);
const ancestorTree = addonInstance.treeGenerator(ancestorPath);
const relativeInteriorPaths = absoluteInteriorPaths.map((absPath) =>
relative(ancestorPath, absPath)
);

return buildFunnel(ancestorTree, {
files: relativeInteriorPaths,
getDestinationPath(relativePath: string): string {
for (let [a, b] of Object.entries(resourceMap)) {
const interiorName = swapInteriorExterior ? b : a;
const exteriorName = swapInteriorExterior ? a : b;
if (join(ancestorPathRel, relativePath) === normalize(interiorName)) {
return exteriorName;
}
}
throw new Error(
`bug in addonV1Shim, no match for ${relativePath} in ${JSON.stringify(
resourceMap
)}`
);
},
});
}

return {
Expand Down Expand Up @@ -72,22 +103,7 @@ export function addonV1Shim(directory: string, options: ShimOptions = {}) {
}
let maybeAppJS = meta['app-js'];
if (maybeAppJS) {
const appJS = maybeAppJS;
return buildFunnel(rootTree(this), {
files: Object.values(appJS),
getDestinationPath(relativePath: string): string {
for (let [exteriorName, interiorName] of Object.entries(appJS)) {
if (relativePath === interiorName) {
return exteriorName;
}
}
throw new Error(
`bug in addonV1Shim, no match for ${relativePath} in ${JSON.stringify(
appJS
)}`
);
},
});
return treeFor(this, maybeAppJS, true);
}
},

Expand All @@ -104,22 +120,7 @@ export function addonV1Shim(directory: string, options: ShimOptions = {}) {
}
let maybeAssets = meta['public-assets'];
if (maybeAssets) {
const assets = maybeAssets;
return buildFunnel(rootTree(this), {
files: Object.keys(assets),
getDestinationPath(relativePath: string): string {
for (let [interiorName, exteriorName] of Object.entries(assets)) {
if (relativePath === interiorName) {
return exteriorName;
}
}
throw new Error(
`bug in addonV1Shim, no match for ${relativePath} in ${JSON.stringify(
assets
)}`
);
},
});
return treeFor(this, maybeAssets);
}
},

Expand Down
2 changes: 1 addition & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/compat",
"version": "3.4.8",
"version": "3.5.0",
"private": false,
"description": "Backward compatibility layer for the Embroider build system.",
"repository": {
Expand Down
22 changes: 20 additions & 2 deletions packages/compat/src/compat-adapters/ember-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type * as Babel from '@babel/core';
import type { NodePath } from '@babel/traverse';
import Plugin from 'broccoli-plugin';
import type { Node } from 'broccoli-node-api';
import { existsSync } from 'fs';

export default class extends V1Addon {
get v2Tree() {
Expand All @@ -21,11 +22,27 @@ export default class extends V1Addon {
return this.app.options.staticEmberSource;
}

// ember-source inlines a whole bunch of dependencies into itself
// versions of ember-source prior to
// https://github.com/emberjs/ember.js/pull/20675 ship dist/packages and
// dist/dependencies separately and the imports between them are package-name
// imports. Since many of the dependencies are also true package.json
// dependencies (in order to get typescript types), and our module-resolver
// prioritizes true dependencies, it's necessary to detect and remove the
// package.json dependencies.
//
// After the above linked change, ember-source ships only dist/packages and
// the inter-package imports are all relative. Some of the things in
// dist/packages are still the rolled-in dependencies, but now that the
// imports are all relative we need no special handling for them (beyond the
// normal v2 addon renamed-modules support.
@Memoize()
private get includedDependencies() {
let result: string[] = [];
for (let name of readdirSync(resolve(this.root, 'dist', 'dependencies'))) {
let depsDir = resolve(this.root, 'dist', 'dependencies');
if (!existsSync(depsDir)) {
return result;
}
for (let name of readdirSync(depsDir)) {
if (name[0] === '@') {
for (let innerName of readdirSync(resolve(this.root, 'dist', 'dependencies', name))) {
if (innerName.endsWith('.js')) {
Expand Down Expand Up @@ -87,6 +104,7 @@ export default class extends V1Addon {
packages,
buildFunnel(this.rootTree, {
srcDir: 'dist/dependencies',
allowEmpty: true,
}),
];

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/core",
"version": "3.4.8",
"version": "3.4.9",
"private": false,
"description": "A build system for EmberJS applications.",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions packages/macros/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/macros",
"version": "1.16.0",
"version": "1.16.1",
"private": false,
"description": "Standardized build-time macros for ember apps.",
"keywords": [
Expand All @@ -23,17 +23,17 @@
"test": "jest"
},
"dependencies": {
"@babel/core": "^7.24.0",
"@embroider/shared-internals": "workspace:*",
"assert-never": "^1.2.1",
"babel-import-util": "^2.0.0",
"ember-cli-babel": "^8.2.0",
"ember-cli-babel": "^7.26.6",
"find-up": "^5.0.0",
"lodash": "^4.17.21",
"resolve": "^1.20.0",
"semver": "^7.3.2"
},
"devDependencies": {
"@babel/core": "^7.14.5",
"@babel/plugin-transform-modules-amd": "^7.19.6",
"@babel/traverse": "^7.14.5",
"@embroider/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/router",
"version": "2.1.6",
"version": "2.1.7",
"description": "Lazy loading router",
"keywords": [
"ember-addon"
Expand Down
25 changes: 20 additions & 5 deletions packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ type EngineInfoByRoute = Record<string, { name: string }>;

let Router: typeof EmberRouter;

interface GetRoute {
(name: string): ReturnType<EmberRouter['_routerMicrolib']['getRoute']>;
isEmbroiderRouterHandler?: true;
}

interface Internals {
_routerMicrolib: {
getRoute: GetRoute;
};
}

if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ?? false)) {
const waiter = buildWaiter('@embroider/router:lazy-route-waiter');

Expand Down Expand Up @@ -65,16 +76,18 @@ if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ??

// This is the framework method that we're overriding to provide our own
// handlerResolver.
setupRouter(...args: unknown[]) {
setupRouter(this: this & Internals, ...args: unknown[]) {
// @ts-expect-error extending private method
let isSetup = super.setupRouter(...args);
let microLib = (this as unknown as { _routerMicrolib: { getRoute: (name: string) => unknown } })._routerMicrolib;
microLib.getRoute = this._handlerResolver(microLib.getRoute.bind(microLib));
let microLib = this._routerMicrolib;
if (!microLib.getRoute.isEmbroiderRouterHandler) {
microLib.getRoute = this._handlerResolver(microLib.getRoute.bind(microLib));
}
return isSetup;
}

private _handlerResolver(original: (name: string) => unknown) {
return (name: string) => {
let handler = ((name: string) => {
const bundle = this.lazyBundle(name);
if (!bundle || bundle.loaded) {
return original(name);
Expand All @@ -93,7 +106,9 @@ if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ??
throw err;
}
);
};
}) as GetRoute;
handler.isEmbroiderRouterHandler = true;
return handler;
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/util",
"version": "1.13.0",
"version": "1.13.1",
"description": "Utilities for app and addon authors.",
"keywords": [
"ember-addon"
Expand All @@ -27,10 +27,9 @@
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
"@babel/core": "^7.24.0",
"@embroider/macros": "workspace:^",
"broccoli-funnel": "^3.0.5",
"ember-cli-babel": "^8.2.0"
"ember-cli-babel": "^7.26.11"
},
"peerDependencies": {
"ember-source": "*",
Expand All @@ -46,6 +45,7 @@
}
},
"devDependencies": {
"@babel/core": "^7.19.6",
"@ember/jquery": "^2.0.0",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
Expand Down

0 comments on commit 706d56f

Please sign in to comment.