Skip to content

(un)feat: remove MU support from the default blueprint #826

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

Merged
merged 2 commits into from
Aug 28, 2019
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

### 💥 Breaking

- Removes support in the default blueprint for initializing new Module Unification projects, in line with [MU's removal][MU] from Ember's roadmap in favor of other directions. Existing MU projects should continue to build and typecheck according to the local `tsconfig.json`. ([#826](https://github.com/typed-ember/ember-cli-typescript/pull/826))

[MU]: https://blog.emberjs.com/2019/03/11/update-on-module-unification-and-octane.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lol, I'm always asking for changelog in PRs at work, but didn't think to require that here 😉

## [2.0.2] - 2019-07-05

- Lock `@babel/plugin-transform-typescript` version pending a fix to [babel/babel#10162](https://github.com/babel/babel/issues/10162) ([#751](https://github.com/typed-ember/ember-cli-typescript/pull/751))
Expand Down
54 changes: 15 additions & 39 deletions ts/blueprints/ember-cli-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export {};`;

/**
* @param {string} projectName
* @param {'classic' | 'pods' | 'mu'} layout
* @param {'classic' | 'pods'} layout
*/
function buildTemplateDeclarations(projectName, layout) {
const comment = '// Types for compiled templates';
Expand All @@ -30,9 +30,6 @@ declare module '${projectName}/templates/*' { ${moduleBody}}`;
case 'pods':
return `${comment}
declare module '${projectName}/*/template' { ${moduleBody}}`;
case 'mu':
return `${comment}
declare module '${projectName}/ui/components/*/template' { ${moduleBody}}`;
default:
throw new Error(`Unexpecte project layout type: "${layout}"`);
}
Expand All @@ -57,13 +54,12 @@ module.exports = {
let inRepoAddons = (this.project.pkg['ember-addon'] || {}).paths || [];
let hasMirage = 'ember-cli-mirage' in (this.project.pkg.devDependencies || {});
let isAddon = this.project.isEmberCLIAddon();
let isMU = this._detectMU();
let includes = isMU ? ['src'] : ['app', isAddon && 'addon'].filter(Boolean);
let includes = ['app', isAddon && 'addon'].filter(Boolean);
const isPods = this.pod;

includes = includes.concat(['tests', 'types']).concat(inRepoAddons);

if (isAddon && !isMU) {
if (isAddon) {
includes.push('test-support', 'addon-test-support');
}
// Mirage is already covered for addons because it's under `tests/`
Expand All @@ -88,26 +84,17 @@ module.exports = {
paths[`${appName}/mirage/*`] = [`${isAddon ? 'tests/dummy/' : ''}mirage/*`];
}

if (isMU) {
if (isAddon) {
paths[`${appName}/src/*`] = ['tests/dummy/src/*'];
paths[`${dasherizedName}/src/*`] = ['src/*'];
} else {
paths[`${appName}/src/*`] = ['src/*'];
}
if (isAddon) {
paths[`${appName}/*`] = ['tests/dummy/app/*', 'app/*'];
} else {
if (isAddon) {
paths[`${appName}/*`] = ['tests/dummy/app/*', 'app/*'];
} else {
paths[`${appName}/*`] = ['app/*'];
}

if (isAddon) {
paths[dasherizedName] = ['addon'];
paths[`${dasherizedName}/*`] = ['addon/*'];
paths[`${dasherizedName}/test-support`] = ['addon-test-support'];
paths[`${dasherizedName}/test-support/*`] = ['addon-test-support/*'];
}
paths[`${appName}/*`] = ['app/*'];
}

if (isAddon) {
paths[dasherizedName] = ['addon'];
paths[`${dasherizedName}/*`] = ['addon/*'];
paths[`${dasherizedName}/test-support`] = ['addon-test-support'];
paths[`${dasherizedName}/test-support/*`] = ['addon-test-support/*'];
}

for (let addon of inRepoAddons) {
Expand All @@ -124,31 +111,24 @@ module.exports = {
return useAppDeclarations ? APP_DECLARATIONS : '';
},
globalDeclarations: dasherizedName => {
/** @type {'classic' | 'pods' | 'mu'} */
/** @type {'classic' | 'pods'} */
let projectLayout;
if (isPods) projectLayout = 'pods';
else if (isMU) projectLayout = 'mu';
else projectLayout = 'classic';
return buildTemplateDeclarations(dasherizedName, projectLayout);
},
};
},

fileMapTokens(/*options*/) {
let isMU = this._detectMU();

// Return custom tokens to be replaced in your files.
return {
__app_name__(options) {
return options.inAddon ? 'dummy' : options.dasherizedModuleName;
},

__config_root__(options) {
if (isMU) {
return options.inAddon ? 'tests/dummy' : '.';
} else {
return options.inAddon ? 'tests/dummy/app' : 'app';
}
return options.inAddon ? 'tests/dummy/app' : 'app';
},
};
},
Expand Down Expand Up @@ -205,10 +185,6 @@ module.exports = {
return files;
},

_detectMU() {
return this.project.isModuleUnification && this.project.isModuleUnification();
},

_transformAddonPackage() {
const pkgPath = `${this.project.root}/package.json`;

Expand Down
118 changes: 0 additions & 118 deletions ts/tests/blueprints/ember-cli-typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path';
import helpers from 'ember-cli-blueprint-test-helpers/helpers';
import chaiHelpers from 'ember-cli-blueprint-test-helpers/chai';
import Blueprint from 'ember-cli/lib/models/blueprint';
import Project from 'ember-cli/lib/models/project';

import ects from '../../blueprints/ember-cli-typescript/index';

Expand Down Expand Up @@ -170,123 +169,6 @@ describe('Acceptance: ember-cli-typescript generator', function() {
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
});

describe('module unification', () => {
const originalIsMU = Project.prototype.isModuleUnification;

beforeEach(function() {
Project.prototype.isModuleUnification = () => true;
});

afterEach(function() {
Project.prototype.isModuleUnification = originalIsMU;
});

it('basic app', async () => {
const args = ['ember-cli-typescript'];

await helpers.emberNew();
await helpers.emberGenerate(args);

const pkg = file('package.json');
expect(pkg).to.exist;

const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.scripts.prepublishOnly).to.be.undefined;
expect(pkgJson.scripts.postpublish).to.be.undefined;
expect(pkgJson.dependencies).to.not.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.include.all.keys('ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-qunit', '@types/qunit');
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-mocha', '@types/mocha');

const tsconfig = file('tsconfig.json');
expect(tsconfig).to.exist;

const tsconfigJson = JSON.parse(tsconfig.content);
expect(tsconfigJson.compilerOptions.paths).to.deep.equal({
'my-app/tests/*': ['tests/*'],
'my-app/src/*': ['src/*'],
'*': ['types/*'],
});

expect(tsconfigJson.compilerOptions.inlineSourceMap).to.equal(true);
expect(tsconfigJson.compilerOptions.inlineSources).to.equal(true);

expect(tsconfigJson.include).to.deep.equal(['src/**/*', 'tests/**/*', 'types/**/*']);

const projectTypes = file('types/my-app/index.d.ts');
expect(projectTypes).to.exist;
expect(projectTypes).to.include(ects.APP_DECLARATIONS);

const globalTypes = file('types/global.d.ts');
expect(globalTypes).to.exist;
expect(globalTypes).to.include("declare module 'my-app/ui/components/*/template'").to
.include(` import { TemplateFactory } from 'htmlbars-inline-precompile';
const tmpl: TemplateFactory;
export default tmpl;
`);

const environmentTypes = file('config/environment.d.ts');
expect(environmentTypes).to.exist;

const emberDataCatchallTypes = file('types/ember-data/types/registries/model.d.ts');
expect(emberDataCatchallTypes).to.exist;
});

it('basic addon', async () => {
const args = ['ember-cli-typescript'];

await helpers.emberNew({ target: 'addon' });
await helpers.emberGenerate(args);
const pkg = file('package.json');
expect(pkg).to.exist;

const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.scripts.prepublishOnly).to.equal('ember ts:precompile');
expect(pkgJson.scripts.postpublish).to.equal('ember ts:clean');
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-data');
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-qunit', '@types/qunit');
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-mocha', '@types/mocha');

const tsconfig = file('tsconfig.json');
expect(tsconfig).to.exist;

const tsconfigJson = JSON.parse(tsconfig.content);
expect(tsconfigJson.compilerOptions.paths).to.deep.equal({
'dummy/tests/*': ['tests/*'],
'dummy/src/*': ['tests/dummy/src/*'],
'my-addon/src/*': ['src/*'],
'*': ['types/*'],
});

expect(tsconfigJson.include).to.deep.equal(['src/**/*', 'tests/**/*', 'types/**/*']);

const projectTypes = file('types/dummy/index.d.ts');
expect(projectTypes).to.exist;
expect(projectTypes).not.to.include(ects.APP_DECLARATIONS);

const globalTypes = file('types/global.d.ts');
expect(globalTypes).to.exist;
expect(globalTypes).to.include("declare module 'my-addon/ui/components/*/template'").to
.include(` import { TemplateFactory } from 'htmlbars-inline-precompile';
const tmpl: TemplateFactory;
export default tmpl;
`);

const environmentTypes = file('tests/dummy/config/environment.d.ts');
expect(environmentTypes).to.exist;

const emberDataCatchallTypes = file('types/ember-data/types/registries/model.d.ts');
expect(emberDataCatchallTypes).not.to.exist;
});
});

it('in-repo addons', async () => {
const args = ['ember-cli-typescript'];

Expand Down
4 changes: 2 additions & 2 deletions ts/tests/commands/precompile-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('Acceptance: ts:precompile command', function() {
expect(declaration).not.to.exist;
});

describe('module unification', function() {
it('generates .d.ts files from the src tree', async () => {
describe('custom project layout', function() {
it('generates .d.ts files from the specified source tree', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fs.ensureDirSync('src');
fs.writeFileSync('src/test-file.ts', `export const testString: string = 'hello';`);

Expand Down
1 change: 0 additions & 1 deletion ts/types/ember-cli/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,5 @@ declare module 'ember-cli/lib/models/project' {
name(): string;
isEmberCLIAddon(): boolean;
require(module: string): unknown;
isModuleUnification(): boolean;
}
}
29 changes: 21 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@
"inlineSources": true,
"baseUrl": ".",
"paths": {
"dummy/tests/*": ["tests/*", "tests/dummy/lib/in-repo-a/test-support/*"],
"dummy/src/*": ["tests/dummy/src/*"],
"dummy/*": ["tests/dummy/app/*", "tests/dummy/lib/in-repo-a/app/*", "tests/dummy/lib/in-repo-b/app/*"],
"in-repo-a/*": ["tests/dummy/lib/in-repo-a/addon/*"],
"in-repo-a/test-support": ["tests/dummy/lib/in-repo-a/addon-test-support/"],
"in-repo-a/test-support/*": ["tests/dummy/lib/in-repo-a/addon-test-support/*"],
"in-repo-b/*": ["tests/dummy/lib/in-repo-b/addon/*"],
"in-repo-c/src/*": ["tests/dummy/lib/in-repo-c/src/*"]
"dummy/tests/*": [
"tests/*",
"tests/dummy/lib/in-repo-a/test-support/*"
],
"dummy/*": [
"tests/dummy/app/*",
"tests/dummy/lib/in-repo-a/app/*",
"tests/dummy/lib/in-repo-b/app/*"
],
"in-repo-a/*": [
"tests/dummy/lib/in-repo-a/addon/*"
],
"in-repo-a/test-support": [
"tests/dummy/lib/in-repo-a/addon-test-support/"
],
"in-repo-a/test-support/*": [
"tests/dummy/lib/in-repo-a/addon-test-support/*"
],
"in-repo-b/*": [
"tests/dummy/lib/in-repo-b/addon/*"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

}
},
"include": [
Expand Down