Skip to content

Commit

Permalink
Rename vendor.* to be from @embroider/virtual instead of @embroider/c…
Browse files Browse the repository at this point in the history
…ore (#2139)

* Rename vendor.* to be from @embroider/virtual instead of @embroider/core

* lint:fix
  • Loading branch information
NullVoxPopuli authored Oct 3, 2024
1 parent 72d2f54 commit d195a3b
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 29 deletions.
16 changes: 12 additions & 4 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,11 @@ export class Resolver {

private handleVendorStyles<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = ['@embroider/core/vendor.css', '/@embroider/core/vendor.css', './@embroider/core/vendor.css'];
const candidates = [
'@embroider/virtual/vendor.css',
'/@embroider/virtual/vendor.css',
'./@embroider/virtual/vendor.css',
];

if (!candidates.includes(request.specifier)) {
return request;
Expand All @@ -569,7 +573,7 @@ export class Resolver {
let pkg = this.packageCache.ownerOfFile(request.fromFile);
if (!pkg || !this.options.engines.some(e => e.root === pkg?.root)) {
throw new Error(
`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app or Engine. The top-level Ember app is the only one that has support for @embroider/core/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`
`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app or Engine. The top-level Ember app is the only one that has support for @embroider/virtual/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`
);
}

Expand Down Expand Up @@ -1029,7 +1033,11 @@ export class Resolver {

private handleVendor<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js'];
const candidates = [
'@embroider/virtual/vendor.js',
'/@embroider/virtual/vendor.js',
'./@embroider/virtual/vendor.js',
];

if (!candidates.includes(request.specifier)) {
return request;
Expand All @@ -1038,7 +1046,7 @@ export class Resolver {
let pkg = this.packageCache.ownerOfFile(request.fromFile);
if (pkg?.root !== this.options.engines[0].root) {
throw new Error(
`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`
`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/virtual/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function renderEntrypoint(
// will be inserted via a direct <link> tag.
if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
styles.push({
path: '@embroider/core/vendor.css',
path: '@embroider/virtual/vendor.css',
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function resolver(): Plugin {
buildEnd() {
this.emitFile({
type: 'asset',
fileName: '@embroider/core/vendor.js',
fileName: '@embroider/virtual/vendor.js',
source: virtualContent(
resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'),
resolverLoader.resolver
Expand Down
4 changes: 2 additions & 2 deletions tests/addon-template/tests/dummy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
<link integrity="" rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link integrity="" rel="stylesheet" href="/assets/dummy.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app.js';
import environment from './app/config/environment';
Expand Down
4 changes: 2 additions & 2 deletions tests/addon-template/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{content-for "head"}}
{{content-for "test-head"}}

<link rel="stylesheet" href="/@embroider/core/vendor.css">
<link rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link rel="stylesheet" href="/assets/dummy.css">
<link rel="stylesheet" href="/@embroider/core/test-support.css">

Expand All @@ -28,7 +28,7 @@
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script type="module">import "ember-testing";</script>

Expand Down
4 changes: 2 additions & 2 deletions tests/app-template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
<link integrity="" rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link integrity="" rel="stylesheet" href="/assets/app-template.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app';
import environment from './app/config/environment';
Expand Down
4 changes: 2 additions & 2 deletions tests/app-template/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{{content-for "head"}} {{content-for "test-head"}}

<link rel="stylesheet" href="/@embroider/core/vendor.css" />
<link rel="stylesheet" href="/@embroider/virtual/vendor.css" />
<link rel="stylesheet" href="/assets/app-template.css" />
<link rel="stylesheet" href="/@embroider/core/test-support.css" />

Expand All @@ -25,7 +25,7 @@
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script type="module">import "ember-testing";</script>

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/macro-sample-addon/tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
<link integrity="" rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link integrity="" rel="stylesheet" href="/assets/dummy.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app.js';
import environment from './app/config/environment';
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/macro-sample-addon/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{content-for "head"}}
{{content-for "test-head"}}

<link rel="stylesheet" href="/@embroider/core/vendor.css">
<link rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link rel="stylesheet" href="/assets/dummy.css">
<link rel="stylesheet" href="/@embroider/core/test-support.css">

Expand All @@ -28,7 +28,7 @@
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script type="module">import "ember-testing";</script>

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/macro-test/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{content-for "head"}}
{{content-for "test-head"}}

<link rel="stylesheet" href="/@embroider/core/vendor.css">
<link rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link rel="stylesheet" href="/assets/app-template.css">
<link rel="stylesheet" href="/@embroider/core/test-support.css">

Expand All @@ -32,7 +32,7 @@
self.ORDER = [];
</script>
<script src="/testem.js" integrity=""></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script src="{{rootURL}}apple.js"></script>
<script src="{{rootURL}}ordered.js"></script>
<script src="/@embroider/core/test-support.js"></script>
Expand Down
10 changes: 5 additions & 5 deletions tests/scenarios/compat-addon-classic-features-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ appScenarios
{{content-for "head"}}
<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
<link integrity="" rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link integrity="" rel="stylesheet" href="/assets/app-template.css">
{{content-for "head-footer"}}
Expand All @@ -80,7 +80,7 @@ appScenarios
{{content-for "body"}}
{{content-for "custom"}}
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app.js';
import environment from './app/config/environment';
Expand Down Expand Up @@ -151,7 +151,7 @@ appScenarios
let result = await app.execute('pnpm build');
assert.equal(result.exitCode, 0, result.output);

assert.true(lstatSync(`${app.dir}/dist/@embroider/core/vendor.js`).isFile());
assert.true(lstatSync(`${app.dir}/dist/@embroider/virtual/vendor.js`).isFile());
assert.true(lstatSync(`${app.dir}/dist/@embroider/core/test-support.js`).isFile());
});

Expand All @@ -160,7 +160,7 @@ appScenarios
try {
const [, url] = await server.waitFor(/Local:\s+(https?:\/\/.*)\//g);

let response = await fetch(`${url}/@embroider/core/vendor.js`);
let response = await fetch(`${url}/@embroider/virtual/vendor.js`);
assert.strictEqual(response.status, 200);
// checking the response status 200 is not enough to assert vendor.js is served,
// because when the URL is not recognized, the response contains the index.html
Expand Down Expand Up @@ -240,7 +240,7 @@ appScenarios
try {
const [, url] = await server.waitFor(/Local:\s+(https?:\/\/.*)\//g);

let response = await fetch(`${url}/@embroider/core/vendor.css?direct`);
let response = await fetch(`${url}/@embroider/virtual/vendor.css?direct`);
let text = await response.text();
assert.true(text.includes('.my-addon-p { color: blue; }'));

Expand Down
4 changes: 2 additions & 2 deletions tests/ts-app-template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="/@embroider/core/vendor.css">
<link integrity="" rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link integrity="" rel="stylesheet" href="/assets/ts-app-template.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app.ts';
import environment from './app/config/environment';
Expand Down
4 changes: 2 additions & 2 deletions tests/ts-app-template/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{content-for "head"}}
{{content-for "test-head"}}

<link rel="stylesheet" href="/@embroider/core/vendor.css">
<link rel="stylesheet" href="/@embroider/virtual/vendor.css">
<link rel="stylesheet" href="/assets/ts-app-template.css">
<link rel="stylesheet" href="/@embroider/core/test-support.css">

Expand All @@ -28,7 +28,7 @@
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/virtual/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script type="module">import "ember-testing";</script>

Expand Down

0 comments on commit d195a3b

Please sign in to comment.