Skip to content

Commit

Permalink
Proxy the barrel module and re-work type publishing to lie about what
Browse files Browse the repository at this point in the history
we've done
  • Loading branch information
NullVoxPopuli committed May 2, 2024
1 parent 4493832 commit 70d0ca8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 33 deletions.
13 changes: 11 additions & 2 deletions packages/ember-testing/tests/reexports_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Ember from 'ember';
import { confirmExport } from 'internal-test-helpers';
import { confirmExport, testUnless } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import * as emberTesting from 'ember-testing';
import { DEPRECATIONS } from '@ember/-internals/deprecations';

class ReexportsTestCase extends AbstractTestCase {}

Expand All @@ -19,7 +20,15 @@ class ReexportsTestCase extends AbstractTestCase {}
exportName = path;
}

ReexportsTestCase.prototype[`@test Ember.${path} exports correctly`] = function (assert) {
ReexportsTestCase.prototype[
`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path).isRemoved
)} Ember.${path} exports correctly`
] = function (assert) {
expectDeprecation(
/'ember' barrel file is deprecated/,
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path).isEnabled
);
confirmExport(Ember, assert, path, moduleId, exportName, emberTesting);
};
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ember/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default new Proxy(doNotUseThis, {

return Reflect.get(target, key, receiver);
},
});
}) as typeof doNotUseThis;
68 changes: 42 additions & 26 deletions packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
import Ember from '../index';
import { FEATURES } from '@ember/canary-features';
import { AbstractTestCase, confirmExport, moduleFor } from 'internal-test-helpers';
import {
AbstractTestCase,
confirmExport,
expectDeprecation,
moduleFor,
testUnless,
} from 'internal-test-helpers';
import { DEBUG } from '@glimmer/env';

moduleFor(
'ember reexports',
class extends AbstractTestCase {
[`@test Ember exports correctly`](assert) {
allExports.forEach((reexport) => {
let [path, moduleId, exportName, mod] = reexport;
class ReExportTests extends AbstractTestCase {
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_EMBER('---any---').isRemoved
)} Ember exports correctly`](assert) {
allExports.forEach((reexport) => {
let [path, moduleId, exportName, mod] = reexport;

// default path === exportName if none present
if (!exportName) {
exportName = path;
}
// default path === exportName if none present
if (!exportName) {
exportName = path;
}

confirmExport(Ember, assert, path, moduleId, exportName, mod);
});
}
confirmExport(Ember, assert, path, moduleId, exportName, mod);
});
}

'@test Ember.FEATURES is exported'(assert) {
if (Object.keys(FEATURES).length === 0) {
assert.expect(0);
}
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_EMBER('FEATURES').isRemoved
)} Ember.FEATURES is exported`](assert) {
if (Object.keys(FEATURES).length === 0) {
assert.expect(0);
}

for (let feature in FEATURES) {
assert.equal(
Ember.FEATURES[feature],
FEATURES[feature],
'Ember.FEATURES contains ${feature} with correct value'
);
}
for (let feature in FEATURES) {
expectDeprecation(
() => {
assert.equal(
Ember.FEATURES[feature],
FEATURES[feature],
'Ember.FEATURES contains ${feature} with correct value'
);
},
/importing FEATURES from the 'ember' barrel file is deprecated/,
DEPRECATIONS.DEPRECATE_IMPORT_EMBER('FEATURES').isEnabled
);
}
}
);
}

moduleFor('ember reexports', ReExportTests);

import * as test0 from '@ember/application';
import * as test1 from '@ember/application/instance';
Expand Down Expand Up @@ -96,6 +111,7 @@ import * as test57 from '@ember/-internals/runtime';
import * as test58 from '@ember/-internals/routing';
import * as test59 from 'backburner.js';
import * as test60 from 'rsvp';
import { DEPRECATIONS } from '@ember/-internals/deprecations';

let allExports = [
['Application', '@ember/application', 'default', test0],
Expand Down
10 changes: 6 additions & 4 deletions packages/internal-test-helpers/lib/ember-dev/setup-qunit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getOnerror, setOnerror } from '@ember/-internals/error-handling';

import { getDebugFunction, setDebugFunction } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -51,11 +53,11 @@ export default function setupQUnit() {
message?: string
) {
let error: unknown;
let prevOnError = window.onerror;
let prevOnError = getOnerror();

window.onerror = (e: string | Event) => {
setOnerror((e: Error) => {
error = e;
};
});

try {
await promise;
Expand All @@ -73,7 +75,7 @@ export default function setupQUnit() {
message
);

window.onerror = prevOnError;
setOnerror(prevOnError);
};

QUnit.assert.throwsAssertion = function (
Expand Down
7 changes: 7 additions & 0 deletions types/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ async function main() {

doOrDie(() => spawnSync('pnpm', ['tsc', '--project', 'tsconfig/publish-types.json']));

// We're deprecating the barrel file, so this is temporary. The Ember global is a namespace,
// and namespaces can't be both exported and used as a type with the same semantics and
// capabilities as when defined in the original file -- so we're going to LIE and
// pretend that the barrel file is the index file (which is the same behavior as
// prior to the deprecation)
await fs.cp(path.join(TYPES_DIR, 'ember/barrel.d.ts'), path.join(TYPES_DIR, 'ember/index.d.ts'));

let remappedLocationExcludes = await doOrDie(copyHandwrittenDefinitions);
let sideEffectExcludes = await doOrDie(copyRemappedLocationModules);

Expand Down

0 comments on commit 70d0ca8

Please sign in to comment.