Skip to content

Commit

Permalink
Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Saddam M committed Apr 5, 2019
1 parent 2b4652b commit d627f6b
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 2 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
@@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.js]
charset = utf-8
indent_style = tab # Tab indentation (no size specified)
indent_size = 2 # Indentation override

# Matches the exact files either package.json or .travis.yml
[{package.json, .travis.yml}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
./src
29 changes: 29 additions & 0 deletions .eslintrc
@@ -0,0 +1,29 @@
{
"rules": {
"no-constant-condition": 1,
"no-debugger": 1,
"no-dupe-args": 1,
"no-dupe-keys": 1,
"no-duplicate-case": 1,
"no-empty": 1,
"no-ex-assign": 1,
"no-extra-parens": [1, "all"],
"no-extra-semi": 1,
"no-func-assign": 1,
"no-obj-calls": 1,
"eqeqeq": [1, "smart"],
"no-caller": 1,
"no-extra-bind": 1,
"no-loop-func": 1,
"no-new-func": 1,
"no-octal": 1,
"no-useless-call": 1,
"no-warning-comments": [
1,
{ "terms": ["todo", " fixme", " bug"], "location": "anywhere" }
],
"no-with": 1,
"no-undefined": 1,
"no-bitwise": 1
}
}
7 changes: 7 additions & 0 deletions .gitattributes
@@ -0,0 +1,7 @@
# Convert text file line endings to lf
# ESLint will warn but won't prevent a push
# from coinciding with this issue.
# Might be buggy on Windows.
* text=auto

*.js text eol=lf
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -5,6 +5,10 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Lock files
yarn.lock
package-lock.json

# Runtime data
pids
*.pid
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
@@ -0,0 +1,9 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
Empty file added CHANGELOG.md
Empty file.
Empty file added CODE_OF_CONDUCT.md
Empty file.
Empty file added CONTRIBUTING.md
Empty file.
45 changes: 43 additions & 2 deletions README.md
@@ -1,5 +1,46 @@
<p align="center"><img src="" /></p>
<p align="center"><img src="https://raw.githubusercontent.com/packem/packem/master/resources/packem-logo.png" /></p>

<h1 align="center">Packem</h1>

Packem is a precompiled JavaScript module bundler
Packem is an extensively _precompiled_ general-purpose JavaScript module bundler with a focus on performance, flexibility and extendibility. Its crust is built with [Rust](), a zero-cost abstraction systems programming language with guaranteed memory safety.

## How Packem Works

<p align="center"><img src="https://raw.githubusercontent.com/packem/packem/master/resources/bundle-cycle.png" /></p>

A static configuration (`packem.config.yml`) is used to outline the general flow of the process. From the root of your project, all dependencies are recursively matched, tracked then stacked into a __Module Graph__ which is essentially a giant (depending on the nature of your project) mutable flat list of interfaces which represent a _'living resource'_ in your project. Packem works with the principle that each file type is treated as a module even though the same interface is not necessarily maintained.

__ES Dynamic Imports__ could be used to create a seperate sub-graph that lives on its own, quite independant of the main graph or sibling/child graphs. Such complexity can be caused if multiple dynamic imports are nested which is not quite what one would need most of the time even though Packem can take care of it.

All the scripts are transpiled first (any Babel plugin can be included at this point as well) afterwhich plugins are instantiated to allow easy manipulation of the module graph. Under the hood, a built-in event dispatcher is used to trigger each event which a child or sibling plugin hooks onto.

Finally, the Graph Serializer concatenates all the transformed scripts which is eventually written to the output path. This defines a complete __Bundling Cycle__.

### Logical and Runtime Contexes

Since most of the bundling decisions go into the module graph generator, it is simply abstracted into Rust. The entire layer of the bundling cycle which involves Rusty OS-specific dynamic libraries _arbitrating_ the bundling process is what we refer to as the _Logical Context_. Every other process is regressed into NodeJS (due to certain issues involving binary compilation and FFI thread issues). This layer is called the _Runtime Context_.

> Since execution of plugins is decided entirely by the runtime context, they also belong to the same context.
## Plugins

Packem uses a comprehensive _class-based_ event system. Based off of this, plugins are instantiated in order of definition in the configuration during build time. Built-in events are also rehydrated into the plugins which they can hook onto using the `PackemEventDispatcher` API. More details on this can be found in the [Plugins API](/).

Most of the common plugins are not included with a single installation of Packem and will require you to install them manually. Some of these common plugins include:

- `dev-plugin` - An abstraction of the Packem's development toolkit i.e. the development server, watcher and other development utilities. This means, in essence, Packem doesn't include development tools by default.
- `file-plugin` - Loads common structural and text-based file formats to their appropriate equivalents in JavaScript like _txt_ to string & _YAML_ to a JSON object.
- `minify-plugin` - Uses [terserjs](https://github.com/terser-js/terser) to crunch and optimize your JavaScript into tiny obfuscated files and write it to the output path.
- `style-plugin` - Responsible for bundling SASS/SCSS, LESS & PostCSS to plain CSS which is then injected into the webpage at runtime.
- `image-plugin` - Processes a PNG, JPG/JPEG, GIF, WebP or SVG file, compresses it with a few options like `quality`, `compressionRatio` and `dithering` to create efficiently optimized images that still retain fidelity.
- `bundle-stats-plugin` - Checks if your bundles exceed a certain custom constraint/limit and issues tabular diagnostics with details like bundle size vs the pre-defined limit.
- `markdown-plugin` - Transforms a Markdown file into escaped HTML and then returns the result into the bundling pipeline.
- `coffeescript-plugin` - Compiles CoffeeScript to JavaScript then appends it to the mainstream bundle.

## API Reference

If you wish to get started right away, check the `docs` section for more details on configurations and the necessary API to get you started.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
Empty file added SUPPORT.md
Empty file.
16 changes: 16 additions & 0 deletions jest.config.js
@@ -0,0 +1,16 @@
// All tests reside in the `test` directory

const { defaults } = require("jest-config");

module.exports = {
verbose: true,
maxConcurrency: 4,
moduleFileExtensions: [...defaults.moduleFileExtensions, "js"],
globals: {
CONFIG_MOCK: {
// Necessary needed
root: "./mock/index.js",
output: "./mock/dist/"
}
}
};
Binary file added resources/bundle-cycle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/mock/index.js
@@ -0,0 +1 @@
console.log("✔ Mock successfully running!");
14 changes: 14 additions & 0 deletions tests/test-utils.js
@@ -0,0 +1,14 @@
// Utility functions for suites
const { PackemPlugin } = require("../");

// Creates an empty Packem plugin
exports.createBasePackemPlugin = () => class extends PackemPlugin {};

// Checks if a given plugin is a Packem plugin
exports.isPackemPlugin = plugin => plugin.constructor === "PackemPlugin";

// Returns a Packem config mock with the transformer field as the arguments
exports.overrideTransformers = transformer => ({
...global.CONFIG_MOCK,
transformer
});

0 comments on commit d627f6b

Please sign in to comment.