Skip to content

Commit 8e4954a

Browse files
authored
Merge pull request #114 from kratiahuja/schema-versioning
Introduce schema version in FastBoot
2 parents b8e16d7 + 80aad14 commit 8e4954a

23 files changed

Lines changed: 84189 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
npm-debug.log
33
tmp*
44
dist/
5+
yarn.lock

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ language: node_js
22
node_js:
33
- "stable"
44
- "4"
5-
- "0.12"
65

76
env:
87
- CXX=g++-4.8 WORKER_COUNT=2

src/ember-app.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require('fs');
44
const path = require('path');
55
const RSVP = require('rsvp');
6+
const chalk = require('chalk');
67

78
const najax = require('najax');
89
const SimpleDOM = require('simple-dom');
@@ -11,6 +12,7 @@ const debug = require('debug')('fastboot:ember-app');
1112

1213
const FastBootInfo = require('./fastboot-info');
1314
const Result = require('./result');
15+
const FastBootSchemaVersions = require('./fastboot-schema-versions');
1416

1517
/**
1618
* @private
@@ -344,39 +346,44 @@ class EmberApp {
344346
}
345347

346348
let manifest;
349+
let schemaVersion;
347350
let pkg;
348351

349352
try {
350353
pkg = JSON.parse(file);
351354
manifest = pkg.fastboot.manifest;
355+
schemaVersion = pkg.fastboot.schemaVersion;
352356
} catch (e) {
353357
throw new Error(`${pkgPath} was malformed or did not contain a manifest. Ensure that you have a compatible version of ember-cli-fastboot.`);
354358
}
355359

356-
var appFiles = [];
357-
if (manifest.appFiles) {
358-
debug("reading array of app file paths from manifest");
359-
manifest.appFiles.forEach(function(appFile) {
360-
appFiles.push(path.join(distPath, appFile));
361-
});
362-
} else if (manifest.appFile) {
363-
// TODO : remove after Fastboot 1.0
364-
debug("reading app file path from manifest");
365-
appFiles = [path.join(distPath, manifest.appFile)];
360+
const currentSchemaVersion = FastBootSchemaVersions.latest;
361+
// set schema version to 1 if not defined
362+
schemaVersion = schemaVersion || FastBootSchemaVersions.base;
363+
debug('Current schemaVersion from `ember-cli-fastboot` is %s while latest schema version is %s', (schemaVersion, currentSchemaVersion));
364+
365+
if (schemaVersion > currentSchemaVersion) {
366+
let errorMsg = chalk.bold.red('An incompatible version between `ember-cli-fastboot` and `fastboot` was found. Please update the version of fastboot library that is compatible with ember-cli-fastboot.');
367+
throw new Error(errorMsg);
366368
}
367369

368-
var vendorFiles = [];
369-
if (manifest.vendorFiles) {
370-
debug("reading array of vendor file paths from manifest");
371-
manifest.vendorFiles.forEach(function(vendorFile) {
372-
vendorFiles.push(path.join(distPath, vendorFile));
373-
});
374-
} else if (manifest.vendorFile) {
375-
// TODO : remove after Fastboot 1.0
376-
debug("reading vendor file path from manifest");
377-
vendorFiles = [path.join(distPath, manifest.vendorFile)];
370+
if (schemaVersion < FastBootSchemaVersions.manifestFileArrays) {
371+
// transform app and vendor file to array of files
372+
manifest = this.transformManifestFiles(manifest);
378373
}
379374

375+
var appFiles = [];
376+
debug("reading array of app file paths from manifest");
377+
manifest.appFiles.forEach(function(appFile) {
378+
appFiles.push(path.join(distPath, appFile));
379+
});
380+
381+
var vendorFiles = [];
382+
debug("reading array of vendor file paths from manifest");
383+
manifest.vendorFiles.forEach(function(vendorFile) {
384+
vendorFiles.push(path.join(distPath, vendorFile));
385+
});
386+
380387
return {
381388
appFiles: appFiles,
382389
vendorFiles: vendorFiles,
@@ -386,6 +393,16 @@ class EmberApp {
386393
appConfig: pkg.fastboot.appConfig
387394
};
388395
}
396+
397+
/**
398+
* Function to transform the manifest app and vendor files to an array.
399+
*/
400+
transformManifestFiles(manifest) {
401+
manifest.appFiles = [manifest.appFile];
402+
manifest.vendorFiles = [manifest.vendorFile];
403+
404+
return manifest;
405+
}
389406
}
390407

391408
/*

src/fastboot-schema-versions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Map of maintaining schema version history so that transformation of the manifest
3+
* file can be performed correctly to maintain backward compatibility of older
4+
* schema version.
5+
*
6+
* Note: `latest` schema version should always be updated (and transformation
7+
* should be added in fastboot lib) everytime fastboot addon schema version is bumped.
8+
*/
9+
const FastBootSchemaVersions = {
10+
'latest': 2, // latest schema version supported by fastboot library
11+
'base': 1, // first schema version supported by fastboot library
12+
'manifestFileArrays': 2 // schema version when app and vendor in manifest supported an array of files
13+
};
14+
15+
module.exports = FastBootSchemaVersions;

test/fastboot-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ describe("FastBoot", function() {
2828
expect(fn).to.throw(/Couldn't find (.+)\/fixtures\/no-package-json/);
2929
});
3030

31+
it('throws an error when manifest schema version is higher than fastboot schema version', function() {
32+
var distPath = fixture('higher-schema-version');
33+
var fn = function() {
34+
return new FastBoot({
35+
distPath: distPath
36+
});
37+
};
38+
39+
expect(fn).to.throw(/An incompatible version between `ember-cli-fastboot` and `fastboot` was found/);
40+
});
41+
3142
it("doesn't throw an exception if a package.json is provided", function() {
3243
var distPath = fixture('empty-package-json');
3344
var fn = function() {

test/fixtures/app-with-console-log/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {},
33
"fastboot": {
44
"moduleWhitelist": [],
5+
"schemaVersion": 1,
56
"manifest": {
67
"appFile": "assets/fastboot-test.js",
78
"htmlFile": "index.html",

test/fixtures/basic-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {},
33
"fastboot": {
44
"moduleWhitelist": [],
5+
"schemaVersion": 1,
56
"manifest": {
67
"appFile": "assets/fastboot-test.js",
78
"htmlFile": "index.html",

test/fixtures/boot-time-failing-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {},
33
"fastboot": {
44
"moduleWhitelist": [],
5+
"schemaVersion": 1,
56
"manifest": {
67
"appFile": "assets/fastboot-test.js",
78
"htmlFile": "index.html",

test/fixtures/config-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {},
33
"fastboot": {
44
"moduleWhitelist": [],
5+
"schemaVersion": 1,
56
"manifest": {
67
"appFile": "assets/fastboot-test.js",
78
"htmlFile": "index.html",

test/fixtures/config-not-in-meta-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {},
33
"fastboot": {
44
"moduleWhitelist": [],
5+
"schemaVersion": 1,
56
"manifest": {
67
"appFile": "assets/fastboot-test.js",
78
"htmlFile": "index.html",

0 commit comments

Comments
 (0)