Skip to content

Commit 0653f6d

Browse files
authored
Merge pull request #1952 from embroider-build/merge-stable
Merge stable into Main
2 parents 216c23b + ebe6cd1 commit 0653f6d

File tree

13 files changed

+96
-43
lines changed

13 files changed

+96
-43
lines changed

CHANGELOG.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Embroider Changelog
22

3+
## Release (2024-05-29)
4+
5+
@embroider/router 2.1.8 (patch)
6+
7+
#### :bug: Bug Fix
8+
* `@embroider/router`
9+
* [#1945](https://github.com/embroider-build/embroider/pull/1945) avoid loading of lazy engines when generating linkto urls for routes ([@void-mAlex](https://github.com/void-mAlex))
10+
11+
#### Committers: 1
12+
- Alex ([@void-mAlex](https://github.com/void-mAlex))
13+
14+
## Release (2024-05-29)
15+
16+
@embroider/compat 3.5.1 (patch)
17+
@embroider/core 3.4.10 (patch)
18+
@embroider/macros 1.16.2 (patch)
19+
@embroider/shared-internals 2.6.1 (patch)
20+
@embroider/webpack 4.0.1 (patch)
21+
22+
#### :bug: Bug Fix
23+
* `@embroider/shared-internals`, `@embroider/test-support`, `@embroider/test-scenarios`
24+
* [#1949](https://github.com/embroider-build/embroider/pull/1949) Fix ownerOfFile bug on windows ([@ef4](https://github.com/ef4))
25+
26+
#### Committers: 1
27+
- Edward Faulkner ([@ef4](https://github.com/ef4))
28+
329
## Release (2024-05-22)
430

531
@embroider/addon-shim 1.8.9 (patch)

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"browserslist": "^4.14.0",
3535
"graceful-fs": "^4.0.0",
3636
"@types/eslint": "^8.37.0",
37-
"babel-plugin-module-resolver@5.0.1": "5.0.0"
37+
"babel-plugin-module-resolver@5.0.1": "5.0.0",
38+
"@embroider/shared-internals": "workspace:*"
3839
},
3940
"patchedDependencies": {
4041
"ember-source@5.8.0": "patches/ember-source@5.8.0.patch"

packages/compat/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/compat",
3-
"version": "3.5.0",
3+
"version": "3.5.1",
44
"private": false,
55
"description": "Backward compatibility layer for the Embroider build system.",
66
"repository": {

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/core",
3-
"version": "3.4.9",
3+
"version": "3.4.10",
44
"private": false,
55
"description": "A build system for EmberJS applications.",
66
"repository": {

packages/macros/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/macros",
3-
"version": "1.16.1",
3+
"version": "1.16.2",
44
"private": false,
55
"description": "Standardized build-time macros for ember apps.",
66
"keywords": [

packages/router/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/router",
3-
"version": "2.1.7",
3+
"version": "2.1.8",
44
"description": "Lazy loading router",
55
"keywords": [
66
"ember-addon"

packages/router/src/index.ts

+44-16
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ interface GlobalConfig {
1010
'@embroider/core'?: { active: boolean };
1111
}
1212

13-
type EngineInfoByRoute = Record<string, { name: string }>;
14-
1513
let Router: typeof EmberRouter;
1614

1715
interface GetRoute {
@@ -20,25 +18,40 @@ interface GetRoute {
2018
}
2119

2220
interface Internals {
21+
_engineInfoByRoute: Record<string, { name: string }>;
2322
_routerMicrolib: {
2423
getRoute: GetRoute;
2524
};
2625
}
2726

27+
interface EmbroiderBundle {
28+
names: string[];
29+
loaded?: true;
30+
load: () => Promise<void>;
31+
}
32+
2833
if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ?? false)) {
2934
const waiter = buildWaiter('@embroider/router:lazy-route-waiter');
3035

3136
function embroiderBundles(): {
32-
_embroiderEngineBundles_?: { names: string[]; loaded?: true; load: () => Promise<void> }[];
33-
_embroiderRouteBundles_?: { names: string[]; loaded?: true; load: () => Promise<void> }[];
37+
_embroiderEngineBundles_?: EmbroiderBundle[];
38+
_embroiderRouteBundles_?: EmbroiderBundle[];
3439
} {
3540
return window as ReturnType<typeof embroiderBundles>;
3641
}
3742

3843
class EmbroiderRouter extends EmberRouter {
39-
private lazyBundle(routeName: string) {
40-
let engineInfoByRoute = (this as unknown as { _engineInfoByRoute: EngineInfoByRoute })._engineInfoByRoute;
44+
private seenByRoute = new Set<string>();
4145

46+
private lazyRoute(this: this & Internals, routeName: string): EmbroiderBundle | undefined {
47+
let bundles = embroiderBundles();
48+
if (bundles._embroiderRouteBundles_) {
49+
return bundles._embroiderRouteBundles_.find(bundle => bundle.names.indexOf(routeName) !== -1);
50+
}
51+
return undefined;
52+
}
53+
54+
private lazyEngine(this: this & Internals, routeName: string): EmbroiderBundle | undefined {
4255
// Here we map engine names to route names. We need to do this because
4356
// engines can be specified with "as" such as:
4457
//
@@ -48,28 +61,42 @@ if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ??
4861
// router is dynamic and the string could be defined as anything. Luckly, this._engineInfoByRoute contains
4962
// mappings from routeName to the engines "original name" (which we know at build time).
5063
let bundles = embroiderBundles();
51-
let engine = engineInfoByRoute[routeName];
64+
let engine = this._engineInfoByRoute[routeName];
5265
if (engine && bundles._embroiderEngineBundles_) {
5366
let engineName = engine.name;
5467
return bundles._embroiderEngineBundles_.find(bundle => bundle.names.indexOf(engineName) !== -1);
5568
}
69+
return undefined;
70+
}
5671

57-
if (bundles._embroiderRouteBundles_) {
58-
return bundles._embroiderRouteBundles_.find(bundle => bundle.names.indexOf(routeName) !== -1);
59-
}
60-
61-
return false;
72+
private isEngine(this: this & Internals, name: string): boolean {
73+
return Boolean(this._engineInfoByRoute[name]);
6274
}
6375

6476
// This is necessary in order to prevent the premature loading of lazy routes
6577
// when we are merely trying to render a link-to that points at them.
6678
// Unfortunately the stock query parameter behavior pulls on routes just to
6779
// check what their previous QP values were.
68-
_getQPMeta(handlerInfo: { name: string }, ...rest: unknown[]) {
69-
let bundle = this.lazyBundle(handlerInfo.name);
80+
_getQPMeta(this: this & Internals, handlerInfo: { name: string }, ...rest: unknown[]) {
81+
let bundle = this.lazyRoute(handlerInfo.name);
7082
if (bundle && !bundle.loaded) {
83+
// unloaded split routes
84+
return undefined;
85+
}
86+
87+
if (this.isEngine(handlerInfo.name) && !this.seenByRoute.has(handlerInfo.name)) {
88+
// unvisited engines, whether loaded or not, because the same bundle
89+
// could by mounted multiple places and engines expect to only run the
90+
// super._getQPMeta after they've been visited.
7191
return undefined;
7292
}
93+
94+
bundle = this.lazyEngine(handlerInfo.name);
95+
if (bundle && !bundle.loaded) {
96+
// unloaded lazy engines
97+
return undefined;
98+
}
99+
73100
// @ts-expect-error extending private method
74101
return super._getQPMeta(handlerInfo, ...rest);
75102
}
@@ -86,9 +113,10 @@ if (macroCondition(getGlobalConfig<GlobalConfig>()['@embroider/core']?.active ??
86113
return isSetup;
87114
}
88115

89-
private _handlerResolver(original: (name: string) => unknown) {
116+
private _handlerResolver(this: this & Internals, original: (name: string) => unknown) {
90117
let handler = ((name: string) => {
91-
const bundle = this.lazyBundle(name);
118+
const bundle = this.lazyRoute(name) ?? this.lazyEngine(name);
119+
this.seenByRoute.add(name);
92120
if (!bundle || bundle.loaded) {
93121
return original(name);
94122
}

packages/shared-internals/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/shared-internals",
3-
"version": "2.6.0",
3+
"version": "2.6.1",
44
"private": false,
55
"description": "Utilities shared among the other embroider packages",
66
"repository": {

packages/shared-internals/src/package-cache.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Package from './package';
22
import { existsSync, realpathSync } from 'fs';
33
import { getOrCreate } from './get-or-create';
44
import resolvePackagePath from 'resolve-package-path';
5-
import { dirname, posix } from 'path';
5+
import { basename, dirname, join, resolve } from 'path';
66

77
const realpathSyncCache = new Map<string, string>();
88

@@ -66,33 +66,35 @@ export default class PackageCache {
6666
return p;
6767
}
6868

69-
ownerOfFile(filenameInput: string): Package | undefined {
70-
let filename = filenameInput;
69+
ownerOfFile(filename: string): Package | undefined {
70+
let candidate = filename;
7171
const virtualPrefix = 'embroider_virtual:';
7272

73-
if (filename.includes(virtualPrefix)) {
74-
filename = filename.replace(/^.*embroider_virtual:/, '');
73+
if (candidate.includes(virtualPrefix)) {
74+
candidate = candidate.replace(/^.*embroider_virtual:/, '');
7575
}
7676

77-
let segments = filename.replace(/\\/g, '/').split(posix.sep);
78-
7977
// first we look through our cached packages for any that are rooted right
8078
// at or above the file.
81-
for (let length = segments.length; length >= 0; length--) {
82-
if (segments[length - 1] === 'node_modules' || segments[length - 1] === '') {
83-
// once we hit a node_modules or the filesystem root, we're leaving the
79+
while (true) {
80+
if (basename(candidate) === 'node_modules') {
81+
// once we hit a node_modules, we're leaving the
8482
// package we were in, so any higher caches don't apply to us
8583
break;
8684
}
8785

88-
let usedSegments = segments.slice(0, length);
89-
let candidate = usedSegments.join(posix.sep);
9086
if (this.rootCache.has(candidate)) {
9187
return this.rootCache.get(candidate);
9288
}
93-
if (getCachedExists([...usedSegments, 'package.json'].join(posix.sep))) {
89+
if (getCachedExists(join(candidate, 'package.json'))) {
9490
return this.get(candidate);
9591
}
92+
let nextCandidate = resolve(candidate, '..');
93+
if (nextCandidate === candidate) {
94+
// got to the top
95+
break;
96+
}
97+
candidate = nextCandidate;
9698
}
9799
}
98100

packages/webpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@embroider/webpack",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"private": false,
55
"description": "Builds EmberJS apps with Webpack",
66
"repository": {

pnpm-lock.yaml

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-packages/support/suite-setup-util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function githubMatrix() {
1010
let dir = resolve(__dirname, '..', '..', 'tests', 'scenarios');
1111
let { stdout } = await execa(
1212
'scenario-tester',
13-
['list', '--require', 'ts-node/register', '--files', '*-test.ts', '--matrix', 'pnpm run test --filter %s'],
13+
['list', '--require', 'ts-node/register', '--files', '*-test.ts', '--matrix', 'pnpm run test --filter "/^%s/"'],
1414
{
1515
cwd: dir,
1616
preferLocal: true,

tests/scenarios/util-test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Scenarios.fromDir(dirname(require.resolve('@embroider/util/package.json')))
1919
'test.js': `
2020
const { module: QModule, test } = require("qunit");
2121
const semver = require("semver");
22-
const { PackageCache } = require("@embroider/shared-internals");
23-
2422
QModule("shared-internals", function () {
2523
test("testing on node 12", function (assert) {
2624
assert.ok(

0 commit comments

Comments
 (0)