diff --git a/packages/repl-sdk/package.json b/packages/repl-sdk/package.json index 16760f1f1..da34d9902 100644 --- a/packages/repl-sdk/package.json +++ b/packages/repl-sdk/package.json @@ -6,6 +6,9 @@ ".": { "types": "./src/index.d.ts", "default": "./src/index.js" + }, + "./compilers/ember/*": { + "default": "./src/compilers/ember/*.js" } }, "scripts": { @@ -37,6 +40,7 @@ ], "license": "MIT", "devDependencies": { + "@babel/plugin-proposal-decorators": "^7.23.9", "@nullvoxpopuli/eslint-configs": "^4.0.0", "@tsconfig/ember": "^3.0.7", "eslint": "^8.55.0", diff --git a/packages/repl-sdk/src/compilers/cdn.js b/packages/repl-sdk/src/compilers/cdn.js index 3439bec8b..5b8700a17 100644 --- a/packages/repl-sdk/src/compilers/cdn.js +++ b/packages/repl-sdk/src/compilers/cdn.js @@ -44,7 +44,7 @@ export const jsdelivr = { async import(versions, importPath) { let url = esmRun(versions, importPath); - return await import(/* vite-ignore */ url); + return await import(/* @vite-ignore */ url); }, /** * @param {Record} versions @@ -67,7 +67,7 @@ export const esmsh = { async import(versions, importPath) { let url = esmSh(versions, importPath); - return await import(/* vite-ignore */ url); + return await import(/* @vite-ignore */ url); }, /** * @param {Record} versions diff --git a/packages/repl-sdk/src/compilers/ember/macros.js b/packages/repl-sdk/src/compilers/ember/macros.js new file mode 100644 index 000000000..418c9e49a --- /dev/null +++ b/packages/repl-sdk/src/compilers/ember/macros.js @@ -0,0 +1,17 @@ +/** + * This is a replacement module for `@embroider/macros` which is a babel plugin that was never meant to be ran in the browser. + * + * This provides runtime implementations of all the macros' behaviors. + */ + +export function macroCondition(result) { + return result; +} + +export function dependencySatisfies() { + return true; +} + +export function isDevelopingApp() { + return true; +} diff --git a/packages/repl-sdk/src/compilers/glimmer-js.js b/packages/repl-sdk/src/compilers/glimmer-js.js index 6019c339d..904c7fc6f 100644 --- a/packages/repl-sdk/src/compilers/glimmer-js.js +++ b/packages/repl-sdk/src/compilers/glimmer-js.js @@ -12,10 +12,6 @@ export async function compiler(config = {} /*, api */) { templatePlugin, { default: templateCompiler }, { Preprocessor }, - { default: MacrosPlugin }, - , - { buildPlugin: makeMacrosGlimmerPlugin }, - { default: AdjustImports }, { default: DebugMacros }, ] = await esmsh.importAll(versions, [ /** @@ -39,15 +35,6 @@ export async function compiler(config = {} /*, api */) { * Converts gjs/gts to standard js/ts */ 'content-tag', - /** - * Build-time macros - * (partly because import.meta.env.DEV isn't standard - * partly because we needed more than what meta.env could offer) - */ - '@embroider/macros/src/babel/macros-babel-plugin.js', - '@embroider/macros/src/node.js', - '@embroider/macros/src/glimmer/ast-transform.js', - '@embroider/compat/src/babel-plugin-adjust-imports.js', /** * Older-style build macros * (before import.meta.env was even a thing) @@ -63,9 +50,6 @@ export async function compiler(config = {} /*, api */) { ]); async function transform(text) { - // eslint-disable-next-line - console.log(templateCompiler, templatePlugin); - return babel.transform(text, { filename: `dynamic-repl.js`, plugins: [ @@ -73,10 +57,7 @@ export async function compiler(config = {} /*, api */) { templatePlugin, { compiler: templateCompiler, - transforms: [ - makeMacrosGlimmerPlugin({ methodName: 'makeFirstTransform' }), - makeMacrosGlimmerPlugin({ methodName: 'makeSecondTransform' }), - ], + transforms: [], }, ], [ @@ -116,73 +97,6 @@ export async function compiler(config = {} /*, api */) { }, '@ember/application/deprecations stripping', ], - /** - * TODO: I may need a safer browser-time implementation - * of @embroider/macros - */ - [ - MacrosPlugin, - { - userConfigs: {}, - globalConfig: { - '@embroider/macros': { - isTesting: false, - }, - WarpDrive: { - debug: { - LOG_GRAPH: false, - LOG_IDENTIFIERS: false, - LOG_INSTANCE_CACHE: false, - LOG_MUTATIONS: false, - LOG_NOTIFICATIONS: false, - LOG_OPERATIONS: false, - LOG_PAYLOADS: false, - LOG_REQUESTS: false, - LOG_REQUEST_STATUS: false, - }, - polyfillUUID: false, - includeDataAdapter: true, - compatWith: null, - deprecations: { - DEPRECATE_CATCH_ALL: true, - DEPRECATE_COMPUTED_CHAINS: true, - DEPRECATE_EMBER_INFLECTOR: true, - DEPRECATE_LEGACY_IMPORTS: true, - DEPRECATE_MANY_ARRAY_DUPLICATES: true, - DEPRECATE_NON_STRICT_ID: true, - DEPRECATE_NON_STRICT_TYPES: true, - DEPRECATE_NON_UNIQUE_PAYLOADS: true, - DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: true, - DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: true, - ENABLE_LEGACY_SCHEMA_SERVICE: true, - }, - features: { - SAMPLE_FEATURE_FLAG: false, - }, - env: { - TESTING: true, - PRODUCTION: false, - DEBUG: true, - }, - }, - '@embroider/core': { - active: true, - }, - }, - owningPackageRoot: null, - isDevelopingPackageRoots: ['/home/nvp/Development/tmp/my-fancy-app'], - appPackageRoot: '/home/nvp/Development/tmp/my-fancy-app', - embroiderMacrosConfigMarker: true, - mode: 'run-time', - hideRequires: true, - }, - ], - [ - AdjustImports, - { - appRoot: '/home/nvp/Development/tmp/my-fancy-app', - }, - ], // [babel.availablePlugins['proposal-decorators'], { legacy: true }], // [babel.availablePlugins['proposal-class-properties']], ], @@ -216,18 +130,20 @@ export async function compiler(config = {} /*, api */) { return `https://esm.sh/*ember-source/dist/dependencies/${id}.js`; } - // if (id.startsWith('@embroider/macros')) { - // return `https://esm.sh/*@embroider/macros/src/addon/runtime.js`; - // } + console.log({ id }); + + if (id.startsWith('@embroider/macros')) { + return `repl-sdk/compilers/ember/macros.js`; + } }, compile: async (text) => { let preprocessed = preprocessor.process(text, 'dynamic-repl.js'); - let transformed = await transform({ babel, templatePlugin, templateCompiler }, preprocessed); + let transformed = await transform(preprocessed); let code = transformed.code; // eslint-disable-next-line - console.log(code); + console.log({ code }); return code; }, diff --git a/packages/repl-sdk/src/index.js b/packages/repl-sdk/src/index.js index 385150e48..175706c7b 100644 --- a/packages/repl-sdk/src/index.js +++ b/packages/repl-sdk/src/index.js @@ -41,6 +41,7 @@ export class Compiler { mapOverrides: true, // default false // Hook all module resolutions resolve: (id) => { + console.debug('resolving', id); if (id.startsWith('blob:')) return id; if (id.startsWith('https://')) return id; if (id.startsWith('.')) return id; diff --git a/packages/repl-sdk/tests-self/package.json b/packages/repl-sdk/tests-self/package.json index 586d9dec3..5134e6831 100644 --- a/packages/repl-sdk/tests-self/package.json +++ b/packages/repl-sdk/tests-self/package.json @@ -9,6 +9,7 @@ }, "author": "NullvoxPopuli", "devDependencies": { + "@babel/plugin-proposal-decorators": "^7.23.9", "@babel/standalone": "^7.24.5", "@nullvoxpopuli/eslint-configs": "^4.0.0", "@testing-library/dom": "^10.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 562c5896c..291787065 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1761,6 +1761,9 @@ importers: specifier: ^1.10.0 version: 1.10.0 devDependencies: + '@babel/plugin-proposal-decorators': + specifier: ^7.23.9 + version: 7.24.7(@babel/core@7.25.2) '@nullvoxpopuli/eslint-configs': specifier: ^4.0.0 version: 4.0.0(@babel/core@7.25.2)(@babel/eslint-parser@7.25.1(@babel/core@7.25.2)(eslint@8.57.0))(@babel/plugin-proposal-decorators@7.24.7(@babel/core@7.25.2))(@types/eslint@9.6.0)(@typescript-eslint/eslint-plugin@8.5.0(@typescript-eslint/parser@8.5.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(@typescript-eslint/parser@8.5.0(eslint@8.57.0)(typescript@5.5.4))(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint-plugin-ember@12.2.0(@babel/core@7.25.2)(@typescript-eslint/parser@8.5.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint-plugin-qunit@8.1.2(eslint@8.57.0))(eslint@8.57.0)(prettier@3.3.3)(typescript@5.5.4) @@ -1798,6 +1801,9 @@ importers: specifier: ^3.4.33 version: 3.4.33(typescript@5.5.4) devDependencies: + '@babel/plugin-proposal-decorators': + specifier: ^7.23.9 + version: 7.24.7(@babel/core@7.25.2) '@babel/standalone': specifier: ^7.24.5 version: 7.24.10