Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ rules:
react/display-name: off
# Disable for convenience
react/prop-types: off
'@typescript-eslint/no-require-imports': off
6 changes: 5 additions & 1 deletion .eslintrc.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ rules:
import/no-anonymous-default-export: error
import/no-duplicates: error
import/no-namespace: error
import/no-unassigned-import: error
import/no-unassigned-import:
- error
- allow:
- '**/*.css'
- dotenv/config
settings:
import/extensions:
- .cjs
Expand Down
3 changes: 0 additions & 3 deletions .eslintrc.react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ extends:
- plugin:react/recommended
plugins:
- react
settings:
react:
version: 18.2.0
3 changes: 3 additions & 0 deletions .eslintrc.typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ parser: '@typescript-eslint/parser'
plugins:
- '@typescript-eslint'
rules:
# Shortening if-statement into &&, ||, or ternary operators.
'@typescript-eslint/no-unused-expressions': off

'@typescript-eslint/no-unused-vars':
- error
- argsIgnorePattern: ^_
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
name: Prepare release

on:
workflow_dispatch: {}
workflow_dispatch:
inputs:
version-to-bump:
default: patch
description: Version to bump
options:
- major
- minor
- patch
required: true
type: choice

jobs:
call-workflow:
Expand All @@ -10,3 +20,5 @@ jobs:
id-token: write
secrets: inherit
uses: compulim/workflows/.github/workflows/prepare-release.yml@main
with:
version-to-bump: ${{ inputs.version-to-bump }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- 💢 Moved to ESM only, in PR [#27](https://github.com/compulim/version-from-git/pull/27)
- Ported to TypeScript, in PR [#24](https://github.com/compulim/version-from-git/pull/24)
- Bumped dependencies, in PR [#23](https://github.com/compulim/version-from-git/pull/23)
- Production dependencies
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
],
"scripts": {
"build": "npm run build --if-present --workspaces",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix && npm run bump:packages && npm run bump:eslintrc",
"bump:auditfix": "npm audit fix || exit 0",
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:packages && npm run bump:eslintrc",
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump:eslintrc": "if [ -f node_modules/react/package.json ]; then docker run -e VERSION=$(cat node_modules/react/package.json | jq -r '.version') -i --rm mikefarah/yq '.settings.react.version = strenv(VERSION)' < ./.eslintrc.react.yml | tee /tmp/output.tmp && mv /tmp/output.tmp ./.eslintrc.react.yml; fi",
"bump:packages": "npm run bump --if-present --workspaces",
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"postscaffold": "npm run postscaffold:eslint:react && npm run postscaffold --if-present --workspaces",
"postscaffold:eslint:react": "npm run bump:eslintrc",
"precommit": "npm run precommit --if-present --workspaces",
Expand Down
2 changes: 2 additions & 0 deletions packages/integration-test/.eslintrc.custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
browser: true
2 changes: 2 additions & 0 deletions packages/integration-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extends:
- ./.eslintrc.custom.yml
2 changes: 2 additions & 0 deletions packages/integration-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/package-lock.json
38 changes: 38 additions & 0 deletions packages/integration-test/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"testMatch": ["**/__tests__/**/*.?([cm])[jt]s?(x)", "**/?(*.)+(spec|test).?([cm])[jt]s?(x)"],
"transform": {
"\\.cjsx?$": [
"babel-jest",
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "classic"
}
]
]
}
],
"\\.mjsx?$": [
"babel-jest",
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "classic"
}
],
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": "defaults"
}
]
]
}
]
}
}
3 changes: 3 additions & 0 deletions packages/integration-test/tsconfig.custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/strictest/tsconfig.json"
}
7 changes: 7 additions & 0 deletions packages/integration-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This configuration file is for VSCode only.
{
"compilerOptions": {
"jsx": "react"
},
"extends": "./tsconfig.custom.json"
}
Empty file.
4 changes: 4 additions & 0 deletions packages/pages/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
browser: true
extends:
- ./.eslintrc.custom.yml
2 changes: 2 additions & 0 deletions packages/pages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/public/static/
3 changes: 3 additions & 0 deletions packages/pages/src/tsconfig.custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/strictest/tsconfig.json"
}
18 changes: 18 additions & 0 deletions packages/pages/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"esModuleInterop": true,
"jsx": "react",
"lib": [
"DOM",
"ESNext",
"WebWorker"
],
"moduleResolution": "Bundler",
"noEmit": true,
"strict": true,
"target": "ESNext",
"types": []
},
"extends": "./tsconfig.custom.json"
}
Empty file.
2 changes: 2 additions & 0 deletions packages/version-from-git/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extends:
- ./.eslintrc.custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Notes: to test changes in this file, run "jest" with "--no-cache" argument.

const run = ({ filename }) => {
const escapeStringRegexp = require('escape-string-regexp');
const fs = require('fs/promises');
const { extname } = require('path');
const typeScript = require('typescript');

const TS_EXPECT_ERROR = /(\/\/\s+)(@ts-expect-error)[\s+(.*)]/gu;
const TSCONFIG = {
allowImportingTsExtensions: true,
allowSyntheticDefaultImports: true,
jsx: typeScript.JsxEmit.React,
noEmit: true,
skipLibCheck: true,
strict: true
};

async function compile(filename) {
const program = typeScript.createProgram([filename], TSCONFIG);

const emitResult = program.emit();
const allDiagnostics = typeScript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

allDiagnostics.forEach(({ file, messageText, start }) => {
if (file && start) {
const { line, character } = file.getLineAndCharacterOfPosition(start);
const message = typeScript.flattenDiagnosticMessageText(messageText, '\n');

throw new Error(`Failed to compile ${file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
throw new Error(typeScript.flattenDiagnosticMessageText(messageText, '\n'));
}
});
}

async function checkExpectError(filename) {
const sourceText = await fs.readFile(filename, 'utf-8');
const sourceTextWithoutExpectError = sourceText.replace(TS_EXPECT_ERROR, '$1');

const extension = extname(filename);
const tempFilename = filename.substring(0, filename.length - extension.length) + `.tmp${extension}`;

await fs.writeFile(tempFilename, sourceTextWithoutExpectError);

try {
const program = typeScript.createProgram([tempFilename], TSCONFIG);

const emitResult = program.emit();
const allDiagnostics = typeScript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

allDiagnostics.forEach(({ file, messageText, start }) => {
if (file && start) {
const { line } = file.getLineAndCharacterOfPosition(start);
const message = typeScript.flattenDiagnosticMessageText(messageText, '\n');

const expectedErrorLine = file.getFullText().split('\n')[line - 1];
const expectedError = expectedErrorLine?.replace(/\s*\/\/\s+/u, '').trim();
let expectedErrors = [expectedError];

try {
const parsed = JSON.parse(expectedError);

if (Array.isArray(expectedErrors) && expectedErrors.every(value => typeof value === 'string')) {
expectedErrors = parsed;
}
} catch {}

expect(message).toEqual(expect.stringMatching(new RegExp(expectedErrors.map(escapeStringRegexp).join('|'))));
} else {
throw new Error(typeScript.flattenDiagnosticMessageText(messageText, '\n'));
}
});
} finally {
fs.unlink(tempFilename);
}
}

describe(filename, () => {
test('should succeed', () => compile(filename));
test('should have @ts-expect-error describing compile errors correctly', () => checkExpectError(filename));
});
};

module.exports = {
process(_, filename) {
return { code: `(${run})(${JSON.stringify({ filename })})` };
}
};
1 change: 1 addition & 0 deletions packages/version-from-git/__tests__/types/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tmp.tsx
40 changes: 40 additions & 0 deletions packages/version-from-git/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"testPathIgnorePatterns": [
"/__setup__/",
"/lib/",
"/node_modules/",
"/__types__/",
"\\.pnp\\.[^\\/]+$"
],
"transform": {
"/__tests__/types/": [
"<rootDir>/__tests__/__setup__/typingTestTransformer.js"
],
"\\.[jt]sx?$": [
"babel-jest",
{
"presets": [
[
"@babel/preset-typescript",
{
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "18"
}
}
]
],
"sourceMaps": true
}
]
},
"watchPathIgnorePatterns": [
"\\.tmp\\."
]
}
14 changes: 7 additions & 7 deletions packages/version-from-git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"files": [
"./dist/"
],
"main": "./dist/version-from-git.mjs",
"type": "module",
"main": "./dist/version-from-git.js",
"bin": {
"version-from-git": "./dist/version-from-git.mjs"
"version-from-git": "./dist/version-from-git.js"
},
"scripts": {
"build": "tsup-node",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix",
"bump:auditfix": "npm audit fix || exit 0",
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump": "npm run bump:prod && npm run bump:dev",
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
"precommit": "npm run precommit:eslint && npm run precommit:publint && npm run precommit:typescript:production",
"precommit:eslint": "eslint ./src/",
"precommit:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint ./src/",
"precommit:publint": "publint",
"precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
"-precommit:typescript:test": "tsc --noEmit --project ./src/tsconfig.precommit.test.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { major, minor, patch } from 'semver';

const { green, magenta, red, yellow } = chalk;
const { log } = console;

const ourPackageJSON = await readPackage({ cwd: join(fileURLToPath(import.meta.url), '../../') });

const DEFAULT_TEMPLATE = 'branch.short';
Expand Down
3 changes: 3 additions & 0 deletions packages/version-from-git/src/tsconfig.custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/strictest/tsconfig.json"
}
3 changes: 1 addition & 2 deletions packages/version-from-git/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"strict": true,
"target": "ESNext",
"types": [
"jest",
"node"
]
},
"extends": "@tsconfig/strictest/tsconfig.json"
"extends": "./tsconfig.custom.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"noEmit": true,
"strict": true,
"target": "ESNext",
"types": [
"node"
]
"types": []
},
"exclude": [
"**/*.spec.ts",
Expand All @@ -19,5 +17,5 @@
"**/*.test.tsx",
"__tests__/**/*"
],
"extends": "@tsconfig/strictest/tsconfig.json"
"extends": "./tsconfig.custom.json"
}
5 changes: 4 additions & 1 deletion packages/version-from-git/src/tsconfig.precommit.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"noEmit": true,
"strict": true,
"target": "ESNext",
"types": ["jest", "node"]
"types": [
"jest",
"node"
]
},
"extends": "@tsconfig/recommended/tsconfig.json",
"include": [
Expand Down
Loading