Skip to content

Solve 'The Mystery of the Missing app.js 🕵️‍♂️' #89

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 1 commit into from
Jan 24, 2018
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
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs');
const path = require('path');
const SilentError = require('silent-error');
const TsPreprocessor = require('./lib/typescript-preprocessor');
const ServeTS = require('./lib/serve-ts');
const buildServeCommand = require('./lib/serve-ts');
const funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const mkdirp = require('mkdirp');
Expand All @@ -28,7 +28,7 @@ module.exports = {

includedCommands() {
return {
'serve-ts': ServeTS,
'serve-ts': buildServeCommand(this.project),
};
},

Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
return mergeTrees([tree, ...additionalTrees]);
}

const roots = ['.', ...includes, ...this._inRepoAddons()].map(root => path.join(root, 'app'));
const roots = ['.', ...includes, ...this._inRepoAddons()].map(root => path.join(root, 'app/'));

// funnel will fail if the directory doesn't exist
roots.forEach(root => {
Expand All @@ -84,7 +84,7 @@ module.exports = {
const prefix = roots.find(root => relativePath.startsWith(root));
if (prefix) {
// strip any app/ or lib/in-repo-addon/app/ prefix
return relativePath.substr(prefix.length + 1);
return relativePath.substr(prefix.length);
}

return relativePath;
Expand Down
178 changes: 89 additions & 89 deletions lib/serve-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,100 @@ const child_process = require('child_process');
const fs = require('fs');

const rimraf = require('rimraf');

const root = process.env.DEVELOPING ? `${process.cwd()}/node_modules/` : '';
const Serve = require(`${root}ember-cli/lib/commands/serve`);
const Builder = require(`${root}ember-cli/lib/models/builder`);
const Watcher = require(`${root}ember-cli/lib/models/watcher`);

const OUT_DIR = '.e-c-ts';

/**
* Exclude .ts files from being watched
*/
function filterTS(name) {
if (name.startsWith('.')) {
// these files are filtered by default
return false;
}

// typescript sources are watched by `tsc --watch` instead
return !name.endsWith('.ts');
}
module.exports = (project) => {
const Serve = project.require('ember-cli/lib/commands/serve');
const Builder = project.require('ember-cli/lib/models/builder');
const Watcher = project.require('ember-cli/lib/models/watcher');

/**
* Exclude .ts files from being watched
*/
function filterTS(name) {
if (name.startsWith('.')) {
// these files are filtered by default
return false;
}

class WatcherNonTS extends Watcher {
buildOptions() {
let options = super.buildOptions();
options.filter = filterTS;
return options;
// typescript sources are watched by `tsc --watch` instead
return !name.endsWith('.ts');
}
}

module.exports = Serve.extend({
name: 'serve-ts',
aliases: ['st'],
works: 'insideProject',
description:
'Serve the app/addon with the TypeScript compiler in incremental mode. (Much faster!)',

run(options) {
this.project._isRunningServeTS = true;

const builder = new Builder({
ui: this.ui,
outputPath: options.outputPath,
project: this.project,
environment: options.environment,
});

// We're ignoring this because TS doesn't have types for `Watcher`; this is
// fine, though.
// @ts-ignore
const watcher = new WatcherNonTS({
ui: this.ui,
builder,
analytics: this.analytics,
options,
serving: true,
});

options._builder = builder;
options._watcher = watcher;
class WatcherNonTS extends Watcher {
buildOptions() {
let options = super.buildOptions();
options.filter = filterTS;
return options;
}
}

// TODO: typescript might be installed globally?
// argument sequence here is meaningful; don't apply prettier.
// prettier-ignore
this.tsc = child_process.fork(
'node_modules/typescript/bin/tsc',
[
'--watch',
'--outDir', OUT_DIR,
'--allowJs', 'false',
'--noEmit', 'false',
'--sourceMap', 'false', // TODO: enable if sourcemaps=true
],
{
silent: true,
execArgv: [],
return Serve.extend({
name: 'serve-ts',
aliases: ['st'],
works: 'insideProject',
description:
'Serve the app/addon with the TypeScript compiler in incremental mode. (Much faster!)',

run(options) {
this.project._isRunningServeTS = true;

const builder = new Builder({
ui: this.ui,
outputPath: options.outputPath,
project: this.project,
environment: options.environment,
});

// We're ignoring this because TS doesn't have types for `Watcher`; this is
// fine, though.
// @ts-ignore
const watcher = new WatcherNonTS({
ui: this.ui,
builder,
analytics: this.analytics,
options,
serving: true,
});

options._builder = builder;
options._watcher = watcher;

// TODO: typescript might be installed globally?
// argument sequence here is meaningful; don't apply prettier.
// prettier-ignore
this.tsc = child_process.fork(
'node_modules/typescript/bin/tsc',
[
'--watch',
'--outDir', OUT_DIR,
'--allowJs', 'false',
'--noEmit', 'false',
'--sourceMap', 'false', // TODO: enable if sourcemaps=true
],
{
silent: true,
execArgv: [],
}
);
this.tsc.stdout.on('data', data => {
this.ui.write(data);
});
this.tsc.stderr.on('data', data => {
this.ui.writeError(data);
});

return Serve.prototype.run.call(this, options);
},

onInterrupt() {
if (this.tsc) {
this.tsc.kill();
}
);
this.tsc.stdout.on('data', data => {
this.ui.write(data);
});
this.tsc.stderr.on('data', data => {
this.ui.writeError(data);
});

return Serve.prototype.run.call(this, options);
},

onInterrupt() {
if (this.tsc) {
this.tsc.kill();
}

if (fs.existsSync(OUT_DIR)) {
rimraf.sync(OUT_DIR);
}
},
});
if (fs.existsSync(OUT_DIR)) {
rimraf.sync(OUT_DIR);
}
},
});
};