Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Jan 12, 2019
1 parent c75fbf7 commit 01b833a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.1 Maintenance release (2018-01-12)
* Updated dependencies

## 0.6.0 Feature release (2018-08-04)
* Updated dependencies
* Include resource paths in result object
Expand Down
16 changes: 6 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,26 @@ function shortbread(js, css, critical, slot, callback, config) {
result.resources[resourceHash] = `${options.prefix}${jsFile.relative}`;
result.initial += `<script src="${result.resources[resourceHash]}" id="${resourceHash}" async defer onreadystatechange="SHORTBREAD_INSTANCE.onloadScript(this)" onload="SHORTBREAD_INSTANCE.onloadScript(this)"></script>`;
result.subsequent += `<script src="${options.prefix}${jsFile.relative}"></script>`;
})
;
});
jsUrls.forEach((jsUrl) => {
const resourceHash = shortbread.createHash(jsUrl);
result.resources[resourceHash] = jsUrl;
result.initial += `<script src="${jsUrl}" id="${resourceHash}" async defer onreadystatechange="SHORTBREAD_INSTANCE.onloadScript(this)" onload="SHORTBREAD_INSTANCE.onloadScript(this)"></script>`;
result.subsequent += `<script src="${jsUrl}"></script>`;
})
;
});

// 3.a Critical CSS & JavaScript
criticalFiles.forEach((criticalFile) => {
// Detect whether it's a JavaScript resource
for (const r of options.js
) {
) {
if (criticalFile.relative.match(r)) {
result.initial += `<script>${criticalFile.contents}</script>`;
return;
}
}

// Detect whether it's a CSS resource
// Detect whether it's a CSS resource
for (const r of options.css) {
if (criticalFile.relative.match(r)) {
result.initial += `<style>${criticalFile.contents}</style>`;
Expand All @@ -186,15 +184,13 @@ function shortbread(js, css, critical, slot, callback, config) {
result.resources[resourceHash] = `${options.prefix}${cssFile.relative}`;
result.initial += `<link rel="preload" href="${result.resources[resourceHash]}" id="${resourceHash}" as="style" onload="this.rel='stylesheet';SHORTBREAD_INSTANCE.loaded(this.id)">`;
synchronousCSS += `<link rel="stylesheet" href="${result.resources[resourceHash]}">`;
})
;
});
cssUrls.forEach((cssUrl) => {
const resourceHash = shortbread.createHash(cssUrl);
result.resources[resourceHash] = cssUrl;
result.initial += `<link rel="preload" href="${cssUrl}" id="${resourceHash}" as="style" onload="this.rel='stylesheet';SHORTBREAD_INSTANCE.loaded(this.id)">`;
synchronousCSS += `<link rel="stylesheet" href="${cssUrl}">`;
})
;
});
if (synchronousCSS.length) {
result.initial += `<noscript>${synchronousCSS}</noscript>`;
result.subsequent += synchronousCSS;
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "shortbread",
"version": "0.6.0",
"version": "0.6.1",
"description": "Asynchronous, non-blocking loading pattern for CSS and JavaScript resources",
"main": "index.js",
"scripts": {
"test": "npm run build && eslint **/*.js && istanbul test _mocha --report html -- test/*.js --reporter spec",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"build": "babel lib --presets es2015-script --out-dir build",
"prepublish": "npm run build",
"php": "npm run build && node test/php/php.js && php -S 0.0.0.0:8080 -t tmp"
"php": "npm run build && node test/php/php.js && php -S 0.0.0.0:80 -t tmp"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,26 +36,27 @@
"homepage": "https://github.com/jkphl/shortbread#readme",
"dependencies": {
"crypto": "1.0.1",
"fg-loadcss": "^2.0.1",
"fg-loadcss": "^2.1.0",
"is-url": "^1.2.4",
"through2": "^2.0.3",
"uglify-js": "^3.4.6",
"npm-check-updates": "^2.15.0",
"through2": "^3.0.0",
"uglify-js": "^3.4.9",
"vinyl": "^2.2.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-cli": "^6.26.0",
"babel-preset-es2015-script": "^1.1.0",
"coveralls": "^3.0.2",
"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "^7.10.0",
"fs-extra": "^7.0.0",
"gulp": "^3.9.1",
"eslint": "^5.12.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "^7.12.3",
"fs-extra": "^7.0.1",
"gulp": "^4.0.0",
"gulp-filter": "^5.1.0",
"gulp-template": "^5.0.0",
"handlebars": "^4.0.10",
"handlebars": "^4.0.12",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.3.0",
Expand Down
9 changes: 5 additions & 4 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('shortbread().stream', () => {
});

it('should set result data other resources', (done) => {
gulp.src(['fixtures/*.js', 'fixtures/style.css', 'gulp/gulp.php'], { cwd: __dirname })
gulp.src(['fixtures/script.js', 'fixtures/style.css', 'gulp/gulp.php'], { cwd: __dirname })
.pipe(shortbread.stream())
.pipe(assert.length(3))
.pipe(assert.nth(0, (d) => {
Expand Down Expand Up @@ -390,11 +390,12 @@ describe('shortbread().stream', () => {

gulp.src(['fixtures/*', 'gulp/gulp.php'], { cwd: __dirname })
.pipe(shortbread.stream(null, null, null, { css: ['\\.scss$'], js: ['\\.jsx$'] }))
.pipe(assert.length(6))
.pipe(assert.length(7))
.pipe(assert.nth(2, assertData))
.pipe(assert.nth(3, assertData))
.pipe(assert.nth(4, assertData))
.pipe(assert.nth(5, assertData))
.pipe(assert.nth(6, assertData))
.pipe(assert.end(done));
});

Expand Down Expand Up @@ -425,7 +426,7 @@ describe('shortbread().stream', () => {
});

it('data JSON file', (done) => {
gulp.src('none')
gulp.src('none', { allowEmpty: true })
.pipe(shortbread.stream(null, null, null, { data: true }))
.pipe(assert.length(1))
.pipe(assert.nth(0, (d) => {
Expand All @@ -444,7 +445,7 @@ describe('shortbread().stream', () => {
it('external resources / URLs', (done) => {
const resources = { jsUrl: [jsUrl], cssUrl: [cssUrl], data: true };
const resourceHash = shortbread.createHash(`${jsHash}-${jsUrlHash}-${cssHash}-${cssUrlHash}`);
gulp.src(['fixtures/*.js', 'fixtures/style.css', 'gulp/gulp.php'], { cwd: __dirname })
gulp.src(['fixtures/script.js', 'fixtures/style.css', 'gulp/gulp.php'], { cwd: __dirname })
.pipe(shortbread.stream(null, null, null, resources))
.pipe(assert.length(4))
.pipe(assert.nth(3, (d) => {
Expand Down
6 changes: 4 additions & 2 deletions test/php/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const handlebars = require('handlebars');
fs.mkdirsSync(path.join(__dirname, '../tmp'));

const criticalCSS = vinyl.readSync(path.join(__dirname, '../fixtures/critical.css'));
const criticalJS = vinyl.readSync(path.join(__dirname, '../fixtures/critical.js'));
criticalJS.path = `${criticalJS.base}/index.php?asset=critical.js`;
const script = vinyl.readSync(path.join(__dirname, '../fixtures/script.js'));
script.path = `${script.base}/index.php?asset=script.js`;
const js = [script];
const js = [criticalJS, script];
const style = vinyl.readSync(path.join(__dirname, '../fixtures/style.css'));
style.path = `${style.base}/index.php?asset=style.css`;
const css = [style];
const result = shortbread(js, css, criticalCSS, 'main', 'allLoaded');
const result = shortbread(js, css, [criticalCSS, criticalJS], 'main', 'allLoaded');

// Compile and store the PHP test file
const hbs = fs.readFileSync(path.join(__dirname, 'index.hbs'));
Expand Down

0 comments on commit 01b833a

Please sign in to comment.