Skip to content

Commit

Permalink
Merge pull request #2131 from embroider-build/create-embroider-virtual
Browse files Browse the repository at this point in the history
Rename @embroider/core/entrypoint to @embroider/virtual/compat-modules
  • Loading branch information
NullVoxPopuli authored Oct 3, 2024
2 parents aa52b09 + d92cda2 commit 72d2f54
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 9 deletions.
8 changes: 7 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
"license": "MIT",
"author": "Edward Faulkner",
"main": "src/index.js",
"typesVersions": {
"*": {
"virtual": ["types/virtual"]
}
},
"files": [
"src/**/*.js",
"src/**/*.d.ts",
"src/**/*.js.map"
"src/**/*.js.map",
"types"
],
"scripts": {
"test": "jest"
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,17 @@ export class Resolver {
}

//TODO move the extra forwardslash handling out into the vite plugin
const candidates = ['@embroider/core/entrypoint', '/@embroider/core/entrypoint', './@embroider/core/entrypoint'];
const candidates = [
'@embroider/virtual/compat-modules',
'/@embroider/virtual/compat-modules',
'./@embroider/virtual/compat-modules',
];

if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
return request;
}

const result = /\.?\/?@embroider\/core\/entrypoint(?:\/(?<packageName>.*))?/.exec(request.specifier);
const result = /\.?\/?@embroider\/virtual\/compat-modules(?:\/(?<packageName>.*))?/.exec(request.specifier);

if (!result) {
// TODO make a better error
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 @@ -97,7 +97,7 @@ export function renderEntrypoint(
// deliberately ignoring the app (which is the first entry in the engines array)
let [, ...childEngines] = resolver.options.engines;
for (let childEngine of childEngines) {
let target = `@embroider/core/entrypoint/${childEngine.packageName}`;
let target = `@embroider/virtual/compat-modules/${childEngine.packageName}`;

if (childEngine.isLazy) {
lazyEngines.push({
Expand Down
9 changes: 9 additions & 0 deletions packages/core/types/virtual/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module '@embroider/virtual/compat-modules' {
interface UnknownModule {
[exportName: string]: unknown;
}

const compatModules: Record<string, UnknownModule>;

export default compatModules;
}
3 changes: 3 additions & 0 deletions packages/core/types/virtual/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
throw new Error(
`@embroider/virtual module loaded at runtime! This is likely a mistake. Make sure that you have all the needed plugins for virtually providing embroider's virtual modules.`
);
2 changes: 1 addition & 1 deletion tests/addon-template/tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Application from '@ember/application';
import compatModules from '@embroider/core/entrypoint';
import compatModules from '@embroider/virtual/compat-modules';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'dummy/config/environment';
Expand Down
2 changes: 1 addition & 1 deletion tests/app-template/app/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Application from '@ember/application';
import compatModules from '@embroider/core/entrypoint';
import compatModules from '@embroider/virtual/compat-modules';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/compat-renaming-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ appScenarios
import utilsIndex from 'somebody-elses-package/utils/index';
import utilsIndexJS from 'somebody-elses-package/utils/index.js';
import singleFilePackage from 'single-file-package';
import compat from '@embroider/core/entrypoint';
import compat from '@embroider/virtual/compat-modules';
module('Unit | basics', function () {
test('whole package renaming works for top-level module', async function (assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ts-app-template/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Application from '@ember/application';
import compatModules from '@embroider/core/entrypoint';
import compatModules from '@embroider/virtual/compat-modules';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'ts-app-template/config/environment';
Expand Down
1 change: 0 additions & 1 deletion tests/ts-app-template/types/ts-app-template/entry.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions tests/ts-app-template/types/ts-app-template/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="@embroider/core/virtual" />
import 'ember-source/types';

export {};

0 comments on commit 72d2f54

Please sign in to comment.