From 0c55a8533876007ebccf140e3274e3197e701274 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Thu, 30 Mar 2023 13:30:16 -0500 Subject: [PATCH 01/14] feat: use Rollup for bundling --- .gitignore | 1 + package.json | 9 ++++++++- rollup.config.js | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index 239ecff..cf762fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +dist yarn.lock diff --git a/package.json b/package.json index c622716..08c5500 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,15 @@ "type": "module", "exports": { "types": "./index.d.ts", - "default": "./source/index.js" + "default": "./dist/index.js" }, + "sideEffects": false, "engines": { "node": ">=16.10" }, "scripts": { + "prepublish": "npm run build", + "build": "rollup -c", "test": "xo && ava && tsd" }, "files": [ @@ -59,11 +62,15 @@ "yargs-parser": "^21.1.1" }, "devDependencies": { + "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-json": "^6.0.0", + "@rollup/plugin-node-resolve": "^15.0.1", "ava": "^5.2.0", "common-tags": "^1.8.2", "execa": "^7.1.1", "indent-string": "^5.0.0", "read-pkg": "^7.1.0", + "rollup": "^3.20.2", "tsd": "^0.28.0", "xo": "^0.53.1" }, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..17ff65f --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,20 @@ +import json from '@rollup/plugin-json'; +import commonjs from '@rollup/plugin-commonjs'; +import {nodeResolve} from '@rollup/plugin-node-resolve'; +import {defineConfig} from 'rollup'; + +export default defineConfig({ + input: 'source/index.js', + output: { + file: 'dist/index.js', + interop: 'esModule', + generatedCode: { + preset: 'es2015', + }, + }, + plugins: [ + json(), + commonjs(), + nodeResolve(), + ], +}); From ce2954bd2d8b8489011ca0ee54c3cf9424f5b0bb Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Tue, 1 Aug 2023 12:58:29 -0500 Subject: [PATCH 02/14] chore(`rollup`): use `terser`, handle licenses --- package.json | 19 +++++++++++-------- rollup.config.js | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index dca02a3..61f4c12 100644 --- a/package.json +++ b/package.json @@ -20,12 +20,12 @@ "node": ">=16.10" }, "scripts": { - "prepublish": "npm run build", + "prepack": "npm run build", "build": "rollup -c", "test": "xo && ava && tsd" }, "files": [ - "source", + "dist", "index.d.ts" ], "keywords": [ @@ -62,17 +62,20 @@ "yargs-parser": "^21.1.1" }, "devDependencies": { - "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-commonjs": "^25.0.3", "@rollup/plugin-json": "^6.0.0", - "@rollup/plugin-node-resolve": "^15.0.1", - "ava": "^5.2.0", + "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-terser": "^0.4.3", + "ava": "^5.3.1", "common-tags": "^1.8.2", - "execa": "^7.1.1", + "execa": "^7.2.0", "indent-string": "^5.0.0", "read-pkg": "^8.0.0", - "rollup": "^3.20.2", + "rollup": "^3.27.0", + "rollup-plugin-filesize": "^10.0.0", + "rollup-plugin-license": "^3.0.1", "tsd": "^0.28.1", - "xo": "^0.54.2" + "xo": "^0.55.0" }, "xo": { "rules": { diff --git a/rollup.config.js b/rollup.config.js index 17ff65f..d95a65f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,13 +1,18 @@ import json from '@rollup/plugin-json'; import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; +import license from 'rollup-plugin-license'; +import terser from '@rollup/plugin-terser'; +import filesize from 'rollup-plugin-filesize'; import {defineConfig} from 'rollup'; export default defineConfig({ input: 'source/index.js', output: { file: 'dist/index.js', + // https://rollupjs.org/configuration-options/#output-interop interop: 'esModule', + // https://rollupjs.org/configuration-options/#output-generatedcode generatedCode: { preset: 'es2015', }, @@ -16,5 +21,18 @@ export default defineConfig({ json(), commonjs(), nodeResolve(), + license({ + thirdParty: { + output: 'dist/dependencies.md', + }, + }), + terser({ + module: true, + toplevel: true, + format: { + comments: false, + }, + }), + filesize(), ], }); From 5040a619c49f6d95673a971634b5dca8539a85b0 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 14 Aug 2023 10:42:41 -0500 Subject: [PATCH 03/14] * add `_actualDependencies` to `package.json` * use `build` instead of `dist` * use `prepare` instead of `prepack` * bundle dependencies in a vendor bundle --- .gitignore | 2 +- package.json | 55 +++++++++++++++++++++++++++++++----------------- rollup.config.js | 37 +++++++++++++++++++------------- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index cf762fe..bf4fb70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules -dist +build yarn.lock diff --git a/package.json b/package.json index 61f4c12..8dcffaa 100644 --- a/package.json +++ b/package.json @@ -13,19 +13,19 @@ "type": "module", "exports": { "types": "./index.d.ts", - "default": "./dist/index.js" + "default": "./build/index.js" }, "sideEffects": false, "engines": { "node": ">=16.10" }, "scripts": { - "prepack": "npm run build", + "prepare": "npm run build", "build": "rollup -c", "test": "xo && ava && tsd" }, "files": [ - "dist", + "build", "index.d.ts" ], "keywords": [ @@ -47,41 +47,58 @@ "cmd", "console" ], - "dependencies": { - "@types/minimist": "^1.2.2", - "camelcase-keys": "^8.0.2", - "decamelize": "^6.0.0", - "decamelize-keys": "^2.0.1", - "hard-rejection": "^2.1.0", - "minimist-options": "4.1.0", - "normalize-package-data": "^5.0.0", - "read-pkg-up": "^9.1.0", - "redent": "^4.0.0", - "trim-newlines": "^5.0.0", - "type-fest": "^3.9.0", - "yargs-parser": "^21.1.1" - }, + "_actualDependencies": [ + "@types/minimist", + "camelcase-keys", + "decamelize", + "decamelize-keys", + "hard-rejection", + "minimist-options", + "normalize-package-data", + "read-pkg-up", + "redent", + "trim-newlines", + "type-fest", + "yargs-parser" + ], "devDependencies": { "@rollup/plugin-commonjs": "^25.0.3", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.1.0", "@rollup/plugin-terser": "^0.4.3", + "@types/minimist": "^1.2.2", "ava": "^5.3.1", + "camelcase-keys": "^8.0.2", "common-tags": "^1.8.2", + "decamelize": "^6.0.0", + "decamelize-keys": "^2.0.1", "execa": "^7.2.0", + "hard-rejection": "^2.1.0", "indent-string": "^5.0.0", + "minimist-options": "4.1.0", + "normalize-package-data": "^5.0.0", "read-pkg": "^8.0.0", + "read-pkg-up": "^9.1.0", + "redent": "^4.0.0", "rollup": "^3.27.0", + "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-filesize": "^10.0.0", "rollup-plugin-license": "^3.0.1", + "rollup-plugin-multi-input": "^1.4.1", + "trim-newlines": "^5.0.0", "tsd": "^0.28.1", - "xo": "^0.55.0" + "type-fest": "^3.9.0", + "xo": "^0.55.0", + "yargs-parser": "^21.1.1" }, "xo": { "rules": { "unicorn/no-process-exit": "off", "unicorn/error-message": "off" - } + }, + "ignores": [ + "build" + ] }, "ava": { "files": [ diff --git a/rollup.config.js b/rollup.config.js index d95a65f..636b88d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,35 +2,42 @@ import json from '@rollup/plugin-json'; import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import license from 'rollup-plugin-license'; -import terser from '@rollup/plugin-terser'; import filesize from 'rollup-plugin-filesize'; import {defineConfig} from 'rollup'; +const outDir = 'build'; + export default defineConfig({ - input: 'source/index.js', + input: [ + 'source/index.js', + 'source/options.js', + 'source/parser.js', + 'source/utils.js', + 'source/validate.js', + ], output: { - file: 'dist/index.js', - // https://rollupjs.org/configuration-options/#output-interop + dir: outDir, interop: 'esModule', - // https://rollupjs.org/configuration-options/#output-generatedcode generatedCode: { preset: 'es2015', }, + chunkFileNames: '[name].js', + manualChunks(id) { + if (id.includes('node_modules')) { + return 'dependencies'; + } + }, }, + preserveEntrySignatures: 'allow-extension', plugins: [ - json(), - commonjs(), nodeResolve(), + commonjs({ + include: 'node_modules/**', + }), + json(), license({ thirdParty: { - output: 'dist/dependencies.md', - }, - }), - terser({ - module: true, - toplevel: true, - format: { - comments: false, + output: `${outDir}/licenses.md`, }, }), filesize(), From 78a73865a798885771a546e025d8b0ffbb953468 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 14 Aug 2023 11:38:29 -0500 Subject: [PATCH 04/14] remove unused plugins, strip dependency comments --- package.json | 5 +---- rollup.config.js | 9 +++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8dcffaa..bf7a5b9 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "@rollup/plugin-commonjs": "^25.0.3", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.1.0", - "@rollup/plugin-terser": "^0.4.3", "@types/minimist": "^1.2.2", "ava": "^5.3.1", "camelcase-keys": "^8.0.2", @@ -81,10 +80,8 @@ "read-pkg-up": "^9.1.0", "redent": "^4.0.0", "rollup": "^3.27.0", - "rollup-plugin-cleanup": "^3.2.1", - "rollup-plugin-filesize": "^10.0.0", "rollup-plugin-license": "^3.0.1", - "rollup-plugin-multi-input": "^1.4.1", + "strip-comments": "^2.0.1", "trim-newlines": "^5.0.0", "tsd": "^0.28.1", "type-fest": "^3.9.0", diff --git a/rollup.config.js b/rollup.config.js index 636b88d..12cbc9c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ import json from '@rollup/plugin-json'; import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import license from 'rollup-plugin-license'; -import filesize from 'rollup-plugin-filesize'; +import strip from 'strip-comments'; import {defineConfig} from 'rollup'; const outDir = 'build'; @@ -27,6 +27,12 @@ export default defineConfig({ return 'dependencies'; } }, + plugins: [{ + name: 'strip-dependency-comments', + renderChunk(code, chunk) { + return chunk.name === 'dependencies' ? strip(code) : null; + }, + }], }, preserveEntrySignatures: 'allow-extension', plugins: [ @@ -40,6 +46,5 @@ export default defineConfig({ output: `${outDir}/licenses.md`, }, }), - filesize(), ], }); From 334a5d9e146a9455126e3dcb52932f7002fee546 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 14 Aug 2023 20:30:26 -0500 Subject: [PATCH 05/14] resolve suggestions --- package.json | 2 +- rollup.config.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bf7a5b9..1e39491 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "scripts": { "prepare": "npm run build", - "build": "rollup -c", + "build": "rollup --config", "test": "xo && ava && tsd" }, "files": [ diff --git a/rollup.config.js b/rollup.config.js index 12cbc9c..4eb65e5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,7 +5,7 @@ import license from 'rollup-plugin-license'; import strip from 'strip-comments'; import {defineConfig} from 'rollup'; -const outDir = 'build'; +const outputDirectory = 'build'; export default defineConfig({ input: [ @@ -16,7 +16,7 @@ export default defineConfig({ 'source/validate.js', ], output: { - dir: outDir, + dir: outputDirectory, interop: 'esModule', generatedCode: { preset: 'es2015', @@ -43,7 +43,7 @@ export default defineConfig({ json(), license({ thirdParty: { - output: `${outDir}/licenses.md`, + output: `${outputDirectory}/licenses.md`, }, }), ], From 74784f4d7b5a3106e233b07165501985c9ab979e Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 14 Aug 2023 21:07:33 -0500 Subject: [PATCH 06/14] add bundle tests --- package.json | 6 ++++-- rollup.config.js | 15 ++++++++------- test/build.js | 40 ++++++++++++++++++++++++++++++++++++++++ test/fixtures/build.js | 26 ++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 test/build.js create mode 100755 test/fixtures/build.js diff --git a/package.json b/package.json index 1e39491..2484411 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "scripts": { "prepare": "npm run build", "build": "rollup --config", - "test": "xo && ava && tsd" + "test": "xo && ava && tsd && npm run test:build", + "test:build": "npm run build && ava test/build.js" }, "files": [ "build", @@ -99,7 +100,8 @@ }, "ava": { "files": [ - "test/*" + "test/*", + "!test/build.js" ] } } diff --git a/rollup.config.js b/rollup.config.js index 4eb65e5..0d90a88 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ import json from '@rollup/plugin-json'; import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import license from 'rollup-plugin-license'; -import strip from 'strip-comments'; +/// import strip from 'strip-comments'; import {defineConfig} from 'rollup'; const outputDirectory = 'build'; @@ -27,12 +27,13 @@ export default defineConfig({ return 'dependencies'; } }, - plugins: [{ - name: 'strip-dependency-comments', - renderChunk(code, chunk) { - return chunk.name === 'dependencies' ? strip(code) : null; - }, - }], + // TODO: strip deletes `https://...` + // plugins: [{ + // name: 'strip-dependency-comments', + // renderChunk(code, chunk) { + // return chunk.name === 'dependencies' ? strip(code) : null; + // }, + // }], }, preserveEntrySignatures: 'allow-extension', plugins: [ diff --git a/test/build.js b/test/build.js new file mode 100644 index 0000000..33c315b --- /dev/null +++ b/test/build.js @@ -0,0 +1,40 @@ +/* eslint-disable ava/no-ignored-test-files */ +import test from 'ava'; +import {readPackage} from 'read-pkg'; +import meow from '../build/index.js'; +import {spawnFixture} from './_utils.js'; + +test('main', t => { + const cli = meow(` + Usage + foo + `, { + importMeta: import.meta, + argv: 'foo --foo-bar --u cat -- unicorn cake'.split(' '), + flags: { + unicorn: {shortFlag: 'u'}, + meow: {default: 'dog'}, + '--': true, + }, + }); + + t.like(cli, { + input: ['foo'], + flags: { + fooBar: true, + meow: 'dog', + unicorn: 'cat', + '--': ['unicorn', 'cake'], + }, + pkg: { + name: 'meow', + }, + help: '\n CLI app helper\n\n Usage\n foo \n', + }); +}); + +test('spawn cli and show version', async t => { + const pkg = await readPackage(); + const {stdout} = await spawnFixture(['--version']); + t.is(stdout, pkg.version); +}); diff --git a/test/fixtures/build.js b/test/fixtures/build.js new file mode 100755 index 0000000..5bea1c0 --- /dev/null +++ b/test/fixtures/build.js @@ -0,0 +1,26 @@ +#!/usr/bin/env node +import process from 'node:process'; +import meow from '../../build/index.js'; + +const cli = meow(` + Usage + foo +`, { + importMeta: import.meta, + description: 'Custom description', + autoVersion: !process.argv.includes('--no-auto-version'), + autoHelp: !process.argv.includes('--no-auto-help'), + flags: { + unicorn: {shortFlag: 'u'}, + meow: {default: 'dog'}, + camelCaseOption: {default: 'foo'}, + }, +}); + +if (cli.flags.camelCaseOption === 'foo') { + for (const x of Object.keys(cli.flags)) { + console.log(x); + } +} else { + console.log(cli.flags.camelCaseOption); +} From 9e12abf96049807df81736a7a999d7f687a85d50 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 14 Aug 2023 23:50:02 -0500 Subject: [PATCH 07/14] consolidate build tests --- package.json | 6 ++---- test/build.js | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2484411..3b818ce 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,7 @@ "scripts": { "prepare": "npm run build", "build": "rollup --config", - "test": "xo && ava && tsd && npm run test:build", - "test:build": "npm run build && ava test/build.js" + "test": "xo && tsd && npm run build && ava" }, "files": [ "build", @@ -100,8 +99,7 @@ }, "ava": { "files": [ - "test/*", - "!test/build.js" + "test/*" ] } } diff --git a/test/build.js b/test/build.js index 33c315b..ee661dd 100644 --- a/test/build.js +++ b/test/build.js @@ -1,4 +1,3 @@ -/* eslint-disable ava/no-ignored-test-files */ import test from 'ava'; import {readPackage} from 'read-pkg'; import meow from '../build/index.js'; From aed54ab932bbe9e3f7e22cd515f4313891e6e5b5 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Tue, 15 Aug 2023 10:13:06 -0500 Subject: [PATCH 08/14] remove empty `node:` imports from build --- rollup.config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 0d90a88..c868dda 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -27,6 +27,7 @@ export default defineConfig({ return 'dependencies'; } }, + hoistTransitiveImports: false, // TODO: strip deletes `https://...` // plugins: [{ // name: 'strip-dependency-comments', @@ -35,7 +36,9 @@ export default defineConfig({ // }, // }], }, - preserveEntrySignatures: 'allow-extension', + treeshake: { + moduleSideEffects: 'no-external', + }, plugins: [ nodeResolve(), commonjs({ From 485ffad1a737925dcaa37e6cb47db62ecf76361f Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Tue, 15 Aug 2023 10:58:42 -0500 Subject: [PATCH 09/14] fix removing comments from deps bundle --- package.json | 4 ++-- rollup.config.js | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 2385930..7dd3b3d 100644 --- a/package.json +++ b/package.json @@ -68,9 +68,10 @@ "@types/minimist": "^1.2.2", "ava": "^5.3.1", "camelcase-keys": "^8.0.2", - "common-tags": "^1.8.2", + "common-tags": "^2.0.0-alpha.1", "decamelize": "^6.0.0", "decamelize-keys": "^2.0.1", + "delete_comments": "^0.0.2", "execa": "^7.2.0", "hard-rejection": "^2.1.0", "indent-string": "^5.0.0", @@ -81,7 +82,6 @@ "redent": "^4.0.0", "rollup": "^3.27.0", "rollup-plugin-license": "^3.0.1", - "strip-comments": "^2.0.1", "trim-newlines": "^5.0.0", "tsd": "^0.28.1", "type-fest": "^4.2.0", diff --git a/rollup.config.js b/rollup.config.js index c868dda..2c7c6fb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,9 +2,17 @@ import json from '@rollup/plugin-json'; import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import license from 'rollup-plugin-license'; -/// import strip from 'strip-comments'; +import {createTag, replaceResultTransformer} from 'common-tags'; +import {delete_comments as deleteComments} from 'delete_comments'; import {defineConfig} from 'rollup'; +const stripComments = createTag( + {onEndResult: deleteComments}, + // Remove empty lines + // https://stackoverflow.com/q/16369642/10292952 + replaceResultTransformer(/^\s*[\r\n]/gm, ''), +); + const outputDirectory = 'build'; export default defineConfig({ @@ -28,13 +36,12 @@ export default defineConfig({ } }, hoistTransitiveImports: false, - // TODO: strip deletes `https://...` - // plugins: [{ - // name: 'strip-dependency-comments', - // renderChunk(code, chunk) { - // return chunk.name === 'dependencies' ? strip(code) : null; - // }, - // }], + plugins: [{ + name: 'strip-dependency-comments', + renderChunk(code, chunk) { + return chunk.name === 'dependencies' ? stripComments(code) : null; + }, + }], }, treeshake: { moduleSideEffects: 'no-external', From 93d281be12564dc1cfc33e40009454e7bcad9933 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Tue, 15 Aug 2023 11:12:15 -0500 Subject: [PATCH 10/14] fix failing test from `common-tags` update --- test/_utils.js | 7 +++++++ test/choices.js | 2 +- test/errors.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/_utils.js b/test/_utils.js index 2b7f498..f09a405 100644 --- a/test/_utils.js +++ b/test/_utils.js @@ -1,6 +1,7 @@ import path from 'node:path'; import {fileURLToPath} from 'node:url'; import {execa} from 'execa'; +import {createTag, stripIndentTransformer, trimResultTransformer} from 'common-tags'; export const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -15,3 +16,9 @@ export const spawnFixture = async (fixture = 'fixture.js', args = []) => { return execa(getFixture(fixture), args); }; + +// Use old behavior prior to zspecza/common-tags#165 +export const stripIndent = createTag( + stripIndentTransformer(), + trimResultTransformer(), +); diff --git a/test/choices.js b/test/choices.js index e786d8b..7fcf78b 100644 --- a/test/choices.js +++ b/test/choices.js @@ -1,6 +1,6 @@ import test from 'ava'; -import {stripIndent} from 'common-tags'; import meow from '../source/index.js'; +import {stripIndent} from './_utils.js'; const importMeta = import.meta; diff --git a/test/errors.js b/test/errors.js index f20f175..dd28aac 100644 --- a/test/errors.js +++ b/test/errors.js @@ -1,6 +1,6 @@ import test from 'ava'; -import {stripIndent} from 'common-tags'; import meow from '../source/index.js'; +import {stripIndent} from './_utils.js'; const importMeta = import.meta; From 6b7046402a25af833b420c9f20e71420326cd60f Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Tue, 15 Aug 2023 15:28:02 -0500 Subject: [PATCH 11/14] glob input --- package.json | 1 + rollup.config.js | 20 ++++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 7dd3b3d..1d8ffff 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "decamelize-keys": "^2.0.1", "delete_comments": "^0.0.2", "execa": "^7.2.0", + "globby": "^13.2.2", "hard-rejection": "^2.1.0", "indent-string": "^5.0.0", "minimist-options": "4.1.0", diff --git a/rollup.config.js b/rollup.config.js index 2c7c6fb..55f7ab0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,28 +1,24 @@ -import json from '@rollup/plugin-json'; -import commonjs from '@rollup/plugin-commonjs'; import {nodeResolve} from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import json from '@rollup/plugin-json'; import license from 'rollup-plugin-license'; +import {globby} from 'globby'; import {createTag, replaceResultTransformer} from 'common-tags'; import {delete_comments as deleteComments} from 'delete_comments'; import {defineConfig} from 'rollup'; +/** Matches empty lines: https://stackoverflow.com/q/16369642/10292952 */ +const emptyLineRegex = /^\s*[\r\n]/gm; + const stripComments = createTag( {onEndResult: deleteComments}, - // Remove empty lines - // https://stackoverflow.com/q/16369642/10292952 - replaceResultTransformer(/^\s*[\r\n]/gm, ''), + replaceResultTransformer(emptyLineRegex, ''), ); const outputDirectory = 'build'; export default defineConfig({ - input: [ - 'source/index.js', - 'source/options.js', - 'source/parser.js', - 'source/utils.js', - 'source/validate.js', - ], + input: await globby('source/**/*.js'), output: { dir: outputDirectory, interop: 'esModule', From b8b71301e9838fcc990bdad54a0bd660cadd9323 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 16 Aug 2023 12:59:22 +0200 Subject: [PATCH 12/14] Update build.js --- test/fixtures/build.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/build.js b/test/fixtures/build.js index 5bea1c0..382d2a4 100755 --- a/test/fixtures/build.js +++ b/test/fixtures/build.js @@ -18,8 +18,8 @@ const cli = meow(` }); if (cli.flags.camelCaseOption === 'foo') { - for (const x of Object.keys(cli.flags)) { - console.log(x); + for (const flagKey of Object.keys(cli.flags)) { + console.log(flagKey); } } else { console.log(cli.flags.camelCaseOption); From 8bdc9e3a479889587bdca69cc32bc90504517c22 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 16 Aug 2023 12:59:55 +0200 Subject: [PATCH 13/14] Update build.js --- test/build.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/build.js b/test/build.js index ee661dd..5607ef7 100644 --- a/test/build.js +++ b/test/build.js @@ -11,8 +11,12 @@ test('main', t => { importMeta: import.meta, argv: 'foo --foo-bar --u cat -- unicorn cake'.split(' '), flags: { - unicorn: {shortFlag: 'u'}, - meow: {default: 'dog'}, + unicorn: { + shortFlag: 'u', + }, + meow: { + default: 'dog', + }, '--': true, }, }); @@ -23,7 +27,10 @@ test('main', t => { fooBar: true, meow: 'dog', unicorn: 'cat', - '--': ['unicorn', 'cake'], + '--': [ + 'unicorn', + 'cake', + ], }, pkg: { name: 'meow', From e8455db20eb294fc753d277db916d8e8ae2a2582 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 16 Aug 2023 13:00:55 +0200 Subject: [PATCH 14/14] Update build.js --- test/fixtures/build.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/fixtures/build.js b/test/fixtures/build.js index 382d2a4..83f7222 100755 --- a/test/fixtures/build.js +++ b/test/fixtures/build.js @@ -11,9 +11,15 @@ const cli = meow(` autoVersion: !process.argv.includes('--no-auto-version'), autoHelp: !process.argv.includes('--no-auto-help'), flags: { - unicorn: {shortFlag: 'u'}, - meow: {default: 'dog'}, - camelCaseOption: {default: 'foo'}, + unicorn: { + shortFlag: 'u', + }, + meow: { + default: 'dog', + }, + camelCaseOption: { + default: 'foo', + }, }, });