diff --git a/package-lock.json b/package-lock.json index 77a584a..347b76a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -674,15 +674,11 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, - "bluebird": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -911,9 +907,9 @@ } }, "commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==" + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", + "integrity": "sha512-e2i4wANQiSXgnrBlIatyHtP1odfUp0BbV5Y5nEGbxtIrStkEOAAzCUirvLBNXHLr7kwLvJl6V+4V3XV9x7Wd9w==" }, "commitizen": { "version": "4.2.4", @@ -1037,7 +1033,8 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true }, "conventional-changelog": { "version": "3.1.25", @@ -2093,16 +2090,33 @@ } }, "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", + "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", + "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", + "requires": { + "brace-expansion": "^2.0.1" + } + } } }, "glob-parent": { @@ -2744,19 +2758,19 @@ "dev": true }, "knifecycle": { - "version": "12.0.2", - "resolved": "https://registry.npmjs.org/knifecycle/-/knifecycle-12.0.2.tgz", - "integrity": "sha512-pz8zHHnCSagdbJ79L4p21lGkKdRywCKSuzpNYNkfv4F+5WWczJe+Wj8SunCzQfZ06zWE2zWcvVYq1eU7Pbn5WQ==", + "version": "12.0.4", + "resolved": "https://registry.npmjs.org/knifecycle/-/knifecycle-12.0.4.tgz", + "integrity": "sha512-DMJ1xQQR1HLHv54+9lGjHvC0IUNO7EUV+ddK79OZV0tNv0j2uy8O4og2KaJTK096XGuvBuGxUIFVjoBtfmNvIw==", "requires": { - "debug": "^4.3.1", - "type-fest": "^1.0.1", - "yerror": "^6.0.0" + "debug": "^4.3.4", + "type-fest": "^2.13.0", + "yerror": "^6.0.2" }, "dependencies": { "type-fest": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", - "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==" + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.13.0.tgz", + "integrity": "sha512-lPfAm42MxE4/456+QyIaaVBAwgpJb6xZ8PRu09utnhPdWwcyj9vgy6Sq0Z5yNbJ21EdxB5dRU/Qg8bsyAMtlcw==" } } }, @@ -3000,14 +3014,14 @@ "dev": true }, "metapak-nfroidure": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/metapak-nfroidure/-/metapak-nfroidure-11.2.0.tgz", - "integrity": "sha512-Nv8sCekW+5U8FQbAC+q/uFyzBkyHr9lZM3HOCbOTwrr/lMsUK/sb+OxVw1yKLoQNg2hGROjhVjzhvX4BuwrFJA==", + "version": "11.2.1", + "resolved": "https://registry.npmjs.org/metapak-nfroidure/-/metapak-nfroidure-11.2.1.tgz", + "integrity": "sha512-h9tAZKZoTjdMiR32l+is7akI0mgf1o5ih4dE/MYdpPLDKE613M3/bYSGnzUX+tgxCDOoM3DBmBwpRokvpEWi2g==", "dev": true, "requires": { "escape-string-regexp": "^4.0.0", "rimraf": "^3.0.2", - "yerror": "^6.0.1" + "yerror": "^6.0.2" }, "dependencies": { "escape-string-regexp": { @@ -3059,6 +3073,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3405,12 +3420,35 @@ "wrap-ansi": "^6.2.0" } }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, "string-width": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", @@ -3602,7 +3640,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true }, "path-key": { "version": "3.1.1", @@ -4028,6 +4067,31 @@ "dev": true, "requires": { "glob": "^7.1.3" + }, + "dependencies": { + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + } } }, "run-async": { @@ -4343,6 +4407,33 @@ "@istanbuljs/schema": "^0.1.2", "glob": "^7.1.4", "minimatch": "^3.0.4" + }, + "dependencies": { + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "dependencies": { + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + } + } + } } }, "text-extensions": { @@ -4734,9 +4825,9 @@ } }, "yerror": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/yerror/-/yerror-6.0.1.tgz", - "integrity": "sha512-0Bxo+NyeucjxhmPB5z3lmI/N/cOu8L1Q8JVta6/I5G6J/JhCSSPwk8qt9N4yOFSjwkvhDwzUSQglfBIAllvi1Q==" + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/yerror/-/yerror-6.0.2.tgz", + "integrity": "sha512-ETI/l4pRa0Id3VJK4ABHbmltWFh+tBp/jJVRtnp9OM18rfCSoCrANijcTJ4Ng4EPEWswjQsQsL03wW9UIx2vxg==" }, "yocto-queue": { "version": "0.1.0", diff --git a/package.json b/package.json index cf0433b..fdb24d1 100644 --- a/package.json +++ b/package.json @@ -53,18 +53,17 @@ }, "homepage": "https://github.com/nfroidure/metapak#readme", "dependencies": { - "bluebird": "^3.7.2", "chalk": "^4.1.0", - "commander": "^7.2.0", + "commander": "^9.2.0", "debug": "^4.3.4", "deep-strict-equal": "^0.2.0", "diff": "^5.1.0", - "glob": "^7.1.6", - "knifecycle": "^12.0.2", + "glob": "^8.0.3", + "knifecycle": "^12.0.4", "mkdirp": "^1.0.4", "pkg-dir": "^5.0.0", "sort-keys": "^4.2.0", - "yerror": "^6.0.1" + "yerror": "^6.0.2" }, "devDependencies": { "commitizen": "^4.2.4", @@ -73,7 +72,7 @@ "cz-conventional-changelog": "^3.3.0", "eslint": "^8.16.0", "eslint-plugin-prettier": "^4.0.0", - "metapak-nfroidure": "11.2.0", + "metapak-nfroidure": "11.2.1", "mocha": "^10.0.0", "nyc": "^15.1.0", "prettier": "^2.6.2", diff --git a/src/metapak.js b/src/metapak.js index 6546948..b2ebace 100644 --- a/src/metapak.js +++ b/src/metapak.js @@ -1,5 +1,4 @@ const path = require('path'); -const Promise = require('bluebird'); const YError = require('yerror').default; const { autoService } = require('knifecycle'); @@ -185,40 +184,44 @@ function _reorderMetapakModulesNames( return metapakModulesNames; } -function _getPackageMetapakModulesConfigs( +async function _getPackageMetapakModulesConfigs( { fs, log }, metapakModulesSequence, metapackConfigsSequence, resolveModule, packageConf ) { - return Promise.props( - metapakModulesSequence.reduce( - (metapakModulesConfigs, metapakModuleName) => { - const modulePath = path.join( - resolveModule(metapakModuleName, packageConf), - 'src' - ); + const allModulesConfigs = metapakModulesSequence.reduce( + (metapakModulesConfigs, metapakModuleName) => { + const modulePath = path.join( + resolveModule(metapakModuleName, packageConf), + 'src' + ); - metapakModulesConfigs[metapakModuleName] = fs - .readdirAsync(modulePath) - .then((metapakModuleConfigs) => { - metapakModuleConfigs = metapackConfigsSequence.filter( - (metapakModuleConfig) => - metapakModuleConfigs.includes(metapakModuleConfig) - ); - log( - 'debug', - 'Found configs for "' + metapakModuleName + '":', - metapakModuleConfigs - ); - return metapakModuleConfigs; - }); - return metapakModulesConfigs; - }, - {} - ) + metapakModulesConfigs[metapakModuleName] = fs + .readdirAsync(modulePath) + .then((metapakModuleConfigs) => { + metapakModuleConfigs = metapackConfigsSequence.filter( + (metapakModuleConfig) => + metapakModuleConfigs.includes(metapakModuleConfig) + ); + log( + 'debug', + 'Found configs for "' + metapakModuleName + '":', + metapakModuleConfigs + ); + return metapakModuleConfigs; + }); + return metapakModulesConfigs; + }, + {} ); + return await Object.keys(allModulesConfigs).reduce(async (p, key) => { + return { + ...(await p), + [key]: await allModulesConfigs[key], + }; + }, Promise.resolve({})); } function _awaitPromisesFullfil(promises) { diff --git a/src/runMetapak.js b/src/runMetapak.js index 9b399a5..9bf2c22 100644 --- a/src/runMetapak.js +++ b/src/runMetapak.js @@ -11,8 +11,8 @@ const os = require('os'); const mkdirp = require('mkdirp'); const path = require('path'); const glob = require('glob'); +const { promisify } = require('util'); const program = require('commander'); -const Promise = require('bluebird'); const { exec } = require('child_process'); const initMetapak = require('../src/metapak'); @@ -45,7 +45,7 @@ async function prepareMetapak($ = new Knifecycle()) { $.register(constant('exit', process.exit)); $.register(constant('mkdirp', mkdirp)); $.register(constant('os', os)); - $.register(constant('glob', Promise.promisify(glob))); + $.register(constant('glob', promisify(glob))); $.register( constant('log', (type, ...args) => { if ('debug' === type || 'stack' === type) { @@ -62,36 +62,34 @@ async function prepareMetapak($ = new Knifecycle()) { $.register(initBuildPackageAssets); $.register(initBuildPackageGitHooks); $.register(initResolveModule); - - program - .version(require(path.join(__dirname, '..', 'package.json')).version) - .option('-s, --safe', 'Exit with 1 when changes are detected') - .option('-d, --dry-run', 'Print the changes without doing it') - .parse(process.argv); - - $.register( - autoService(async function initProgram({ packageConf }) { - return program - .version(packageConf.version) - .option('-b, --base [value]', 'Base for links') - .parse(process.argv); - }) - ); - + $.register(autoService(initProgramOptions)); + $.register(autoService(initPreventChanges)); $.register(autoService(initMkdirp)); $.register(name('fs', autoService(initFS))); return $; } -function preventChanges(path) { - if (program.safe) { - return Promise.reject(new YError('E_UNEXPECTED_CHANGES', path)); - } - return {}.undef; +async function initProgramOptions() { + return program + .version(require(path.join(__dirname, '..', 'package.json')).version) + .option('-s, --safe', 'Exit with 1 when changes are detected') + .option('-d, --dry-run', 'Print the changes without doing it') + .option('-b, --base [value]', 'Base for links') + .parse(process.argv) + .opts(); } -async function initGitHooksDir({ PROJECT_DIR, log }) { +async function initPreventChanges({ programOptions }) { + return function preventChanges(path) { + if (programOptions.safe) { + return Promise.reject(new YError('E_UNEXPECTED_CHANGES', path)); + } + return {}.undef; + }; +} + +async function initGitHooksDir({ PROJECT_DIR, fs, log }) { return new Promise((resolve) => { exec( 'git rev-parse --git-dir', @@ -130,11 +128,11 @@ async function initGitHooksDir({ PROJECT_DIR, log }) { }); } -async function initMkdirp({ log }) { - const mkdirpAsync = Promise.promisify(mkdirp.mkdirp); +async function initMkdirp({ programOptions, preventChanges, log }) { + const mkdirpAsync = promisify(mkdirp.mkdirp); return Promise.resolve((path, ...args) => { - if (program.dryRun) { + if (programOptions.dryRun) { log('debug', 'Create a folder:', path); return Promise.resolve(); } @@ -142,27 +140,25 @@ async function initMkdirp({ log }) { }); } -async function initFS({ log }) { - const baseFS = Promise.promisifyAll(fs); - +async function initFS({ programOptions, preventChanges, log }) { return Promise.resolve({ - readFileAsync: baseFS.readFileAsync.bind(baseFS), - accessAsync: baseFS.accessAsync.bind(baseFS), - readdirAsync: baseFS.readdirAsync.bind(baseFS), + readFileAsync: fs.promises.readFile, + accessAsync: fs.promises.access, + readdirAsync: fs.promises.readdir, unlinkAsync: (path, ...args) => { - if (program.dryRun) { - log('debug', 'Delete a file:', path); + if (programOptions.dryRun) { + log('warn', 'Delete a file:', path); return Promise.resolve(); } - return preventChanges(path) || baseFS.unlinkAsync(path, ...args); + return preventChanges(path) || fs.promises.unlink(path, ...args); }, writeFileAsync: (path, ...args) => { - if (program.dryRun) { - log('debug', 'Modify a file:', path); + if (programOptions.dryRun) { + log('warn', 'Modify a file:', path); return Promise.resolve(); } - return preventChanges(path) || baseFS.writeFileAsync(path, ...args); + return preventChanges(path) || fs.promises.writeFile(path, ...args); }, - constants: baseFS.constants, + constants: fs.constants, }); }