Skip to content

Commit

Permalink
Merge pull request parcel-bundler#9 from parcel-bundler/master
Browse files Browse the repository at this point in the history
new features
  • Loading branch information
Jasper De Moor committed Dec 15, 2017
2 parents 1d90425 + c008bb0 commit 51bfe22
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 178 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
"htmlnano": "^0.1.6",
"is-url": "^1.2.2",
"js-yaml": "^3.10.0",
"json5": "^0.5.1",
"micromatch": "^3.0.4",
"mkdirp": "^0.5.1",
"node-libs-browser": "^2.0.0",
"opn": "^5.1.0",
"parse-json": "^4.0.0",
"physical-cpu-count": "^2.0.0",
"postcss": "^6.0.10",
"postcss-value-parser": "^3.3.0",
"posthtml": "^0.10.1",
"resolve": "^1.4.0",
"serve-static": "^1.12.4",
"strip-json-comments": "^2.0.1",
"uglify-es": "^3.2.1",
"v8-compile-cache": "^1.1.0",
"worker-farm": "^1.4.1",
Expand Down
4 changes: 2 additions & 2 deletions src/FSCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const md5 = require('./utils/md5');
const objectHash = require('./utils/objectHash');
const pkg = require('../package.json');
const parseJson = require('parse-json');
const json5 = require('json5');

// These keys can affect the output, so if they differ, the cache should not match
const OPTION_KEYS = ['publicURL', 'minify', 'hmr'];
Expand Down Expand Up @@ -56,7 +56,7 @@ class FSCache {
}

let data = await fs.readFile(cacheFile);
return parseJson(data);
return json5.parse(data);
} catch (err) {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Parser {
this.registerExtension('yml', './assets/YAMLAsset');

this.registerExtension('css', './assets/CSSAsset');
this.registerExtension('pcss', './assets/CSSAsset');
this.registerExtension('styl', './assets/StylusAsset');
this.registerExtension('less', './assets/LESSAsset');
this.registerExtension('sass', './assets/SASSAsset');
Expand Down
2 changes: 1 addition & 1 deletion src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function middleware(bundler) {
function sendIndex() {
// If the main asset is an HTML file, serve it
if (bundler.mainAsset.type === 'html') {
req.url = '/' + bundler.mainAsset.basename;
req.url = `/${bundler.mainAsset.generateBundleName(true)}`;
serve(req, res, send404);
} else {
send404();
Expand Down
8 changes: 7 additions & 1 deletion src/assets/JSAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JSAsset extends Asset {
);
}

async parse(code) {
async getParserOptions() {
// Babylon options. We enable a few plugins by default.
const options = {
filename: this.name,
Expand All @@ -56,6 +56,12 @@ class JSAsset extends Asset {
options.plugins.push(...file.parserOpts.plugins);
}

return options;
}

async parse(code) {
const options = await this.getParserOptions();

return babylon.parse(code, options);
}

Expand Down
7 changes: 6 additions & 1 deletion src/assets/TypeScriptAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class TypeScriptAsset extends JSAsset {
let tsconfig = await config.load(this.name, ['tsconfig.json']);

// Overwrite default if config is found
if (tsconfig) transpilerOptions.compilerOptions = tsconfig.compilerOptions;
if (tsconfig) {
transpilerOptions.compilerOptions = Object.assign(
transpilerOptions.compilerOptions,
tsconfig.compilerOptions
);
}
transpilerOptions.compilerOptions.noEmit = false;

// Transpile Module using TypeScript and parse result as ast format through babylon
Expand Down
2 changes: 1 addition & 1 deletion src/packagers/HTMLPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HTMLPackager extends Packager {
let html = asset.generated.html || '';

// Find child bundles (e.g. JS) that have a sibling CSS bundle,
// add add them to the head so they are loaded immediately.
// add them to the head so they are loaded immediately.
let cssBundles = Array.from(this.bundle.childBundles)
.map(b => b.siblingBundles.get('css'))
.filter(Boolean);
Expand Down
5 changes: 2 additions & 3 deletions src/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('./fs');
const path = require('path');
const parseJson = require('parse-json');
const stripJsonComments = require('strip-json-comments');
const json5 = require('json5');

const existsCache = new Map();

Expand Down Expand Up @@ -37,7 +36,7 @@ async function load(filepath, filenames, root = path.parse(filepath).root) {
}

let configStream = await fs.readFile(configFile);
return parseJson(stripJsonComments(configStream.toString()));
return json5.parse(configStream.toString());
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions test/hmr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rimraf = require('rimraf');
const promisify = require('../src/utils/promisify');
const ncp = promisify(require('ncp'));
const WebSocket = require('ws');
const parseJson = require('parse-json');
const json5 = require('json5');

describe('hmr', function() {
let b, ws;
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('hmr', function() {
'exports.a = 5; exports.b = 5;'
);

let msg = parseJson(await nextEvent(ws, 'message'));
let msg = json5.parse(await nextEvent(ws, 'message'));
assert.equal(msg.type, 'update');
assert.equal(msg.assets.length, 1);
assert.equal(msg.assets[0].generated.js, 'exports.a = 5; exports.b = 5;');
Expand All @@ -65,7 +65,7 @@ describe('hmr', function() {
'require("fs"); exports.a = 5; exports.b = 5;'
);

let msg = parseJson(await nextEvent(ws, 'message'));
let msg = json5.parse(await nextEvent(ws, 'message'));
assert.equal(msg.type, 'update');
assert.equal(msg.assets.length, 2);
});
Expand Down

0 comments on commit 51bfe22

Please sign in to comment.