Skip to content

Commit

Permalink
Merge branch 'master' into kotlin-asset
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Dec 11, 2018
2 parents 52baf20 + 697b234 commit b25299e
Show file tree
Hide file tree
Showing 36 changed files with 270 additions and 1,464 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -4,6 +4,7 @@
# in the same file

packages/*/*/test/integration/**
packages/*/*/test/mochareporters.json

# Generated by the build
lib
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -2,4 +2,5 @@ packages/core/parcel-bundler/src/builtins
packages/core/parcel-bundler/test/integration
packages/core/parcel-bundler/test/input
packages/core/parcel-bundler/test/dist
packages/core/parcel-bundler/test/mochareporters.json
tmp
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -87,7 +87,7 @@ Anyone can file an expense. If the expense makes sense for the development of th
### Contributors

Thank you to all the people who have already contributed to parcel!
<a href="graphs/contributors"><img src="https://opencollective.com/parcel/contributors.svg?width=890" /></a>
<a href="https://github.com/parcel-bundler/parcel/graphs/contributors"><img src="https://opencollective.com/parcel/contributors.svg?width=890" /></a>

### Backers

Expand Down
11 changes: 11 additions & 0 deletions azure-pipelines-template.yml
Expand Up @@ -42,3 +42,14 @@ jobs:
displayName: 'Run tests'
- script: yarn lint
displayName: 'Lint'
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFiles: '**/junit-*.xml'
testRunTitle: TestRun ${{ parameters.name }} $(node_version)
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '**/coverage/cobertura-coverage.xml'
reportDirectory: '**/parcel-bundler/coverage'
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Expand Up @@ -11,5 +11,5 @@ jobs:

- template: azure-pipelines-template.yml
parameters:
name: Windows
vmImage: vs2017-win2016
name: Windows
vmImage: vs2017-win2016
5 changes: 1 addition & 4 deletions packages/core/logger/src/Logger.js
Expand Up @@ -75,10 +75,7 @@ class Logger {
if (this.logLevel > 4) {
if (!this.logFile) {
this.logFile = fs.createWriteStream(
path.join(
process.cwd(),
`parcel-debug-${currDate.toLocaleDateString()}@${currDate.toLocaleTimeString()}.log`
)
path.join(process.cwd(), `parcel-debug-${currDate.toISOString()}.log`)
);
}
this.logFile.write(stripAnsi(message) + '\n');
Expand Down
30 changes: 16 additions & 14 deletions packages/core/parcel-bundler/package.json
Expand Up @@ -27,6 +27,12 @@
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"@iarna/toml": "^2.2.0",
"@parcel/fs": "^1.10.3",
"@parcel/logger": "^1.10.3",
"@parcel/utils": "^1.10.3",
"@parcel/watcher": "1.10.3",
"@parcel/workers": "^1.10.3",
"ansi-to-html": "^0.6.4",
"babylon-walk": "^1.0.2",
"browserslist": "^4.1.0",
Expand All @@ -36,7 +42,7 @@
"commander": "^2.11.0",
"cross-spawn": "^6.0.4",
"cssnano": "^4.0.0",
"deasync": "^0.1.13",
"deasync": "^0.1.14",
"dotenv": "^5.0.0",
"dotenv-expand": "^4.2.0",
"fast-glob": "^2.2.2",
Expand Down Expand Up @@ -64,22 +70,17 @@
"serve-static": "^1.12.4",
"source-map": "0.6.1",
"terser": "^3.7.3",
"toml": "^2.3.3",
"tomlify-j0.4": "^3.0.0",
"v8-compile-cache": "^2.0.0",
"ws": "^5.1.1",
"@parcel/watcher": "1.10.3",
"@parcel/workers": "^1.10.3",
"@parcel/logger": "^1.10.3",
"@parcel/utils": "^1.10.3",
"@parcel/fs": "^1.10.3"
"ws": "^5.1.1"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-export-namespace-from": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@parcel/babel-register": "^1.10.3",
"@parcel/test-utils": "^1.10.3",
"@vue/component-compiler-utils": "^2.0.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
Expand All @@ -89,6 +90,7 @@
"coffeescript": "^2.0.3",
"cross-env": "^5.1.1",
"elm": "^0.19.0",
"elm-hot": "^1.0.1",
"eslint": "^4.13.0",
"glslify-bundle": "^5.0.0",
"glslify-deps": "^1.3.0",
Expand All @@ -98,6 +100,8 @@
"less": "^3.0.1",
"lint-staged": "^7.1.2",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi-reporters": "^1.1.7",
"ncp": "^2.0.0",
"nib": "^1.1.2",
"node-elm-compiler": "^5.0.1",
Expand All @@ -115,14 +119,12 @@
"sugarss": "^2.0.0",
"typescript": "^3.0.0",
"vue": "^2.5.16",
"vue-template-compiler": "^2.5.16",
"@parcel/babel-register": "^1.10.3",
"@parcel/test-utils": "^1.10.3"
"vue-template-compiler": "^2.5.16"
},
"scripts": {
"test": "cross-env NODE_ENV=test mocha",
"test-coverage": "rm -rf coverage/* && nyc yarn test",
"report-coverage": "nyc report --reporter=lcov && codecov",
"test-coverage": "rm -rf coverage/* && nyc yarn test --reporter mocha-multi-reporters --reporter-options configFile=./test/mochareporters.json",
"report-coverage": "nyc report --reporter=lcov --reporter=cobertura --reporter=html && codecov",
"test-ci": "yarn test-coverage && yarn report-coverage",
"format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"",
"build": "yarn minify && babel src -d lib && ncp src/builtins lib/builtins",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/assets/CSSAsset.js
Expand Up @@ -122,7 +122,7 @@ class CSSAsset extends Asset {

if (this.cssModules) {
js +=
'module.exports = ' + JSON.stringify(this.cssModules, false, 2) + ';';
'module.exports = ' + JSON.stringify(this.cssModules, null, 2) + ';';
}

return [
Expand Down
6 changes: 5 additions & 1 deletion packages/core/parcel-bundler/src/assets/ElmAsset.js
Expand Up @@ -9,7 +9,6 @@ class ElmAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
this.hmrPageReload = true;
}

async parse() {
Expand Down Expand Up @@ -40,12 +39,17 @@ class ElmAsset extends Asset {
await this.getConfig(['elm.json'], {load: false});
}

options.debug = !this.options.production;
if (this.options.minify) {
options.optimize = true;
}

let compiled = await this.elm.compileToString(this.name, options);
this.contents = compiled.toString();
if (this.options.hmr) {
let {inject} = await localRequire('elm-hot', this.name);
this.contents = inject(this.contents);
}
}

async collectDependencies() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/assets/GraphqlAsset.js
Expand Up @@ -60,7 +60,7 @@ class GraphqlAsset extends Asset {
}

generate() {
return `module.exports=${JSON.stringify(this.ast, false, 2)};`;
return `module.exports=${JSON.stringify(this.ast, null, 2)};`;
}
}

Expand Down
14 changes: 14 additions & 0 deletions packages/core/parcel-bundler/src/assets/HTMLAsset.js
Expand Up @@ -153,6 +153,20 @@ class HTMLAsset extends Asset {
}
}

if (
node.tag === 'link' &&
node.attrs.rel === 'manifest' &&
node.attrs.href
) {
node.attrs.href = this.getAttrDepHandler('href').call(
this,
node.attrs.href,
{entry: true}
);
this.isAstDirty = true;
return node;
}

for (let attr in node.attrs) {
let elements = ATTRS[attr];
// Check for virtual paths
Expand Down
4 changes: 2 additions & 2 deletions packages/core/parcel-bundler/src/assets/RustAsset.js
Expand Up @@ -3,7 +3,7 @@ const commandExists = require('command-exists');
const childProcess = require('child_process');
const {promisify} = require('@parcel/utils');
const exec = promisify(childProcess.execFile);
const tomlify = require('tomlify-j0.4');
const toml = require('@iarna/toml');
const fs = require('@parcel/fs');
const Asset = require('../Asset');
const config = require('../utils/config');
Expand Down Expand Up @@ -118,7 +118,7 @@ class RustAsset extends Asset {
cargoConfig.lib['crate-type'].push('cdylib');
await fs.writeFile(
path.join(cargoDir, 'Cargo.toml'),
tomlify.toToml(cargoConfig)
toml.stringify(cargoConfig)
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/assets/TOMLAsset.js
@@ -1,5 +1,5 @@
const Asset = require('../Asset');
const toml = require('toml');
const toml = require('@iarna/toml');
const serializeObject = require('../utils/serializeObject');

class TOMLAsset extends Asset {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/assets/VueAsset.js
Expand Up @@ -100,7 +100,7 @@ class VueAsset extends Asset {
supplemental += this.compileCSSModules(generated, optsVar);
supplemental += this.compileHMR(generated, optsVar);

if (this.options.minify && !this.options.scopeHoist && supplemental) {
if (this.options.minify && !this.options.scopeHoist) {
let {code, error} = minify(supplemental, {toplevel: true});
if (error) {
throw error;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/parcel-bundler/src/scope-hoisting/hoist.js
Expand Up @@ -51,6 +51,8 @@ function hasSideEffects(asset, {sideEffects} = asset._package) {
module.exports = {
Program: {
enter(path, asset) {
path.scope.crawl();

asset.cacheData.imports = asset.cacheData.imports || Object.create(null);
asset.cacheData.exports = asset.cacheData.exports || Object.create(null);
asset.cacheData.wildcards = asset.cacheData.wildcards || [];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/parcel-bundler/src/scope-hoisting/renamer.js
Expand Up @@ -25,9 +25,9 @@ function rename(scope, oldName, newName) {
}

// Rename binding identifier, and update scope.
binding.identifier.name = newName;
scope.removeOwnBinding(oldName);
scope.bindings[newName] = binding;
delete scope.bindings[oldName];
binding.identifier.name = newName;
}

module.exports = rename;
1 change: 0 additions & 1 deletion packages/core/parcel-bundler/src/transforms/posthtml.js
Expand Up @@ -7,7 +7,6 @@ async function parse(code, asset) {
if (!config) {
config = {};
}
config = Object.assign({lowerCaseAttributeNames: true}, config);
return posthtmlParse(code, config);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/utils/config.js
Expand Up @@ -4,7 +4,7 @@ const clone = require('clone');

const PARSERS = {
json: require('json5').parse,
toml: require('toml').parse
toml: require('@iarna/toml').parse
};

const existsCache = new Map();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/parcel-bundler/src/utils/md5.js
Expand Up @@ -11,11 +11,11 @@ function md5(string, encoding = 'hex') {
md5.file = function(filename) {
return new Promise((resolve, reject) => {
fs.createReadStream(filename)
.on('error', reject)
.pipe(crypto.createHash('md5').setEncoding('hex'))
.on('finish', function() {
resolve(this.read());
})
.on('error', reject);
});
});
};

Expand Down
2 changes: 2 additions & 0 deletions packages/core/parcel-bundler/src/visitors/dependencies.js
Expand Up @@ -54,6 +54,8 @@ module.exports = {
types.isStringLiteral(args[0]);

if (isDynamicImport) {
if (isURL(args[0].value)) return;

asset.addDependency('_bundle_loader');
addDependency(asset, args[0], {dynamic: true});

Expand Down
31 changes: 31 additions & 0 deletions packages/core/parcel-bundler/test/elm.js
Expand Up @@ -14,6 +14,37 @@ describe('elm', function() {
let output = await run(b);
assert.equal(typeof output().Elm.Main.init, 'function');
});
it('should produce a elm bundle with debugger', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js');

await run(b);
let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8');
assert(js.includes('elm$browser$Debugger'));
});

it('should apply elm-hot if HMR is enabled', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
hmr: true
});

await assertBundleTree(b, {
type: 'js',
assets: ['Main.elm', 'hmr-runtime.js', 'index.js']
});

let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8');
assert(js.includes('[elm-hot]'));
});

it('should remove debugger in production', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
production: true
});

await run(b);
let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8');
assert(!js.includes('elm$browser$Debugger'));
});

it('should minify Elm in production mode', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
Expand Down
22 changes: 21 additions & 1 deletion packages/core/parcel-bundler/test/html.js
Expand Up @@ -320,7 +320,7 @@ describe('html', function() {
// minifySvg is false
assert(
html.includes(
'<svg version="1.1" baseprofile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="red"></rect><circle cx="150" cy="100" r="80" fill="green"></circle><text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text></svg>'
'<svg version="1.1" baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="red"></rect><circle cx="150" cy="100" r="80" fill="green"></circle><text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text></svg>'
)
);
});
Expand Down Expand Up @@ -591,6 +591,26 @@ describe('html', function() {
});
});

it("should treat webmanifest as an entry module so it doesn't get content hashed", async function() {
const b = await bundle(
path.join(__dirname, '/integration/html-manifest/index.html')
);

await assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'webmanifest',
assets: ['manifest.webmanifest']
}
]
});

const html = await fs.readFile(path.join(__dirname, '/dist/index.html'));
assert(html.includes('<link rel="manifest" href="/manifest.webmanifest">'));
});

it('should bundle svg files correctly', async function() {
let b = await bundle(
path.join(__dirname, '/integration/html-svg/index.html')
Expand Down
@@ -0,0 +1,5 @@
const lodash = import('https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js');

export default function () {
return lodash.then(() => _);
};
@@ -0,0 +1,8 @@
<!doctype html>
<html>
<head>
<link rel="manifest" href="manifest.webmanifest" />
</head>
<body>
</body>
</html>
@@ -0,0 +1,3 @@
{

}
@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-transform-react-jsx"]
}

0 comments on commit b25299e

Please sign in to comment.