summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rw-r--r--support/aliases.json24
-rw-r--r--support/build.test.js2
-rw-r--r--support/build/aggregate-build.js20
-rw-r--r--support/build/aggregate-bundle.js22
-rw-r--r--support/build/aggregate-cjs.js9
-rwxr-xr-xsupport/build/compile-module.js32
-rw-r--r--support/build/compile-modules.js45
-rw-r--r--support/build/modules-cjs.js3
-rw-r--r--support/build/plugin-lodash-import-rename.js24
-rw-r--r--support/es.test.js15
-rw-r--r--support/generate-index.js66
-rw-r--r--support/get-alias.js12
-rw-r--r--support/index-template.js80
-rw-r--r--support/jsdoc/theme/tmpl/layout.tmpl1
-rw-r--r--support/list-aliases.js25
-rwxr-xr-xsupport/sync-cjs-package.js2
-rwxr-xr-xsupport/sync-es-package.js4
17 files changed, 271 insertions, 115 deletions
diff --git a/support/aliases.json b/support/aliases.json
new file mode 100644
index 0000000..a7ed776
--- /dev/null
+++ b/support/aliases.json
@@ -0,0 +1,24 @@
+{
+ "all": "every",
+ "allLimit": "everyLimit",
+ "allSeries": "everySeries",
+ "any": "some",
+ "anyLimit": "someLimit",
+ "anySeries": "someSeries",
+ "find": "detect",
+ "findLimit": "detectLimit",
+ "findSeries": "detectSeries",
+ "forEach": "each",
+ "forEachSeries": "eachSeries",
+ "forEachLimit": "eachLimit",
+ "forEachOf": "eachOf",
+ "forEachOfSeries": "eachOfSeries",
+ "forEachOfLimit": "eachOfLimit",
+ "inject": "reduce",
+ "foldl": "reduce",
+ "foldr": "reduceRight",
+ "select": "filter",
+ "selectLimit": "filterLimit",
+ "selectSeries": "filterSeries",
+ "wrapSync": "asyncify"
+}
diff --git a/support/build.test.js b/support/build.test.js
index cc56348..ebf18b7 100644
--- a/support/build.test.js
+++ b/support/build.test.js
@@ -1,5 +1,5 @@
// Smoke test for the CJS build
-var methods = ["each", "waterfall", "queue", "eachSeries"];
+var methods = ["each", "waterfall", "queue", "eachSeries", "forEachOf"];
var expect = require('chai').expect;
var rollup = require('rollup').rollup;
var rollupPluginNodeResolve = require('rollup-plugin-node-resolve');
diff --git a/support/build/aggregate-build.js b/support/build/aggregate-build.js
deleted file mode 100644
index 7269291..0000000
--- a/support/build/aggregate-build.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import compileModules from './compile-modules';
-import {rollup} from 'rollup';
-import rimraf from 'rimraf/rimraf';
-
-export default function buildBundle(options) {
- function bundle() {
- rollup({
- entry: options.outpath + '/index.js'
- }).then(function ( bundle ) {
- bundle.write({
- format: options.format,
- moduleName: 'async',
- dest: options.outfile
- });
- rimraf.sync(options.outpath);
- }).catch(console.error);
- }
-
- compileModules(bundle, options);
-}
diff --git a/support/build/aggregate-bundle.js b/support/build/aggregate-bundle.js
index 482bfcd..c48b25f 100644
--- a/support/build/aggregate-bundle.js
+++ b/support/build/aggregate-bundle.js
@@ -1,9 +1,15 @@
-import aggregateBuild from './aggregate-build';
+const {rollup} = require('rollup');
+const nodeResolve = require('rollup-plugin-node-resolve');
-aggregateBuild({
- es6: true,
- outpath:'build/build-modules-es6',
- outfile: 'build/dist/async.js',
- format: 'umd',
- lodashRename: true
-});
+rollup({
+ entry: 'build-es/index.js',
+ plugins: [ nodeResolve() ]
+})
+.then(function ( bundle ) {
+ return bundle.write({
+ format: 'umd',
+ moduleName: 'async',
+ dest: 'build/dist/async.js'
+ });
+})
+.catch((err) => { throw err; });
diff --git a/support/build/aggregate-cjs.js b/support/build/aggregate-cjs.js
deleted file mode 100644
index 077ca49..0000000
--- a/support/build/aggregate-cjs.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import aggregateBuild from './aggregate-build';
-
-aggregateBuild({
- es6: true,
- outpath:'build/build-modules-es6',
- outfile: 'build/index.js',
- format: 'cjs',
- lodashRename: false
-});
diff --git a/support/build/compile-module.js b/support/build/compile-module.js
new file mode 100755
index 0000000..38a4d38
--- /dev/null
+++ b/support/build/compile-module.js
@@ -0,0 +1,32 @@
+#!/usr/bin/env node
+
+const yargs = require('yargs');
+const fs = require('fs');
+const {transformFile} = require('babel-core');
+const pluginCJS = require('babel-plugin-transform-es2015-modules-commonjs');
+const pluginModuleExports = require('babel-plugin-add-module-exports');
+
+compileModule(yargs.argv, (err) => {
+ if (err) throw err;
+})
+
+function compileModule(options, callback) {
+ const {file, output} = options;
+ const plugins = [
+ pluginModuleExports,
+ pluginCJS
+ ];
+
+ transformFile(file, {
+ babelrc: false,
+ ast: false,
+ plugins
+ }, (err, content) => {
+ if (err) return callback(err);
+ if (!output) {
+ process.stdout.write(content.code);
+ return callback();
+ }
+ fs.writeFile(output, content.code, callback)
+ })
+}
diff --git a/support/build/compile-modules.js b/support/build/compile-modules.js
deleted file mode 100644
index 16aa1ca..0000000
--- a/support/build/compile-modules.js
+++ /dev/null
@@ -1,45 +0,0 @@
-import async from '../../lib';
-import {transformFile} from 'babel-core';
-import _ from 'lodash';
-import readdirR from 'recursive-readdir';
-import pluginCJS from 'babel-plugin-transform-es2015-modules-commonjs';
-import pluginModuleExports from 'babel-plugin-add-module-exports';
-import pluginLodashImportRename from './plugin-lodash-import-rename';
-import {join as joinPath} from 'path';
-import fs from 'fs-extra';
-
-export default function(cb, options) {
- options = _.defaults({}, options, {
- path:'lib/',
- outpath:'build',
- es6: false,
- lodashRename: false
- });
- let plugins = [];
-
- if (options.lodashRename) {
- plugins.push(pluginLodashImportRename);
- }
- if (!options.es6) {
- plugins.push(pluginModuleExports);
- plugins.push(pluginCJS);
- }
-
- readdirR(options.path, [], function(err, files) {
- fs.emptyDirSync(options.outpath);
- fs.emptyDirSync(joinPath(options.outpath, 'internal'));
- async.each(files, (file, callback) => {
- let filename = file.startsWith(options.path) ?
- file.slice(options.path.length) :
- file;
-
- transformFile(file, {
- babelrc: false,
- plugins: plugins
- }, function(err, content) {
- let outpath = joinPath(options.outpath, filename);
- fs.writeFile(outpath, content.code, callback);
- });
- }, cb);
- });
-}
diff --git a/support/build/modules-cjs.js b/support/build/modules-cjs.js
deleted file mode 100644
index 09632ff..0000000
--- a/support/build/modules-cjs.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import compileModules from './compile-modules';
-
-compileModules(function() {}, {es6: false});
diff --git a/support/build/plugin-lodash-import-rename.js b/support/build/plugin-lodash-import-rename.js
deleted file mode 100644
index 6fe893b..0000000
--- a/support/build/plugin-lodash-import-rename.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import _ from 'lodash';
-import {dirname, sep} from 'path';
-
-export default function() {
- return {
- visitor: {
-
- ImportDeclaration(path, mapping) {
- let {node} = path;
- let {value} = node.source;
-
- if (/\blodash\b/.test(value)) {
- let f = mapping.file.opts.filename;
- let dir = dirname(f).split(sep);
- let relative = _.repeat('../', dir.length + 1);
-
- node.source.value = value.replace(
- /\blodash\b/,
- relative + 'node_modules/lodash-es');
- }
- }
- }
- };
-}
diff --git a/support/es.test.js b/support/es.test.js
index 9f7fd5e..3dbb7d6 100644
--- a/support/es.test.js
+++ b/support/es.test.js
@@ -1,8 +1,10 @@
// simple async example to test ES module build output
import {waterfall as waterfall} from "../build-es/index";
+import {wrapSync} from "../build-es/index";
import async from "../build-es/index";
import constant from "../build-es/constant";
+import forEachOf from "../build-es/forEachOf";
waterfall([
constant(42),
@@ -10,6 +12,19 @@ waterfall([
async.setImmediate(function () {
next(null, val);
});
+ },
+ wrapSync(function (a) { return a; }),
+ function (val, next) {
+ async.forEachOf({a: 1}, function (val, key, cb) {
+ if (val !== 1 && key !== 'a') return cb(new Error('fail!'));
+ cb();
+ }, function (err) { next (err, val)});
+ },
+ function (val, next) {
+ forEachOf([1, 2, 3], function (v, key, cb) {
+ val += key
+ cb()
+ }, function (err) { next(err, val - 3) })
}
], function (err, result) {
if (err) { throw err; }
diff --git a/support/generate-index.js b/support/generate-index.js
new file mode 100644
index 0000000..4154d03
--- /dev/null
+++ b/support/generate-index.js
@@ -0,0 +1,66 @@
+#!/usr/bin/env node
+'use strict'
+
+const fs = require('fs')
+const path = require('path')
+require('babel-core/register')
+const autoInject = require('../lib/autoInject').default
+
+generateIndex(err => {
+ if (err) throw err
+})
+
+function generateIndex(cb) {
+ autoInject({
+ entries: cb => readEntries(cb),
+ aliases: cb => cb(null, require('./aliases')),
+ template: cb => fs.readFile(path.join(__dirname, './index-template.js'), 'utf8', cb),
+ generated: (entries, aliases, template, cb) => {
+ cb(null, renderTemplate(entries, aliases, template))
+ }
+ }, (err, results) => {
+ if (err) return cb(err)
+ console.log(results.generated)
+ })
+}
+
+function readEntries (cb) {
+ const libDir = path.join(__dirname, '../lib')
+ fs.readdir(libDir, (err, files) => {
+ if (err) return cb(err)
+ cb(null, files
+ .map(file => path.basename(file, '.js'))
+ .filter(file => !file.match(/(^(index|internal)$)/)))
+ })
+}
+
+function renderTemplate(entries, aliases, template) {
+ return template
+ .replace(
+ `/*__imports__*/`,
+ entries
+ .map(entry => `import ${entry} from './${entry}'`)
+ .join('\n'))
+ .replace(
+ `/*__default_object__*/`,
+ entries
+ .map(entry => ` ${entry}: ${entry}`)
+ .join(',\n') + ',')
+
+ .replace(
+ `/*__default_aliases__*/`,
+ Object.keys(aliases)
+ .map(alias => ` ${alias}: ${aliases[alias]}`)
+ .join(',\n'))
+ .replace(
+ `/*__exports__*/`,
+ entries
+ .map(entry => ` ${entry} as ${entry}`)
+ .join(',\n') + ',')
+
+ .replace(
+ `/*__alias_exports__*/`,
+ Object.keys(aliases)
+ .map(alias => ` ${aliases[alias]} as ${alias}`)
+ .join(',\n'))
+}
diff --git a/support/get-alias.js b/support/get-alias.js
new file mode 100644
index 0000000..0323fc0
--- /dev/null
+++ b/support/get-alias.js
@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+const path = require('path')
+const aliases = require('./aliases.json')
+
+const toAlias = process.argv[2]
+const baseName = path.basename(toAlias, '.js')
+
+const alias = aliases[baseName] || baseName
+
+process.stdout.write(toAlias
+ .replace(/^[^/]+\//, 'lib/')
+ .replace(baseName, alias))
diff --git a/support/index-template.js b/support/index-template.js
new file mode 100644
index 0000000..58ba867
--- /dev/null
+++ b/support/index-template.js
@@ -0,0 +1,80 @@
+/**
+ * An "async function" in the context of Async is an asynchronous function with
+ * a variable number of parameters, with the final parameter being a callback.
+ * (`function (arg1, arg2, ..., callback) {}`)
+ * The final callback is of the form `callback(err, results...)`, which must be
+ * called once the function is completed. The callback should be called with a
+ * Error as its first argument to signal that an error occurred.
+ * Otherwise, if no error occurred, it should be called with `null` as the first
+ * argument, and any additional `result` arguments that may apply, to signal
+ * successful completion.
+ * The callback must be called exactly once, ideally on a later tick of the
+ * JavaScript event loop.
+ *
+ * This type of function is also referred to as a "Node-style async function",
+ * or a "continuation passing-style function" (CPS). Most of the methods of this
+ * library are themselves CPS/Node-style async functions, or functions that
+ * return CPS/Node-style async functions.
+ *
+ * Wherever we accept a Node-style async function, we also directly accept an
+ * [ES2017 `async` function]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function}.
+ * In this case, the `async` function will not be passed a final callback
+ * argument, and any thrown error will be used as the `err` argument of the
+ * implicit callback, and the return value will be used as the `result` value.
+ * (i.e. a `rejected` of the returned Promise becomes the `err` callback
+ * argument, and a `resolved` value becomes the `result`.)
+ *
+ * Note, due to JavaScript limitations, we can only detect native `async`
+ * functions and not transpilied implementations.
+ * Your environment must have `async`/`await` support for this to work.
+ * (e.g. Node > v7.6, or a recent version of a modern browser).
+ * If you are using `async` functions through a transpiler (e.g. Babel), you
+ * must still wrap the function with [asyncify]{@link module:Utils.asyncify},
+ * because the `async function` will be compiled to an ordinary function that
+ * returns a promise.
+ *
+ * @typedef {Function} AsyncFunction
+ * @static
+ */
+
+/**
+ * Async is a utility module which provides straight-forward, powerful functions
+ * for working with asynchronous JavaScript. Although originally designed for
+ * use with [Node.js](http://nodejs.org) and installable via
+ * `npm install --save async`, it can also be used directly in the browser.
+ * @module async
+ * @see AsyncFunction
+ */
+
+
+/**
+ * A collection of `async` functions for manipulating collections, such as
+ * arrays and objects.
+ * @module Collections
+ */
+
+/**
+ * A collection of `async` functions for controlling the flow through a script.
+ * @module ControlFlow
+ */
+
+/**
+ * A collection of `async` utility functions.
+ * @module Utils
+ */
+
+/*__imports__*/
+
+export default {
+/*__default_object__*/
+
+ // aliases
+/*__default_aliases__*/
+};
+
+export {
+/*__exports__*/
+
+ // Aliases
+/*__alias_exports__*/
+};
diff --git a/support/jsdoc/theme/tmpl/layout.tmpl b/support/jsdoc/theme/tmpl/layout.tmpl
index 631efa4..a5a3421 100644
--- a/support/jsdoc/theme/tmpl/layout.tmpl
+++ b/support/jsdoc/theme/tmpl/layout.tmpl
@@ -41,6 +41,7 @@
</li>
<li><a href="./index.html">Home</a></li>
<li><a href="./docs.html">Docs</a></li>
+ <li><a href="https://github.com/caolan/async/blob/master/CHANGELOG.md">Changelog</a></li>
<li><a href="https://github.com/caolan/async"><i class="ion-social-github" aria-hidden="true"></i></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
diff --git a/support/list-aliases.js b/support/list-aliases.js
new file mode 100644
index 0000000..d1eeed5
--- /dev/null
+++ b/support/list-aliases.js
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+const path = require('path')
+const yargs = require('yargs')
+const aliases = require('./aliases')
+
+const argv = yargs
+ .option('sources', {
+ type: 'boolean',
+ default: false
+ })
+ .argv
+
+const prefix = argv._[0] || 'build-es/'
+
+const targets = Object.keys(aliases).map(argv.sources ? expandSource : expandAlias)
+process.stdout.write(targets.join(' '))
+
+
+function expandAlias (alias) {
+ return path.join(prefix, `${alias}.js`)
+}
+
+function expandSource (alias) {
+ return path.join(prefix, `${aliases[alias]}.js`)
+}
diff --git a/support/sync-cjs-package.js b/support/sync-cjs-package.js
index 7db78b0..1ef530d 100755
--- a/support/sync-cjs-package.js
+++ b/support/sync-cjs-package.js
@@ -6,5 +6,3 @@ var json = JSON.parse(fs.readFileSync(__dirname + "/../package.json"), "utf8");
delete json.dependencies["lodash-es"];
process.stdout.write(JSON.stringify(json, null, 2));
-
-
diff --git a/support/sync-es-package.js b/support/sync-es-package.js
index bb72f47..e6c8aa6 100755
--- a/support/sync-es-package.js
+++ b/support/sync-es-package.js
@@ -5,10 +5,8 @@ var json = JSON.parse(fs.readFileSync(__dirname + "/../package.json"), "utf8");
json.name = "async-es";
json.main = "index.js";
+json.sideEffects = false;
delete json.dependencies["lodash"];
-delete json.volo;
-delete json.spm;
-delete json.jam;
process.stdout.write(JSON.stringify(json, null, 2));