From c9291afe13c069b1ec541b1d64bc708a1de5808b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:53:51 -0400 Subject: [PATCH] Rename @embroider/core/entrypoint to @embroider/virtual/compat-modules, Resolving #2025 Approach #1: Create package, @embroider/virtual --- packages/core/src/module-resolver.ts | 8 +- packages/core/src/virtual-entrypoint.ts | 2 +- packages/virtual/.editorconfig | 19 +++++ packages/virtual/.eslintignore | 27 +++++++ packages/virtual/.eslintrc.js | 80 +++++++++++++++++++ packages/virtual/.prettierignore | 25 ++++++ packages/virtual/.prettierrc.js | 12 +++ packages/virtual/package.json | 21 +++++ packages/virtual/src/compat-modules.d.ts | 7 ++ packages/virtual/src/not-used.js | 12 +++ pnpm-lock.yaml | 14 ++++ tests/addon-template/package.json | 1 + tests/addon-template/tests/dummy/app/app.js | 2 +- tests/app-template/app/app.js | 2 +- tests/app-template/package.json | 1 + tests/scenarios/compat-renaming-test.ts | 2 +- tests/ts-app-template-classic/package.json | 1 + tests/ts-app-template/app/app.ts | 2 +- tests/ts-app-template/package.json | 1 + .../types/ts-app-template/entry.d.ts | 1 - 20 files changed, 232 insertions(+), 8 deletions(-) create mode 100644 packages/virtual/.editorconfig create mode 100644 packages/virtual/.eslintignore create mode 100644 packages/virtual/.eslintrc.js create mode 100644 packages/virtual/.prettierignore create mode 100644 packages/virtual/.prettierrc.js create mode 100644 packages/virtual/package.json create mode 100644 packages/virtual/src/compat-modules.d.ts create mode 100644 packages/virtual/src/not-used.js delete mode 100644 tests/ts-app-template/types/ts-app-template/entry.d.ts diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index 44369c4dc..a6dc96297 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -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(?:\/(?.*))?/.exec(request.specifier); + const result = /\.?\/?@embroider\/virtual\/compat-modules(?:\/(?.*))?/.exec(request.specifier); if (!result) { // TODO make a better error diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index da5d4716a..8b4de6685 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -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({ diff --git a/packages/virtual/.editorconfig b/packages/virtual/.editorconfig new file mode 100644 index 000000000..c35a00240 --- /dev/null +++ b/packages/virtual/.editorconfig @@ -0,0 +1,19 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.hbs] +insert_final_newline = false + +[*.{diff,md}] +trim_trailing_whitespace = false diff --git a/packages/virtual/.eslintignore b/packages/virtual/.eslintignore new file mode 100644 index 000000000..7616988ac --- /dev/null +++ b/packages/virtual/.eslintignore @@ -0,0 +1,27 @@ +# unconventional js +/blueprints/*/files/ +/vendor/ + +# compiled output +/dist/ +/tmp/ +/src/**/*.js +/src/**/*.d.ts + +# dependencies +/bower_components/ +/node_modules/ + +# misc +/coverage/ +!.* +.*/ +.eslintcache + +# ember-try +/.node_modules.ember-try/ +/bower.json.ember-try +/npm-shrinkwrap.json.ember-try +/package.json.ember-try +/package-lock.json.ember-try +/yarn.lock.ember-try diff --git a/packages/virtual/.eslintrc.js b/packages/virtual/.eslintrc.js new file mode 100644 index 000000000..275041165 --- /dev/null +++ b/packages/virtual/.eslintrc.js @@ -0,0 +1,80 @@ +'use strict'; + +module.exports = { + root: true, + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + ecmaFeatures: { + legacyDecorators: true, + }, + }, + plugins: ['ember'], + extends: [ + 'eslint:recommended', + 'plugin:ember/recommended', + 'plugin:prettier/recommended', + ], + env: { + browser: true, + }, + overrides: [ + // node files + { + files: [ + './.eslintrc.js', + './.prettierrc.js', + './.template-lintrc.js', + './ember-cli-build.js', + './addon-main.js', + './testem.js', + './blueprints/*/index.js', + './config/**/*.js', + './tests/dummy/config/**/*.js', + ], + parserOptions: { + sourceType: 'script', + }, + env: { + browser: false, + node: true, + }, + plugins: ['node'], + extends: ['plugin:node/recommended'], + }, + // node typescript files + { + files: ['src/**/*.ts'], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 2017, + sourceType: 'module', + }, + plugins: ['@typescript-eslint'], + extends: ['prettier'], + rules: { + '@typescript-eslint/naming-convention': [ + 'error', + { + selector: 'typeLike', + format: ['PascalCase'], + }, + ], + '@typescript-eslint/consistent-type-assertions': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_' }, + ], + 'no-unused-vars': 'off', + '@typescript-eslint/no-require-imports': 'error', + }, + }, + { + // test files + files: ['tests/**/*-test.{js,ts}'], + extends: ['plugin:qunit/recommended'], + }, + ], +}; diff --git a/packages/virtual/.prettierignore b/packages/virtual/.prettierignore new file mode 100644 index 000000000..4178fd571 --- /dev/null +++ b/packages/virtual/.prettierignore @@ -0,0 +1,25 @@ +# unconventional js +/blueprints/*/files/ +/vendor/ + +# compiled output +/dist/ +/tmp/ + +# dependencies +/bower_components/ +/node_modules/ + +# misc +/coverage/ +!.* +.eslintcache +.lint-todo/ + +# ember-try +/.node_modules.ember-try/ +/bower.json.ember-try +/npm-shrinkwrap.json.ember-try +/package.json.ember-try +/package-lock.json.ember-try +/yarn.lock.ember-try diff --git a/packages/virtual/.prettierrc.js b/packages/virtual/.prettierrc.js new file mode 100644 index 000000000..52881f37e --- /dev/null +++ b/packages/virtual/.prettierrc.js @@ -0,0 +1,12 @@ +'use strict'; + +module.exports = { + overrides: [ + { + files: '*{js,ts}', + options: { + singleQuote: true, + }, + }, + ], +}; diff --git a/packages/virtual/package.json b/packages/virtual/package.json new file mode 100644 index 000000000..8f2894804 --- /dev/null +++ b/packages/virtual/package.json @@ -0,0 +1,21 @@ +{ + "name":"@embroider/virtual", + "version": "0.0.0", + "description": "Provides types for virtual modules", + "exports": { + ".": "./src/not-used.js", + "./compat-modules": { + "types": "./src/compat-modules.d.ts", + "default": "./src/not-used.js" + }, + "./*": "./src/not-used.js" + }, + "typesVersions": { + "*": { + "*": ["./src/*"] + } + }, + "files": [ + "src" + ] +} diff --git a/packages/virtual/src/compat-modules.d.ts b/packages/virtual/src/compat-modules.d.ts new file mode 100644 index 000000000..0af6b7652 --- /dev/null +++ b/packages/virtual/src/compat-modules.d.ts @@ -0,0 +1,7 @@ +interface UnknownModule { + [exportName: string]: unknown; +} + +declare const compatModules: Record; + +export default compatModules; diff --git a/packages/virtual/src/not-used.js b/packages/virtual/src/not-used.js new file mode 100644 index 000000000..113fe2af2 --- /dev/null +++ b/packages/virtual/src/not-used.js @@ -0,0 +1,12 @@ +/** + * This file exists to appease both type checking and require.resolve + * checks for the existance of `@embroider/virtual`. + * + * This library has a '.' entrypoint which points to this file for require.resolve (if a consumer needed), as well as every other export. + * + * Real types are provided for the non-'.' exports. + */ + +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.` +); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 799f6e9f9..b0958edf0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -945,6 +945,8 @@ importers: specifier: ^5.74.0 version: 5.94.0 + packages/virtual: {} + packages/vite: dependencies: '@babel/core': @@ -1364,6 +1366,9 @@ importers: '@embroider/test-setup': specifier: workspace:* version: link:../../packages/test-setup + '@embroider/virtual': + specifier: workspace:* + version: link:../../packages/virtual '@embroider/vite': specifier: workspace:* version: link:../../packages/vite @@ -1505,6 +1510,9 @@ importers: '@embroider/test-setup': specifier: workspace:* version: link:../../packages/test-setup + '@embroider/virtual': + specifier: workspace:* + version: link:../../packages/virtual '@embroider/vite': specifier: workspace:* version: link:../../packages/vite @@ -1952,6 +1960,9 @@ importers: '@embroider/test-setup': specifier: workspace:* version: link:../../packages/test-setup + '@embroider/virtual': + specifier: workspace:* + version: link:../../packages/virtual '@embroider/vite': specifier: workspace:* version: link:../../packages/vite @@ -2114,6 +2125,9 @@ importers: '@embroider/test-setup': specifier: workspace:* version: link:../../packages/test-setup + '@embroider/virtual': + specifier: workspace:* + version: link:../../packages/virtual '@embroider/vite': specifier: workspace:* version: link:../../packages/vite diff --git a/tests/addon-template/package.json b/tests/addon-template/package.json index 6c03e21ae..1265e0291 100644 --- a/tests/addon-template/package.json +++ b/tests/addon-template/package.json @@ -39,6 +39,7 @@ "@embroider/compat": "workspace:*", "@embroider/core": "workspace:*", "@embroider/test-setup": "workspace:*", + "@embroider/virtual": "workspace:*", "@embroider/vite": "workspace:*", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", diff --git a/tests/addon-template/tests/dummy/app/app.js b/tests/addon-template/tests/dummy/app/app.js index 0856d883b..d26b01ace 100644 --- a/tests/addon-template/tests/dummy/app/app.js +++ b/tests/addon-template/tests/dummy/app/app.js @@ -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'; diff --git a/tests/app-template/app/app.js b/tests/app-template/app/app.js index 9f0c04383..1b2e0a134 100644 --- a/tests/app-template/app/app.js +++ b/tests/app-template/app/app.js @@ -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'; diff --git a/tests/app-template/package.json b/tests/app-template/package.json index 8c9e25fd0..b11a5520b 100644 --- a/tests/app-template/package.json +++ b/tests/app-template/package.json @@ -41,6 +41,7 @@ "@embroider/core": "workspace:*", "@embroider/router": "workspace:*", "@embroider/test-setup": "workspace:*", + "@embroider/virtual": "workspace:*", "@embroider/vite": "workspace:*", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", diff --git a/tests/scenarios/compat-renaming-test.ts b/tests/scenarios/compat-renaming-test.ts index d1e3a6d5f..d89525c32 100644 --- a/tests/scenarios/compat-renaming-test.ts +++ b/tests/scenarios/compat-renaming-test.ts @@ -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) { diff --git a/tests/ts-app-template-classic/package.json b/tests/ts-app-template-classic/package.json index 81a5974f5..898415dee 100644 --- a/tests/ts-app-template-classic/package.json +++ b/tests/ts-app-template-classic/package.json @@ -36,6 +36,7 @@ "@embroider/core": "workspace:*", "@embroider/router": "workspace:*", "@embroider/test-setup": "workspace:*", + "@embroider/virtual": "workspace:*", "@embroider/vite": "workspace:*", "@glimmer/component": "^1.1.2", "@glimmer/interfaces": "^0.84.2", diff --git a/tests/ts-app-template/app/app.ts b/tests/ts-app-template/app/app.ts index dc71d8aac..f8ec92774 100644 --- a/tests/ts-app-template/app/app.ts +++ b/tests/ts-app-template/app/app.ts @@ -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'; diff --git a/tests/ts-app-template/package.json b/tests/ts-app-template/package.json index 2b35c5725..7bcd3b341 100644 --- a/tests/ts-app-template/package.json +++ b/tests/ts-app-template/package.json @@ -40,6 +40,7 @@ "@embroider/core": "workspace:*", "@embroider/router": "workspace:*", "@embroider/test-setup": "workspace:*", + "@embroider/virtual": "workspace:*", "@embroider/vite": "workspace:*", "@glimmer/component": "^1.1.2", "@glimmer/interfaces": "^0.84.2", diff --git a/tests/ts-app-template/types/ts-app-template/entry.d.ts b/tests/ts-app-template/types/ts-app-template/entry.d.ts deleted file mode 100644 index 0aa0610dd..000000000 --- a/tests/ts-app-template/types/ts-app-template/entry.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@embroider/core/entrypoint';