Skip to content

Commit

Permalink
@dr-js/dev@0.4.3-dev.9
Browse files Browse the repository at this point in the history
notable change:
- deprecate: `fileProcessorWebpack`
- add: `copyAfterEdit` to `node/file`
- temp-fix: ci: wait for npm/cli#2411
- script sort
- package update
  • Loading branch information
dr-js committed Jan 5, 2021
1 parent 1aefc12 commit c6c692f
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 79 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci-test.yml
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion 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
Expand Down
8 changes: 4 additions & 4 deletions SPEC.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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 |
95 changes: 55 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions 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",
Expand Down Expand Up @@ -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
}
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resource/eslint/[react]/package.json
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion resource/eslint/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion resource/webpack/package.json
Expand Up @@ -4,7 +4,7 @@
"INIT#package.json"
],
"dependencies": {
"webpack": "^5.11.0",
"webpack": "^5.11.1",
"babel-loader": "^8.2.2"
}
}
9 changes: 5 additions & 4 deletions source/fileProcessor.js
Expand Up @@ -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
}
38 changes: 19 additions & 19 deletions 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
Expand All @@ -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 }) => {
Expand Down
10 changes: 9 additions & 1 deletion 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'
Expand Down Expand Up @@ -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
}

0 comments on commit c6c692f

Please sign in to comment.