Skip to content

Commit

Permalink
fix loader
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Dec 3, 2024
1 parent f5eec6d commit 5ae9d0f
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 201 deletions.
1 change: 1 addition & 0 deletions doc-app/app/app.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 0 additions & 8 deletions doc-app/app/ember-fetch.js

This file was deleted.

68 changes: 68 additions & 0 deletions doc-app/app/loader.ts
Original file line number Diff line number Diff line change
@@ -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 };
21 changes: 21 additions & 0 deletions doc-app/app/setup-inspector-support.ts
Original file line number Diff line number Diff line change
@@ -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,
}));
6 changes: 0 additions & 6 deletions doc-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
<body>
{{content-for "body"}}

<script type='module'>
import * as loader from 'loader.js';
globalThis.define = loader.define;
globalThis.require = loader.require;
</script>

<script src="%BASE_URL%@embroider/virtual/vendor.js"></script>
<script type="module">
import Application from './app/app';
Expand Down
1 change: 1 addition & 0 deletions doc-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"ember-truth-helpers": "^4.0.3",
"ember-try": "^3.0.0",
"ember-vite-hmr": "^1.8.3",
"ember-fetch": "^8.1.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-ember": "^12.1.1",
Expand Down
20 changes: 1 addition & 19 deletions doc-app/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ const extensions = [
'.json',
];

let aliasPlugin = {
name: 'env',
setup(build) {
// Intercept import paths called "env" so esbuild doesn't attempt
// to map them to a file system location. Tag them with the "env-ns"
// namespace to reserve them for this plugin.
build.onResolve({ filter: /^fetch$/ }, (args) => ({
path: resolve('./app/ember-fetch.js'),
}));
},
};

let docsUrl = process.env.ADDON_DOCS_VERSION_PATH;
if (docsUrl && !docsUrl.endsWith('/')) {
docsUrl += '/';
Expand Down Expand Up @@ -95,13 +83,7 @@ export default defineConfig(({ mode }) => {
scss: sassOptions,
},
},
optimizeDeps: {
...optimizeDeps(),
esbuildOptions: {
...optimizeDeps().esbuildOptions,
plugins: [aliasPlugin, ...optimizeDeps().esbuildOptions.plugins],
},
},
optimizeDeps: optimizeDeps(),
server: {
port: 4200,
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"pnpm": {
"overrides": {
"ember-fetch": "https://codeload.github.com/NullVoxPopuli/ember-fetch/tar.gz/v2-addon",
"@types/ember": "../_EXCLUDED",
"ember-composable-helpers": "../_EXCLUDED",
"babel-plugin-ember-template-compilation": "^2.2.5",
Expand Down
Loading

0 comments on commit 5ae9d0f

Please sign in to comment.