From 774a4bca92802e6e8b5bcc80a77d741e1c147463 Mon Sep 17 00:00:00 2001 From: Victor Korzunin <5180700+floydspace@users.noreply.github.com> Date: Sat, 24 Sep 2022 23:34:59 +0200 Subject: [PATCH] style: use floydspace opinionated prettier rules; use strict node engine v16 development version --- .github/ISSUE_TEMPLATE/bug_report.md | 9 +- .github/ISSUE_TEMPLATE/feature_request.md | 1 - .npmrc | 1 + .prettierrc | 5 - README.md | 8 +- examples/complete/package.json | 12 +- examples/config/config.js | 10 +- examples/config/package.json | 6 +- examples/individually/hello1.ts | 1 - examples/individually/hello2.ts | 1 - examples/individually/package.json | 6 +- examples/individually/plugins.js | 2 +- examples/individually/serverless.yml | 3 +- examples/minimal/package.json | 12 +- package-lock.json | 270 ++++++++++++++++++++-- package.json | 89 +++---- src/bundle.ts | 18 +- src/pack-externals.ts | 80 ++----- src/pack.ts | 44 +--- src/packagers/npm.ts | 5 +- src/packagers/pnpm.ts | 9 +- src/tests/bundle.test.ts | 3 +- src/tests/helper.test.ts | 17 +- src/tests/pack.test.ts | 6 +- src/tests/packagers/npm.test.ts | 58 ++--- src/utils.ts | 29 +-- 26 files changed, 404 insertions(+), 301 deletions(-) create mode 100644 .npmrc delete mode 100644 .prettierrc diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 1b896255..ea16182a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -4,7 +4,6 @@ about: Create a report to help us improve title: '' labels: bug assignees: '' - --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior. If you have an example repository that would be even better: + 1. Set X to `true` 2. Run `sls package` @@ -22,9 +22,10 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots or logs to help explain your problem. **Versions (please complete the following information):** - - OS: [e.g. Linux, Mac, Windows] - - Serverless Framework Version: [e.g. 3.0.0] - - Plugin Version: [e.g. 1.25.0] + +- OS: [e.g. Linux, Mac, Windows] +- Serverless Framework Version: [e.g. 3.0.0] +- Plugin Version: [e.g. 1.25.0] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11fc491e..5f0a04ce 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -4,7 +4,6 @@ about: Suggest an idea for this project title: '' labels: enhancement assignees: '' - --- **Is your feature request related to a problem? Please describe.** diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..b6f27f13 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index ace696c0..00000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "tabWidth": 2, - "printWidth": 100, - "singleQuote": true -} diff --git a/README.md b/README.md index f2947c24..26f8f380 100644 --- a/README.md +++ b/README.md @@ -111,10 +111,10 @@ The following `esbuild` options are automatically set. #### Watch Options -| Option | Description | Default | -| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -| `pattern` | An [anymatch-compatible definition](https://github.com/es128/anymatch) for the watcher to respond to | `./\*_/_.(js\|ts)` (watches all `.js` and `.ts` files) | -| `ignore` | An [anymatch-compatible definition](https://github.com/es128/anymatch) for the watcher to ignore | `'.esbuild', 'dist', 'node_modules', '.build']` | +| Option | Description | Default | +| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | +| `pattern` | An [anymatch-compatible definition](https://github.com/es128/anymatch) for the watcher to respond to | `./\*_/_.(js\|ts)` (watches all `.js` and `.ts` files) | +| `ignore` | An [anymatch-compatible definition](https://github.com/es128/anymatch) for the watcher to ignore | `'.esbuild', 'dist', 'node_modules', '.build']` | ## Supported Runtimes diff --git a/examples/complete/package.json b/examples/complete/package.json index 0b617ceb..75fbc5dd 100644 --- a/examples/complete/package.json +++ b/examples/complete/package.json @@ -1,6 +1,12 @@ { "name": "complete", "version": "0.1.0", + "scripts": { + "start": "sls offline" + }, + "dependencies": { + "isin-validator": "^1.1.1" + }, "devDependencies": { "@types/node": "^11.13.0", "esbuild": "^0.14.2", @@ -9,11 +15,5 @@ "serverless-offline": "^6.4.0", "ts-node": "^8.1.0", "typescript": "~3.9.7" - }, - "dependencies": { - "isin-validator": "^1.1.1" - }, - "scripts": { - "start": "sls offline" } } diff --git a/examples/config/config.js b/examples/config/config.js index 261e770d..016a74b8 100644 --- a/examples/config/config.js +++ b/examples/config/config.js @@ -5,19 +5,17 @@ module.exports = () => { minify: true, sourcemap: false, keepNames: true, - external: [ - 'lodash' - ], + external: ['lodash'], plugins: [ { name: 'log-lodash', setup(build) { // test interception : log all lodash imports - build.onResolve({ filter: /^lodash$/ }, args => { + build.onResolve({ filter: /^lodash$/ }, (args) => { console.log(args); }); }, - } - ] + }, + ], }; }; diff --git a/examples/config/package.json b/examples/config/package.json index 68232afb..ddbce4f9 100644 --- a/examples/config/package.json +++ b/examples/config/package.json @@ -1,5 +1,8 @@ { "main": "handler.js", + "scripts": { + "start": "sls offline" + }, "dependencies": { "lodash": "^4.17.4" }, @@ -10,8 +13,5 @@ "serverless": "^2.36.0", "serverless-esbuild": "file:../..", "serverless-offline": "^6.4.0" - }, - "scripts": { - "start": "sls offline" } } diff --git a/examples/individually/hello1.ts b/examples/individually/hello1.ts index cc6162d6..7c4fda1e 100644 --- a/examples/individually/hello1.ts +++ b/examples/individually/hello1.ts @@ -2,7 +2,6 @@ import * as _ from 'lodash'; // modern module syntax export async function handler(event, context, callback) { - // dependencies work as expected console.log(_.VERSION); diff --git a/examples/individually/hello2.ts b/examples/individually/hello2.ts index cc6155e8..308402f5 100644 --- a/examples/individually/hello2.ts +++ b/examples/individually/hello2.ts @@ -1,4 +1,3 @@ - // modern module syntax export async function handler(event, context, callback) { // async/await also works out of the box diff --git a/examples/individually/package.json b/examples/individually/package.json index ffbc2498..731658f1 100644 --- a/examples/individually/package.json +++ b/examples/individually/package.json @@ -1,5 +1,8 @@ { "main": "handler.js", + "scripts": { + "start": "sls offline" + }, "dependencies": { "lodash": "^4.17.4" }, @@ -10,8 +13,5 @@ "serverless": "^2.36.0", "serverless-esbuild": "^1.26.1", "serverless-offline": "^6.4.0" - }, - "scripts": { - "start": "sls offline" } } diff --git a/examples/individually/plugins.js b/examples/individually/plugins.js index 713e57b7..cfd57b1b 100644 --- a/examples/individually/plugins.js +++ b/examples/individually/plugins.js @@ -2,7 +2,7 @@ let envPlugin = { name: 'log-lodash', setup(build) { // test interception : log all lodash imports - build.onResolve({ filter: /^lodash$/ }, args => { + build.onResolve({ filter: /^lodash$/ }, (args) => { console.log(args); }); }, diff --git a/examples/individually/serverless.yml b/examples/individually/serverless.yml index 35973ed9..8f3be7c0 100644 --- a/examples/individually/serverless.yml +++ b/examples/individually/serverless.yml @@ -13,7 +13,7 @@ provider: custom: esbuild: - plugins : ./plugins.js + plugins: ./plugins.js packager: yarn bundle: true minify: true @@ -22,7 +22,6 @@ custom: external: - lodash - functions: hello1: handler: hello1.handler diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 78af9a22..b5bb8d3d 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -1,17 +1,17 @@ { "name": "minimal", "version": "0.1.0", + "scripts": { + "start": "sls offline" + }, + "dependencies": { + "isin-validator": "^1.1.1" + }, "devDependencies": { "@types/node": "^11.13.0", "esbuild": "^0.14.2", "serverless": "^2.17.0", "serverless-esbuild": "^1.26.1", "serverless-offline": "^6.4.0" - }, - "dependencies": { - "isin-validator": "^1.1.1" - }, - "scripts": { - "start": "sls offline" } } diff --git a/package-lock.json b/package-lock.json index b0452f80..a68b36cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "devDependencies": { "@commitlint/cli": "^13.2.0", "@commitlint/config-conventional": "^13.2.0", + "@floydspace/prettier-config": "^1.36.4", "@types/archiver": "^5.1.1", "@types/fs-extra": "^9.0.1", "@types/jest": "^26.0.14", @@ -40,13 +41,13 @@ "lint-staged": "^11.1.2", "mock-fs": "^4.12.0", "mock-spawn": "^0.2.6", - "prettier": "^2.3.2", + "prettier": "^2.7.1", "semantic-release": "^19.0.2", "ts-jest": "^26.4.0", - "typescript": "^4.0.3" + "typescript": "~4.4.4" }, "engines": { - "node": ">=12" + "node": ">=16.0.0" }, "peerDependencies": { "esbuild": ">=0.8 <0.16" @@ -1026,6 +1027,18 @@ "node": ">= 4" } }, + "node_modules/@floydspace/prettier-config": { + "version": "1.36.5", + "resolved": "https://registry.npmjs.org/@floydspace/prettier-config/-/prettier-config-1.36.5.tgz", + "integrity": "sha512-mdNRqfiqtU0WFxIT0KCyB8OJCYNMFEaOwQ58aGZdh6uLdCYkjs6jwy5Z64FbZi0i5Ns7/j63oxOezQv19f7pMw==", + "dev": true, + "dependencies": { + "@prettier/plugin-xml": "~2.0.1", + "prettier": "^2.7.1", + "prettier-plugin-organize-attributes": "~0.0.5", + "sort-package-json": "^1.55.0" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", @@ -1480,6 +1493,16 @@ "@octokit/openapi-types": "^11.2.0" } }, + "node_modules/@prettier/plugin-xml": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@prettier/plugin-xml/-/plugin-xml-2.0.1.tgz", + "integrity": "sha512-zJ2+/J5ujo23oHwaiuo3DEnxnRWSw/52IP7to+XmHiTC/qG17w2ld6FbDfVrsnO2PTPp0HFotPtZFlbrPJnaqA==", + "dev": true, + "dependencies": { + "@xml-tools/parser": "^1.0.11", + "prettier": ">=2.4.0" + } + }, "node_modules/@semantic-release/commit-analyzer": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-9.0.2.tgz", @@ -2034,6 +2057,15 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@xml-tools/parser": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@xml-tools/parser/-/parser-1.0.11.tgz", + "integrity": "sha512-aKqQ077XnR+oQtHJlrAflaZaL7qZsulWc/i/ZEooar5JiWj1eLt0+Wg28cpa+XLney107wXqneC+oG1IZvxkTA==", + "dev": true, + "dependencies": { + "chevrotain": "7.1.1" + } + }, "node_modules/abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -2866,6 +2898,15 @@ "node": ">=10" } }, + "node_modules/chevrotain": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-7.1.1.tgz", + "integrity": "sha512-wy3mC1x4ye+O+QkEinVJkPf5u2vsrDIYW9G7ZuwFl6v/Yu0LwUuT2POsb+NUWApebyxfkQq6+yDfRExbnI5rcw==", + "dev": true, + "dependencies": { + "regexp-to-ast": "0.5.0" + } + }, "node_modules/chokidar": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", @@ -3535,6 +3576,15 @@ "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", "dev": true }, + "node_modules/detect-indent": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", + "integrity": "sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -4858,6 +4908,15 @@ "node": ">=0.10.0" } }, + "node_modules/git-hooks-list": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/git-hooks-list/-/git-hooks-list-1.0.3.tgz", + "integrity": "sha512-Y7wLWcrLUXwk2noSka166byGCvhMtDRpgHdzCno1UQv/n/Hegp++a2xBWJL1lJarnKD3SWaljD+0z1ztqxuKyQ==", + "dev": true, + "funding": { + "url": "https://github.com/fisker/git-hooks-list?sponsor=1" + } + }, "node_modules/git-log-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/git-log-parser/-/git-log-parser-1.2.0.tgz", @@ -10540,15 +10599,30 @@ } }, "node_modules/prettier": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.0.tgz", - "integrity": "sha512-FM/zAKgWTxj40rH03VxzIPdXmj39SwSjwG0heUcNFwI+EMZJnY93yAiKXM3dObIKAM5TA88werc8T/EwhB45eg==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-plugin-organize-attributes": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/prettier-plugin-organize-attributes/-/prettier-plugin-organize-attributes-0.0.5.tgz", + "integrity": "sha512-dSts16q8wd+oq8Zwk5mwmYXo1aN3B+ZkEJqx/ar5fedNHdOvx7S4XDMH/pNK7rmBW0bPXkp/kJX5gAANsWzh3A==", + "dev": true, + "engines": { + "node": ">=11.0.0" + }, + "peerDependencies": { + "prettier": "^2.0.0" } }, "node_modules/pretty-format": { @@ -10846,6 +10920,12 @@ "node": ">=0.10.0" } }, + "node_modules/regexp-to-ast": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.5.0.tgz", + "integrity": "sha512-tlbJqcMHnPKI9zSrystikWKwHkBqu2a/Sgw01h3zFjvYrMxEDYHzzoMZnUrbIfpTFEsoRnnviOXNCzFiSc54Qw==", + "dev": true + }, "node_modules/regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -11830,6 +11910,57 @@ "node": ">=0.10.0" } }, + "node_modules/sort-object-keys": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sort-object-keys/-/sort-object-keys-1.1.3.tgz", + "integrity": "sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==", + "dev": true + }, + "node_modules/sort-package-json": { + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.57.0.tgz", + "integrity": "sha512-FYsjYn2dHTRb41wqnv+uEqCUvBpK3jZcTp9rbz2qDTmel7Pmdtf+i2rLaaPMRZeSVM60V3Se31GyWFpmKs4Q5Q==", + "dev": true, + "dependencies": { + "detect-indent": "^6.0.0", + "detect-newline": "3.1.0", + "git-hooks-list": "1.0.3", + "globby": "10.0.0", + "is-plain-obj": "2.1.0", + "sort-object-keys": "^1.1.3" + }, + "bin": { + "sort-package-json": "cli.js" + } + }, + "node_modules/sort-package-json/node_modules/globby": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-10.0.0.tgz", + "integrity": "sha512-3LifW9M4joGZasyYPz2A1U74zbC/45fvpXUvO/9KbSa+VV0aGZarWkfdgKyR9sExNP0t0x0ss/UMJpNpcaTspw==", + "dev": true, + "dependencies": { + "@types/glob": "^7.1.1", + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.0.3", + "glob": "^7.1.3", + "ignore": "^5.1.1", + "merge2": "^1.2.3", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sort-package-json/node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -12581,9 +12712,9 @@ } }, "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -13783,6 +13914,18 @@ } } }, + "@floydspace/prettier-config": { + "version": "1.36.5", + "resolved": "https://registry.npmjs.org/@floydspace/prettier-config/-/prettier-config-1.36.5.tgz", + "integrity": "sha512-mdNRqfiqtU0WFxIT0KCyB8OJCYNMFEaOwQ58aGZdh6uLdCYkjs6jwy5Z64FbZi0i5Ns7/j63oxOezQv19f7pMw==", + "dev": true, + "requires": { + "@prettier/plugin-xml": "~2.0.1", + "prettier": "^2.7.1", + "prettier-plugin-organize-attributes": "~0.0.5", + "sort-package-json": "^1.55.0" + } + }, "@humanwhocodes/config-array": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", @@ -14174,6 +14317,16 @@ "@octokit/openapi-types": "^11.2.0" } }, + "@prettier/plugin-xml": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@prettier/plugin-xml/-/plugin-xml-2.0.1.tgz", + "integrity": "sha512-zJ2+/J5ujo23oHwaiuo3DEnxnRWSw/52IP7to+XmHiTC/qG17w2ld6FbDfVrsnO2PTPp0HFotPtZFlbrPJnaqA==", + "dev": true, + "requires": { + "@xml-tools/parser": "^1.0.11", + "prettier": ">=2.4.0" + } + }, "@semantic-release/commit-analyzer": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-9.0.2.tgz", @@ -14616,6 +14769,15 @@ "eslint-visitor-keys": "^2.0.0" } }, + "@xml-tools/parser": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@xml-tools/parser/-/parser-1.0.11.tgz", + "integrity": "sha512-aKqQ077XnR+oQtHJlrAflaZaL7qZsulWc/i/ZEooar5JiWj1eLt0+Wg28cpa+XLney107wXqneC+oG1IZvxkTA==", + "dev": true, + "requires": { + "chevrotain": "7.1.1" + } + }, "abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -15233,6 +15395,15 @@ "integrity": "sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==", "dev": true }, + "chevrotain": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-7.1.1.tgz", + "integrity": "sha512-wy3mC1x4ye+O+QkEinVJkPf5u2vsrDIYW9G7ZuwFl6v/Yu0LwUuT2POsb+NUWApebyxfkQq6+yDfRExbnI5rcw==", + "dev": true, + "requires": { + "regexp-to-ast": "0.5.0" + } + }, "chokidar": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", @@ -15757,6 +15928,12 @@ "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", "dev": true }, + "detect-indent": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", + "integrity": "sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==", + "dev": true + }, "detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -16727,6 +16904,12 @@ "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=", "dev": true }, + "git-hooks-list": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/git-hooks-list/-/git-hooks-list-1.0.3.tgz", + "integrity": "sha512-Y7wLWcrLUXwk2noSka166byGCvhMtDRpgHdzCno1UQv/n/Hegp++a2xBWJL1lJarnKD3SWaljD+0z1ztqxuKyQ==", + "dev": true + }, "git-log-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/git-log-parser/-/git-log-parser-1.2.0.tgz", @@ -20929,11 +21112,18 @@ "dev": true }, "prettier": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.0.tgz", - "integrity": "sha512-FM/zAKgWTxj40rH03VxzIPdXmj39SwSjwG0heUcNFwI+EMZJnY93yAiKXM3dObIKAM5TA88werc8T/EwhB45eg==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true }, + "prettier-plugin-organize-attributes": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/prettier-plugin-organize-attributes/-/prettier-plugin-organize-attributes-0.0.5.tgz", + "integrity": "sha512-dSts16q8wd+oq8Zwk5mwmYXo1aN3B+ZkEJqx/ar5fedNHdOvx7S4XDMH/pNK7rmBW0bPXkp/kJX5gAANsWzh3A==", + "dev": true, + "requires": {} + }, "pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", @@ -21160,6 +21350,12 @@ "safe-regex": "^1.1.0" } }, + "regexp-to-ast": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.5.0.tgz", + "integrity": "sha512-tlbJqcMHnPKI9zSrystikWKwHkBqu2a/Sgw01h3zFjvYrMxEDYHzzoMZnUrbIfpTFEsoRnnviOXNCzFiSc54Qw==", + "dev": true + }, "regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -21933,6 +22129,50 @@ } } }, + "sort-object-keys": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sort-object-keys/-/sort-object-keys-1.1.3.tgz", + "integrity": "sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==", + "dev": true + }, + "sort-package-json": { + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.57.0.tgz", + "integrity": "sha512-FYsjYn2dHTRb41wqnv+uEqCUvBpK3jZcTp9rbz2qDTmel7Pmdtf+i2rLaaPMRZeSVM60V3Se31GyWFpmKs4Q5Q==", + "dev": true, + "requires": { + "detect-indent": "^6.0.0", + "detect-newline": "3.1.0", + "git-hooks-list": "1.0.3", + "globby": "10.0.0", + "is-plain-obj": "2.1.0", + "sort-object-keys": "^1.1.3" + }, + "dependencies": { + "globby": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-10.0.0.tgz", + "integrity": "sha512-3LifW9M4joGZasyYPz2A1U74zbC/45fvpXUvO/9KbSa+VV0aGZarWkfdgKyR9sExNP0t0x0ss/UMJpNpcaTspw==", + "dev": true, + "requires": { + "@types/glob": "^7.1.1", + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.0.3", + "glob": "^7.1.3", + "ignore": "^5.1.1", + "merge2": "^1.2.3", + "slash": "^3.0.0" + } + }, + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true + } + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -22533,9 +22773,9 @@ } }, "typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index fa666255..9b38c0e4 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,32 @@ { "name": "serverless-esbuild", - "description": "Serverless plugin for zero-config JavaScript and TypeScript code bundling using extremely fast esbuild", "version": "0.0.0-development", + "description": "Serverless plugin for zero-config JavaScript and TypeScript code bundling using extremely fast esbuild", + "keywords": [ + "serverless", + "serverless plugin", + "plugin", + "esbuild", + "aws lambda", + "aws", + "lambda", + "bundler", + "minifier", + "typescript" + ], + "homepage": "https://floydspace.github.io/serverless-esbuild", + "bugs": { + "url": "https://github.com/floydspace/serverless-esbuild/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/floydspace/serverless-esbuild.git" + }, "license": "MIT", - "author": "Victor Korzunin", + "author": { + "name": "Victor Korzunin", + "url": "https://floydspace.github.io" + }, "main": "dist/index.js", "files": [ "dist", @@ -24,29 +47,30 @@ "lint": "eslint .", "prepare": "husky install" }, - "repository": { - "type": "git", - "url": "https://github.com/floydspace/serverless-esbuild.git" + "lint-staged": { + "*.ts": [ + "prettier --write", + "eslint" + ] }, - "bugs": { - "url": "https://github.com/floydspace/serverless-esbuild/issues" + "prettier": "@floydspace/prettier-config", + "dependencies": { + "acorn": "^8.7.1", + "acorn-walk": "^8.2.0", + "anymatch": "^3.1.2", + "archiver": "^5.3.0", + "bestzip": "^2.2.0", + "chokidar": "^3.4.3", + "fs-extra": "^10.1.0", + "globby": "^11.0.1", + "p-map": "^4.0.0", + "ramda": "^0.27.0", + "semver": "^7.3.5" }, - "homepage": "https://floydspace.github.io", - "keywords": [ - "serverless", - "serverless plugin", - "plugin", - "esbuild", - "aws lambda", - "aws", - "lambda", - "bundler", - "minifier", - "typescript" - ], "devDependencies": { "@commitlint/cli": "^13.2.0", "@commitlint/config-conventional": "^13.2.0", + "@floydspace/prettier-config": "^1.36.4", "@types/archiver": "^5.1.1", "@types/fs-extra": "^9.0.1", "@types/jest": "^26.0.14", @@ -63,34 +87,15 @@ "lint-staged": "^11.1.2", "mock-fs": "^4.12.0", "mock-spawn": "^0.2.6", - "prettier": "^2.3.2", + "prettier": "^2.7.1", "semantic-release": "^19.0.2", "ts-jest": "^26.4.0", - "typescript": "^4.0.3" - }, - "dependencies": { - "acorn": "^8.7.1", - "acorn-walk": "^8.2.0", - "anymatch": "^3.1.2", - "archiver": "^5.3.0", - "bestzip": "^2.2.0", - "chokidar": "^3.4.3", - "fs-extra": "^10.1.0", - "globby": "^11.0.1", - "p-map": "^4.0.0", - "ramda": "^0.27.0", - "semver": "^7.3.5" + "typescript": "~4.4.4" }, "peerDependencies": { "esbuild": ">=0.8 <0.16" }, - "lint-staged": { - "*.ts": [ - "prettier --write", - "eslint" - ] - }, "engines": { - "node": ">=12" + "node": ">=16.0.0" } } diff --git a/src/bundle.ts b/src/bundle.ts index b9e9f987..2a93966f 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -39,9 +39,7 @@ export async function bundle(this: EsbuildServerlessPlugin, incremental = false) if (!isESM(this.buildOptions) && this.buildOptions.outputFileExtension === '.mjs') { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore Serverless typings (as of v3.0.2) are incorrect - throw new this.serverless.classes.Error( - 'ERROR: Non esm builds should not output a file with extension ".mjs".' - ); + throw new this.serverless.classes.Error('ERROR: Non esm builds should not output a file with extension ".mjs".'); } if (this.buildOptions.outputFileExtension !== '.js') { @@ -65,8 +63,7 @@ export async function bundle(this: EsbuildServerlessPlugin, incremental = false) /** Build the files */ const bundleMapper = async (entry: string): Promise => { - const bundlePath = - entry.slice(0, entry.lastIndexOf('.')) + this.buildOptions.outputFileExtension; + const bundlePath = entry.slice(0, entry.lastIndexOf('.')) + this.buildOptions.outputFileExtension; // check cache if (this.buildCache) { @@ -102,13 +99,10 @@ export async function bundle(this: EsbuildServerlessPlugin, incremental = false) }); // Create a cache with entry as key - this.buildCache = fileBuildResults.reduce>( - (acc, fileBuildResult) => { - acc[fileBuildResult.entry] = fileBuildResult; - return acc; - }, - {} - ); + this.buildCache = fileBuildResults.reduce>((acc, fileBuildResult) => { + acc[fileBuildResult.entry] = fileBuildResult; + return acc; + }, {}); // Map function entries back to bundles this.buildResults = this.functionEntries.map(({ entry, func, functionAlias }) => { diff --git a/src/pack-externals.ts b/src/pack-externals.ts index 5f82a8be..74812a96 100644 --- a/src/pack-externals.ts +++ b/src/pack-externals.ts @@ -34,11 +34,7 @@ import type { JSONObject } from './types'; function rebaseFileReferences(pathToPackageRoot: string, moduleVersion: string) { if (/^(?:file:[^/]{2}|\.\/|\.\.\/)/.test(moduleVersion)) { const filePath = replace(/^file:/, '', moduleVersion); - return replace( - /\\/g, - '/', - `${startsWith('file:', moduleVersion) ? 'file:' : ''}${pathToPackageRoot}/${filePath}` - ); + return replace(/\\/g, '/', `${startsWith('file:', moduleVersion) ? 'file:' : ''}${pathToPackageRoot}/${filePath}`); } return moduleVersion; @@ -47,11 +43,7 @@ function rebaseFileReferences(pathToPackageRoot: string, moduleVersion: string) /** * Add the given modules to a package json's dependencies. */ -function addModulesToPackageJson( - externalModules: string[], - packageJson: JSONObject, - pathToPackageRoot: string -) { +function addModulesToPackageJson(externalModules: string[], packageJson: JSONObject, pathToPackageRoot: string) { forEach((externalModule) => { const splitModule = split('@', externalModule); // If we have a scoped module we have to re-add the @ @@ -71,11 +63,7 @@ function addModulesToPackageJson( * Resolve the needed versions of production dependencies for external modules. * @this - The active plugin instance */ -function getProdModules( - externalModules: { external: string }[], - packageJsonPath: string, - rootPackageJsonPath: string -) { +function getProdModules(externalModules: { external: string }[], packageJsonPath: string, rootPackageJsonPath: string) { const packageJson = this.serverless.utils.readFileSync(packageJsonPath); const prodModules = []; @@ -87,10 +75,7 @@ function getProdModules( // Get versions of all transient modules forEach((externalModule) => { // (1) If not present in Dev Dependencies or Dependencies - if ( - !packageJson.dependencies[externalModule.external] && - !packageJson.devDependencies[externalModule.external] - ) { + if (!packageJson.dependencies[externalModule.external] && !packageJson.devDependencies[externalModule.external]) { this.log.debug( `INFO: Runtime dependency '${externalModule.external}' not found in dependencies or devDependencies. It has been excluded automatically.` ); @@ -99,22 +84,15 @@ function getProdModules( } // (2) If present in Dev Dependencies - if ( - !packageJson.dependencies[externalModule.external] && - packageJson.devDependencies[externalModule.external] - ) { + if (!packageJson.dependencies[externalModule.external] && packageJson.devDependencies[externalModule.external]) { // To minimize the chance of breaking setups we whitelist packages available on AWS here. These are due to the previously missing check // most likely set in devDependencies and should not lead to an error now. const ignoredDevDependencies = ['aws-sdk']; if (!includes(externalModule.external, ignoredDevDependencies)) { // Runtime dependency found in devDependencies but not forcefully excluded - this.log.error( - `ERROR: Runtime dependency '${externalModule.external}' found in devDependencies.` - ); - throw new this.serverless.classes.Error( - `Serverless-webpack dependency error: ${externalModule.external}.` - ); + this.log.error(`ERROR: Runtime dependency '${externalModule.external}' found in devDependencies.`); + throw new this.serverless.classes.Error(`Serverless-webpack dependency error: ${externalModule.external}.`); } this.log.debug( @@ -147,8 +125,7 @@ function getProdModules( const modulePackage = modulePackagePath ? require(modulePackagePath) : {}; // Get version - const moduleVersion = - packageJson.dependencies[externalModule.external] || modulePackage.version; + const moduleVersion = packageJson.dependencies[externalModule.external] || modulePackage.version; // add dep with version if we have it - versionless otherwise if (moduleVersion) prodModules.push(`${externalModule.external}@${moduleVersion}`); @@ -167,9 +144,7 @@ function getProdModules( ); if (!isEmpty(peerDependenciesWithoutOptionals)) { - this.log.debug( - `Adding explicit non-optionals peers for dependency ${externalModule.external}` - ); + this.log.debug(`Adding explicit non-optionals peers for dependency ${externalModule.external}`); const peerModules = getProdModules.call( this, compose( @@ -182,9 +157,7 @@ function getProdModules( Array.prototype.push.apply(prodModules, peerModules); } } catch (e) { - this.log.warning( - `WARNING: Could not check for peer dependencies of ${externalModule.external}` - ); + this.log.warning(`WARNING: Could not check for peer dependencies of ${externalModule.external}`); } }, externalModules); @@ -239,8 +212,7 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) { // get the local package.json by looking up until we hit a package.json file // if this is *not* a yarn workspace, it will be the same as rootPackageJsonPath const packageJsonPath = - this.buildOptions.packagePath || - path.relative(process.cwd(), path.join(findUp('package.json'), './package.json')); + this.buildOptions.packagePath || path.relative(process.cwd(), path.join(findUp('package.json'), './package.json')); // Determine and create packager const packager = await getPackager.call(this, this.buildOptions.packager); @@ -250,16 +222,13 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) { // Get scripts from packager options const packagerScripts = this.buildOptions.packagerOptions - ? [] - .concat(this.buildOptions.packagerOptions.scripts || []) - .reduce((scripts, script, index) => { - scripts[`script${index}`] = script; - return scripts; - }, {}) + ? [].concat(this.buildOptions.packagerOptions.scripts || []).reduce((scripts, script, index) => { + scripts[`script${index}`] = script; + return scripts; + }, {}) : {}; - const rootPackageJson: Record = - this.serverless.utils.readFileSync(rootPackageJsonPath); + const rootPackageJson: Record = this.serverless.utils.readFileSync(rootPackageJsonPath); const isWorkspace = !!rootPackageJson.workspaces; @@ -305,17 +274,10 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) { ); const relativePath = path.relative(compositeModulePath, path.dirname(packageJsonPath)); addModulesToPackageJson(compositeModules, compositePackage, relativePath); - this.serverless.utils.writeFileSync( - compositePackageJson, - JSON.stringify(compositePackage, null, 2) - ); + this.serverless.utils.writeFileSync(compositePackageJson, JSON.stringify(compositePackage, null, 2)); // (1.a.2) Copy package-lock.json if it exists, to prevent unwanted upgrades - const packageLockPath = path.join( - process.cwd(), - path.dirname(packageJsonPath), - packager.lockfileName - ); + const packageLockPath = path.join(process.cwd(), path.dirname(packageJsonPath), packager.lockfileName); const exists = await fse.pathExists(packageLockPath); if (exists) { this.log.verbose('Package lock found - Using locked versions'); @@ -359,9 +321,9 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) { await packager.runScripts(this.buildDirPath, Object.keys(packagerScripts)); this.log.debug( - `Packager scripts took [${Date.now() - startScripts} ms].\nExecuted scripts: ${Object.values( - packagerScripts - ).map((script) => `\n ${script}`)}` + `Packager scripts took [${Date.now() - startScripts} ms].\nExecuted scripts: ${Object.values(packagerScripts).map( + (script) => `\n ${script}` + )}` ); } } diff --git a/src/pack.ts b/src/pack.ts index 65ca87aa..66f3626e 100644 --- a/src/pack.ts +++ b/src/pack.ts @@ -2,18 +2,7 @@ import path from 'path'; import fs from 'fs-extra'; import globby from 'globby'; -import { - intersection, - isEmpty, - lensProp, - map, - over, - pipe, - reject, - replace, - test, - without, -} from 'ramda'; +import { intersection, isEmpty, lensProp, map, over, pipe, reject, replace, test, without } from 'ramda'; import semver from 'semver'; import { ONLY_PREFIX, SERVERLESS_FOLDER } from './constants'; @@ -67,11 +56,7 @@ export const filterFilesForZipPackage = ({ if (excludedFiles.find((p) => localPath.startsWith(`${p}.`))) return false; // exclude files that belong to individual functions - if ( - localPath.startsWith(ONLY_PREFIX) && - !localPath.startsWith(`${ONLY_PREFIX}${functionAlias}/`) - ) - return false; + if (localPath.startsWith(ONLY_PREFIX) && !localPath.startsWith(`${ONLY_PREFIX}${functionAlias}/`)) return false; // exclude non whitelisted dependencies if (localPath.startsWith('node_modules')) { @@ -95,9 +80,7 @@ export async function pack(this: EsbuildServerlessPlugin) { // Google provider cannot use individual packaging for now - this could be built in a future release if (isGoogleProvider && this.serverless?.service?.package?.individually) - throw new Error( - 'Packaging failed: cannot package function individually when using Google provider' - ); + throw new Error('Packaging failed: cannot package function individually when using Google provider'); // get a list of all path in build const files: IFiles = globby @@ -130,9 +113,7 @@ export async function pack(this: EsbuildServerlessPlugin) { const { size } = fs.statSync(artifactPath); this.log.verbose( - `Zip service ${this.serverless.service.service} - ${humanSize(size)} [${ - Date.now() - startZip - } ms]` + `Zip service ${this.serverless.service.service} - ${humanSize(size)} [${Date.now() - startZip} ms]` ); // defined present zip as output artifact this.serverless.service.package.artifact = artifactPath; @@ -156,18 +137,14 @@ export async function pack(this: EsbuildServerlessPlugin) { const hasExternals = !!externals?.length; // get a tree of all production dependencies - const packagerDependenciesList = hasExternals - ? await packager.getProdDependencies(this.buildDirPath) - : {}; + const packagerDependenciesList = hasExternals ? await packager.getProdDependencies(this.buildDirPath) : {}; const packageFiles = await globby(this.serverless.service.package.patterns); // package each function await Promise.all( buildResults.map(async ({ func, functionAlias, bundlePath }) => { - const excludedFiles = bundlePathList - .filter((p) => !bundlePath.startsWith(p)) - .map(trimExtension); + const excludedFiles = bundlePathList.filter((p) => !bundlePath.startsWith(p)).map(trimExtension); const functionFiles = await globby(func.package.patterns); @@ -177,10 +154,7 @@ export async function pack(this: EsbuildServerlessPlugin) { let depWhiteList = []; if (hasExternals) { - const bundleDeps = getDepsFromBundle( - path.join(this.buildDirPath, bundlePath), - isESM(this.buildOptions) - ); + const bundleDeps = getDepsFromBundle(path.join(this.buildDirPath, bundlePath), isESM(this.buildOptions)); const bundleExternals = intersection(bundleDeps, externals); depWhiteList = flatDep(packagerDependenciesList.dependencies, bundleExternals); } @@ -209,9 +183,7 @@ export async function pack(this: EsbuildServerlessPlugin) { const { size } = fs.statSync(artifactPath); - this.log.verbose( - `Zip function: ${functionAlias} - ${humanSize(size)} [${Date.now() - startZip} ms]` - ); + this.log.verbose(`Zip function: ${functionAlias} - ${humanSize(size)} [${Date.now() - startZip} ms]`); // defined present zip as output artifact setFunctionArtifactPath.call(this, func, path.relative(this.serviceDirPath, artifactPath)); diff --git a/src/packagers/npm.ts b/src/packagers/npm.ts index 73d559a9..dba87d9f 100644 --- a/src/packagers/npm.ts +++ b/src/packagers/npm.ts @@ -143,10 +143,7 @@ export class NPM implements Packager { const hasThrowableErrors = npmErrors.every( (error) => !isEmpty(error) && - !any( - (ignoredError) => startsWith(`npm ERR! ${ignoredError.npmError}`, error), - ignoredNpmErrors - ) + !any((ignoredError) => startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredNpmErrors) ); if (!hasThrowableErrors && !isEmpty(err.stdout)) { diff --git a/src/packagers/pnpm.ts b/src/packagers/pnpm.ts index 39dddbf6..369f46d4 100644 --- a/src/packagers/pnpm.ts +++ b/src/packagers/pnpm.ts @@ -49,10 +49,7 @@ export class Pnpm implements Packager { } return ( !isEmpty(error) && - !any( - (ignoredError) => startsWith(`npm ERR! ${ignoredError.npmError}`, error), - ignoredPnpmErrors - ) + !any((ignoredError) => startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredPnpmErrors) ); }, false, @@ -98,9 +95,7 @@ export class Pnpm implements Packager { async install(cwd, extraArgs: Array, useLockfile = true) { const command = /^win/.test(process.platform) ? 'pnpm.cmd' : 'pnpm'; - const args = useLockfile - ? ['install', '--frozen-lockfile', ...extraArgs] - : ['install', ...extraArgs]; + const args = useLockfile ? ['install', '--frozen-lockfile', ...extraArgs] : ['install', ...extraArgs]; await spawnProcess(command, args, { cwd }); } diff --git a/src/tests/bundle.test.ts b/src/tests/bundle.test.ts index e9b0fb68..97ffd884 100644 --- a/src/tests/bundle.test.ts +++ b/src/tests/bundle.test.ts @@ -495,8 +495,7 @@ describe('buildOption platform neutral', () => { const plugin = esbuildPlugin({ functionEntries, buildOptions: buildOptions as any }); - const expectedError = - 'ERROR: format "esm" or platform "neutral" should not output a file with extension ".cjs".'; + const expectedError = 'ERROR: format "esm" or platform "neutral" should not output a file with extension ".cjs".'; try { await bundle.call(plugin); diff --git a/src/tests/helper.test.ts b/src/tests/helper.test.ts index a3cce8da..8f3bfab2 100644 --- a/src/tests/helper.test.ts +++ b/src/tests/helper.test.ts @@ -159,11 +159,7 @@ describe('getDepsFromBundle', () => { return require('package3'); } `); - expect(getDepsFromBundle(path, false)).toStrictEqual([ - '@scope/package1', - 'package2', - 'package3', - ]); + expect(getDepsFromBundle(path, false)).toStrictEqual(['@scope/package1', 'package2', 'package3']); }); it('should extract the base dep from a string', () => { @@ -179,9 +175,7 @@ describe('getDepsFromBundle', () => { }); it('should remove duplicate package requires', () => { - mocked(fs).readFileSync.mockReturnValue( - 'require("package1/subpath");require("package1");require("package1")' - ); + mocked(fs).readFileSync.mockReturnValue('require("package1/subpath");require("package1");require("package1")'); expect(getDepsFromBundle(path, false)).toStrictEqual(['package1']); }); }); @@ -199,12 +193,7 @@ describe('getDepsFromBundle', () => { } ` ); - expect(getDepsFromBundle(path, true)).toStrictEqual([ - 'package1', - 'package2', - 'package3', - 'package4', - ]); + expect(getDepsFromBundle(path, true)).toStrictEqual(['package1', 'package2', 'package3', 'package4']); }); it('should extract deps from a minified string', () => { diff --git a/src/tests/pack.test.ts b/src/tests/pack.test.ts index 668d5060..e2d4eae8 100644 --- a/src/tests/pack.test.ts +++ b/src/tests/pack.test.ts @@ -19,14 +19,12 @@ describe('filterFilesForZipPackage', () => { filterFilesForZipPackage({ files: [ { - localPath: - '__only_service-otherFnName/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', + localPath: '__only_service-otherFnName/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', rootPath: '/home/capaj/repos/google/search/.esbuild/.build/__only_service-otherFnName/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', }, { - localPath: - '__only_fnAlias/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', + localPath: '__only_fnAlias/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', rootPath: '/home/capaj/repos/google/search/.esbuild/.build/__only_fnAlias/bin/imagemagick/include/ImageMagick/magick/method-attribute.h', }, diff --git a/src/tests/packagers/npm.test.ts b/src/tests/packagers/npm.test.ts index 4027411a..70bc8530 100644 --- a/src/tests/packagers/npm.test.ts +++ b/src/tests/packagers/npm.test.ts @@ -79,8 +79,7 @@ describe('NPM Packager', () => { ], _from: 'samchungy-a@2.0.0', _id: 'samchungy-a@2.0.0', - _integrity: - 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', + _integrity: 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', _location: '/samchungy-a', _phantomChildren: {}, _requested: { @@ -166,8 +165,7 @@ describe('NPM Packager', () => { ], _from: 'samchungy-b@2.0.0', _id: 'samchungy-b@2.0.0', - _integrity: - 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', + _integrity: 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', _location: '/samchungy-b', _phantomChildren: {}, _requested: { @@ -320,8 +318,7 @@ describe('NPM Packager', () => { version: '2.0.0', resolved: 'https://registry.npmjs.org/samchungy-a/-/samchungy-a-2.0.0.tgz', name: 'samchungy-a', - integrity: - 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', + integrity: 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', _id: 'samchungy-a@2.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-a', @@ -350,8 +347,7 @@ describe('NPM Packager', () => { version: '2.0.0', resolved: 'https://registry.npmjs.org/samchungy-b/-/samchungy-b-2.0.0.tgz', name: 'samchungy-b', - integrity: - 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', + integrity: 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', _id: 'samchungy-b@2.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-b', @@ -434,8 +430,7 @@ describe('NPM Packager', () => { ], _from: 'samchungy-a@3.0.0', _id: 'samchungy-a@3.0.0', - _integrity: - 'sha512-5u55rgjPpASgPDU2jLYf4HCt31jUVtzy/r42q4SyJ4W+ItggEk+8w3WBfXRcQgxYyyWflL1F9w85u3Wudj542g==', + _integrity: 'sha512-5u55rgjPpASgPDU2jLYf4HCt31jUVtzy/r42q4SyJ4W+ItggEk+8w3WBfXRcQgxYyyWflL1F9w85u3Wudj542g==', _location: '/samchungy-a', _phantomChildren: {}, _requested: { @@ -503,8 +498,7 @@ describe('NPM Packager', () => { fetchSpec: '1.0.0', }, _requiredBy: ['/samchungy-dep-b'], - _resolved: - 'https://registry.npmjs.org/samchungy-dep-c/-/samchungy-dep-c-1.0.0.tgz', + _resolved: 'https://registry.npmjs.org/samchungy-dep-c/-/samchungy-dep-c-1.0.0.tgz', _spec: '1.0.0', _where: '/workdir/.esbuild/.build', author: '', @@ -531,8 +525,7 @@ describe('NPM Packager', () => { fetchSpec: '1.0.0', }, _requiredBy: ['/samchungy-dep-c', '/samchungy-dep-d'], - _resolved: - 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', + _resolved: 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', _spec: '1.0.0', _where: '/workdir/.esbuild/.build', author: '', @@ -586,8 +579,7 @@ describe('NPM Packager', () => { fetchSpec: '1.0.0', }, _requiredBy: ['/samchungy-dep-b'], - _resolved: - 'https://registry.npmjs.org/samchungy-dep-d/-/samchungy-dep-d-1.0.0.tgz', + _resolved: 'https://registry.npmjs.org/samchungy-dep-d/-/samchungy-dep-d-1.0.0.tgz', _spec: '1.0.0', _where: '/workdir/.esbuild/.build', author: '', @@ -611,8 +603,7 @@ describe('NPM Packager', () => { fetchSpec: '1.0.0', }, _requiredBy: '[Circular]', - _resolved: - 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', + _resolved: 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', _spec: '1.0.0', _where: '/workdir/.esbuild/.build', author: '', @@ -680,8 +671,7 @@ describe('NPM Packager', () => { ], _from: 'samchungy-b@5.0.0', _id: 'samchungy-b@5.0.0', - _integrity: - 'sha512-Swb34L5tb1agVosN97lXr+HzMzYXvwt2XuZAe9YGVzAWYduObaS5Rc0lwYUkILqKmwqLmtb29Jc2veiNAmU2zw==', + _integrity: 'sha512-Swb34L5tb1agVosN97lXr+HzMzYXvwt2XuZAe9YGVzAWYduObaS5Rc0lwYUkILqKmwqLmtb29Jc2veiNAmU2zw==', _location: '/samchungy-b', _phantomChildren: {}, _requested: { @@ -829,8 +819,7 @@ describe('NPM Packager', () => { version: '3.0.0', resolved: 'https://registry.npmjs.org/samchungy-a/-/samchungy-a-3.0.0.tgz', name: 'samchungy-a', - integrity: - 'sha512-5u55rgjPpASgPDU2jLYf4HCt31jUVtzy/r42q4SyJ4W+ItggEk+8w3WBfXRcQgxYyyWflL1F9w85u3Wudj542g==', + integrity: 'sha512-5u55rgjPpASgPDU2jLYf4HCt31jUVtzy/r42q4SyJ4W+ItggEk+8w3WBfXRcQgxYyyWflL1F9w85u3Wudj542g==', _id: 'samchungy-a@3.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-a', @@ -856,8 +845,7 @@ describe('NPM Packager', () => { dependencies: { 'samchungy-dep-c': { version: '1.0.0', - resolved: - 'https://registry.npmjs.org/samchungy-dep-c/-/samchungy-dep-c-1.0.0.tgz', + resolved: 'https://registry.npmjs.org/samchungy-dep-c/-/samchungy-dep-c-1.0.0.tgz', name: 'samchungy-dep-c', integrity: 'sha512-YMLl+vnxi7kNr59zq+FFVfBBKyPyxqc7LUU92ZYTkTJaEGHNlCyC2fVC+diIVaomhn4CNAqmOGIVqbr5sq8lQg==', @@ -870,8 +858,7 @@ describe('NPM Packager', () => { dependencies: { 'samchungy-dep-e': { version: '1.0.0', - resolved: - 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', + resolved: 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', name: 'samchungy-dep-e', integrity: 'sha512-phnrKKAOuZdVrVk86R6CNU62YC4bRr/Ru1SokC5ZqkXh4QR30XU4ApSTuLbFADb6F3HWKZTGelaoklyMW2mveg==', @@ -886,8 +873,7 @@ describe('NPM Packager', () => { }, 'samchungy-dep-d': { version: '1.0.0', - resolved: - 'https://registry.npmjs.org/samchungy-dep-d/-/samchungy-dep-d-1.0.0.tgz', + resolved: 'https://registry.npmjs.org/samchungy-dep-d/-/samchungy-dep-d-1.0.0.tgz', name: 'samchungy-dep-d', integrity: 'sha512-yxXY2+OVhx1e5QZWSWrCajs5b2FCD0CV2ztss+7x4IgQbM0u5gMfzva31kMZFzX2iLJ7iy+09DYpe34TSRrzsA==', @@ -901,8 +887,7 @@ describe('NPM Packager', () => { 'samchungy-dep-e': { version: '1.0.0', name: 'samchungy-dep-e', - resolved: - 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', + resolved: 'https://registry.npmjs.org/samchungy-dep-e/-/samchungy-dep-e-1.0.0.tgz', integrity: 'sha512-phnrKKAOuZdVrVk86R6CNU62YC4bRr/Ru1SokC5ZqkXh4QR30XU4ApSTuLbFADb6F3HWKZTGelaoklyMW2mveg==', _id: 'samchungy-dep-e@1.0.0', @@ -922,8 +907,7 @@ describe('NPM Packager', () => { version: '5.0.0', resolved: 'https://registry.npmjs.org/samchungy-b/-/samchungy-b-5.0.0.tgz', name: 'samchungy-b', - integrity: - 'sha512-Swb34L5tb1agVosN97lXr+HzMzYXvwt2XuZAe9YGVzAWYduObaS5Rc0lwYUkILqKmwqLmtb29Jc2veiNAmU2zw==', + integrity: 'sha512-Swb34L5tb1agVosN97lXr+HzMzYXvwt2XuZAe9YGVzAWYduObaS5Rc0lwYUkILqKmwqLmtb29Jc2veiNAmU2zw==', _id: 'samchungy-b@5.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-b', @@ -1059,8 +1043,7 @@ describe('NPM Packager', () => { version: '2.0.0', resolved: 'https://registry.npmjs.org/samchungy-a/-/samchungy-a-2.0.0.tgz', name: 'samchungy-a', - integrity: - 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', + integrity: 'sha512-gUv/cvd9AFYvvGep0e9m1wSAf3dfnb71eri5TjtgC6N7qvJALXFaFVOkLNBHEYGEm2ZJdosXvGqr3ISZ7Yh46Q==', _id: 'samchungy-a@2.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-a', @@ -1089,8 +1072,7 @@ describe('NPM Packager', () => { version: '2.0.0', resolved: 'https://registry.npmjs.org/samchungy-b/-/samchungy-b-2.0.0.tgz', name: 'samchungy-b', - integrity: - 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', + integrity: 'sha512-i42OG9FC2Py3RfbI8bBFZi3VoN7+MxM0OUvFcWrsIgqvZMUDVI4hNKHqpE6GTt07gDDqQnxlMNehbrsQLtHRVA==', _id: 'samchungy-b@2.0.0', extraneous: false, path: '/workdir/.esbuild/.build/node_modules/samchungy-b', @@ -1136,9 +1118,7 @@ describe('NPM Packager', () => { spawnSpy .mockResolvedValueOnce({ stderr: '', stdout: '7.0.0' }) - .mockRejectedValueOnce( - new utils.SpawnError('a spawn error', JSON.stringify(v7depsList), npm7stderr) - ); + .mockRejectedValueOnce(new utils.SpawnError('a spawn error', JSON.stringify(v7depsList), npm7stderr)); const result = await npm.getProdDependencies(path); expect(result).toStrictEqual({ stdout: JSON.stringify(v7depsList) }); diff --git a/src/utils.ts b/src/utils.ts index b0db9239..513853b8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -25,11 +25,7 @@ export class SpawnError extends Error { * @param {string[]} [args] - Arguments * @param {Object} [options] - Options for child_process.spawn */ -export function spawnProcess( - command: string, - args: string[], - options: childProcess.SpawnOptionsWithoutStdio -) { +export function spawnProcess(command: string, args: string[], options: childProcess.SpawnOptionsWithoutStdio) { return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => { const child = childProcess.spawn(command, args, options); let stdout = ''; @@ -49,13 +45,7 @@ export function spawnProcess( }); child.on('close', (exitCode) => { if (exitCode !== 0) { - reject( - new SpawnError( - `${command} ${join(' ', args)} failed with code ${exitCode}`, - stdout, - stderr - ) - ); + reject(new SpawnError(`${command} ${join(' ', args)} failed with code ${exitCode}`, stdout, stderr)); } else { resolve({ stdout, stderr }); } @@ -66,10 +56,7 @@ export function spawnProcess( /** * Find a file by walking up parent directories */ -export function findUp( - names: string | string[], - directory: string = process.cwd() -): string | undefined { +export function findUp(names: string | string[], directory: string = process.cwd()): string | undefined { const absoluteDirectory = path.resolve(directory); if (typeof names === 'string') { @@ -104,20 +91,14 @@ export const humanSize = (size: number) => { return `${sanitized} ${['B', 'KB', 'MB', 'GB', 'TB'][i]}`; }; -export const zip = async ( - zipPath: string, - filesPathList: IFiles, - useNativeZip = false -): Promise => { +export const zip = async (zipPath: string, filesPathList: IFiles, useNativeZip = false): Promise => { // create a temporary directory to hold the final zip structure const tempDirName = `${path.basename(zipPath).slice(0, -4)}-${Date.now().toString()}`; const tempDirPath = path.join(os.tmpdir(), tempDirName); fs.mkdirpSync(tempDirPath); // copy all required files from origin path to (sometimes modified) target path - await Promise.all( - filesPathList.map((file) => fs.copy(file.rootPath, path.join(tempDirPath, file.localPath))) - ); + await Promise.all(filesPathList.map((file) => fs.copy(file.rootPath, path.join(tempDirPath, file.localPath)))); // prepare zip folder fs.mkdirpSync(path.dirname(zipPath));