Skip to content

Commit

Permalink
Merge pull request #1 from parcel-bundler/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Jasper De Moor authored Dec 7, 2017
2 parents 1afb09f + 4cc343b commit ef5d3e5
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 393 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parcel-bundler",
"version": "1.0.2",
"version": "1.0.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
9 changes: 7 additions & 2 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Bundler extends EventEmitter {

normalizeOptions(options) {
const isProduction = options.production || process.env.NODE_ENV === 'production';
const publicURL = options.publicURL || '/' + Path.basename(options.outDir || 'dist');
const publicURL = options.publicUrl || options.publicURL || '/' + Path.basename(options.outDir || 'dist');
const watch = typeof options.watch === 'boolean' ? options.watch : !isProduction;
return {
outDir: Path.resolve(options.outDir || 'dist'),
Expand Down Expand Up @@ -153,7 +153,12 @@ class Bundler extends EventEmitter {
this.farm = WorkerFarm.getShared(this.options);

if (this.options.watch) {
this.watcher = new FSWatcher;
// FS events on macOS are flakey in the tests, which write lots of files very quickly
// See https://github.com/paulmillr/chokidar/issues/612
this.watcher = new FSWatcher({
useFsEvents: process.env.NODE_ENV !== 'test'
});

this.watcher.on('change', this.onChange.bind(this));
}

Expand Down
9 changes: 7 additions & 2 deletions src/FSCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('./utils/fs');
const path = require('path');
const md5 = require('./utils/md5');
const objectHash = require('./utils/objectHash');
const pkg = require('../package.json');

// These keys can affect the output, so if they differ, the cache should not match
const OPTION_KEYS = ['publicURL', 'minify', 'hmr'];
Expand All @@ -10,8 +11,12 @@ class FSCache {
constructor(options) {
this.dir = path.resolve(options.cacheDir || '.cache');
this.dirExists = false;
this.invalidated = new Set;
this.optionsHash = objectHash(OPTION_KEYS.reduce((p, k) => (p[k] = options[k], p), {}));
this.invalidated = new Set();
this.optionsHash = objectHash(
OPTION_KEYS.reduce((p, k) => ((p[k] = options[k]), p), {
version: pkg.version,
})
);
}

async ensureDirExists() {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/is-url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const isURL = require('is-url');

// Matches anchor (ie: #raptors)
const ANCHOR_REGEXP = /^#/;

// Matches scheme (ie: tel:, mailto:, data:)
const SCHEME_REGEXP = /^[a-z]*\:/i;

module.exports = function (url) {
return isURL(url) || /^#/.test(url);
return isURL(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url);
};
4 changes: 4 additions & 0 deletions src/visitors/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ module.exports = {
addDependency(asset, node.source);
},

ExportDefaultDeclaration(node, asset) {
asset.isES6Module = true;
},

CallExpression(node, asset) {
let {callee, arguments: args} = node;

Expand Down
5 changes: 4 additions & 1 deletion test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {bundle, run, assertBundleTree} = require('./utils');

describe('css', function () {
it('should produce two bundles when importing a CSS file', async function () {
this.timeout(5000);
let b = await bundle(__dirname + '/integration/css/index.js');

assertBundleTree(b, {
Expand Down Expand Up @@ -97,6 +96,10 @@ describe('css', function () {
assert(/url\("[0-9a-f]+\.woff2"\)/.test(css));
assert(css.includes('url("http://google.com")'));
assert(css.includes('.index'));
assert(css.includes('url("data:image/gif;base64,quotes")'));
assert(css.includes('.quotes'));
assert(css.includes('url(data:image/gif;base64,no-quote)'));
assert(css.includes('.no-quote'));

assert(fs.existsSync(__dirname + '/dist/' + css.match(/url\("([0-9a-f]+\.woff2)"\)/)[1]));
});
Expand Down
8 changes: 8 additions & 0 deletions test/integration/css-url/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
.index {
background: url("http://google.com");
}

.quotes {
background: url("data:image/gif;base64,quotes");
}

.no-quote {
background: url(data:image/gif;base64,no-quote);
}
4 changes: 4 additions & 0 deletions test/integration/es6-default-only/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const a = 1;
const b = 2;

export default () => a + b;
Empty file.
2 changes: 2 additions & 0 deletions test/integration/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<h1>Hello world</h1>
<p>Linking to <a href="other.html">another page</a></p>
<a href="#hash_link">Hash link</a>
<a href="mailto:[email protected]">Mailto link</a>
<a href="tel:+33636757575">Tel link</a>
<script src="index.js"></script>
<script src="https://unpkg.com/parcel-bundler"></script>
</body>
Expand Down
12 changes: 12 additions & 0 deletions test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ describe('javascript', function () {
assert.equal(output.default(), 3);
});

it('should produce a JS bundle with default exorts and no imports', async function () {
let b = await bundle(__dirname + '/integration/es6-default-only/index.js');

assert.equal(b.assets.size, 1);
assert.equal(b.childBundles.size, 0);

let output = run(b);
assert.equal(typeof output, 'object');
assert.equal(typeof output.default, 'function');
assert.equal(output.default(), 3);
});

it('should split bundles when a dynamic import is used', async function () {
let b = await bundle(__dirname + '/integration/dynamic/index.js');

Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--timeout 15000
1 change: 0 additions & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('server', function () {
});

it('should serve a default page if the main bundle is an HTML asset', async function () {
this.timeout(5000);
let b = bundler(__dirname + '/integration/html/index.html');
server = b.serve(0);

Expand Down
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function assertBundleTree(bundle, tree) {
}

if (tree.childBundles) {
let children = Array.from(bundle.childBundles);//.sort((a, b) => a.name - b.name);
let children = Array.from(bundle.childBundles).sort((a, b) => Array.from(a.assets).sort()[0].basename < Array.from(b.assets).sort()[0].basename ? -1 : 1);
assert.equal(bundle.childBundles.size, tree.childBundles.length);
tree.childBundles.forEach((b, i) => assertBundleTree(children[i], b));
}
Expand Down
2 changes: 1 addition & 1 deletion test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('watcher', function () {
let bundle = await b.bundle();
let mtimes = fs.readdirSync(__dirname + '/dist').map(f => fs.statSync(__dirname + '/dist/' + f).mtime.getTime() / 1000 | 0);

await sleep(500); // mtime only has second level precision
await sleep(1000); // mtime only has second level precision
fs.writeFileSync(__dirname + '/input/b.js', 'module.exports = require("./common")');

bundle = await nextBundle(b);
Expand Down
Loading

0 comments on commit ef5d3e5

Please sign in to comment.