Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the internal Ember loader to use the standard Ember CLI loader #19390

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions broccoli/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require('path');
const Rollup = require('broccoli-rollup');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const Babel = require('broccoli-babel-transpiler');
const typescript = require('broccoli-typescript-compiler').default;
const BroccoliDebug = require('broccoli-debug');
const findLib = require('./find-lib');
Expand All @@ -18,7 +17,6 @@ const StringReplace = require('broccoli-string-replace');
const GlimmerTemplatePrecompiler = require('./glimmer-template-compiler');
const VERSION_PLACEHOLDER = /VERSION_STRING_PLACEHOLDER/g;
const canaryFeatures = require('./canary-features');
const injectNodeGlobals = require('./transforms/inject-node-globals');

const debugTree = BroccoliDebug.buildDebugCallback('ember-source');

Expand All @@ -44,7 +42,7 @@ module.exports.jquery = function _jquery() {
});
};

module.exports.internalLoader = function _internalLoader() {
module.exports.loader = function _loader() {
return new Funnel('packages/loader/lib', {
files: ['index.js'],
getDestinationPath() {
Expand Down Expand Up @@ -234,6 +232,7 @@ function glimmerTrees(entries) {
let trees = [];
let queue = Array.isArray(entries) ? entries.slice() : [entries];
let name;

while ((name = queue.pop()) !== undefined) {
if (seen.has(name)) {
continue;
Expand All @@ -255,14 +254,8 @@ function glimmerTrees(entries) {
queue.push(...dependencies);
}
}
return new Babel(new MergeTrees(trees), {
sourceMaps: true,
plugins: [
// ensures `@glimmer/compiler` requiring `crypto` works properly
// in both browser and node-land
injectNodeGlobals,
],
});

return new MergeTrees(trees);
}

module.exports.glimmerCompilerES = () => {
Expand Down
52 changes: 0 additions & 52 deletions broccoli/transforms/inject-node-globals.js

This file was deleted.

13 changes: 10 additions & 3 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Error.stackTraceLimit = Infinity;
const {
routerES,
jquery,
internalLoader,
loader,
qunit,
handlebarsES,
rsvpES,
Expand Down Expand Up @@ -246,7 +246,14 @@ function templateCompilerBundle(emberPackages, transpileTree) {
}

function testHarness() {
return new MergeTrees([emptyTestem(), testPolyfills(), testIndexHTML(), qunit(), jquery()]);
return new MergeTrees([
emptyTestem(),
testPolyfills(),
testIndexHTML(),
loader(),
qunit(),
jquery(),
]);
}

function emptyTestem() {
Expand All @@ -262,5 +269,5 @@ function templateCompilerDependencies() {
}

function emberHeaderFiles() {
return new MergeTrees([emberLicense(), internalLoader()]);
return new MergeTrees([emberLicense(), loader()]);
}
10 changes: 2 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,12 @@ module.exports = {
return new MergeTrees([
concatBundle(emberFiles, {
outputFile: 'ember.js',
footer: "require('ember');",
footer: "require('@ember/-internals/bootstrap');",
}),

concatBundle(emberTestingFiles, {
outputFile: 'ember-testing.js',
footer: `
var testing = require('ember-testing');
Ember.Test = testing.Test;
Ember.Test.Adapter = testing.Adapter;
Ember.Test.QUnitAdapter = testing.QUnitAdapter;
Ember.setupForTesting = testing.setupForTesting;
pzuraq marked this conversation as resolved.
Show resolved Hide resolved
`,
footer: "require('ember-testing');",
}),
]);
},
Expand Down
31 changes: 31 additions & 0 deletions packages/@ember/-internals/bootstrap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import require from 'require';
import { context } from '@ember/-internals/environment';

(function () {
let Ember;

function defineEmber(key) {
Object.defineProperty(context.exports, key, {
enumerable: true,
configurable: true,
get() {
if (!Ember) {
Ember = require('ember').default;
}

return Ember;
},
});
}

// Bootstrap the global
defineEmber('Ember');
defineEmber('Em');
pzuraq marked this conversation as resolved.
Show resolved Hide resolved

// Bootstrap Node module
// eslint-disable-next-line no-undef
if (typeof module === 'object' && typeof module.require === 'function') {
// eslint-disable-next-line no-undef
module.exports = Ember = require('ember').default;
}
})();
2 changes: 1 addition & 1 deletion packages/@ember/-internals/environment/lib/global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals global, window, self, mainContext */
/* globals global, window, self */
declare const mainContext: object | undefined;

// from lodash to catch fake globals
Expand Down
34 changes: 19 additions & 15 deletions packages/ember-template-compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { context, ENV } from '@ember/-internals/environment';
import { ENV } from '@ember/-internals/environment';
import { FEATURES } from '@ember/canary-features';
import VERSION from 'ember/version';
import require from 'require';

export const _Ember =
(typeof (context.imports as any).Ember === 'object' && (context.imports as any).Ember) || {};
declare global {
interface NodeRequire {
has(name: string): boolean;
}

// private API used by ember-cli-htmlbars to setup ENV and FEATURES
if (!_Ember.ENV) {
_Ember.ENV = ENV;
}
if (!_Ember.FEATURES) {
_Ember.FEATURES = FEATURES;
}
if (!_Ember.VERSION) {
_Ember.VERSION = VERSION;
function define(path: string, deps: string[], module: () => void): void;
}

// used for adding Ember.Handlebars.compile for backwards compat
import setupGlobal from './lib/compat';
setupGlobal(_Ember);
export let _Ember: unknown;

try {
// tslint:disable-next-line: no-require-imports
_Ember = require('ember');
} catch (e) {
_Ember = {
ENV,
FEATURES,
VERSION,
};
}

export { default as precompile } from './lib/system/precompile';
export { default as compile } from './lib/system/compile';
Expand Down
19 changes: 0 additions & 19 deletions packages/ember-template-compiler/lib/compat.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
declare module 'ember' {
declare const Ember: any;

export default Ember;
}

declare module 'require' {
export function has(path: string): boolean;
export default function require(path: string): any;
Expand Down
Loading