Skip to content

Commit

Permalink
Merge branch 'master' into esm-dynamic-import-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Dec 9, 2017
2 parents 7d1f384 + cdda044 commit a79adfc
Show file tree
Hide file tree
Showing 76 changed files with 1,833 additions and 536 deletions.
45 changes: 45 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!---
Thanks for filing an issue 😄 ! Before you submit, please read the following:
Search open/closed issues before submitting since someone might have asked the same thing before!
-->

**Choose one:** is this a 🐛 bug report or 🙋 feature request?

<!--- Provide a general summary of the issue in the title above -->

### 🎛 Configuration (.babelrc, package.json, cli command)
<!--- If describing a bug, tell us what your babel configuration looks like -->

```js
{
"your": { "config": "here" }
}
```

### 🤔 Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->

### 😯 Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If you are seeing an error, please include the full error message and stack trace -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->

### 💁 Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->

### 🔦 Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->

### 🌍 Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->

| Software | Version(s)
| ---------------- | ----------
| Parcel |
| Node |
| npm/Yarn |
| Operating System |
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage
dist
lib
!test/**/node_modules
.vscode/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/builtins
test/integration
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"bracketSpacing": false,
}
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" width="749">
</a>
</p>
<p align="center">
<a href="https://slack.parceljs.org/">
<img alt="Slack" src="https://slack.parceljs.org/badge.svg">
</a>
</p>

## Features

Expand Down Expand Up @@ -68,10 +73,17 @@ Finally, existing bundlers are built around string loaders/transforms, where the

`parcel` takes as input a single entry asset, which could be any type: a JS file, HTML, CSS, image, etc. There are various asset types defined in `parcel` which know how to handle specific file types. The assets are parsed, their dependencies are extracted, and they are transformed to their final compiled form. This creates a tree of assets.

Once the asset tree as been constructed, the assets are placed into a bundle tree. A bundle is created for the entry asset, and child bundles are created for dynamic imports, which cause code splitting to occur. Child bundles are also created when assets of a different type are imported, for example if you imported a CSS file from JavaScript, it would be placed into a sibling bundle to the corresponding JavaScript. If an asset is required in more than one bundle, it is hoisted up to the nearest common ancestor in the bundle tree so it is not included more than once.
Once the asset tree has been constructed, the assets are placed into a bundle tree. A bundle is created for the entry asset, and child bundles are created for dynamic imports, which cause code splitting to occur. Child bundles are also created when assets of a different type are imported, for example if you imported a CSS file from JavaScript, it would be placed into a sibling bundle to the corresponding JavaScript. If an asset is required in more than one bundle, it is hoisted up to the nearest common ancestor in the bundle tree so it is not included more than once.

After the bundle tree is constructed, each bundle is written to a file by a packager specific to the file type. The packagers know how to combine the code from each asset together into the final file that is loaded by a browser.

## Community

All feedback and suggestions are welcome!

- 💬 Chat: Join us on [slack](https://slack.parceljs.org/).
- 📣 Stay up to date on new features and announcments on [@parceljs](https://twitter.com/parceljs).

## License

MIT
Expand Down
54 changes: 41 additions & 13 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,67 @@ const version = require('../package.json').version;

program.version(version);

program.command('serve [input]')
program
.command('serve [input]')
.description('starts a development server')
.option('-p, --port <port>', 'set the port to serve on. defaults to 1234')
.option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"')
.option('--public-url <url>', 'set the public URL to serve on. defaults to the same as the --out-dir option')
.option(
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
)
.option('--no-hmr', 'disable hot module replacement')
.option('--no-cache', 'disable the filesystem cache')
.action(bundle);

program.command('watch [input]')
program
.command('watch [input]')
.description('starts the bundler in watch mode')
.option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"')
.option('--public-url <url>', 'set the public URL to serve on. defaults to the same as the --out-dir option')
.option(
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
)
.option('--no-hmr', 'disable hot module replacement')
.option('--no-cache', 'disable the filesystem cache')
.action(bundle);

program.command('build [input]')
program
.command('build [input]')
.description('bundles for production')
.option('-d, --out-dir <path>', 'set the output directory. defaults to "dist"')
.option('--public-url <url>', 'set the public URL to serve on. defaults to the same as the --out-dir option')
.option(
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
)
.option('--no-minify', 'disable minification')
.option('--no-cache', 'disable the filesystem cache')
.action(bundle);

program.command('help [command]')
program
.command('help [command]')
.description('display help information for a command')
.action(function (command) {
.action(function(command) {
let cmd = program.commands.find(c => c.name() === command) || program;
cmd.help();
});

program.on('--help', function () {
program.on('--help', function() {
console.log('');
console.log(' Run `' + chalk.bold('parcel help <command>') + '` for more information on specific commands');
console.log(
' Run `' +
chalk.bold('parcel help <command>') +
'` for more information on specific commands'
);
console.log('');
});

Expand All @@ -59,6 +85,8 @@ function bundle(main, command) {

if (command.name() === 'build') {
process.env.NODE_ENV = 'production';
} else {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
}

const bundler = new Bundler(main, command);
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Node 8 supports native async functions - no need to use compiled code!
module.exports = parseInt(process.versions.node) < 8
module.exports = parseInt(process.versions.node, 10) < 8
? require('./lib/Bundler')
: require('./src/Bundler');
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parcel-bundler",
"version": "1.0.3",
"version": "1.1.0",
"main": "index.js",
"license": "MIT",
"repository": {
Expand All @@ -26,6 +26,7 @@
"micromatch": "^3.0.4",
"mkdirp": "^0.5.1",
"node-libs-browser": "^2.0.0",
"parse-json": "^4.0.0",
"physical-cpu-count": "^2.0.0",
"postcss": "^6.0.10",
"postcss-value-parser": "^3.3.0",
Expand All @@ -41,26 +42,35 @@
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.1.1",
"husky": "^0.14.3",
"less": "^2.7.2",
"lint-staged": "^6.0.0",
"mocha": "^3.5.0",
"ncp": "^2.0.0",
"nib": "^1.1.2",
"node-sass": "^4.5.3",
"nyc": "^11.1.0",
"postcss-modules": "^0.8.0",
"posthtml-include": "^1.1.0",
"prettier": "^1.9.1",
"rimraf": "^2.6.1",
"stylus": "^0.54.5"
"stylus": "^0.54.5",
"typescript": "^2.6.2"
},
"scripts": {
"test": "cross-env NODE_ENV=test mocha",
"format": "prettier --write './{src,bin,test}/**/*.{js,json,md}'",
"build": "babel src -d lib",
"prepublish": "yarn build"
"prepublish": "yarn build",
"precommit": "lint-staged"
},
"bin": {
"parcel": "bin/cli.js"
},
"engines": {
"node": ">= 6.0.0"
},
"lint-staged": {
"*.{js,json,md}": ["prettier --write", "git add"]
}
}
26 changes: 18 additions & 8 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class Asset {
this.ast = null;
this.generated = null;
this.hash = null;
this.parentDeps = new Set;
this.dependencies = new Map;
this.depAssets = new Map;
this.parentDeps = new Set();
this.dependencies = new Map();
this.depAssets = new Map();
this.parentBundle = null;
this.bundles = new Set;
this.bundles = new Set();
}

async loadIfNeeded() {
Expand Down Expand Up @@ -71,9 +71,16 @@ class Asset {
from = this.name;
}

let resolved = path.resolve(path.dirname(from), url).replace(/[\?#].*$/, '');
this.addDependency('./' + path.relative(path.dirname(this.name), resolved), Object.assign({dynamic: true}, opts));
return this.options.parser.getAsset(resolved, this.package, this.options).generateBundleName();
let resolved = path
.resolve(path.dirname(from), url)
.replace(/[\?#].*$/, '');
this.addDependency(
'./' + path.relative(path.dirname(this.name), resolved),
Object.assign({dynamic: true}, opts)
);
return this.options.parser
.getAsset(resolved, this.package, this.options)
.generateBundleName();
}

mightHaveDependencies() {
Expand Down Expand Up @@ -139,7 +146,10 @@ class Asset {

generateBundleName(isMainAsset) {
// Resolve the main file of the package.json
let main = this.package && this.package.main ? path.resolve(path.dirname(this.package.pkgfile), this.package.main) : null;
let main =
this.package && this.package.main
? path.resolve(path.dirname(this.package.pkgfile), this.package.main)
: null;
let ext = '.' + this.type;

// If this asset is main file of the package, use the package name
Expand Down
Loading

0 comments on commit a79adfc

Please sign in to comment.