From c6c692fcb5ae91ca5257485c9b38fd73bea1db15 Mon Sep 17 00:00:00 2001 From: dr-js Date: Fri, 25 Dec 2020 10:47:03 +0800 Subject: [PATCH] @dr-js/dev@0.4.3-dev.9 notable change: - deprecate: `fileProcessorWebpack` - add: `copyAfterEdit` to `node/file` - temp-fix: ci: wait for https://github.com/npm/cli/issues/2411 - script sort - package update --- .github/workflows/ci-test.yml | 5 +- LICENSE | 2 +- SPEC.md | 8 +- package-lock.json | 95 +++++++++++-------- package.json | 8 +- .../base/INIT#.github#workflows#ci-test.yml | 2 +- resource/eslint/[react]/package.json | 2 +- resource/eslint/package.json | 2 +- resource/webpack/package.json | 2 +- source/fileProcessor.js | 9 +- source/minify.js | 38 ++++---- source/node/file.js | 10 +- 12 files changed, 104 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 6249e27..a6cd7c0 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -31,7 +31,7 @@ jobs: - name: Patch & log CI info run: | - npx @dr-js/core@^0.4.3-dev.1 -eI .github/ci-patch.js + npx @dr-js/core@^0.4.3 -eI .github/ci-patch.js dr-dev -c .github/cache/config.js --cache-step setup - name: Cache JS @@ -47,6 +47,7 @@ jobs: - run: npm ci - - run: npm test + # TODO: TEMP FIX: use npm@6 and wait for: https://github.com/npm/cli/issues/2411 + - run: npx npm@6 test - run: dr-dev -c .github/cache/config.js --cache-step prune diff --git a/LICENSE b/LICENSE index a4ca39a..75ace12 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 dr-js +Copyright (c) 2021 dr-js Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/SPEC.md b/SPEC.md index f523df7..1dfdefb 100644 --- a/SPEC.md +++ b/SPEC.md @@ -28,7 +28,7 @@ + 📄 [source/node/env.js](source/node/env.js) - `__VERBOSE__`, `argvFlag`, `checkFlag`, `loadEnvKey`, `saveEnvKey`, `syncEnvKey` + 📄 [source/node/file.js](source/node/file.js) - - `findPathFragList`, `getFileListFromPathList`, `resetDirectory`, `withTempDirectory` + - `copyAfterEdit`, `findPathFragList`, `getFileListFromPathList`, `resetDirectory`, `withTempDirectory` + 📄 [source/node/filePreset.js](source/node/filePreset.js) - `getSourceJsFileListFromPathList` + 📄 [source/node/logger.js](source/node/logger.js) @@ -271,14 +271,14 @@ | babel-plugin-minify-replace | ^0.5.0 | | babel-plugin-module-resolver | ^4.1.0 | | babel-plugin-styled-components | ^1.12.0 | -| eslint | ^7.16.0 | +| eslint | ^7.17.0 | | eslint-plugin-import | ^2.22.1 | | eslint-plugin-node | ^11.1.0 | | eslint-plugin-promise | ^4.2.1 | -| eslint-plugin-react | ^7.21.5 | +| eslint-plugin-react | ^7.22.0 | | prop-types | ^15.7.2 | | puppeteer | ^5.5.0 | | react | ^17.0.1 | | styled-components | ^5.2.1 | | terser | ^5.5.1 | -| webpack | ^5.11.0 | +| webpack | ^5.11.1 | diff --git a/package-lock.json b/package-lock.json index edaac12..7512f31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@dr-js/dev", - "version": "0.4.3-dev.8", + "version": "0.4.3-dev.9", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -344,9 +344,9 @@ "dev": true }, "@babel/plugin-proposal-async-generator-functions": { - "version": "7.12.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.12.1.tgz", - "integrity": "sha512-d+/o30tJxFxrA1lhzJqiUcEJdI6jKlNregCv5bASeGf2Q4MXmnwH7viDo7nhx1/ohf09oaH8j1GVYG/e3Yqk6A==", + "version": "7.12.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.12.12.tgz", + "integrity": "sha512-nrz9y0a4xmUrRq51bYkWJIO5SBZyG2ys2qinHsN0zHDHVsUaModrkpyWWWXfGqYQmOL3x9sQIcTNN/pBGpo09A==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.10.4", @@ -614,9 +614,9 @@ } }, "@babel/plugin-transform-block-scoping": { - "version": "7.12.11", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.12.11.tgz", - "integrity": "sha512-atR1Rxc3hM+VPg/NvNvfYw0npQEAcHuJ+MGZnFn6h3bo+1U3BWXMdFMlvVRApBTWKQMX7SOwRJZA5FBF/JQbvA==", + "version": "7.12.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.12.12.tgz", + "integrity": "sha512-VOEPQ/ExOVqbukuP7BYJtI5ZxxsmegTwzZ04j1aF0dkSypGo9XpDHuOrABsJu+ie+penpSJheDJ11x1BEZNiyQ==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.10.4" @@ -1018,17 +1018,17 @@ } }, "@babel/traverse": { - "version": "7.12.10", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.10.tgz", - "integrity": "sha512-6aEtf0IeRgbYWzta29lePeYSk+YAFIC3kyqESeft8o5CkFlYIMX+EQDDWEiAQ9LHOA3d0oHdgrSsID/CKqXJlg==", + "version": "7.12.12", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.12.tgz", + "integrity": "sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w==", "dev": true, "requires": { - "@babel/code-frame": "^7.10.4", - "@babel/generator": "^7.12.10", - "@babel/helper-function-name": "^7.10.4", - "@babel/helper-split-export-declaration": "^7.11.0", - "@babel/parser": "^7.12.10", - "@babel/types": "^7.12.10", + "@babel/code-frame": "^7.12.11", + "@babel/generator": "^7.12.11", + "@babel/helper-function-name": "^7.12.11", + "@babel/helper-split-export-declaration": "^7.12.11", + "@babel/parser": "^7.12.11", + "@babel/types": "^7.12.12", "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.19" @@ -1052,9 +1052,9 @@ } }, "@babel/types": { - "version": "7.12.11", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.12.11.tgz", - "integrity": "sha512-ukA9SQtKThINm++CX1CwmliMrE54J6nIYB5XTwL5f/CLFW9owfls+YSU8tVW15RQ2w+a3fSbPjC6HdQNtWZkiA==", + "version": "7.12.12", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.12.12.tgz", + "integrity": "sha512-lnIX7piTxOH22xE7fDXDbSHg9MM1/6ORnafpJmov5rs0kX5g4BZxeXNJLXsMRiO0U5Rb8/FvMS6xlTnTHvxonQ==", "dev": true, "requires": { "@babel/helper-validator-identifier": "^7.12.11", @@ -1063,24 +1063,32 @@ } }, "@dr-js/core": { - "version": "0.4.3-dev.1", - "resolved": "https://registry.npmjs.org/@dr-js/core/-/core-0.4.3-dev.1.tgz", - "integrity": "sha512-q278L/rVVslx8rEsgV7ziO3p56nO2GtTRAKhjFNeJVMO+oTT+iQiwS5cn+9qGSo5zswFTjov+n8W6I8as+JNkQ==" + "version": "0.4.4-dev.0", + "resolved": "https://registry.npmjs.org/@dr-js/core/-/core-0.4.4-dev.0.tgz", + "integrity": "sha512-m5vVlZ+ezQmthwCWL4jRvdJLd/8+2GTxunBFSH8NWS2RRPObVbuANLd2vs9az72flI+i7VntsK3XcEb8I/orPQ==" }, "@dr-js/dev": { - "version": "0.4.3-dev.7", - "resolved": "https://registry.npmjs.org/@dr-js/dev/-/dev-0.4.3-dev.7.tgz", - "integrity": "sha512-7IvQagTF1F0V+ONivFrYSRc2/mYNuamzPMHK+sXoXsUW1mwaHubqsITqAAZ9sI9M84JRVVYhDCeMD3wft5SKZA==", + "version": "0.4.3-dev.8", + "resolved": "https://registry.npmjs.org/@dr-js/dev/-/dev-0.4.3-dev.8.tgz", + "integrity": "sha512-fP34RnTpo80dcQJ7PA83PacH6VYCmJktxJM0rSUT6xL8nDaLZuliag4lyDvohXAJA7RVAqKkMI4fOo0IqMZMww==", "dev": true, "requires": { - "@dr-js/core": "^0.4.3 || ^0.4.3-dev.0", - "@dr-js/node": "^0.4.2 || ^0.4.3-dev.0" + "@dr-js/core": "^0.4.3 || ^0.4.3-dev.1", + "@dr-js/node": "^0.4.3 || ^0.4.3-dev.0" + }, + "dependencies": { + "@dr-js/core": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@dr-js/core/-/core-0.4.3.tgz", + "integrity": "sha512-aGAMZWitx1rQFYVSF+yUzy7uw00nTnZqgpyfo/Mh5mAEeoE7GN/xkCJmVCZwONaVRFMfYcQ/gyyLR6Fn0A3O0w==", + "dev": true + } } }, "@dr-js/dev-web": { - "version": "0.4.3-dev.7", - "resolved": "https://registry.npmjs.org/@dr-js/dev-web/-/dev-web-0.4.3-dev.7.tgz", - "integrity": "sha512-JBhT+UizHti7b5h2gLGb3IeqR/eXmMZBjeoWikgq2zkrOg3c0qvWD8Xs+52EZA6fq6OggxJj3VScwHW/8Q/g2A==", + "version": "0.4.3-dev.8", + "resolved": "https://registry.npmjs.org/@dr-js/dev-web/-/dev-web-0.4.3-dev.8.tgz", + "integrity": "sha512-4nKdML/bCVE51Lkd4aOcqmHATCT/DGbYSKlUfOiO0Wf/CrGvWxhMW+LnsDLj/9UzHnjPXp0r8GZyLk+/Nk0eyw==", "dev": true, "requires": { "@babel/cli": "^7.12.10", @@ -1104,6 +1112,13 @@ "integrity": "sha512-8ouJ/SxxCOuaQdQMWWHpc+GAwERqRjfzD88as2b9M9bcZ/DNuVPg1DMFLWn2RflInndHQ68wbB6pqFsw9tqM3w==", "requires": { "@dr-js/core": "^0.4.3 || ^0.4.3-dev.1" + }, + "dependencies": { + "@dr-js/core": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@dr-js/core/-/core-0.4.3.tgz", + "integrity": "sha512-aGAMZWitx1rQFYVSF+yUzy7uw00nTnZqgpyfo/Mh5mAEeoE7GN/xkCJmVCZwONaVRFMfYcQ/gyyLR6Fn0A3O0w==" + } } }, "@eslint/eslintrc": { @@ -1209,9 +1224,9 @@ "dev": true }, "@types/node": { - "version": "14.14.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.14.tgz", - "integrity": "sha512-UHnOPWVWV1z+VV8k6L1HhG7UbGBgIdghqF3l9Ny9ApPghbjICXkUJSd/b9gOgQfjM1r+37cipdw/HJ3F6ICEnQ==", + "version": "14.14.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.16.tgz", + "integrity": "sha512-naXYePhweTi+BMv11TgioE2/FXU4fSl29HAH1ffxVciNsH3rYXjNP2yM8wqmSm7jS20gM8TIklKiTen+1iVncw==", "dev": true }, "@webassemblyjs/ast": { @@ -2203,9 +2218,9 @@ } }, "electron-to-chromium": { - "version": "1.3.629", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.629.tgz", - "integrity": "sha512-iSPPJtPvHrMAvYOt+9cdbDmTasPqwnwz4lkP8Dn200gDNUBQOLQ96xUsWXBwXslAo5XxdoXAoQQ3RAy4uao9IQ==", + "version": "1.3.633", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.633.tgz", + "integrity": "sha512-bsVCsONiVX1abkWdH7KtpuDAhsQ3N3bjPYhROSAXE78roJKet0Y5wznA14JE9pzbwSZmSMAW6KiKYf1RvbTJkA==", "dev": true }, "emoji-regex": { @@ -2221,13 +2236,13 @@ "dev": true }, "enhanced-resolve": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.4.0.tgz", - "integrity": "sha512-ZmqfWURB2lConOBM1JdCVfPyMRv5RdKWktLXO6123p97ovVm2CLBgw9t5MBj3jJWA6eHyOeIws9iJQoGFR4euQ==", + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.4.1.tgz", + "integrity": "sha512-4GbyIMzYktTFoRSmkbgZ1LU+RXwf4AQ8Z+rSuuh1dC8plp0PPeaWvx6+G4hh4KnUJ48VoxKbNyA1QQQIUpXjYA==", "dev": true, "requires": { "graceful-fs": "^4.2.4", - "tapable": "^2.0.0" + "tapable": "^2.2.0" } }, "enquirer": { diff --git a/package.json b/package.json index e8f0c22..294bf36 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@dr-js/dev", - "version": "0.4.3-dev.8", + "version": "0.4.3-dev.9", "description": "A collection of strange functions, for development", "author": "dr-js", "license": "MIT", @@ -50,12 +50,12 @@ "npm": ">=6.14" }, "dependencies": { - "@dr-js/core": "^0.4.3 || ^0.4.3-dev.1", + "@dr-js/core": "^0.4.4 || ^0.4.4-dev.0", "@dr-js/node": "^0.4.3 || ^0.4.3-dev.0" }, "devDependencies": { - "@dr-js/dev": "0.4.3-dev.7", - "@dr-js/dev-web": "0.4.3-dev.7" + "@dr-js/dev": "0.4.3-dev.8", + "@dr-js/dev-web": "0.4.3-dev.8" }, "sideEffects": false } diff --git a/resource/__config__/base/INIT#.github#workflows#ci-test.yml b/resource/__config__/base/INIT#.github#workflows#ci-test.yml index 48e9815..fdf2846 100644 --- a/resource/__config__/base/INIT#.github#workflows#ci-test.yml +++ b/resource/__config__/base/INIT#.github#workflows#ci-test.yml @@ -31,7 +31,7 @@ jobs: - name: Patch & log CI info run: | - npx @dr-js/core@^0.4.3-dev.1 -eI .github/ci-patch.js + npx @dr-js/core@^0.4.3 -eI .github/ci-patch.js dr-dev -c .github/cache/config.js --cache-step setup - name: Cache JS diff --git a/resource/eslint/[react]/package.json b/resource/eslint/[react]/package.json index 2bbb51c..7388779 100644 --- a/resource/eslint/[react]/package.json +++ b/resource/eslint/[react]/package.json @@ -5,7 +5,7 @@ "eslint-config-almost-standard-jsx-v8.js" ], "dependencies": { - "eslint-plugin-react": "^7.21.5", + "eslint-plugin-react": "^7.22.0", "babel-eslint": "^10.1.0" } } diff --git a/resource/eslint/package.json b/resource/eslint/package.json index cc23fca..53ad66d 100644 --- a/resource/eslint/package.json +++ b/resource/eslint/package.json @@ -5,7 +5,7 @@ "eslint-config-almost-standard-v14.js" ], "dependencies": { - "eslint": "^7.16.0", + "eslint": "^7.17.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1" diff --git a/resource/webpack/package.json b/resource/webpack/package.json index e9f7857..5e8df4b 100644 --- a/resource/webpack/package.json +++ b/resource/webpack/package.json @@ -4,7 +4,7 @@ "INIT#package.json" ], "dependencies": { - "webpack": "^5.11.0", + "webpack": "^5.11.1", "babel-loader": "^8.2.2" } } diff --git a/source/fileProcessor.js b/source/fileProcessor.js index 870ce17..9d79bc8 100644 --- a/source/fileProcessor.js +++ b/source/fileProcessor.js @@ -58,12 +58,13 @@ const fileProcessorBabel = (inputString) => inputString // - function(){return $a_} => ()=>$a_ // - function(){return wt.a} => ()=>wt.a // don't: -// - function(){return a}() => ()=>a() -const fileProcessorWebpack = (inputString) => inputString - .replace(/function\s*\(\)\s*{\s*return\s+([\w$]+(?:\.[\w$]+)?)\s*}([\s;)\]])/g, '()=>$1$2') // TODO: may break code? +// - function(){return a}() => ()=>a() +// - function(){return this.a}() => ()=>this.a +const fileProcessorWebpack = (inputString) => inputString // TODO: DEPRECATE: risk breaking code & replaceable `function()` is less often seem in minified webpack output +// .replace(/function\s*\(\)\s*{\s*return\s+([\w$]+(?:\.[\w$]+)?)\s*}([\s;)\]])/g, '()=>$1$2') // TODO: may break code? export { processFileList, fileProcessorBabel, - fileProcessorWebpack + fileProcessorWebpack // TODO: DEPRECATE } diff --git a/source/minify.js b/source/minify.js index 1154b65..0f102b4 100644 --- a/source/minify.js +++ b/source/minify.js @@ -1,11 +1,11 @@ import { relative } from 'path' -import { promises as fsAsync } from 'fs' import { minify as terserMinify } from 'terser' import { clock } from '@dr-js/core/module/common/time' import { binary, time, padTable } from '@dr-js/core/module/common/format' import { __VERBOSE__ } from './node/env' +import { copyAfterEdit } from './node/file' const getTerserOption = ({ isReadable = false, // should be much more readable // TODO: option `beautify` is being removed @@ -26,25 +26,25 @@ const getTerserOption = ({ }) const minifyFileWithTerser = async ({ filePath, option, logger }) => { - const timeStart = clock() - const scriptSource = String(await fsAsync.readFile(filePath)) - const { error, code: scriptOutput } = await terserMinify(scriptSource, option) - if (error) { - logger.padLog(`[minifyFileWithTerser] failed to minify file: ${filePath}`) - throw error - } - await fsAsync.writeFile(filePath, scriptOutput) - - const timeEnd = clock() - const sizeSource = Buffer.byteLength(scriptSource) - const sizeOutput = Buffer.byteLength(scriptOutput) - - return { - sizeSource, - sizeOutput, - timeStart, - timeEnd + const result = { + timeStart: clock() + // timeEnd: 0, + // sizeSource: 0, + // sizeOutput: 0 } + await copyAfterEdit(filePath, filePath, async (buffer) => { + const { error, code: scriptOutput } = await terserMinify(String(buffer), option) + if (error) { + logger.padLog(`[minifyFileWithTerser] failed to minify file: ${filePath}`) + throw error + } + const bufferOutput = Buffer.from(scriptOutput) + result.timeEnd = clock() + result.sizeSource = buffer.length + result.sizeOutput = bufferOutput.length + return bufferOutput + }) + return result } const minifyFileListWithTerser = async ({ fileList, option, rootPath = '', logger }) => { diff --git a/source/node/file.js b/source/node/file.js index f2a306c..c82902d 100644 --- a/source/node/file.js +++ b/source/node/file.js @@ -1,4 +1,5 @@ import { resolve, relative, sep } from 'path' +import { promises as fsAsync } from 'fs' import { catchAsync } from '@dr-js/core/module/common/error' import { isString } from '@dr-js/core/module/common/check' import { describe } from '@dr-js/core/module/common/format' @@ -55,9 +56,16 @@ const resetDirectory = async (path) => { await createDirectory(path) } +const copyAfterEdit = async ( + pathFrom, + pathTo, + editFunc = async (buffer) => buffer +) => fsAsync.writeFile(pathTo, await editFunc(await fsAsync.readFile(pathFrom))) + export { getFileListFromPathList, findPathFragList, withTempDirectory, - resetDirectory + resetDirectory, + copyAfterEdit }