Skip to content

Commit

Permalink
recognises and handles deleted entry points, fix multi reload action
Browse files Browse the repository at this point in the history
  • Loading branch information
kommander committed Jul 22, 2017
1 parent da4712c commit 31ea385
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index sdf sdf
40 changes: 33 additions & 7 deletions lib/aden.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ function applyDevConfig(pages, webpackConfigs) {
/\.dist/,
])));

const state = {
needReload: false,
};

webpackConfigs.forEach((config) => config.plugins.push({
apply: (compiler) => {
const state = {
needReload: false,
};

compiler.plugin('compilation', (compilation) => {
// force page reload when html-webpack-plugin template changes
// -> https://github.com/vuejs-templates/webpack/blob/master/template/build/dev-server.js#L37-L43
Expand All @@ -59,15 +59,19 @@ function applyDevConfig(pages, webpackConfigs) {
cb();
});
});
},
}));

compiler.plugin('done', () => {
frontendConfig.plugins.push({
apply: (compiler) => {
compiler.plugin('done', () => {
if (state.needReload) {
this.devHotMiddleware.publish({ action: 'reload' });
state.needReload = false;
}
});
},
}));
});
}

function devRebuild(pages) {
Expand Down Expand Up @@ -194,11 +198,33 @@ function selectPagesForReparse(addedFiles, addedDirs, removedFiles, removedDirs)

const pagesToParse = rootDirs.map((dir) => this.registerPage(dir));

const cleanups = pagesToParse
.filter((page) => page.parsed)
.map((page) => this.cleanPageOutput(page))
;

if (pagesToParse.length > 0) {
this.log.info(`Selected ${pagesToParse.map((page) => page.path.resolved)} for reparse`);
}

return pagesToParse;
return Promise.all(cleanups)
.then(() => {
return pagesToParse
.map((page) => {
page.keys.forEach((key) => {
if (key.resolved && removedFiles.includes(key.resolved)) {
Object.assign(key, {
value: null,
dist: null,
resolved: null,
distFileName: null,
cache: null,
});
}
});
return page;
});
});
});
}

Expand Down
27 changes: 17 additions & 10 deletions lib/aden.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,17 +567,8 @@ function inheritKeys(page, parentPage) {
return page;
}

function removePage(page) {
this.log.info(`Removing page ${page.relativePath || page.name}`);

function cleanPageOutput(page) {
return Promise.resolve()
.then(() => {
const childRemovals = page.children.map((child) =>
this.removePage(child)
);

return Promise.all(childRemovals);
})
.then(() => {
const distPublicPath = path.resolve(
this.settings.dist,
Expand All @@ -598,6 +589,21 @@ function removePage(page) {
rimraf(distDynamicPath, (err) => (err ? reject(err) : resolve()))
});
})
.then(() => page);
}

function removePage(page) {
this.log.info(`Removing page ${page.relativePath || page.name}`);

return Promise.resolve()
// .then(() => {
// const childRemovals = page.children.map((child) =>
// this.removePage(child)
// );

// return Promise.all(childRemovals);
// })
.then(() => this.cleanPageOutput(page))
.then(() => {
delete this.pagesById[page.id];
this.pages.splice(this.pages.indexOf(page), 1);
Expand All @@ -611,6 +617,7 @@ function removePage(page) {
}

module.exports = {
cleanPageOutput,
parsePage,
flattenPages,
applyFileConfig,
Expand Down
Empty file added test/data/devunlink2/.server
Empty file.
1 change: 1 addition & 0 deletions test/data/devunlink2/sub/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
about to be deleted
49 changes: 49 additions & 0 deletions test/integration/dev.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,55 @@ describe('dev', () => {
});
});

she('recognises and handles deleted entry points', (done) => {
const stream = new TestDuplex();
const logParser = Logger.getLogParser();
logParser.attach(stream);

const adn = aden({
dev: true,
logger: {
silent: false,
stdStream: stream,
errStream: stream,
},
});

adn.init(path.resolve(__dirname, '../tmpdata/devunlink2'))
.then((an) => an.run('dev'))
.then((an) => {
request(an.app)
.get('/sub/')
.end((err, res) => {
if (err) {
done(err);
return;
}
expect(res.status).toMatch(200);

logParser.on('error', (err) => done(err));
logParser.on('dev:reload:done', () => {
request(an.app)
.get('/sub/')
.end((err2, res2) => {
if (err2) {
done(err2);
return;
}

expect(res2.status).toMatch(404);

an.shutdown(done);
});
});

setTimeout(() => rimraf.sync(
path.resolve(__dirname, '../tmpdata/devunlink2/sub/index.html')
), 500);
});
});
});

she('does not multi add pages that are already in page graph', (done) => {
const stream = new TestDuplex();
const logParser = Logger.getLogParser();
Expand Down

0 comments on commit 31ea385

Please sign in to comment.