Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

feat!: convert to ESM and vitest #1230

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const { overrides } = require('@netlify/eslint-config-node')

module.exports = {
extends: '@netlify/eslint-config-node',
parserOptions: {
sourceType: 'module',
},
rules: {
'import/extensions': ['error', 'ignorePackages'],
'n/no-missing-import': 'off',
// This is disabled because TypeScript transpiles some features currently
// unsupported by Node 12, i.e. optional chaining
// TODO: re-enable after dropping support for Node 12
'n/no-unsupported-features/es-syntax': 'off',
'no-magic-numbers': 'off',
// This rule enforces using Buffers with `JSON.parse()`. However, TypeScript
// does not recognize yet that `JSON.parse()` accepts Buffers as argument.
'unicorn/prefer-json-parse-buffer': 'off',
Expand Down Expand Up @@ -37,19 +37,15 @@ module.exports = {
},
},
{
files: 'tests/**/*.js',
files: 'tests/**/*.ts',
rules: {
'import/max-dependencies': 'off',
'max-lines-per-function': 'off',
'max-nested-callbacks': 'off',
'max-statements': 'off',
'no-magic-numbers': 'off',
'padding-line-between-statements': 'off',
},
},
{
files: '*.md/*.js',
parserOptions: {
sourceType: 'module',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
token: ${{ steps.get-token.outputs.token }}
release-type: node
package-name: '@netlify/@netlify/zip-it-and-ship-it'
package-name: '@netlify/zip-it-and-ship-it'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did this worked πŸ˜‚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Idea

- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v3
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,28 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Linting
if: "${{ matrix.node-version == '*' }}"
run: npm run format:ci
- name: Tests with coverage
if: "${{ matrix.node-version == '*' }}"
run: npm run test:ci -- --coverage
env:
ZISI_TEST_RATE_LIMIT: 3
- name: Tests
if: "${{ matrix.node-version != '*' }}"
run: npm run test:ci
env:
ZISI_TEST_RATE_LIMIT: 3
- name: Get test coverage flags
if: "${{ matrix.node-version == '*' }}"
id: test-coverage-flags
run: |-
os=${{ matrix.os }}
node=${{ matrix.node-version }}
echo "::set-output name=os::${os/-latest/}"
echo "::set-output name=node::node_${node//[.*]/}"
node=$(node --version)
echo "os=${os/-latest/}" >> $GITHUB_OUTPUT
echo "node=node_${node/.*.*/}" >> $GITHUB_OUTPUT
shell: bash
- uses: codecov/codecov-action@v3
if: "${{ matrix.node-version == '*' }}"
with:
file: coverage/coverage-final.json
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ node_modules
!tests/fixtures/**/node_modules
benchmarks/fixtures/*/package*.json
benchmarks/output
.delta-t.json
.delta.*
/dist
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules
tests/fixtures/
8 changes: 7 additions & 1 deletion benchmarks/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'path'
import process from 'process'

import { zipFunctions } from '../dist/main.js'

Expand All @@ -19,4 +20,9 @@ const runBenchmarks = async function () {
console.log(`${largeDepsEsbuild}ms`)
}

runBenchmarks()
try {
await runBenchmarks()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as information you could now use the vitest bench benchmarking functionality. Nothing to change here but just as a FYI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was wondering, but didn't want to add even more changes.
Not super happy with vitest yet, had to do some workarounds, so do not want to buy in yet fully :)

process.stderr.write('ESBuild benchmark finished\n')
} catch (error) {
console.error(error)
}
35 changes: 17 additions & 18 deletions benchmarks/helpers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ import { fileURLToPath } from 'url'

export const FIXTURES_DIR = fileURLToPath(new URL('../fixtures', import.meta.url))

export const timeFunction = (func, runs = 1) =>
new Promise((resolve) => {
const finishedRuns = new Map()
export const timeFunction = async (func, runs = 1) => {
const finishedRuns = new Map()

const observer = new PerformanceObserver((list) => {
const [entry] = list.getEntries()
const observer = new PerformanceObserver((list) => {
const [entry] = list.getEntries()

finishedRuns.set(entry.name, entry.duration)

if (finishedRuns.size === runs) {
const durations = [...finishedRuns.values()]
const average = durations.reduce((acc, duration) => duration + acc, 0) / runs

resolve(average)
}
})
finishedRuns.set(entry.name, entry.duration)
})

observer.observe({ entryTypes: ['measure'] })
observer.observe({ entryTypes: ['measure'] })

Array.from({ length: runs }).forEach(async (_, index) => {
await Promise.all(
Array.from({ length: runs }).map(async (_, index) => {
performance.mark(`run-${index}-start`)

await func(index)

performance.measure(`run-${index}`, `run-${index}-start`)
})
})
}),
)

const durations = [...finishedRuns.values()]
const average = durations.reduce((acc, duration) => duration + acc, 0) / runs

return average
}
9 changes: 8 additions & 1 deletion benchmarks/nft.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import process from 'process'

import { zipFunctions } from '../dist/main.js'

import { timeFunction, FIXTURES_DIR } from './helpers/main.js'
Expand All @@ -17,4 +19,9 @@ const runBenchmarks = async function () {
console.log(`${largeDepsNft}ms`)
}

runBenchmarks()
try {
await runBenchmarks()
process.stderr.write('NFT benchmark finished\n')
} catch (error) {
console.error(error)
}
2 changes: 2 additions & 0 deletions benchmarks/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -exo pipefail

npm ci --prefix benchmarks/fixtures
npm run build
node benchmarks/nft.js > .delta.largeDepsNft
Expand Down
9 changes: 8 additions & 1 deletion benchmarks/zisi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import process from 'process'

import { zipFunctions } from '../dist/main.js'

import { timeFunction, FIXTURES_DIR } from './helpers/main.js'
Expand All @@ -17,4 +19,9 @@ const runBenchmarks = async function () {
console.log(`${largeDepsZisi}ms`)
}

runBenchmarks()
try {
await runBenchmarks()
process.stderr.write('ZISI benchmark finished\n')
} catch (error) {
console.error(error)
}