diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index ff2cda0..1d2e051 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -7,8 +7,9 @@ jobs: strategy: matrix: node-version: - - 10.x - 12.x + - 14.x + - 16.x steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 18f10ab..9c78e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ faucet-pipeline-js version history ================================== +v3.0.0 +------ + +_unreleased_ + +* Switch from rollup to esbuild +* Support for TypeScript, JSX and minification built-in (no plugin required) +* ESM is the default output format +* `--compact` defaults to minify, mangle remains opt-in +* Drop support for: + * transpilation to pre-ES6 code + * UMD, CJS and IIFE output format (only ESM is supported) + + v2.1.6 ------ diff --git a/README.md b/README.md index cc7e1b2..74981f9 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,7 @@ Contributing Release Process --------------- -1. ensure dependencies are up to date (→ `./bin/update-pkg`) -2. ensure all meta-packages use the same version number (i.e. - `pkg/*/package.json`, both WRT `version` field and faucet-js `dependencies`) -3. `./bin/release`, skipping dependencies' installation (due to meta-packages; - thus the manual first step) +Run `./release` License diff --git a/bin/release b/bin/release deleted file mode 100755 index 5759988..0000000 --- a/bin/release +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -. ./node_modules/release-util-fnd/lib.sh - -root=`dirname $0` -root=`realpath "$root/.."` - -skip=${SKIP_UPDATES:-""} -if [ -z "$skip" ]; then - "$root/bin/update-pkg" -fi - -# ensure meta-packages are in sync and up to date -version=`determine_version "."` -packages=`find "$root/pkg" -type d -d 1` -for dir in $packages; do - package=`basename $dir` - _version=`determine_version "./pkg/$package"` - if [ "$_version" != "$version" ]; then - abort "version mismatch in $package" - fi - unset _version -done -"$root/bin/validate-dependencies" faucet-pipeline-js $packages -unset version - -skip=${SKIP_CHECKS:-""} -if [ -z "$skip" ]; then - pre_release_checks -fi -npm test - -target_dir=`create_package` -# remove meta-packages -rm -r "$target_dir/pkg" - -publish_package -for dir in $packages; do - (cd "$dir"; echo "about to publish `basename $dir`"; npm publish) -done diff --git a/bin/update-pkg b/bin/update-pkg deleted file mode 100755 index 39fc057..0000000 --- a/bin/update-pkg +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -root=`dirname $0` -root="$root/.." -root=`node -r fs -p "fs.realpathSync(process.argv[1]);" "$root"` - -abort() { - message="$@" - - echo "$message" >&2 - exit 1 -} - -which ncu || abort "ERROR: npm-check-updates missing" - -echo "==== updating faucet-pipeline-js ====" >&2 -(cd "$root"; ncu -u) - -for dir in `find "$root/pkg" -type d -d 1`; do - echo "==== updating `basename $dir` ====" >&2 - (cd "$dir"; ncu -u) -done - -echo -cat << EOF -NB: in order to ensure compatibility across faucet plugins, please only \ -increase the version number of faucet-pipeline-core when necessary -EOF -echo -read -n1 -p "press any key to acknowledge" confirmation diff --git a/bin/validate-dependencies b/bin/validate-dependencies deleted file mode 100755 index 2bfe125..0000000 --- a/bin/validate-dependencies +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env node -"use strict"; - -// this script ensures that any candidate package referenced as dependency -// within a meta-package matches the reference version - -let path = require("path"); - -let root = path.resolve(__dirname, ".."); -let { version } = require(`${root}/package.json`); - -let candidates = process.argv.slice(2); -let metaPackages = candidates.slice(1); - -metaPackages.forEach(metaPackage => { // NB: excludes main package - metaPackage = path.basename(metaPackage); - getDependencyGroups(`${root}/pkg/${metaPackage}`).forEach(dependencies => { - candidates.forEach(candidate => { - let versionRange = dependencies[candidate]; - let valid = versionRange === undefined || versionRange === version; - if(!valid) { - console.error(`dependency version mismatch: ${metaPackage} requires ` + - `${candidate} ${versionRange}, expected ${version}`); - process.exit(1); - } - }); - }); -}); - -function getDependencyGroups(directory) { - let meta = require(`${directory}/package.json`); - return Object.keys(meta). - filter(key => /[dD]ependencies$/.test(key)). - map(section => meta[section]); -} diff --git a/greenkeeper.json b/greenkeeper.json deleted file mode 100644 index 1600f9a..0000000 --- a/greenkeeper.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "groups": { - "default": { - "packages": [ - "package.json", - "pkg/faucet-pipeline-esnext/package.json", - "pkg/faucet-pipeline-jsx/package.json", - "pkg/faucet-pipeline-typescript/package.json", - "pkg/faucet-pipeline-jsmin/package.json" - ] - } - } -} diff --git a/lib/bundle.js b/lib/bundle.js new file mode 100644 index 0000000..7c34fcf --- /dev/null +++ b/lib/bundle.js @@ -0,0 +1,41 @@ +"use strict"; + +let esbuild = require("esbuild"); +let { abort } = require("faucet-pipeline-core/lib/util"); + +module.exports = class Bundle { + constructor(entryPoint, target, { format, fingerprint, compact, jsx }) { + if(format && format !== "esm") { + abort(`Unsupported format ${format}`); + } + + this.target = target; + this.fingerprint = fingerprint; + + this.config = { + entryPoints: [entryPoint], + bundle: true, + format: "esm", + write: false, + charset: "utf8", + metafile: true, + minifyWhitespace: !!compact, + minifyIdentifiers: compact === "mangle", + outdir: "out", + jsxFactory: jsx && jsx.pragma, + jsxFragment: jsx && jsx.fragment + }; + } + + // TODO: skip if files are not relevant + // via: Object.keys(res.metafile.inputs); + async compile(filepaths) { + let result = esbuild.buildSync(this.config); + + // TODO: write error if error occurred + // TODO: outputFiles is an array of all files that would have been written + return { + code: result.outputFiles[0].text + }; + } +}; diff --git a/lib/bundle/babel.js b/lib/bundle/babel.js deleted file mode 100644 index 2940fc9..0000000 --- a/lib/bundle/babel.js +++ /dev/null @@ -1,51 +0,0 @@ -"use strict"; - -let { loadExtension } = require("faucet-pipeline-core/lib/util"); - -module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browsers }) { - let settings = { - babelHelpers: "bundled" - }; - let plugins = []; - let extensions = []; - - if(exclude) { - settings.exclude = exclude.map(pkg => { - // distinguish paths from package identifiers - as per Node's - // resolution algorithm , a - // string is a path if it begins with `/`, `./` or `../` - // FIXME: duplicates faucet-core's `resolvePath`, resulting in - // inconsistency WRT working directory - return /^\.{0,2}\//.test(pkg) ? pkg : `node_modules/${pkg}/**`; - }); - } - - if(esnext) { - settings.presets = [ - ["@babel/preset-env", { - modules: false, - targets: { - browsers: browsers || [] - } - }] - ]; - } - - if(jsx) { - extensions.push(".jsx"); - let { pragma, pragmaFrag } = jsx; - plugins.push(["@babel/plugin-transform-react-jsx", - { pragma, pragmaFrag }]); - } - - if(plugins.length) { - settings.plugins = plugins; - } - - let babel = loadExtension("@rollup/plugin-babel", - "failed to activate ESNext transpiler", "faucet-pipeline-esnext"); - return { - plugin: babel.default(settings), - extensions - }; -}; diff --git a/lib/bundle/basic.js b/lib/bundle/basic.js deleted file mode 100644 index 6c9d495..0000000 --- a/lib/bundle/basic.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; - -let generateBundle = require("./bundler"); -let generateConfig = require("./config"); -let { generateError } = require("../util"); - -let DEFAULTS = { - format: "iife" -}; - -module.exports = class BasicBundle { - constructor(config, { browsers, plugins }) { - config = Object.assign({}, DEFAULTS, config); - this._config = generateConfig(config, { browsers }); - } - - compile(entryPoint) { - return generateBundle(entryPoint, this._config, this._cache). - then(({ code, modules, cache }) => { - this._modules = modules; // XXX: only required for non-basic bundles - this._cache = cache; - return { code }; - }, err => ({ - // also report error from within bundle, to avoid it being overlooked - code: generateError(err), - error: err - })); - } -}; diff --git a/lib/bundle/bundler.js b/lib/bundle/bundler.js deleted file mode 100644 index f0fb301..0000000 --- a/lib/bundle/bundler.js +++ /dev/null @@ -1,35 +0,0 @@ -let rollup = require("rollup"); - -let SMPREFIX = "//# sourceMappingURL="; - -module.exports = function generateBundle(entryPoint, config, cache) { - let { readConfig, writeConfig } = config; - let options = Object.assign({}, readConfig, { - input: entryPoint, - cache - }); - return rollup.rollup(options). - then(bundle => { - cache = bundle; - return bundle.generate(writeConfig); - }). - then(({ output }) => { - if(output.length !== 1) { // just to be safe - throw new Error("unexpected chunking"); - } - - let { code, map, modules } = output[0]; - return { - code: map ? `${code}\n${SMPREFIX}${map.toUrl()}\n` : code, - modules: collectModulePaths(modules), - cache - }; - }); -}; - -function collectModulePaths(modules) { - return Object.keys(modules).reduce((memo, id) => { - // skip plugin helper modules (`"\0"` prefix is a Rollup convention) - return /\0/.test(id) ? memo : memo.add(id); - }, new Set()); -} diff --git a/lib/bundle/config.js b/lib/bundle/config.js deleted file mode 100644 index aa4fde9..0000000 --- a/lib/bundle/config.js +++ /dev/null @@ -1,184 +0,0 @@ -/* eslint-disable object-curly-newline */ -"use strict"; - -let generateTranspiler = require("./babel"); -let { loadExtension, abort, repr } = require("faucet-pipeline-core/lib/util"); -let commonjs = require("@rollup/plugin-commonjs"); -let { nodeResolve } = require("@rollup/plugin-node-resolve"); - -let MODULE_FORMATS = { // maps faucet identifiers to Rollup identifiers - esm: true, - es: "esm", // alias - es6: "esm", // alias - umd: true, - amd: true, - commonjs: "cjs", - cjs: false, // deprecated in favor of `commonjs` - iife: true -}; -let NAMELESS_MODULES = new Set(["es", "amd", "cjs"]); // NB: Rollup identifiers - -module.exports = generateConfig; - -// generates Rollup configuration -// * `extensions` is a list of additional file extensions for loading modules -// (e.g. `[".jsx"]`) -// * `externals` determines which modules/packages to exclude from the bundle -// (e.g. `{ jquery: "jQuery" }` - the key refers to the respective -// module/package name, the value refers to a corresponding global variable) -// * `format` determines the bundle format: ES, UMD, AMD, CommonJS or IIFE -// (case-insensitive, defaults to IIFE) -// * `exports` determines the bundle's API, as per the entry point's exported -// value (if any) -// * `esnext`, if truthy, activates ESNext transpilation -// * `esnext.browserslist` is the name of the Browserslist group to select - -// if `false`, this suppresses automatic configuration via Browserslist -// * `esnext.exclude` is a list of modules for which to skip transpilation -// (e.g. `esnext: { exclude: ["jquery"] }`, perhaps due to a distribution -// already optimized for ES5) -// * `jsx`, if truthy, activates JSX transpilation -// * `jsx.pragma` determines the function to use for JSX expressions -// (e.g. `jsx: { pragma: "createElement" }`) -// * `jsx.fragment` determines the function to use for JSX fragments -// (e.g. `jsx: { fragment: "Fragment" }`) -// * additionally accepts the same options as `esnext` -// * `typescript`, if truthy, activates TypeScript transpilation - anything -// other than `true` will be passed through as TypeScript compiler options -// * `sourcemaps`, if truthy, activates inline source-map generation -// * `compact`, if truthy, compresses the bundle's code - see `determineCompacting` -// for compression levels, determined by the respective value -function generateConfig({ extensions = [], // eslint-disable-next-line indent - externals, format, exports, // eslint-disable-next-line indent - esnext, jsx, typescript, // eslint-disable-next-line indent - sourcemaps, sourcemap, compact }, { browsers }) { - if(sourcemap !== undefined) { // for backwards compatibility (explicit error) - abort(`ERROR: ${repr("sourcemap", false)} has been deprecated in ` + - `favor of ${repr("sourcemaps", false)}`); - } - - let cfg = { sourcemap: sourcemaps }; - let plugins = []; - - if(esnext || jsx) { - let transpiler = Object.assign({}, esnext, jsx); - if(esnext) { - transpiler.esnext = true; - } - if(jsx) { - // just to be safe, discard JSX-specifics on parent object - delete transpiler.pragma; - delete transpiler.fragment; - - transpiler.jsx = selectiveAssign({}, { - pragma: jsx.pragma, - pragmaFrag: jsx.fragment - }); - } - - let { browserslist } = transpiler; - browsers = browserslist === false ? null : browsers[browserslist || "defaults"]; - if(browsers && browsers.length) { - console.error("transpiling JavaScript for", browsers.join(", ")); - } - - let { plugin, extensions: ext } = generateTranspiler(transpiler, { browsers }); - extensions = ext.concat(extensions); - plugins.push(plugin); - } - if(typescript) { - let ts = loadExtension("@rollup/plugin-typescript", - "failed to activate TypeScript", "faucet-pipeline-typescript"); - extensions.push(".ts"); - // TODO: provide defaults and abstractions for low-level options? - plugins.push(typescript === true ? ts() : ts(typescript)); - } - - let resolve = { - // NB: `jsnext:main` retained for backwards compatibility - mainFields: ["module", "jsnext:main", "main"] - }; - if(extensions.length) { - resolve.extensions = [".js"].concat(extensions); - } - - plugins = plugins.concat([ - nodeResolve(resolve), - commonjs({ include: "node_modules/**" }) - ]); - if(compact) { - cfg.compact = true; - plugins = plugins.concat(determineCompacting(compact)); - } - cfg.plugins = plugins; - - cfg.format = determineModuleFormat(format); - if(exports) { - if(NAMELESS_MODULES.has(format)) { - console.error(`WARNING: ${repr(format, false)} bundles ignore ` + - `${repr("exports", false)} configuration`); - } - cfg.name = exports; - } - - if(externals) { // excluded from bundle - cfg.external = Object.keys(externals); - cfg.globals = externals; - } - - // distinguish between (roughly) read and write settings - let read = ["external", "plugins"]; - return Object.keys(cfg).reduce((memo, key) => { - let type = read.includes(key) ? "readConfig" : "writeConfig"; - memo[type][key] = cfg[key]; - return memo; - }, { - readConfig: {}, - writeConfig: { indent: false } - }); -} - -function determineModuleFormat(format = "iife") { - format = format.toLowerCase(); - let _format = MODULE_FORMATS[format]; - switch(_format) { - case undefined: - return abort(`unrecognized module format: ${repr(format)}`); - case false: - console.error(`WARNING: ${repr(format)} is deprecated`); - return format; - case true: - return format; - default: - return _format; - } -} - -function determineCompacting(type = true) { - switch(type) { - case true: // default - case "compact": - return require("rollup-plugin-cleanup")(); - case "minify": - var options = { compress: false, mangle: false }; // eslint-disable-line no-var - break; - case "mangle": - options = { compress: false, mangle: true }; - break; - default: - abort(`unknown compacting option ${type}`); - } - - let { terser } = loadExtension("rollup-plugin-terser", - "failed to activate minification", "faucet-pipeline-jsmin"); - return terser(options); -} - -// merges `source` properties into `target`, skipping `undefined` values -function selectiveAssign(target, source) { - Object.entries(source).forEach(([key, value]) => { - if(value !== undefined) { - target[key] = value; - } - }); - return target; -} diff --git a/lib/bundle/diskless.js b/lib/bundle/diskless.js deleted file mode 100644 index fc428b6..0000000 --- a/lib/bundle/diskless.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; - -let path = require("path"); - -let PREFIX = "diskless:"; - -// Rollup plugin for virtual modules -// `referenceDir` is used for relative imports from diskless modules -// `resolver` is the Rollup plugin responsible for import paths -// `modules` maps file names to source code -module.exports = (referenceDir, resolver, modules = new Map(), prefix = PREFIX) => ({ - name: "diskless", - resolveId(importee, importer) { - if(importer && importer.startsWith(prefix)) { - let virtual = path.resolve(referenceDir, importer); - // this is pretty hacky, but necessary because Rollup doesn't - // support combining different plugins' `#resolveId` - return resolver.resolveId(importee, virtual); - } - return importee.startsWith(prefix) ? importee : null; - }, - load(id) { - if(!id.startsWith(prefix)) { - return null; - } - - let filename = id.substr(prefix.length); - let source = modules.get(filename); - if(source === undefined) { - throw new Error(`missing diskless module: ${filename}`); - } - return source; - }, - register(filename, source) { - modules.set(filename, source); - }, - deregister(filename) { - return modules.delete(filename); - }, - get prefix() { - return prefix; - } -}); diff --git a/lib/bundle/index.js b/lib/bundle/index.js deleted file mode 100644 index 08c9719..0000000 --- a/lib/bundle/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; - -let BasicBundle = require("./basic"); - -module.exports = class Bundle extends BasicBundle { - constructor(entryPoint, target, config, { browsers }) { - // extract bundle-specific fingerprinting, if any - config = Object.assign({}, config); - if(config.fingerprint !== undefined) { - var fingerprint = config.fingerprint; // eslint-disable-line no-var - delete config.fingerprint; - } - super(config, { browsers }); - - this.entryPoint = entryPoint; - this.target = target; - if(fingerprint !== undefined) { - this.fingerprint = fingerprint; - } - } - - // compiles the bundle - if a list of file paths is provided, compilation - // will be aborted unless the dependency graph includes any of those files - compile(filepaths) { - if(!filepaths) { // initial compilation - this._modules = new Set([this.entryPoint]); // XXX: awkward? - } - - let modules = this._modules; - if(filepaths && !filepaths.some(fp => modules.has(fp))) { - return false; - } - - return super.compile(this.entryPoint); - } -}; diff --git a/lib/bundle/virtual.js b/lib/bundle/virtual.js deleted file mode 100644 index 4d9bb28..0000000 --- a/lib/bundle/virtual.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; - -let BasicBundle = require("./basic"); -let diskless = require("./diskless"); -let crypto = require("crypto"); - -exports.VirtualBundle = class VirtualBundle extends BasicBundle { - constructor(referenceDir, config, { browsers }) { - super(config, { browsers }); - // inject diskless plugin, initializing it with existing resolver - // this is pretty convoluted, but necessary due to Rollup limitations - // (see diskless internals for details) - let { plugins } = this._config.readConfig; - let resolver = plugins.find(plugin => plugin.name === "node-resolve"); - let plugin = diskless(referenceDir, resolver); - plugins.unshift(plugin); - this.diskless = plugin; - } - - compile(source) { - let { diskless } = this; - // NB: unique-ish ID avoids potential race condition for concurrent - // access with identical sources - // TODO: does file extension matter? - let id = generateHash(new Date().getTime() + source); - let filename = `entry_point_${id}.js`; - - diskless.register(filename, source); - let cleanup = () => void diskless.deregister(filename); - - return super.compile(diskless.prefix + filename). - then(res => { - cleanup(); - return res; - }). - catch(err => { - cleanup(); - throw err; - }); - } -}; - -// XXX: duplicates private faucet-core's fingerprinting -function generateHash(str) { - let hash = crypto.createHash("md5"); - hash.update(str); - return hash.digest("hex"); -} diff --git a/lib/index.js b/lib/index.js index 0a4a1b9..7dc36d3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -35,7 +35,7 @@ function makeBundler(bundleConfig, assetManager, { browsers, compact, sourcemaps let { resolvePath } = assetManager; entryPoint = resolvePath(entryPoint); target = resolvePath(target, { enforceRelative: true }); - let bundle = new Bundle(entryPoint, target, config, { browsers }); + let bundle = new Bundle(entryPoint, target, config); let writer = makeWriter(bundle, assetManager); return filepaths => { diff --git a/lib/util.js b/lib/util.js deleted file mode 100644 index d5b8359..0000000 --- a/lib/util.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -let NOTIFY = '(typeof alert !== "undefined" ? alert : console.error)'; - -exports.generateError = err => { - let msg = `ERROR: ${err}`; - console.error(`✗ ${msg}`); - if(err.code) { // Rollup-augmented exception; emit in full detail - if(err.codeFrame) { // excerpt, provided by Babel - reportCodeFrame(err, "codeFrame"); - } else if(err.frame) { // excerpt, provided by Rollup - reportCodeFrame(err, "frame"); - } else { - console.error(err); - } - - let { url } = err; - if(url) { - console.error(`🔗 visit ${url} for details`); - } - } - return `${NOTIFY}("${msg.replace(/"/g, '\\"')}");`; -}; - -function reportCodeFrame(err, prop) { - let frame = err[prop]; - delete err[prop]; - console.error(err); - console.error(`\n${frame}\n`); -} diff --git a/package.json b/package.json index aef758f..365208f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "faucet-pipeline-js", - "version": "2.1.7", + "version": "3.0.0", "description": "JavaScript module bundling for faucet-pipeline", "author": "FND", "contributors": [ @@ -17,29 +17,20 @@ }, "main": "lib/index.js", "scripts": { - "test": "npm-run-all lint --parallel test:unit test:cli", + "test": "npm-run-all lint test:cli", "test:cli": "./test/cli/run", - "test:unit": "mocha test/unit/test_*.js", - "lint": "eslint --cache --ext .js --ext .jsx lib bin/validate-dependencies test/unit samples pkg && echo ✓" + "lint": "eslint --cache --ext .js --ext .jsx lib && echo ✓" }, "engines": { - "node": ">=8" + "node": ">=12" }, "dependencies": { - "@rollup/plugin-commonjs": "~16.0.0", - "@rollup/plugin-node-resolve": "~10.0.0", - "faucet-pipeline-core": "^1.4.0", - "rollup": "^2.33.3", - "rollup-plugin-cleanup": "~3.2.1" + "esbuild": "^0.12.1", + "faucet-pipeline-core": "^1.4.0" }, "devDependencies": { "eslint-config-fnd-jsx": "^1.8.0", - "faucet-pipeline-esnext": "file:pkg/faucet-pipeline-esnext", - "faucet-pipeline-jsmin": "file:pkg/faucet-pipeline-jsmin", - "faucet-pipeline-jsx": "file:pkg/faucet-pipeline-jsx", - "faucet-pipeline-typescript": "file:pkg/faucet-pipeline-typescript", "json-diff": "^0.5.4", - "mocha": "^8.2.1", "npm-run-all": "^4.1.5", "release-util-fnd": "^2.0.1" } diff --git a/pkg/faucet-pipeline-esnext/README.md b/pkg/faucet-pipeline-esnext/README.md deleted file mode 100644 index dff9b9f..0000000 --- a/pkg/faucet-pipeline-esnext/README.md +++ /dev/null @@ -1,2 +0,0 @@ -[faucet-pipeline](http://faucet-pipeline.org) plugin for transpiling ES6 and -beyond diff --git a/pkg/faucet-pipeline-esnext/package.json b/pkg/faucet-pipeline-esnext/package.json deleted file mode 100644 index 1cebb45..0000000 --- a/pkg/faucet-pipeline-esnext/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "faucet-pipeline-esnext", - "version": "2.1.7", - "description": "ES6 and beyond for faucet-pipeline", - "author": "FND", - "license": "Apache-2.0", - "homepage": "https://www.faucet-pipeline.org", - "repository": { - "type": "git", - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js.git" - }, - "bugs": { - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js/issues" - }, - "dependencies": { - "@babel/core": "~7.12.3", - "@babel/preset-env": "~7.12.1", - "@rollup/plugin-babel": "~5.2.1", - "faucet-pipeline-js": "2.1.7" - } -} diff --git a/pkg/faucet-pipeline-esnext/samples/.browserslistrc b/pkg/faucet-pipeline-esnext/samples/.browserslistrc deleted file mode 100644 index 49f49fc..0000000 --- a/pkg/faucet-pipeline-esnext/samples/.browserslistrc +++ /dev/null @@ -1 +0,0 @@ -IE 11 diff --git a/pkg/faucet-pipeline-esnext/samples/faucet.config.js b/pkg/faucet-pipeline-esnext/samples/faucet.config.js deleted file mode 100644 index dbacda3..0000000 --- a/pkg/faucet-pipeline-esnext/samples/faucet.config.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -module.exports = { - js: [{ - source: "./index.js", - target: "./dist/bundle.js", - esnext: true - }] -}; diff --git a/pkg/faucet-pipeline-esnext/samples/index.js b/pkg/faucet-pipeline-esnext/samples/index.js deleted file mode 100644 index 6821e3f..0000000 --- a/pkg/faucet-pipeline-esnext/samples/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import { log } from "./util"; - -log("hello world"); diff --git a/pkg/faucet-pipeline-esnext/samples/util.js b/pkg/faucet-pipeline-esnext/samples/util.js deleted file mode 100644 index 0301de0..0000000 --- a/pkg/faucet-pipeline-esnext/samples/util.js +++ /dev/null @@ -1,3 +0,0 @@ -export function log(level, message) { - console.log(`[${level}] ${message}`); // eslint-disable-line no-console -} diff --git a/pkg/faucet-pipeline-jsmin/README.md b/pkg/faucet-pipeline-jsmin/README.md deleted file mode 100644 index 82e5538..0000000 --- a/pkg/faucet-pipeline-jsmin/README.md +++ /dev/null @@ -1 +0,0 @@ -[faucet-pipeline](http://faucet-pipeline.org) plugin for JavaScript minification diff --git a/pkg/faucet-pipeline-jsmin/package.json b/pkg/faucet-pipeline-jsmin/package.json deleted file mode 100644 index a3761fc..0000000 --- a/pkg/faucet-pipeline-jsmin/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "faucet-pipeline-jsmin", - "version": "2.1.7", - "description": "JavaScript minification for faucet-pipeline", - "author": "FND", - "license": "Apache-2.0", - "homepage": "https://www.faucet-pipeline.org", - "repository": { - "type": "git", - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js.git" - }, - "bugs": { - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js/issues" - }, - "dependencies": { - "rollup-plugin-terser": "^7.0.2" - } -} diff --git a/pkg/faucet-pipeline-jsx/README.md b/pkg/faucet-pipeline-jsx/README.md deleted file mode 100644 index ffbc774..0000000 --- a/pkg/faucet-pipeline-jsx/README.md +++ /dev/null @@ -1 +0,0 @@ -[faucet-pipeline](http://faucet-pipeline.org) plugin for transpiling JSX diff --git a/pkg/faucet-pipeline-jsx/package.json b/pkg/faucet-pipeline-jsx/package.json deleted file mode 100644 index f318d5a..0000000 --- a/pkg/faucet-pipeline-jsx/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "faucet-pipeline-jsx", - "version": "2.1.7", - "description": "JSX for faucet-pipeline", - "author": "FND", - "license": "Apache-2.0", - "homepage": "https://www.faucet-pipeline.org", - "repository": { - "type": "git", - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js.git" - }, - "bugs": { - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js/issues" - }, - "dependencies": { - "@babel/plugin-transform-react-jsx": "~7.12.5", - "faucet-pipeline-esnext": "2.1.7" - } -} diff --git a/pkg/faucet-pipeline-jsx/samples/faucet.config.js b/pkg/faucet-pipeline-jsx/samples/faucet.config.js deleted file mode 100644 index bd48b82..0000000 --- a/pkg/faucet-pipeline-jsx/samples/faucet.config.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -module.exports = { - js: [{ - source: "./index.js", - target: "./dist/bundle.js", - jsx: { pragma: "createElement" } - }] -}; diff --git a/pkg/faucet-pipeline-jsx/samples/index.js b/pkg/faucet-pipeline-jsx/samples/index.js deleted file mode 100644 index 4480c10..0000000 --- a/pkg/faucet-pipeline-jsx/samples/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import render from "./template"; - -render("Hello World", "lorem ipsum"); diff --git a/pkg/faucet-pipeline-jsx/samples/template.jsx b/pkg/faucet-pipeline-jsx/samples/template.jsx deleted file mode 100644 index 6d90811..0000000 --- a/pkg/faucet-pipeline-jsx/samples/template.jsx +++ /dev/null @@ -1,6 +0,0 @@ -/* global createElement */ - -export default (title, desc) =>
-

{title}

-

{desc}

-
; diff --git a/pkg/faucet-pipeline-typescript/README.md b/pkg/faucet-pipeline-typescript/README.md deleted file mode 100644 index 2655496..0000000 --- a/pkg/faucet-pipeline-typescript/README.md +++ /dev/null @@ -1,2 +0,0 @@ -[faucet-pipeline](http://faucet-pipeline.org) plugin for compiling -[TypeScript](http://typescriptlang.org) diff --git a/pkg/faucet-pipeline-typescript/package.json b/pkg/faucet-pipeline-typescript/package.json deleted file mode 100644 index d2d353c..0000000 --- a/pkg/faucet-pipeline-typescript/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "faucet-pipeline-typescript", - "version": "2.1.7", - "description": "TypeScript for faucet-pipeline", - "author": "FND", - "contributors": [ - "Till Schulte-Coerne " - ], - "license": "Apache-2.0", - "homepage": "https://www.faucet-pipeline.org", - "repository": { - "type": "git", - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js.git" - }, - "bugs": { - "url": "https://github.com/faucet-pipeline/faucet-pipeline-js/issues" - }, - "dependencies": { - "@rollup/plugin-typescript": "~6.1.0", - "faucet-pipeline-js": "2.1.7", - "typescript": "~4.1.2" - } -} diff --git a/release b/release new file mode 100755 index 0000000..8402572 --- /dev/null +++ b/release @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eu + +. ./node_modules/release-util-fnd/lib.sh + +pre_release_checks +npm run test + +create_package > /dev/null +publish_package diff --git a/samples/faucet.config.js b/samples/faucet.config.js deleted file mode 100644 index ae22e71..0000000 --- a/samples/faucet.config.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; - -module.exports = { - js: [{ - source: "./index.js", - target: "./dist/bundle.js" - }] -}; diff --git a/samples/index.js b/samples/index.js deleted file mode 100644 index 6821e3f..0000000 --- a/samples/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import { log } from "./util"; - -log("hello world"); diff --git a/samples/util.js b/samples/util.js deleted file mode 100644 index 0301de0..0000000 --- a/samples/util.js +++ /dev/null @@ -1,3 +0,0 @@ -export function log(level, message) { - console.log(`[${level}] ${message}`); // eslint-disable-line no-console -} diff --git a/test/cli/run b/test/cli/run index 66cdeb7..46e508e 100755 --- a/test/cli/run +++ b/test/cli/run @@ -14,19 +14,15 @@ end begin "$root/test_basic" # once more with fingerprinting faucet --fingerprint - assert_identical "./dist/bundle-56a55e40e1b060b637dba590df3ff10b.js" "./expected.js" + assert_identical "./dist/bundle-f119f696e321180ef10ae365ccdbbe0b.js" "./expected.js" end -begin "$root/test_transpilation" - faucet - assert_identical "./dist/bundle.js" "./expected.js" -end - -begin "$root/test_sourcemap" - faucet --sourcemaps - assert_identical_sourcemap "./dist/bundle.js" "./expected.js" "./expected.js.map" - assert_identical_sourcemap "./dist/bundle_esnext.js" "./expected_esnext.js" "./expected_esnext.js.map" -end +# TODO: Add sourcemap support +# begin "$root/test_sourcemap" +# faucet --sourcemaps +# assert_identical_sourcemap "./dist/bundle.js" "./expected.js" "./expected.js.map" +# assert_identical_sourcemap "./dist/bundle_esnext.js" "./expected_esnext.js" "./expected_esnext.js.map" +# end begin "$root/test_jsx" faucet @@ -38,12 +34,13 @@ begin "$root/test_typescript" assert_identical "./dist/bundle.js" "./expected.js" end -begin "$root/test_browserslist" - faucet - assert_identical "./dist/bundle.js" "./expected.js" - assert_identical "./dist/bundle_alt.js" "./expected_legacy.js" - assert_identical "./dist/bundle_legacy.js" "./expected_legacy.js" -end +# TODO figure out which parts can be supported +# begin "$root/test_browserslist" +# faucet +# assert_identical "./dist/bundle.js" "./expected.js" +# assert_identical "./dist/bundle_alt.js" "./expected_legacy.js" +# assert_identical "./dist/bundle_legacy.js" "./expected_legacy.js" +# end begin "$root/test_multi" faucet @@ -64,30 +61,15 @@ end begin "$root/test_fingerprinting" faucet --fingerprint - assert_identical "./dist/bundle-56a55e40e1b060b637dba590df3ff10b.js" "./expected.js" + assert_identical "./dist/bundle-f119f696e321180ef10ae365ccdbbe0b.js" "./expected.js" assert_identical "./dist/bundle_alt.js" "./expected.js" end -begin "$root/test_bundle_customization" - faucet - assert_identical "./dist/bundle_iife.js" "./expected_iife.js" - assert_identical "./dist/bundle_umd.js" "./expected_umd.js" - assert_identical "./dist/bundle_cjs.js" "./expected_cjs.js" -end - begin "$root/test_custom_config" faucet -c assets.js assert_identical "./dist/bundle.js" "./expected.js" end -begin "$root/test_compact" - faucet --compact - assert_identical "./dist/bundle.js" "./expected_compacted.js" - - faucet - assert_identical "./dist/bundle.js" "./expected_uncompacted.js" -end - begin "$root/test_minify" faucet --compact assert_identical "./dist/bundle.js" "./expected_compacted.js" diff --git a/test/cli/test_basic/expected.js b/test/cli/test_basic/expected.js index 3c42058..376402b 100644 --- a/test/cli/test_basic/expected.js +++ b/test/cli/test_basic/expected.js @@ -1,3 +1,5 @@ -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -console.log(`[…] ${util}`); +// src/index.js +console.log(`[…] ${util_default}`); diff --git a/test/cli/test_basic/faucet.config.js b/test/cli/test_basic/faucet.config.js index b2737b2..86b637e 100644 --- a/test/cli/test_basic/faucet.config.js +++ b/test/cli/test_basic/faucet.config.js @@ -5,8 +5,7 @@ let path = require("path"); module.exports = { js: [{ source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm" + target: "./dist/bundle.js" }], plugins: [path.resolve(__dirname, "../../..")] }; diff --git a/test/cli/test_browserslist/faucet.config.js b/test/cli/test_browserslist/faucet.config.js index 17959da..f8025b3 100644 --- a/test/cli/test_browserslist/faucet.config.js +++ b/test/cli/test_browserslist/faucet.config.js @@ -6,19 +6,16 @@ module.exports = { js: [{ source: "./src/index.js", target: "./dist/bundle.js", - format: "esm", esnext: true }, { source: "./src/index.js", target: "./dist/bundle_alt.js", - format: "esm", esnext: { browserslist: false } }, { source: "./src/index.js", target: "./dist/bundle_legacy.js", - format: "esm", esnext: { browserslist: "legacy" } diff --git a/test/cli/test_bundle_customization/expected_cjs.js b/test/cli/test_bundle_customization/expected_cjs.js deleted file mode 100644 index 323c4b3..0000000 --- a/test/cli/test_bundle_customization/expected_cjs.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -var index = _ => { - console.log("lipsum"); -}; - -module.exports = index; diff --git a/test/cli/test_bundle_customization/expected_iife.js b/test/cli/test_bundle_customization/expected_iife.js deleted file mode 100644 index 8e71d43..0000000 --- a/test/cli/test_bundle_customization/expected_iife.js +++ /dev/null @@ -1,10 +0,0 @@ -var MYLIB = (function () { -'use strict'; - -var index = _ => { - console.log("lipsum"); -}; - -return index; - -}()); diff --git a/test/cli/test_bundle_customization/expected_umd.js b/test/cli/test_bundle_customization/expected_umd.js deleted file mode 100644 index c6f7ebe..0000000 --- a/test/cli/test_bundle_customization/expected_umd.js +++ /dev/null @@ -1,13 +0,0 @@ -(function (global, factory) { -typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : -typeof define === 'function' && define.amd ? define(factory) : -(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MYLIB = factory()); -}(this, (function () { 'use strict'; - -var index = _ => { - console.log("lipsum"); -}; - -return index; - -}))); diff --git a/test/cli/test_bundle_customization/faucet.config.js b/test/cli/test_bundle_customization/faucet.config.js deleted file mode 100644 index d69a5b4..0000000 --- a/test/cli/test_bundle_customization/faucet.config.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; - -let path = require("path"); - -module.exports = { - js: [{ - source: "./src/index.js", - target: "./dist/bundle_umd.js", - format: "umd", - exports: "MYLIB" - }, { - source: "./src/index.js", - target: "./dist/bundle_iife.js", - exports: "MYLIB" - }, { - source: "./src/index.js", - target: "./dist/bundle_cjs.js", - format: "commonjs" - }], - plugins: [path.resolve(__dirname, "../../..")] -}; diff --git a/test/cli/test_bundle_customization/src/index.js b/test/cli/test_bundle_customization/src/index.js deleted file mode 100644 index d4800e8..0000000 --- a/test/cli/test_bundle_customization/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export default _ => { - console.log("lipsum"); -}; diff --git a/test/cli/test_compact/expected_compacted.js b/test/cli/test_compact/expected_compacted.js deleted file mode 100644 index 7177acc..0000000 --- a/test/cli/test_compact/expected_compacted.js +++ /dev/null @@ -1,7 +0,0 @@ -var util = "UTIL";function info() { - console.log(`[…] ${util}`); -} -function help() { - info(); -} -help(); \ No newline at end of file diff --git a/test/cli/test_compact/expected_uncompacted.js b/test/cli/test_compact/expected_uncompacted.js deleted file mode 100644 index d684add..0000000 --- a/test/cli/test_compact/expected_uncompacted.js +++ /dev/null @@ -1,14 +0,0 @@ -// dolor sit amet -var util = "UTIL"; - -// lorem ipsum -function info() { - console.log(`[…] ${util}`); -} - -// dolor sit amet -function help() { - info(); -} - -help(); diff --git a/test/cli/test_compact/faucet.config.js b/test/cli/test_compact/faucet.config.js deleted file mode 100644 index b2737b2..0000000 --- a/test/cli/test_compact/faucet.config.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; - -let path = require("path"); - -module.exports = { - js: [{ - source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm" - }], - plugins: [path.resolve(__dirname, "../../..")] -}; diff --git a/test/cli/test_compact/src/index.js b/test/cli/test_compact/src/index.js deleted file mode 100644 index c23ad61..0000000 --- a/test/cli/test_compact/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import util from "./util"; - -// lorem ipsum -function info() { - console.log(`[…] ${util}`); -} - -// dolor sit amet -function help() { - info(); -} - -help(); diff --git a/test/cli/test_compact/src/util.js b/test/cli/test_compact/src/util.js deleted file mode 100644 index 1178bcc..0000000 --- a/test/cli/test_compact/src/util.js +++ /dev/null @@ -1,2 +0,0 @@ -// dolor sit amet -export default "UTIL"; diff --git a/test/cli/test_custom_config/assets.js b/test/cli/test_custom_config/assets.js index c62fb69..dff6a34 100644 --- a/test/cli/test_custom_config/assets.js +++ b/test/cli/test_custom_config/assets.js @@ -5,8 +5,7 @@ let path = require("path"); module.exports = { js: [{ source: "./index.js", - target: "./dist/bundle.js", - format: "esm" + target: "./dist/bundle.js" }], plugins: [path.resolve(__dirname, "../../..")] }; diff --git a/test/cli/test_custom_config/expected.js b/test/cli/test_custom_config/expected.js index accefce..c78bdda 100644 --- a/test/cli/test_custom_config/expected.js +++ b/test/cli/test_custom_config/expected.js @@ -1 +1,2 @@ +// index.js console.log("Hello World"); diff --git a/test/cli/test_fingerprinting/expected.js b/test/cli/test_fingerprinting/expected.js index 3c42058..376402b 100644 --- a/test/cli/test_fingerprinting/expected.js +++ b/test/cli/test_fingerprinting/expected.js @@ -1,3 +1,5 @@ -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -console.log(`[…] ${util}`); +// src/index.js +console.log(`[…] ${util_default}`); diff --git a/test/cli/test_fingerprinting/faucet.config.js b/test/cli/test_fingerprinting/faucet.config.js index b147649..80c55e3 100644 --- a/test/cli/test_fingerprinting/faucet.config.js +++ b/test/cli/test_fingerprinting/faucet.config.js @@ -5,12 +5,10 @@ let path = require("path"); module.exports = { js: [{ source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm" + target: "./dist/bundle.js" }, { source: "./src/index.js", target: "./dist/bundle_alt.js", - format: "esm", fingerprint: false }], plugins: [path.resolve(__dirname, "../../..")] diff --git a/test/cli/test_jsx/expected.js b/test/cli/test_jsx/expected.js index cd36eab..6a074d1 100644 --- a/test/cli/test_jsx/expected.js +++ b/test/cli/test_jsx/expected.js @@ -1,14 +1,10 @@ -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -} - -var MyComponent = function MyComponent() { - _classCallCheck(this, MyComponent); +// src/component.js +var MyComponent = class { }; +var component_default = MyComponent; -var el = createElement(MyComponent, { +// src/index.jsx +var el = /* @__PURE__ */ createElement(component_default, { type: "dummy" -}, createElement("my-element", null, "lorem ipsum", createElement(Fragment, null, createElement("mark", null, "666"), "dolor sit amet"))); +}, /* @__PURE__ */ createElement("my-element", null, "lorem ipsum", /* @__PURE__ */ createElement(Fragment, null, /* @__PURE__ */ createElement("mark", null, "666"), "dolor sit amet"))); console.log(el); diff --git a/test/cli/test_jsx/faucet.config.js b/test/cli/test_jsx/faucet.config.js index 801b8b8..a6f5142 100644 --- a/test/cli/test_jsx/faucet.config.js +++ b/test/cli/test_jsx/faucet.config.js @@ -6,8 +6,6 @@ module.exports = { js: [{ source: "./src/index.jsx", target: "./dist/bundle.js", - format: "esm", - esnext: true, jsx: { pragma: "createElement", fragment: "Fragment" diff --git a/test/cli/test_mangle/expected_compacted.js b/test/cli/test_mangle/expected_compacted.js index 8b7fd0c..0f35192 100644 --- a/test/cli/test_mangle/expected_compacted.js +++ b/test/cli/test_mangle/expected_compacted.js @@ -1 +1 @@ -var n="UTIL";function o(){console.log(`[…] ${n}`)}function c(){o()}c(); \ No newline at end of file +var o="UTIL";function t(){console.log(`[…] ${o}`)}function i(){t()}i(); diff --git a/test/cli/test_mangle/expected_uncompacted.js b/test/cli/test_mangle/expected_uncompacted.js index d684add..4aacf11 100644 --- a/test/cli/test_mangle/expected_uncompacted.js +++ b/test/cli/test_mangle/expected_uncompacted.js @@ -1,14 +1,11 @@ -// dolor sit amet -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -// lorem ipsum +// src/index.js function info() { - console.log(`[…] ${util}`); + console.log(`[…] ${util_default}`); } - -// dolor sit amet function help() { - info(); + info(); } - help(); diff --git a/test/cli/test_mangle/faucet.config.js b/test/cli/test_mangle/faucet.config.js index 00eb476..f25bd3e 100644 --- a/test/cli/test_mangle/faucet.config.js +++ b/test/cli/test_mangle/faucet.config.js @@ -6,7 +6,6 @@ module.exports = { js: [{ source: "./src/index.js", target: "./dist/bundle.js", - format: "esm", compact: "mangle" }], plugins: [path.resolve(__dirname, "../../..")] diff --git a/test/cli/test_manifest/expected.json b/test/cli/test_manifest/expected.json index cbf549a..3530e02 100644 --- a/test/cli/test_manifest/expected.json +++ b/test/cli/test_manifest/expected.json @@ -1 +1 @@ -{"dist/bundle.js":"/assets/dist/bundle-6f9cdfdf5d45a70ad818b45090761ede.js"} +{"dist/bundle.js":"/assets/dist/bundle-d41d8cd98f00b204e9800998ecf8427e.js"} diff --git a/test/cli/test_manifest_uris/expected.json b/test/cli/test_manifest_uris/expected.json index 870488d..e15087a 100644 --- a/test/cli/test_manifest_uris/expected.json +++ b/test/cli/test_manifest_uris/expected.json @@ -1,4 +1 @@ -{ - "dist/foo.js":"/assets/foo-d252bfc59a9fd54bdd04535a90a0be25.js", - "dist/bar.js":"/assets/bar-913a3395880f817dd562e4adccf94168.js" -} +{"dist/bar.js":"/assets/bar-b378b3bd735c3d302dce83b141d97391.js","dist/foo.js":"/assets/foo-19bf26902b9b197de06e888a96568bc9.js"} diff --git a/test/cli/test_manifest_uris/faucet.config.js b/test/cli/test_manifest_uris/faucet.config.js index a58059d..c8e1e1c 100644 --- a/test/cli/test_manifest_uris/faucet.config.js +++ b/test/cli/test_manifest_uris/faucet.config.js @@ -8,8 +8,7 @@ module.exports = { target: "./dist/foo.js" }, { source: "./src/bar.js", - target: "./dist/bar.js", - esnext: true + target: "./dist/bar.js" }], manifest: { target: "./dist/manifest.json", diff --git a/test/cli/test_minify/expected_compacted.js b/test/cli/test_minify/expected_compacted.js index 552c621..00a07f8 100644 --- a/test/cli/test_minify/expected_compacted.js +++ b/test/cli/test_minify/expected_compacted.js @@ -1 +1 @@ -var util="UTIL";function info(){console.log(`[…] ${util}`)}function help(){info()}help(); \ No newline at end of file +var util_default="UTIL";function info(){console.log(`[…] ${util_default}`)}function help(){info()}help(); diff --git a/test/cli/test_minify/expected_uncompacted.js b/test/cli/test_minify/expected_uncompacted.js index d684add..4aacf11 100644 --- a/test/cli/test_minify/expected_uncompacted.js +++ b/test/cli/test_minify/expected_uncompacted.js @@ -1,14 +1,11 @@ -// dolor sit amet -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -// lorem ipsum +// src/index.js function info() { - console.log(`[…] ${util}`); + console.log(`[…] ${util_default}`); } - -// dolor sit amet function help() { - info(); + info(); } - help(); diff --git a/test/cli/test_minify/faucet.config.js b/test/cli/test_minify/faucet.config.js index 56ca414..86b637e 100644 --- a/test/cli/test_minify/faucet.config.js +++ b/test/cli/test_minify/faucet.config.js @@ -5,9 +5,7 @@ let path = require("path"); module.exports = { js: [{ source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm", - compact: "minify" + target: "./dist/bundle.js" }], plugins: [path.resolve(__dirname, "../../..")] }; diff --git a/test/cli/test_multi/expected_bar.js b/test/cli/test_multi/expected_bar.js index 57c2469..3695be1 100644 --- a/test/cli/test_multi/expected_bar.js +++ b/test/cli/test_multi/expected_bar.js @@ -1,3 +1,5 @@ -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -console.log("[BAR] ".concat(util)); +// src/bar.js +console.log(`[BAR] ${util_default}`); diff --git a/test/cli/test_multi/expected_foo.js b/test/cli/test_multi/expected_foo.js index 2efed80..17d6cc2 100644 --- a/test/cli/test_multi/expected_foo.js +++ b/test/cli/test_multi/expected_foo.js @@ -1,3 +1,5 @@ -var util = "UTIL"; +// src/util.js +var util_default = "UTIL"; -console.log(`[FOO] ${util}`); +// src/foo.js +console.log(`[FOO] ${util_default}`); diff --git a/test/cli/test_multi/faucet.config.js b/test/cli/test_multi/faucet.config.js index 5e5a402..f52c378 100644 --- a/test/cli/test_multi/faucet.config.js +++ b/test/cli/test_multi/faucet.config.js @@ -5,13 +5,10 @@ let path = require("path"); module.exports = { js: [{ source: "./src/foo.js", - target: "./dist/foo.js", - format: "esm" + target: "./dist/foo.js" }, { source: "./src/bar.js", - target: "./dist/bar.js", - format: "esm", - esnext: true + target: "./dist/bar.js" }], manifest: { target: "./dist/manifest.json", diff --git a/test/cli/test_sourcemap/faucet.config.js b/test/cli/test_sourcemap/faucet.config.js index 8f15cd9..4c8bb4e 100644 --- a/test/cli/test_sourcemap/faucet.config.js +++ b/test/cli/test_sourcemap/faucet.config.js @@ -5,13 +5,10 @@ let path = require("path"); module.exports = { js: [{ source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm" + target: "./dist/bundle.js" }, { source: "./src/index.js", - target: "./dist/bundle_esnext.js", - format: "esm", - esnext: true + target: "./dist/bundle_esnext.js" }], plugins: [path.resolve(__dirname, "../../..")] }; diff --git a/test/cli/test_transpilation/expected.js b/test/cli/test_transpilation/expected.js deleted file mode 100644 index 1fcf137..0000000 --- a/test/cli/test_transpilation/expected.js +++ /dev/null @@ -1,13 +0,0 @@ -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -} - -var Util = function Util() { - _classCallCheck(this, Util); -}; -var FOO = "lorem ipsum"; -var BAR = "dolor sit amet"; - -console.log("~~ ".concat(Util, " ~~ ").concat(FOO, " ~~ ").concat(BAR, " ~~")); diff --git a/test/cli/test_transpilation/faucet.config.js b/test/cli/test_transpilation/faucet.config.js deleted file mode 100644 index 0d06a8b..0000000 --- a/test/cli/test_transpilation/faucet.config.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; - -let path = require("path"); - -module.exports = { - js: [{ - source: "./src/index.js", - target: "./dist/bundle.js", - format: "esm", - esnext: true - }], - plugins: [path.resolve(__dirname, "../../..")] -}; diff --git a/test/cli/test_transpilation/src/index.js b/test/cli/test_transpilation/src/index.js deleted file mode 100644 index afb4485..0000000 --- a/test/cli/test_transpilation/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Util, { FOO, BAR } from "./util"; - -console.log(`~~ ${Util} ~~ ${FOO} ~~ ${BAR} ~~`); diff --git a/test/cli/test_transpilation/src/util.js b/test/cli/test_transpilation/src/util.js deleted file mode 100644 index f9fa1e9..0000000 --- a/test/cli/test_transpilation/src/util.js +++ /dev/null @@ -1,4 +0,0 @@ -export default class Util {} - -export const FOO = "lorem ipsum"; -export const BAR = "dolor sit amet"; diff --git a/test/cli/test_typescript/expected.js b/test/cli/test_typescript/expected.js index 3ea8fe9..0a0b3bd 100644 --- a/test/cli/test_typescript/expected.js +++ b/test/cli/test_typescript/expected.js @@ -1,35 +1,31 @@ -(function () { -'use strict'; - +// src/util.ts var LogLevel; -(function (LogLevel) { - LogLevel[LogLevel["Debug"] = 0] = "Debug"; - LogLevel[LogLevel["Info"] = 1] = "Info"; - LogLevel[LogLevel["Critical"] = 2] = "Critical"; +(function(LogLevel2) { + LogLevel2[LogLevel2["Debug"] = 0] = "Debug"; + LogLevel2[LogLevel2["Info"] = 1] = "Info"; + LogLevel2[LogLevel2["Critical"] = 2] = "Critical"; })(LogLevel || (LogLevel = {})); function log(level, msg) { - if (level === LogLevel.Critical) { - console.error(msg); - } - else { - console.log(msg); - } + if (level === 2) { + console.error(msg); + } else { + console.log(msg); + } } -var generateArticle = function (params) { - var title = params.title, authors = params.authors; - if (typeof title !== "string") { - log(LogLevel.Debug, "auto-generating title"); - title = title.main + ": " + title.sub; - } - return title + "\n" + authors.join(", "); +// src/index.ts +var generateArticle = (params) => { + let { title, authors } = params; + if (typeof title !== "string") { + log(LogLevel.Debug, "auto-generating title"); + title = `${title.main}: ${title.sub}`; + } + return title + "\n" + authors.join(", "); }; generateArticle({ - title: { - main: "Hello World", - sub: "sup" - }, - authors: ["foo", "bar"] + title: { + main: "Hello World", + sub: "sup" + }, + authors: ["foo", "bar"] }); - -}()); diff --git a/test/unit/expected/virtual_bundle_js1.js b/test/unit/expected/virtual_bundle_js1.js deleted file mode 100644 index a5fd37d..0000000 --- a/test/unit/expected/virtual_bundle_js1.js +++ /dev/null @@ -1,8 +0,0 @@ -(function () { -'use strict'; - -var UTIL = "UTIL"; - -console.log(UTIL); - -}()); diff --git a/test/unit/expected/virtual_bundle_js2.js b/test/unit/expected/virtual_bundle_js2.js deleted file mode 100644 index b25552a..0000000 --- a/test/unit/expected/virtual_bundle_js2.js +++ /dev/null @@ -1,10 +0,0 @@ -(function () { -'use strict'; - -var UTIL = "UTIL"; - -var MYLIB = "MY-LIB"; - -console.log(UTIL + MYLIB); - -}()); diff --git a/test/unit/expected/virtual_bundle_jsx.js b/test/unit/expected/virtual_bundle_jsx.js deleted file mode 100644 index 368d0ab..0000000 --- a/test/unit/expected/virtual_bundle_jsx.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var UTIL = "UTIL"; - -var MYLIB = "MY-LIB"; - -function createElement(tag, params, ...children) { - return `<${tag} ${JSON.stringify(params)}>${JSON.stringify(children)}`; -} - -function Button({ - type, - label -}) { - return createElement("button", { - type: type - }, label); -} -function List(_, ...children) { - return createElement("ul", null, children.map(item => createElement("li", null, item))); -} - -console.log(createElement(List, null, createElement(Button, { - label: UTIL -}), createElement(Fragment, null, createElement(Button, { - type: "reset", - label: MYLIB -})))); diff --git a/test/unit/fixtures/node_modules/dummy/src/index.js b/test/unit/fixtures/node_modules/dummy/src/index.js deleted file mode 100644 index 654313f..0000000 --- a/test/unit/fixtures/node_modules/dummy/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import util from "./util"; - -console.log(`[DUMMY] ${util}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/node_modules/dummy/src/util.js b/test/unit/fixtures/node_modules/dummy/src/util.js deleted file mode 100644 index a371f27..0000000 --- a/test/unit/fixtures/node_modules/dummy/src/util.js +++ /dev/null @@ -1 +0,0 @@ -export default "DUMMY-UTIL"; diff --git a/test/unit/fixtures/node_modules/my-lib/components.jsx b/test/unit/fixtures/node_modules/my-lib/components.jsx deleted file mode 100644 index 3b04aec..0000000 --- a/test/unit/fixtures/node_modules/my-lib/components.jsx +++ /dev/null @@ -1,13 +0,0 @@ -import createElement from "./elements"; - -export function Button({ type, label }) { - return ; -} - -export function List(_, ...children) { - return ; -} diff --git a/test/unit/fixtures/node_modules/my-lib/dist.js b/test/unit/fixtures/node_modules/my-lib/dist.js deleted file mode 100644 index f636882..0000000 --- a/test/unit/fixtures/node_modules/my-lib/dist.js +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable */ -(function(window) { - -var MYLIB = "MY-LIB"; - -if(typeof module !== "undefined" && typeof module.exports !== "undefined") { - module.exports = MYLIB; -} else if(typeof define === "function" && define.amd) { - define("my-lib", [], function() { - return MYLIB; - }); -} else if(typeof window === "object") { - window.MYLIB = MYLIB; -} - -}(this)); diff --git a/test/unit/fixtures/node_modules/my-lib/elements.js b/test/unit/fixtures/node_modules/my-lib/elements.js deleted file mode 100644 index 99c4f2d..0000000 --- a/test/unit/fixtures/node_modules/my-lib/elements.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function createElement(tag, params, ...children) { - return `<${tag} ${JSON.stringify(params)}>${JSON.stringify(children)}`; -} diff --git a/test/unit/fixtures/node_modules/my-lib/index.js b/test/unit/fixtures/node_modules/my-lib/index.js deleted file mode 100644 index 26a6862..0000000 --- a/test/unit/fixtures/node_modules/my-lib/index.js +++ /dev/null @@ -1 +0,0 @@ -export default "MY-LIB"; diff --git a/test/unit/fixtures/src/alt.js b/test/unit/fixtures/src/alt.js deleted file mode 100644 index eaffa18..0000000 --- a/test/unit/fixtures/src/alt.js +++ /dev/null @@ -1,3 +0,0 @@ -import MYLIB from "my-lib"; - -console.log(`[…] ${MYLIB}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/src/alt2.js b/test/unit/fixtures/src/alt2.js deleted file mode 100644 index c92d685..0000000 --- a/test/unit/fixtures/src/alt2.js +++ /dev/null @@ -1,3 +0,0 @@ -import MYLIB from "my-lib/dist"; - -console.log(`[…] ${MYLIB}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/src/helper.coffee b/test/unit/fixtures/src/helper.coffee deleted file mode 100644 index b642a37..0000000 --- a/test/unit/fixtures/src/helper.coffee +++ /dev/null @@ -1 +0,0 @@ -export default { foo: "lorem", bar: "ipsum" }; diff --git a/test/unit/fixtures/src/index.coffee b/test/unit/fixtures/src/index.coffee deleted file mode 100644 index 84ef08b..0000000 --- a/test/unit/fixtures/src/index.coffee +++ /dev/null @@ -1,3 +0,0 @@ -import helper from "./helper"; - -console.log(`[…] ${helper}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/src/index.js b/test/unit/fixtures/src/index.js deleted file mode 100644 index a945391..0000000 --- a/test/unit/fixtures/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import util from "./util"; - -console.log(`[…] ${util}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/src/lib.js b/test/unit/fixtures/src/lib.js deleted file mode 100644 index e8263f5..0000000 --- a/test/unit/fixtures/src/lib.js +++ /dev/null @@ -1,5 +0,0 @@ -import util from "./util"; - -export default msg => { - console.log(`[…] ${util} ${msg}`); // eslint-disable-line no-console -}; diff --git a/test/unit/fixtures/src/multiline.js b/test/unit/fixtures/src/multiline.js deleted file mode 100644 index c4a7220..0000000 --- a/test/unit/fixtures/src/multiline.js +++ /dev/null @@ -1,5 +0,0 @@ -let txt = `foo - -bar`; - -console.log(`[…] ${txt}`); // eslint-disable-line no-console diff --git a/test/unit/fixtures/src/util.js b/test/unit/fixtures/src/util.js deleted file mode 100644 index afc4747..0000000 --- a/test/unit/fixtures/src/util.js +++ /dev/null @@ -1 +0,0 @@ -export default "UTIL"; diff --git a/test/unit/test_bundling.js b/test/unit/test_bundling.js deleted file mode 100644 index 1b6f359..0000000 --- a/test/unit/test_bundling.js +++ /dev/null @@ -1,448 +0,0 @@ -/* global describe, it, beforeEach, afterEach */ -"use strict"; - -let { MockAssetManager, makeBundle, FIXTURES_DIR } = require("./util"); -let faucetJS = require("../../lib").plugin; -let path = require("path"); -let assert = require("assert"); - -let DEFAULT_OPTIONS = { - browsers: {} -}; - -describe("bundling", _ => { - let { exit } = process; - beforeEach(() => { - process.exit = code => { - throw new Error(`exit ${code}`); - }; - }); - afterEach(() => { - process.exit = exit; - }); - - it("should verify configuration", () => { - let config = [{}]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - let fn = _ => faucetJS(config, assetManager, DEFAULT_OPTIONS)(); - assert.throws(fn, /exit 1/); // aborts with "missing `source` configuration" - config[0].source = "./src/index.js"; - assert.throws(fn, /exit 1/); // aborts with "missing `target` configuration" - }); - - it("should combine ES6 modules into a bundle", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "UTIL"; - -console.log(\`[…] $\{util}\`); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should optionally transpile ES6 to ES5", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js", - esnext: true - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "UTIL"; - -console.log("[\\u2026] ".concat(util)); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should support skipping transpilation for select packages", () => { - let cwd = process.cwd(); - process.chdir(FIXTURES_DIR); // XXX: should not be test-specific!? - let restore = _ => process.chdir(cwd); - - let config = [{ - source: "./src/alt2.js", - target: "./dist/bundle.js", - esnext: { - exclude: ["my-lib"] - } - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(restore, restore). // XXX: hacky - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - /* eslint-disable max-len */ - content: makeBundle(` -function createCommonjsModule(fn, basedir, module) { - return module = { - path: basedir, - exports: {}, - require: function (path, base) { - return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); - } - }, fn(module, module.exports), module.exports; -} - -function commonjsRequire () { - throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); -} - -var dist = createCommonjsModule(function (module) { -/* eslint-disable */ -(function(window) { - -var MYLIB = "MY-LIB"; - -{ - module.exports = MYLIB; -} - -}()); -}); - -console.log("[\\u2026] ".concat(dist)); // eslint-disable-line no-console - `.trim()) - /* eslint-enable max-len */ - }]); - }); - }); - - it("should support custom file extensions", () => { - let config = [{ - source: "./src/index.coffee", - target: "./dist/bundle.js", - extensions: [".coffee"] - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var helper = { foo: "lorem", bar: "ipsum" }; - -console.log(\`[…] $\{helper}\`); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should support customizing bundle's API", () => { - let config = [{ - source: "./src/lib.js", - target: "./dist/bundle.js", - exports: "MYLIB" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: "var MYLIB = " + makeBundle(` -var util = "UTIL"; - -var lib = msg => { - console.log(\`[…] $\{util} $\{msg}\`); // eslint-disable-line no-console -}; - -return lib; - `.trim()) - }]); - }); - }); - - it("should support customizing bundle format", () => { - let config = [{ - source: "./src/lib.js", - target: "./dist/bundle.js", - format: "amd" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: ` -define(function () { 'use strict'; - -var util = "UTIL"; - -var lib = msg => { - console.log(\`[…] $\{util} $\{msg}\`); // eslint-disable-line no-console -}; - -return lib; - -}); - `.trim() + "\n" - }]); - }); - }); - - it("should support importing third-party packages", () => { - let config = [{ - source: "./src/alt.js", - target: "./dist/bundle.js" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var MYLIB = "MY-LIB"; - -console.log(\`[…] $\{MYLIB}\`); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should support excluding module/package references", () => { - let config = [{ - source: "./src/alt.js", - target: "./dist/bundle.js", - externals: { "my-lib": "MYLIB" } - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - return faucetJS(config, assetManager, DEFAULT_OPTIONS)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: ` -(function (MYLIB) { -'use strict'; - -function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } - -var MYLIB__default = /*#__PURE__*/_interopDefaultLegacy(MYLIB); - -console.log(\`[…] $\{MYLIB__default['default']}\`); // eslint-disable-line no-console - -}(MYLIB)); - `.trim() + "\n" - }]); - }); - }); - - it("should take into account Browserslist while transpiling", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js", - esnext: true - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - let browsers = { defaults: ["Chrome 63"] }; - return faucetJS(config, assetManager, { browsers })(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "UTIL"; - -console.log(\`[…] $\{util}\`); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should allow suppressing Browserslist auto-config while transpiling", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js", - esnext: { - browserslist: false - } - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - let browsers = { defaults: ["Chrome 63"] }; - return faucetJS(config, assetManager, { browsers })(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "UTIL"; - -console.log("[\\u2026] ".concat(util)); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should allow specifying an alternative Browserslist group", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js", - esnext: { - browserslist: "modern" - } - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - let browsers = { - defaults: ["IE 11"], - modern: ["Chrome 63"] - }; - return faucetJS(config, assetManager, { browsers })(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "UTIL"; - -console.log(\`[…] $\{util}\`); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should optionally compact bundle", () => { - let config = [{ - source: "./src/multiline.js", - target: "./dist/bundle.js" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - - let options = { browsers: {}, compact: true }; - return faucetJS(config, assetManager, options)(). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(`let txt = \`foo - -bar\`; -console.log(\`[…] $\{txt}\`); - `.trim(), { compact: true }) - }]); - - config[0].esnext = true; - assetManager = new MockAssetManager(FIXTURES_DIR); - return faucetJS(config, assetManager, options)(); - }). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var txt = "foo\\n\\nbar"; -console.log("[\\u2026] ".concat(txt)); - `.trim(), { compact: true }) - }]); - - config[0].compact = false; // overrides global option - assetManager = new MockAssetManager(FIXTURES_DIR); - return faucetJS(config, assetManager, options)(); - }). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var txt = "foo\\n\\nbar"; -console.log("[\\u2026] ".concat(txt)); // eslint-disable-line no-console - `.trim()) - }]); - }); - }); - - it("should balk at non-relative paths for target", () => { - let assetManager = new MockAssetManager(FIXTURES_DIR); - let entryPoint = "src/index.js"; - let target = "dist/bundle.js"; - let compile = (source, target) => faucetJS([{ source, target }], - assetManager, DEFAULT_OPTIONS)(); - - let fn = _ => compile(`./${entryPoint}`, target); - assert.throws(fn, /exit 1/); // aborts with "path must be relative" - - // non-relative path is acceptable for entry point, but a suitable - // package path does not exist - fn = _ => compile("dummy/src/does_not_exist.js", `./${target}`); - assert.throws(fn, /exit 1/); // aborts with "could not resolve" - - return compile(`./${entryPoint}`, `./${target}`); - }); - - it("should support Node resolution algorithm for entry point", () => { - let entryPoint = "dummy/src/index.js"; - let target = "./dist/bundle.js"; - let assetManager = new MockAssetManager(FIXTURES_DIR); - let compile = (source, target) => faucetJS([{ source, target }], - assetManager, DEFAULT_OPTIONS)(); - - return compile(entryPoint, target). - then(_ => { - assetManager.assertWrites([{ - filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), - content: makeBundle(` -var util = "DUMMY-UTIL"; - -console.log(\`[DUMMY] $\{util}\`); // eslint-disable-line no-console - `.trim()) - }]); - - let fn = _ => compile("dummy/src/does_not_exist.js", target); - assert.throws(fn, /exit 1/); // aborts with "could not resolve" - - fn = _ => compile(entryPoint, "dist/bundle.js"); - assert.throws(fn, /exit 1/); // aborts with "path must be relative" - }); - }); - - it("should build when the provided path is part of the bundle", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - let buildJS = faucetJS(config, assetManager, DEFAULT_OPTIONS); - let relevantModule = path.join(FIXTURES_DIR, "src/util.js"); - - return buildJS(). - then(_ => buildJS([relevantModule])). - then(_ => { - assetManager.assertWriteCount(2); - }); - }); - - it("should not build when the provided path is not part of the bundle", () => { - let config = [{ - source: "./src/index.js", - target: "./dist/bundle.js" - }]; - let assetManager = new MockAssetManager(FIXTURES_DIR); - let buildJS = faucetJS(config, assetManager, DEFAULT_OPTIONS); - let unusedModule = path.join(FIXTURES_DIR, "src/alt.js"); - - return buildJS(). - then(_ => buildJS([unusedModule])). - then(_ => { - assetManager.assertWriteCount(1); - }); - }); -}); diff --git a/test/unit/test_virtual.js b/test/unit/test_virtual.js deleted file mode 100644 index cffe6f9..0000000 --- a/test/unit/test_virtual.js +++ /dev/null @@ -1,67 +0,0 @@ -/* global describe, it */ -"use strict"; - -let { FIXTURES_DIR } = require("./util"); -let { VirtualBundle } = require("../../lib/bundle/virtual"); -let fs = require("fs"); -let path = require("path"); -let assert = require("assert"); - -let assertSame = assert.strictEqual; - -let DEFAULT_OPTIONS = { - browsers: {} -}; - -describe("virtual bundle", _ => { - it("should bundle JavaScript from a source string", async () => { - let bundle = new VirtualBundle(FIXTURES_DIR, null, DEFAULT_OPTIONS); - - let res = await bundle.compile(` -import UTIL from "./src/util"; - -console.log(UTIL); - `); - assertSame(res.error, undefined); - assertSame(res.code, expectedBundle("virtual_bundle_js1.js")); - - res = await bundle.compile(` -import UTIL from "./src/util"; -import MYLIB from "my-lib"; - -console.log(UTIL + MYLIB); - `); - assertSame(res.error, undefined); - assertSame(res.code, expectedBundle("virtual_bundle_js2.js")); - }); - - it("should support JSX", async () => { - let bundle = new VirtualBundle(FIXTURES_DIR, { - format: "CommonJS", - jsx: { - pragma: "createElement", - fragment: "Fragment" - } - }, DEFAULT_OPTIONS); - - let { code, error } = await bundle.compile(` -import UTIL from "./src/util"; -import MYLIB from "my-lib"; -import { Button, List } from "my-lib/components"; -import createElement from "my-lib/elements"; - -console.log( -