From 5ae9d0f48d9e892d6b67009729f305914a0aa7dd Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 3 Dec 2024 13:01:39 +0100 Subject: [PATCH] fix loader --- doc-app/app/app.ts | 1 + doc-app/app/ember-fetch.js | 8 -- doc-app/app/loader.ts | 68 +++++++++ doc-app/app/setup-inspector-support.ts | 21 +++ doc-app/index.html | 6 - doc-app/package.json | 1 + doc-app/vite.config.mjs | 20 +-- package.json | 1 + pnpm-lock.yaml | 186 +++---------------------- 9 files changed, 111 insertions(+), 201 deletions(-) delete mode 100644 doc-app/app/ember-fetch.js create mode 100644 doc-app/app/loader.ts create mode 100644 doc-app/app/setup-inspector-support.ts diff --git a/doc-app/app/app.ts b/doc-app/app/app.ts index 2b759c68..669bf96e 100644 --- a/doc-app/app/app.ts +++ b/doc-app/app/app.ts @@ -1,3 +1,4 @@ +import './setup-inspector-support.ts'; import Application from '@ember/application'; import compatModules from '@embroider/virtual/compat-modules'; import Resolver from 'ember-resolver'; diff --git a/doc-app/app/ember-fetch.js b/doc-app/app/ember-fetch.js deleted file mode 100644 index 7c75fc4c..00000000 --- a/doc-app/app/ember-fetch.js +++ /dev/null @@ -1,8 +0,0 @@ -import Ember from 'ember'; -import rsvp from 'rsvp'; - -window.define('ember', () => Ember); -window.define('rsvp', () => rsvp); - -export default window.require('fetch').default; -export const setupFastboot = window.require('fetch').setupFastboot; diff --git a/doc-app/app/loader.ts b/doc-app/app/loader.ts new file mode 100644 index 00000000..eb9286e3 --- /dev/null +++ b/doc-app/app/loader.ts @@ -0,0 +1,68 @@ +/* eslint-disable */ +// @ts-nocheck + +const windowDef = window.define; +let define = window.define && ((...args) => windowDef(...args)), + exports = undefined, + module = undefined, + require = window.requireModule, + requireModule = window.requireModule; + +/* eslint-enable */ +if (typeof define !== 'function' || typeof requireModule !== 'function') { + (function () { + let registry = {}, + seen = {}; + + define = function (name, deps, callback) { + if (arguments.length < 3) { + callback = deps; + deps = []; + } + + registry[name] = { deps, callback }; + }; + + requireModule = function (name) { + if (seen[name]) { + return seen[name]; + } + + let mod = registry[name]; + + if (!mod) { + throw new Error(`Module: '${name}' not found.`); + } + + seen[name] = {}; + + let deps = mod.deps; + let callback = mod.callback; + let reified = []; + let exports; + + for (let i = 0, l = deps.length; i < l; i++) { + if (deps[i] === 'exports') { + reified.push((exports = {})); + } else { + reified.push(requireModule(deps[i])); + } + } + + let value = callback.apply(this, reified); + + seen[name] = exports || value; + + return seen[name]; + }; + + requireModule.has = function (name) { + return !!registry[name]; + } + + define.registry = registry; + define.seen = seen; + })(); +} + +export { define, require, requireModule }; diff --git a/doc-app/app/setup-inspector-support.ts b/doc-app/app/setup-inspector-support.ts new file mode 100644 index 00000000..45ae4498 --- /dev/null +++ b/doc-app/app/setup-inspector-support.ts @@ -0,0 +1,21 @@ +import Ember from 'ember'; +import * as runtime from '@glimmer/runtime'; +import * as tracking from '@glimmer/tracking'; +import * as validator from '@glimmer/validator'; +import { RSVP } from '@ember/-internals/runtime'; + +import config from './config/environment'; +import * as loader from './loader'; + +window.define = loader.define; +window.require = loader.require; +window.requireModule = loader.requireModule; + +window.define('@glimmer/tracking', () => tracking); +window.define('@glimmer/runtime', () => runtime); +window.define('@glimmer/validator', () => validator); +window.define('rsvp', () => RSVP); +window.define('ember', () => ({ default: Ember })); +window.define('doc-app/config/environment', () => ({ + default: config, +})); diff --git a/doc-app/index.html b/doc-app/index.html index 8b5614ba..cc0cbcf4 100644 --- a/doc-app/index.html +++ b/doc-app/index.html @@ -16,12 +16,6 @@ {{content-for "body"}} - -