Skip to content

Commit

Permalink
Merge pull request #43 from homer0/next
Browse files Browse the repository at this point in the history
v5.0.0
  • Loading branch information
homer0 committed Aug 26, 2019
2 parents 96f21b1 + 3f48bfa commit 18a7c0a
Show file tree
Hide file tree
Showing 19 changed files with 1,475 additions and 761 deletions.
25 changes: 3 additions & 22 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
{
"extends": "airbnb-base",
"rules": {
indent: ['error', 2, {
MemberExpression: 0,
}],
"no-underscore-dangle": ["error", { "allowAfterThis": true }],
"comma-dangle": ["error", {
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
functions: "never",
}],
"class-methods-use-this": "off",
"import/no-unresolved": "off",
"import/no-extraneous-dependencies": "off",
"function-paren-newline": "off",
"arrow-parens": ["error", "always"],
"no-plusplus": "off",
"lines-between-class-members": "off",
"operator-linebreak": ["error", "after"]
}
"root": true,
"plugins": ["homer0"],
"extends": ["plugin:homer0/node"]
}
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
"name": "projext-plugin-rollup",
"description": "Allows projext to use Rollup as a build engine.",
"homepage": "https://homer0.github.io/projext-plugin-rollup/",
"version": "4.0.0",
"version": "5.0.0",
"repository": "homer0/projext-plugin-rollup",
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"projext": "^7.0.0",
"wootils": "^2.6.0",
"projext": "^7.1.0",
"wootils": "^2.6.5",
"jimple": "^1.5.0",
"fs-extra": "^8.1.0",
"extend": "^3.0.2",
"magic-string": "0.25.3",

"rollup": "^1.17.0",
"rollup-plugin-commonjs": "^10.0.1",
"rollup": "^1.20.2",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-uglify": "^6.0.2",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-html": "0.2.1",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-sass": "^1.2.2",
"rollup-pluginutils": "^2.8.1",
"rollup-plugin-polyfill": "^3.0.0",
"rollup-plugin-visualizer": "^2.5.4",

"builtin-modules": "^3.1.0",

Expand All @@ -36,29 +37,28 @@
"opener": "^1.5.1",
"prettysize": "^2.0.0",
"colors": "^1.3.3",
"statuses": "^1.5.0",

"core-js": "^3.1.4",
"core-js": "^3.2.1",
"regenerator-runtime": "0.13.3",

"@babel/core": "7.5.5",
"@babel/preset-env": "7.5.5"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^9.1.0",
"eslint": "^6.2.2",
"eslint-plugin-homer0": "^2.0.0",
"@babel/plugin-transform-runtime": "7.5.5",
"jest-ex": "^6.1.1",
"jest-cli": "^24.8.0",
"jest-cli": "^24.9.0",
"jasmine-expect": "^4.0.3",
"jimpex": "^4.0.1",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "^1.0.4",
"leasot": "^8.0.0",
"coveralls": "^3.0.5",
"husky": "^3.0.2"
"coveralls": "^3.0.6",
"husky": "^3.0.4"
},
"engine-strict": true,
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/stylesheetAssets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ class ProjextRollupStylesheetAssetsPlugin {
* @ignore
*/
_parseURL(urlPath) {
// eslint-disable-next-line node/no-deprecated-api
const parsed = url.parse(urlPath);
const urlQuery = parsed.search || '';
const urlHash = parsed.hash || '';
Expand Down
23 changes: 20 additions & 3 deletions src/services/building/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class RollupConfiguration {
}
/**
* This method generates a complete Rollup configuration for a target.
* @param {Target} target The target information.
* @param {string} buildType The intended build type: `production` or `development`.
* @param {Target} target The target information.
* @param {string} buildType The intended build type: `production` or `development`.
* @return {Object}
* @throws {Error} If there's no base configuration for the target type.
* @throws {Error} If there's no base configuration for the target type and build type.
Expand All @@ -68,7 +68,7 @@ class RollupConfiguration {

const input = path.join(target.paths.source, target.entry[buildType]);

const defaultFormat = target.is.node ? 'cjs' : 'iife';
const defaultFormat = this._getTargetDefaultFormat(target);
const output = {
sourcemap: !!(target.sourceMap && target.sourceMap[buildType]),
name: target.name.replace(/-(\w)/ig, (match, letter) => letter.toUpperCase()),
Expand Down Expand Up @@ -116,6 +116,11 @@ class RollupConfiguration {
paths,
copy,
additionalWatch,
/**
* The reason we are taking this property is because it's not part of the `Target` entity,
* but it may be injected by the build engine.
*/
analyze: !!target.analyze,
};

let config = this.targetConfiguration(
Expand All @@ -129,6 +134,18 @@ class RollupConfiguration {

return config;
}
/**
* Based on the taget type, this method will decide which will be the default output format
* the target will use. The reason this is the "default" format, it's because the service
* can later changed dependeding in whether the target is a library or not.
* @param {Target} target The target information.
* @return {string}
* @access protected
* @ignore
*/
_getTargetDefaultFormat(target) {
return target.is.node ? 'cjs' : 'iife';
}
/**
* Generates a function that when called will return a dictionary with definitions that will be
* replaced on the bundle.
Expand Down
34 changes: 25 additions & 9 deletions src/services/building/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class RollupBuildEngine {
* @property {string} inspect Whether or not to enable the Node inspector. This will be like a
* fake boolean as the CLI doesn't support boolean variables, so its
* value will be either `'true'` or `'false'`.
* @property {string} analyze Whether or not to enable the bundle analyzer. This will be like a
* fake boolean as the CLI doesn't support boolean variables, so its
* value will be either `'true'` or `'false'`.
* @access protected
* @ignore
*/
Expand All @@ -64,6 +67,7 @@ class RollupBuildEngine {
run: 'PXTRP_RUN',
watch: 'PXTRP_WATCH',
inspect: 'PXTRP_INSPECT',
analyze: 'PXTRP_ANALYZE',
};
}
/**
Expand All @@ -76,21 +80,24 @@ class RollupBuildEngine {
* setting for the required build type is set to `false`.
* @param {boolean} [forceInspect=false] Enables the Node inspector even if the target setting
* is set to `false`.
* @param {boolean} [forceAnalyze=false] Enables the bundle analyzer.
* @return {string}
*/
getBuildCommand(
target,
buildType,
forceRun = false,
forceWatch = false,
forceInspect = false
forceInspect = false,
forceAnalyze = false
) {
const vars = this._getEnvVarsAsString({
target: target.name,
type: buildType,
run: forceRun,
watch: forceWatch,
inspect: forceInspect,
analyze: forceAnalyze,
});

const config = path.join(
Expand Down Expand Up @@ -130,17 +137,26 @@ class RollupBuildEngine {
throw new Error('This file can only be run by using the `build` command');
}

const { type, run, inspect } = vars;
const {
type,
run,
inspect,
analyze,
} = vars;
const target = Object.assign({}, this.targets.getTarget(vars.target));
if (run === 'true') {
target.runOnDevelopment = true;
if (inspect === 'true') {
target.inspect.enabled = true;
if (analyze === 'true') {
target.analyze = true;
} else {
if (run === 'true') {
target.runOnDevelopment = true;
if (inspect === 'true') {
target.inspect.enabled = true;
}
}
}

if (vars.watch === 'true') {
target.watch[type] = true;
if (vars.watch === 'true') {
target.watch[type] = true;
}
}

return this.getConfiguration(target, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sass = require('rollup-plugin-sass');
const html = require('rollup-plugin-html');
const json = require('rollup-plugin-json');
const polyfill = require('rollup-plugin-polyfill');
const visualizer = require('rollup-plugin-visualizer');

const { provider } = require('jimple');
const ConfigurationFile = require('../../abstracts/configurationFile');
Expand Down Expand Up @@ -72,6 +73,7 @@ class RollupBrowserDevelopmentConfiguration extends ConfigurationFile {
input,
output,
target,
analyze,
} = params;
// Create the `stats` plugin instance.
const statsPlugin = stats({
Expand Down Expand Up @@ -123,6 +125,11 @@ class RollupBrowserDevelopmentConfiguration extends ConfigurationFile {
template(pluginSettings.template),
copy(pluginSettings.copy),
statsPlugin.log(statsLogSettings),
...(
analyze ?
[visualizer(pluginSettings.visualizer)] :
[]
),
];
// Get the list of external dependencies.
const { external } = pluginSettings.external;
Expand Down
11 changes: 9 additions & 2 deletions src/services/configurations/browserProductionConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const sass = require('rollup-plugin-sass');
const html = require('rollup-plugin-html');
const json = require('rollup-plugin-json');
const polyfill = require('rollup-plugin-polyfill');
const { uglify } = require('rollup-plugin-uglify');
const { terser } = require('rollup-plugin-terser');
const visualizer = require('rollup-plugin-visualizer');

const { provider } = require('jimple');
const ConfigurationFile = require('../../abstracts/configurationFile');
Expand Down Expand Up @@ -73,6 +74,7 @@ class RollupBrowserProductionConfiguration extends ConfigurationFile {
input,
output,
target,
analyze,
} = params;
// Create the `stats` plugin instance.
const statsPlugin = stats({
Expand Down Expand Up @@ -115,10 +117,15 @@ class RollupBrowserProductionConfiguration extends ConfigurationFile {
urls(pluginSettings.urls),
...(
target.uglifyOnProduction ?
[uglify(pluginSettings.uglify)] :
[terser(pluginSettings.terser)] :
[]
),
copy(pluginSettings.copy),
...(
analyze ?
[visualizer(pluginSettings.visualizer)] :
[]
),
];
// If the target is not a library, push the template plugin for the HTML file.
if (!target.library) {
Expand Down
7 changes: 7 additions & 0 deletions src/services/configurations/nodeDevelopmentConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sass = require('rollup-plugin-sass');
const html = require('rollup-plugin-html');
const json = require('rollup-plugin-json');
const polyfill = require('rollup-plugin-polyfill');
const visualizer = require('rollup-plugin-visualizer');

const { provider } = require('jimple');
const ConfigurationFile = require('../../abstracts/configurationFile');
Expand Down Expand Up @@ -67,6 +68,7 @@ class RollupNodeDevelopmentConfiguration extends ConfigurationFile {
input,
output,
target,
analyze,
} = params;
// Create the `stats` plugin instance.
const statsPlugin = stats({
Expand Down Expand Up @@ -103,6 +105,11 @@ class RollupNodeDevelopmentConfiguration extends ConfigurationFile {
urls(pluginSettings.urls),
copy(pluginSettings.copy),
statsPlugin.log(pluginSettings.statsLog),
...(
analyze ?
[visualizer(pluginSettings.visualizer)] :
[]
),
];
// Get the list of external dependencies.
const { external } = pluginSettings.external;
Expand Down
7 changes: 7 additions & 0 deletions src/services/configurations/nodeProductionConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sass = require('rollup-plugin-sass');
const html = require('rollup-plugin-html');
const json = require('rollup-plugin-json');
const polyfill = require('rollup-plugin-polyfill');
const visualizer = require('rollup-plugin-visualizer');

const { provider } = require('jimple');
const ConfigurationFile = require('../../abstracts/configurationFile');
Expand Down Expand Up @@ -66,6 +67,7 @@ class RollupNodeProductionConfiguration extends ConfigurationFile {
input,
output,
target,
analyze,
} = params;
// Create the `stats` plugin instance.
const statsPlugin = stats({
Expand Down Expand Up @@ -102,6 +104,11 @@ class RollupNodeProductionConfiguration extends ConfigurationFile {
urls(pluginSettings.urls),
copy(pluginSettings.copy),
statsPlugin.log(pluginSettings.statsLog),
...(
analyze ?
[visualizer(pluginSettings.visualizer)] :
[]
),
];
// Get the list of external dependencies.
const { external } = pluginSettings.external;
Expand Down

0 comments on commit 18a7c0a

Please sign in to comment.