1
0
Fork 0

feature(build): replace rollup with esbuild

BREAKING CHANGE: this changes how the config schema is loaded and while it passes the tests, has
the potential to break some workflows.
This commit is contained in:
Sean Sube 2023-01-01 17:15:22 -06:00
parent e7c5312637
commit 618cab74f0
61 changed files with 657 additions and 1602 deletions

View File

@ -17,16 +17,6 @@
"eslint-plugin-sonarjs",
"@typescript-eslint"
],
"overrides": [
{
"files": [
"Test*"
],
"rules": {
"@typescript-eslint/unbound-method": "off"
}
}
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": [
@ -241,13 +231,9 @@
],
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": "off",
"@typescript-eslint/no-redeclare": [
"error"
],
"@typescript-eslint/no-shadow": [
"error"
],
"no-shadow": "off",
"@typescript-eslint/no-redeclare": ["error"],
"@typescript-eslint/no-shadow": ["error"],
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
@ -306,4 +292,4 @@
"sonarjs/no-useless-catch": "error",
"sonarjs/prefer-immediate-return": "error"
}
}
}

View File

@ -1,6 +1,6 @@
include:
- local: /config/gitlab/ci-tools.yml
- local: /config/gitlab/ci-rules.yml
- local: /.gitlab/ci-tools.yml
- local: /.gitlab/ci-rules.yml
stages:
- status-pre

173
Makefile
View File

@ -1,174 +1 @@
# Git
export GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
export GIT_COMMIT ?= $(shell git rev-parse HEAD)
export GIT_OPTIONS ?=
export GIT_REMOTES ?= $(shell git remote -v | awk '{ print $1; }' | sort | uniq)
export GIT_TAG ?= $(shell git tag -l --points-at HEAD | head -1)
# Paths
# resolve the makefile's path and directory, from https://stackoverflow.com/a/18137056
export MAKE_PATH ?= $(abspath $(lastword $(MAKEFILE_LIST)))
export ROOT_PATH ?= $(dir $(MAKE_PATH))
export CONFIG_PATH ?= $(ROOT_PATH)/config
export DOCS_PATH ?= $(ROOT_PATH)/docs
export SCRIPT_PATH ?= $(ROOT_PATH)/scripts
export SOURCE_PATH ?= $(ROOT_PATH)/src
export TARGET_PATH ?= $(ROOT_PATH)/out
export TARGET_LOG ?= $(TARGET_PATH)/make.log
export TARGET_MAIN ?= $(TARGET_PATH)/index.js
export TEST_PATH ?= $(ROOT_PATH)/test
export VENDOR_PATH ?= $(ROOT_PATH)/vendor
# CI
export CI_COMMIT_REF_SLUG ?= $(GIT_BRANCH)
export CI_COMMIT_SHA ?= $(GIT_COMMIT)
export CI_COMMIT_TAG ?= $(GIT_TAG)
export CI_ENVIRONMENT_SLUG ?= local
export CI_JOB_ID ?= 0
export CI_PROJECT_PATH ?= $(shell ROOT_PATH=$(ROOT_PATH) ${SCRIPT_PATH}/ci-project-path.sh)
export CI_RUNNER_DESCRIPTION ?= $(shell hostname)
export CI_RUNNER_ID ?= $(shell hostname)
export CI_RUNNER_VERSION ?= 0.0.0
# Debug
export DEBUG_BIND ?= 127.0.0.1
export DEBUG_PORT ?= 9229
# Versions
export NODE_VERSION := $(shell node -v || echo "none")
export RUNNER_VERSION := $(CI_RUNNER_VERSION)
# Node options
NODE_BIN := $(ROOT_PATH)/node_modules/.bin
NODE_CMD ?= $(shell env node)
NODE_DEBUG ?= --inspect-brk=$(DEBUG_BIND):$(DEBUG_PORT) --nolazy
NODE_INFO := $(shell node -v)
# Tool options
COVER_OPTS ?= --reporter=lcov --reporter=text-summary --reporter=html --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap
MOCHA_OPTS ?= --check-leaks --colors --sort --ui bdd --require $(ROOT_PATH)/scripts/mocha-preload.cjs
RELEASE_OPTS ?= --commit-all
.PHONY: all clean clean-deps clean-target configure help todo
.PHONY: build build-bundle build-docs build-image test test-check test-cover test-watch
.PHONY: yarn-install yarn-upgrade git-push git-stats license-check release release-dry upload-climate upload-codecov
all: build test ## builds, bundles, and tests the application
@echo Success!
clean: ## clean up everything added by the default target
clean: clean-deps clean-target
clean-deps: ## clean up the node_modules directory
rm -rf node_modules
clean-target: ## clean up the target directory
rm -rf $(TARGET_PATH)
configure: ## create the target directory and other files not in git
mkdir -p $(TARGET_PATH)
node_modules: yarn-install
# from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort \
| sed 's/^.*\/\(.*\)/\1/' \
| awk 'BEGIN {FS = ":[^:]*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
todo:
@echo "Remaining tasks:"
@echo ""
@grep -i "todo" -r docs/ src/ test/ || true
@echo ""
@echo "Pending tests:"
@echo ""
@grep "[[:space:]]xit" -r test/ || true
@echo "Casts to any:"
@echo ""
@grep "as any" -r src/ test/ || true
@echo ""
# Build targets
build: ## builds, bundles, and tests the application
build: build-bundle build-docs
build-bundle: node_modules
$(NODE_BIN)/rollup --config $(CONFIG_PATH)/rollup/config.js
sed -i '1s;^;#! /usr/bin/env node\n\n;' $(TARGET_PATH)/index.js
build-docs: ## generate html docs
$(NODE_BIN)/api-extractor run --config $(CONFIG_PATH)/api-extractor.json --local -v
$(NODE_BIN)/api-documenter markdown -i $(TARGET_PATH)/api -o $(DOCS_PATH)/api
build-image: ## build a docker image
$(SCRIPT_PATH)/docker-build.sh --push
test: ## run mocha unit tests
test: test-check
test-check: ## run mocha unit tests with coverage reports
$(NODE_BIN)/c8 $(COVER_OPTS) \
$(NODE_BIN)/mocha $(MOCHA_OPTS) \
$(TARGET_PATH)/test.js
test-cover: ## run mocha unit tests with coverage reports
test-cover: test-check
sed -i $(TARGET_PATH)/coverage/lcov.info \
-e '/external ".*"$$/,/end_of_record/d' \
-e '/ sync$$/,/end_of_record/d' \
-e '/test sync/,/end_of_record/d' \
-e '/node_modules/,/end_of_record/d' \
-e '/bootstrap$$/,/end_of_record/d' \
-e '/universalModuleDefinition/,/end_of_record/d'
sed -n '/^SF/,$$p' -i $(TARGET_PATH)/coverage/lcov.info
sed '1s;^;TN:\n;' -i $(TARGET_PATH)/coverage/lcov.info
yarn-install: ## install dependencies from package and lock file
NODE_ENV='' yarn
yarn-global: ## install bundle as a global tool
yarn global add file:$(ROOT_PATH)
yarn-update: ## check yarn for outdated packages
yarn upgrade-interactive --latest
# release targets
git-push: ## push to both gitlab and github (this assumes you have both remotes set up)
git push $(GIT_OPTIONS) github $(GIT_BRANCH)
git push $(GIT_OPTIONS) gitlab $(GIT_BRANCH)
# from https://gist.github.com/amitchhajer/4461043#gistcomment-2349917
git-stats: ## print git contributor line counts (approx, for fun)
git ls-files | while read f; do git blame -w -M -C -C --line-porcelain "$$f" |\
grep -I '^author '; done | sort -f | uniq -ic | sort -n
license-check: ## check license status
licensed cache
licensed status
release: ## create a release
$(NODE_BIN)/standard-version --sign $(RELEASE_OPTS)
GIT_OPTIONS=--tags $(MAKE) git-push
release-dry: ## test creating a release
$(NODE_BIN)/standard-version --sign $(RELEASE_OPTS) --dry-run
upload-climate:
cc-test-reporter format-coverage -t lcov -o $(TARGET_PATH)/coverage/codeclimate.json -p $(ROOT_PATH) $(TARGET_PATH)/coverage/lcov.info
cc-test-reporter upload-coverage --debug -i $(TARGET_PATH)/coverage/codeclimate.json -r "$(shell echo "${CODECLIMATE_SECRET}" | base64 -d)"
upload-codecov:
codecov --disable=gcov --file=$(TARGET_PATH)/coverage/lcov.info --token=$(shell echo "${CODECOV_SECRET}" | base64 -d)
upload-sonar: node_modules
sonar-scanner \
-Dsonar.projectKey=${CI_PROJECT_NAMESPACE}_${CI_PROJECT_NAME} \
-Dsonar.projectVersion=${CI_COMMIT_REF_SLUG} \
-Dsonar.organization=${CI_PROJECT_NAMESPACE}-github \
-Dsonar.sources=src/,test/ \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=${SONAR_SECRET} \
-Dsonar.typescript.lcov.reportPaths=out/coverage/lcov.info
include $(shell find $(ROOT_PATH) -name '*.mk' | grep -v node_modules)

View File

@ -4,31 +4,27 @@
"mainEntryPointFilePath": "<projectFolder>/out/src/index.d.ts",
"apiReport": {
"enabled": true,
"reportFolder": "<projectFolder>/out/",
"reportFolder": "<projectFolder>/docs/",
"reportTempFolder": "<projectFolder>/out/tmp/"
},
"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/out/api/<unscopedPackageName>.api.json"
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/out/index.d.ts",
"betaTrimmedFilePath": "<projectFolder>/out/index-beta.d.ts",
"publicTrimmedFilePath": "<projectFolder>/out/index-public.d.ts"
},
"tsdocMetadata": {
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning"

92
config/common.mk Normal file
View File

@ -0,0 +1,92 @@
SHELL := bash
# Git
export GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
export GIT_COMMIT ?= $(shell git rev-parse HEAD)
export GIT_OPTIONS ?=
export GIT_REMOTES ?= $(shell git remote -v | awk '{ print $1; }' | sort | uniq)
export GIT_TAG ?= $(shell git tag -l --points-at HEAD | head -1)
# Paths
# resolve the makefile's path and directory, from https://stackoverflow.com/a/18137056
export MAKE_PATH ?= $(abspath $(firstword $(MAKEFILE_LIST)))
export ROOT_PATH ?= $(dir $(MAKE_PATH))
export CONFIG_PATH ?= $(ROOT_PATH)/config
export DOCS_PATH ?= $(ROOT_PATH)/docs
export SCRIPT_PATH ?= $(ROOT_PATH)/scripts
export SOURCE_PATH ?= $(ROOT_PATH)/src
export TARGET_PATH ?= $(ROOT_PATH)/out
export TARGET_LOG ?= $(TARGET_PATH)/make.log
export TARGET_MAIN ?= $(TARGET_PATH)/index.js
export TEST_PATH ?= $(ROOT_PATH)/test
export VENDOR_PATH ?= $(ROOT_PATH)/vendor
# CI
export CI_COMMIT_REF_SLUG ?= $(GIT_BRANCH)
export CI_COMMIT_SHA ?= $(GIT_COMMIT)
export CI_COMMIT_TAG ?= $(GIT_TAG)
export CI_ENVIRONMENT_SLUG ?= local
export CI_JOB_ID ?= 0
export CI_PROJECT_PATH ?= $(shell ROOT_PATH=$(ROOT_PATH) ${SCRIPT_PATH}/ci-project-path.sh)
export CI_RUNNER_DESCRIPTION ?= $(shell hostname)
export CI_RUNNER_ID ?= $(shell hostname)
export CI_RUNNER_VERSION ?= 0.0.0
.PHONY: all ci clean clean-target configure help release release-dry todo
# Targets that must be provided by other files: bundle, build, cover, docs, clean-deps
all: lint build cover docs ## builds, bundles, and tests the application
@echo Success!
clean: ## clean up everything added by the default target
clean: clean-deps clean-target
clean-target: ## clean up the target directory
rm -rf out/
configure: ## create the target directory and other files not in git
mkdir -p $(TARGET_PATH)
# from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort \
| sed 's/^.*\/\(.*\)/\1/' \
| awk 'BEGIN {FS = ":[^:]*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
RELEASE_ARGS ?= --commit-all --sign
release: ## tag and push a release
release: node_modules
if [[ "$(GIT_BRANCH)" != master ]]; \
then \
echo "Please merge to master before releasing."; \
exit 1; \
fi
yarn standard-version $(RELEASE_ARGS)
GIT_ARGS=--follow-tags $(MAKE) push
release-dry: ## test creating a release
RELEASE_ARGS="$(RELEASE_ARGS) --dry-run" make release
todo:
@echo "Remaining tasks:"
@echo ""
@grep -i "todo" -r docs/ src/ test/ || true
@echo ""
@echo "Pending tests:"
@echo ""
@grep "[[:space:]]xit" -r test/ || true
@echo ""
@echo "Casts to any:"
@echo ""
@grep "as any" -r src/ test/ || true
@echo ""
@echo "Uses of null:"
@echo ""
@grep -P -e "null(?!able)" -r src/ test/ || true
@echo ""
@echo "Uses of ==:"
@echo ""
@grep -e "[^=!]==[^=]" -r src/ test/ || true
@echo ""

24
config/esbuild.mjs Normal file
View File

@ -0,0 +1,24 @@
import { build } from 'esbuild';
import { join } from 'path';
const root = process.cwd();
build({
bundle: true,
entryPoints: [
join(root, 'out/src/index.js'),
],
format: 'cjs',
keepNames: true,
loader: {
'.yml': 'text',
},
outdir: 'out/bundle/',
outExtension: {
'.js': '.cjs',
},
platform: 'node',
}).catch((err) => {
console.error(err);
process.exit(1);
});

12
config/git.mk Normal file
View File

@ -0,0 +1,12 @@
.PHONY: push git-stats git-push
push: git-push
# from https://gist.github.com/amitchhajer/4461043#gistcomment-2349917
git-stats: ## print git contributor line counts (approx, for fun)
git ls-files | while read f; do git blame -w -M -C -C --line-porcelain "$$f" |\
grep -I '^author '; done | sort -f | uniq -ic | sort -n
git-push: ## push to both github and gitlab
git push $(GIT_ARGS) github $(GIT_BRANCH)
git push $(GIT_ARGS) gitlab $(GIT_BRANCH)

18
config/image.mk Normal file
View File

@ -0,0 +1,18 @@
.PHONY: image image-build image-run
image: ## build the docker image
docker build $(DOCKER_ARGS) -f Dockerfile -t $(DOCKER_IMAGE) .
image-build: ## build a docker image
$(SCRIPT_PATH)/docker-build.sh --push
image-run: ## run the development image
image-run:
podman run --rm -it \
-e SSH_AUTH_SOCK=${SSH_AUTH_SOCK} \
-v /run/user/$(shell id -u)/:/run/user/$(shell id -u)/:ro \
-v $(shell dirname ${SSH_AUTH_SOCK}):$(shell dirname ${SSH_AUTH_SOCK}):rw \
-v ${HOME}/.gnupg/:/root/.gnupg/:rw \
-v $(ROOT_PATH):$(ROOT_PATH):rw \
-w $(ROOT_PATH) \
docker.artifacts.apextoaster.com/apextoaster/node:16.6 bash

86
config/node.mk Normal file
View File

@ -0,0 +1,86 @@
export NODE_VERSION := $(shell node -v 2>/dev/null || echo "none")
export PACKAGE_NAME := $(shell jq -r '.name' package.json 2>/dev/null || echo "unknown")
export PACKAGE_VERSION := $(shell jq -r '.version' package.json 2>/dev/null || echo "unknown")
export RUNNER_VERSION := $(CI_RUNNER_VERSION)
# Debug
export DEBUG_BIND ?= 127.0.0.1
export DEBUG_PORT ?= 9229
# Node options
NODE_CMD ?= $(shell env node)
NODE_DEBUG ?= --inspect-brk=$(DEBUG_BIND):$(DEBUG_PORT) --nolazy
.PHONY: build bundle ci clean-deps cover deps docs lint test yarn-global yarn-upgrade
# directory targets
node_modules: deps
out: build
# phony targets
build: ## build the app
build: node_modules
yarn tsc
cat $(TARGET_PATH)/src/version.js | envsubst > $(TARGET_PATH)/src/version-out.js
mv $(TARGET_PATH)/src/version-out.js $(TARGET_PATH)/src/version.js
bundle: build
cp $(ROOT_PATH)/src/config/schema.yml $(TARGET_PATH)/src/config/schema.yml
node config/esbuild.mjs
bundle-shebang: bundle
sed -i '1s;^;#! /usr/bin/env node\n\n;' $(TARGET_PATH)/bundle/index.cjs
chmod ug+x $(TARGET_PATH)/bundle/index.cjs
ci: clean-target lint build bundle bundle-shebang cover docs
clean-deps: ## clean up the node_modules directory
rm -rf node_modules/
COVER_ARGS := --all \
--check-coverage \
--exclude ".eslintrc.js" \
--exclude "bundle/**" \
--exclude "config/**" \
--exclude "docs/**" \
--exclude "examples/**" \
--exclude "out/bundle/**" \
--exclude "out/coverage/**" \
--exclude "vendor/**" \
--reporter=text-summary \
--reporter=lcov \
--report-dir=out/coverage
cover: ## run tests with coverage
cover: node_modules out
yarn c8 $(COVER_ARGS) yarn mocha $(MOCHA_ARGS) "out/**/Test*.js"
deps:
yarn
docs:
yarn api-extractor run -c config/api-extractor.json
yarn api-documenter markdown -i out/api -o docs/api
lint: ## run eslint
lint: node_modules
yarn eslint src/ --ext .ts,.tsx
MOCHA_ARGS := --async-only \
--check-leaks \
--forbid-only \
--require source-map-support/register \
--require out/test/setup.js \
--recursive \
--sort
test: ## run tests
test: node_modules out
yarn mocha $(MOCHA_ARGS) "out/**/Test*.js"
yarn-global: ## install bundle as a global tool
yarn global add file:$(ROOT_PATH)
yarn-upgrade: ## check yarn for potential upgrades
yarn upgrade-interactive --latest

69
config/project.mk Normal file
View File

@ -0,0 +1,69 @@
.PHONY: cover-fixup
IMAGE_OPTIONS ?=
ci-full: ci test-examples test-rules
cover-fixup: ## run mocha unit tests with coverage reports
cover-fixup: cover
sed -i $(TARGET_PATH)/coverage/lcov.info \
-e '/external ".*"$$/,/end_of_record/d' \
-e '/ sync$$/,/end_of_record/d' \
-e '/test sync/,/end_of_record/d' \
-e '/node_modules/,/end_of_record/d' \
-e '/bootstrap$$/,/end_of_record/d' \
-e '/universalModuleDefinition/,/end_of_record/d'
sed -n '/^SF/,$$p' -i $(TARGET_PATH)/coverage/lcov.info
sed '1s;^;TN:\n;' -i $(TARGET_PATH)/coverage/lcov.info
full: ## ultra thorough build (looong)
$(MAKE) clean-target ci
$(MAKE) clean-target local-alpine local-chown-leaks
$(MAKE) clean-target local-stretch local-chown-leaks
$(MAKE) clean-target
@echo "Full build (CI, alpine, stretch) succeeded!"
local: build cover run-help
local-alpine:
podman run $(IMAGE_OPTIONS) --rm -v "$(shell pwd):/salty-dog" -w /salty-dog docker.io/node:16-alpine sh -c "apk add bash build-base git && make ci"
local-stretch:
podman run $(IMAGE_OPTIONS) --rm -v "$(shell pwd):/salty-dog" -w /salty-dog docker.io/node:16-stretch bash -c "make ci"
local-chown-leaks: ## clean up root-owned files the containers may leak
sudo chown -R ${USER}:${USER} $(ROOT_PATH)
# run targets
run-help: ## print the help
@node out/index.js --help
run-stream: ## validate stdin and write it to stdout, errors to stderr
@node out/index.js \
--config-path $(ROOT_PATH)/docs \
--config-name config-stderr.yml \
--dest - \
--format yaml \
--rules $(ROOT_PATH)/rules/tsconfig.yml \
--source - \
--tag tsconfig
test-examples: ## run medium (feature) tests
$(SCRIPT_PATH)/test-examples.sh
test-rules: ## validate the rules directory
test-rules: build
find $(ROOT_PATH)/rules -maxdepth 1 -name '*.yml' | while read file; \
do \
echo "Validating $${file}..."; \
node out/src/index.js \
--config-path $(ROOT_PATH)/docs \
--config-name config-stderr.yml \
--rules $(ROOT_PATH)/rules/salty-dog.yml \
--source $${file} \
--tag salty-dog 2>&1 >/dev/null | yarn bunyan || exit 1; \
done
upload-climate:
cc-test-reporter format-coverage -t lcov -o $(TARGET_PATH)/coverage/codeclimate.json -p $(ROOT_PATH) $(TARGET_PATH)/coverage/lcov.info
cc-test-reporter upload-coverage --debug -i $(TARGET_PATH)/coverage/codeclimate.json -r "$(shell echo "${CODECLIMATE_SECRET}" | base64 -d)"

View File

@ -1,49 +0,0 @@
{
"chunks": [
{
"name": "index",
"includes": [
"/src/index"
],
"match": []
},
{
"name": "test",
"includes": [
"/test/"
],
"match": [
"node_modules/chai",
"node_modules/chai-as-promised",
"node_modules/sinon",
"node_modules/sinon-chai"
]
},
{
"name": "vendor",
"includes": [
"node_modules/"
],
"match": [
"commonjs-external",
"commonjsHelpers",
"node-resolve:"
]
},
{
"name": "main",
"includes": [
"/src/",
"/rules/"
],
"match": []
},
{
"name": "virtual",
"includes": [],
"match": [
"virtual:"
]
}
]
}

View File

@ -1,103 +0,0 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import multiEntry from '@rollup/plugin-multi-entry';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import yaml from '@rollup/plugin-yaml';
import { join } from 'path';
import { eslint } from 'rollup-plugin-eslint';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
const { chunkMap } = require('./map.cjs');
const { plugins } = require('./project.cjs');
const flag_debug = process.env['DEBUG'] === 'TRUE';
const flag_devel = process.env['NODE_ENV'] === 'production';
const flag_serve = flag_devel || process.env['SERVE'] === 'TRUE';
const metadata = require('../../package.json');
const chunks = require('./chunks.json').chunks;
const external = require('./external.json').names;
const rootPath = process.env['ROOT_PATH'];
const targetPath = process.env['TARGET_PATH'];
const bundle = {
external,
input: {
include: [
join(rootPath, 'src', 'index.ts'),
join(rootPath, 'test', 'harness.ts'),
join(rootPath, 'test', '**', 'Test*.ts'),
],
},
manualChunks: chunkMap(chunks, flag_debug),
output: {
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
exports: 'named',
format: 'module',
minifyInternalExports: false,
sourcemap: true,
},
plugins: [
multiEntry(),
json(),
yaml(),
replace({
delimiters: ['{{ ', ' }}'],
values: {
BUILD_JOB: process.env['CI_JOB_ID'],
BUILD_RUNNER: process.env['CI_RUNNER_DESCRIPTION'],
GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'],
GIT_COMMIT: process.env['CI_COMMIT_SHA'],
NODE_VERSION: process.env['NODE_VERSION'],
PACKAGE_NAME: metadata.name,
PACKAGE_VERSION: metadata.version,
},
}),
...plugins,
resolve({
preferBuiltins: true,
}),
commonjs(),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
join('node_modules', '**'),
join('src', 'resource'),
join('src', '**', '*.json'),
join('src', '**', '*.yml'),
],
include: [
join('src', '**', '*.ts'),
join('test', '**', '*.ts'),
],
throwOnError: true,
useEslintrc: false,
}),
typescript({
cacheRoot: join(targetPath, 'cache', 'rts2'),
rollupCommonJSResolveHack: true,
}),
(flag_serve ? serve({
host: '0.0.0.0',
open: true,
verbose: true,
contentBase: [
join(rootPath, 'out'),
join(rootPath, 'resources'),
],
mimeTypes: {
'application/javascript': ['mjs'],
},
}) : undefined),
],
};
export default [
bundle,
];

View File

@ -1,13 +0,0 @@
{
"names": [
"@gitbeaker/node",
"@octokit",
"async_hooks",
"chai",
"dtrace-provider",
"node-fetch",
"sinon",
"source-map",
"source-map-support"
]
}

View File

@ -1,45 +0,0 @@
function chunkMap(map, debug = false) {
return function (name) {
for (const def of map) {
const chunk = def.name;
for (const include of def.includes) {
if (name.includes(include)) {
if (debug) {
console.info('chunk includes name', chunk, name);
}
return chunk;
}
}
for (const match of def.match) {
if (name.match(match)) {
if (debug) {
console.info('chunk matches name', chunk, name);
}
return chunk;
}
}
}
if (name.length === 30 && name.match(/^[a-f0-9]+$/)) {
if (debug) {
console.info('generated chunk name', chunk, name);
}
return 'vendor';
}
if (debug) {
console.info('name does not match any chunk', chunk, name);
}
return 'unknown';
}
}
module.exports = {
chunkMap,
};

View File

@ -1,15 +0,0 @@
const { join } = require('path');
const alias = require('rollup-plugin-alias');
module.exports = {
plugins: [
alias({
resolve: ['.tsx', '.ts'],
entries: {
'@gitbeaker/node': require.resolve('@gitbeaker/node'),
'universal-user-agent': join('.', 'node_modules', 'universal-user-agent', 'dist-node', 'index.js'),
'universal-github-app-jwt': join('.', 'node_modules', 'universal-github-app-jwt', 'dist-node', 'index.js'),
},
}),
],
};

View File

@ -14,7 +14,7 @@
"es2017",
"esnext.asynciterable"
],
"module": "es6",
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,

View File

@ -14,8 +14,8 @@ export interface ChangeSet
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [adds](./cautious-journey.changeset.adds.md) | Array&lt;LabelRef&gt; | |
| [removes](./cautious-journey.changeset.removes.md) | Array&lt;LabelRef&gt; | |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [adds](./cautious-journey.changeset.adds.md) | | Array&lt;LabelRef&gt; | |
| [removes](./cautious-journey.changeset.removes.md) | | Array&lt;LabelRef&gt; | |

View File

@ -11,7 +11,7 @@ Github/Octokit API implementation of the `Remote` contract.
```typescript
export declare class GithubRemote extends BaseRemote<Octokit, RemoteOptions> implements Remote
```
<b>Extends:</b> BaseRemote&lt;Octokit, [RemoteOptions](./cautious-journey.remoteoptions.md)
<b>Extends:</b> BaseRemote&lt;Octokit, [RemoteOptions](./cautious-journey.remoteoptions.md)<!-- -->&gt;
<b>Implements:</b> [Remote](./cautious-journey.remote.md)

View File

@ -11,7 +11,7 @@ Gitlab API implementation of the `Remote` contract.
```typescript
export declare class GitlabRemote extends BaseRemote<GitlabType, RemoteOptions> implements Remote
```
<b>Extends:</b> BaseRemote&lt;GitlabType, [RemoteOptions](./cautious-journey.remoteoptions.md)
<b>Extends:</b> BaseRemote&lt;GitlabType, [RemoteOptions](./cautious-journey.remoteoptions.md)<!-- -->&gt;
<b>Implements:</b> [Remote](./cautious-journey.remote.md)

View File

@ -22,6 +22,6 @@ export interface Remote
| [deleteLabel(options)](./cautious-journey.remote.deletelabel.md) | Delete an existing label. |
| [listIssues(options)](./cautious-journey.remote.listissues.md) | List all issues. |
| [listLabels(options)](./cautious-journey.remote.listlabels.md) | List all labels. |
| [updateIssue(options)](./cautious-journey.remote.updateissue.md) | Update an issue.<!-- -->Only labels will be modified. |
| [updateIssue(options)](./cautious-journey.remote.updateissue.md) | <p>Update an issue.</p><p>Only labels will be modified.</p> |
| [updateLabel(options)](./cautious-journey.remote.updatelabel.md) | Update a label. |

View File

@ -13,10 +13,10 @@ export interface RemoteOptions extends BaseOptions
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [data](./cautious-journey.remoteoptions.data.md) | Record&lt;string, string&gt; | Arbitrary key-value data for this remote, usually credentials and base URLs. |
| [dryrun](./cautious-journey.remoteoptions.dryrun.md) | boolean | If set, do not make any real changes. |
| [logger](./cautious-journey.remoteoptions.logger.md) | Logger | |
| [type](./cautious-journey.remoteoptions.type.md) | string | Remote class/type name. |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [data](./cautious-journey.remoteoptions.data.md) | | Record&lt;string, string&gt; | Arbitrary key-value data for this remote, usually credentials and base URLs. |
| [dryrun](./cautious-journey.remoteoptions.dryrun.md) | | boolean | If set, do not make any real changes. |
| [logger](./cautious-journey.remoteoptions.logger.md) | | Logger | |
| [type](./cautious-journey.remoteoptions.type.md) | | string | Remote class/type name. |

View File

@ -14,10 +14,10 @@ export interface ResolveInput
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [flags](./cautious-journey.resolveinput.flags.md) | Array&lt;[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->&gt; | |
| [initial](./cautious-journey.resolveinput.initial.md) | Array&lt;string&gt; | |
| [labels](./cautious-journey.resolveinput.labels.md) | Array&lt;string&gt; | |
| [states](./cautious-journey.resolveinput.states.md) | Array&lt;[StateLabel](./cautious-journey.statelabel.md)<!-- -->&gt; | |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [flags](./cautious-journey.resolveinput.flags.md) | | Array&lt;[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->&gt; | |
| [initial](./cautious-journey.resolveinput.initial.md) | | Array&lt;string&gt; | |
| [labels](./cautious-journey.resolveinput.labels.md) | | Array&lt;string&gt; | |
| [states](./cautious-journey.resolveinput.states.md) | | Array&lt;[StateLabel](./cautious-journey.statelabel.md)<!-- -->&gt; | |

View File

@ -14,9 +14,9 @@ export interface ResolveResult
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [changes](./cautious-journey.resolveresult.changes.md) | Array&lt;ChangeRecord&gt; | |
| [errors](./cautious-journey.resolveresult.errors.md) | Array&lt;ErrorRecord&gt; | |
| [labels](./cautious-journey.resolveresult.labels.md) | Array&lt;string&gt; | |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [changes](./cautious-journey.resolveresult.changes.md) | | Array&lt;ChangeRecord&gt; | |
| [errors](./cautious-journey.resolveresult.errors.md) | | Array&lt;ErrorRecord&gt; | |
| [labels](./cautious-journey.resolveresult.labels.md) | | Array&lt;string&gt; | |

View File

@ -15,8 +15,8 @@ export interface StateLabel extends BaseLabel
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [divider](./cautious-journey.statelabel.divider.md) | string | |
| [values](./cautious-journey.statelabel.values.md) | Array&lt;[StateValue](./cautious-journey.statevalue.md)<!-- -->&gt; | Values for this state. |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [divider](./cautious-journey.statelabel.divider.md) | | string | |
| [values](./cautious-journey.statelabel.values.md) | | Array&lt;[StateValue](./cautious-journey.statevalue.md)<!-- -->&gt; | Values for this state. |

View File

@ -15,7 +15,7 @@ export interface StateValue extends BaseLabel
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [becomes](./cautious-journey.statevalue.becomes.md) | Array&lt;StateChange&gt; | State changes that could occur to this value. |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [becomes](./cautious-journey.statevalue.becomes.md) | | Array&lt;StateChange&gt; | State changes that could occur to this value. |

View File

@ -12,10 +12,10 @@ export interface SyncOptions
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [logger](./cautious-journey.syncoptions.logger.md) | Logger | |
| [project](./cautious-journey.syncoptions.project.md) | ProjectConfig | |
| [random](./cautious-journey.syncoptions.random.md) | RandomGenerator | |
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [logger](./cautious-journey.syncoptions.logger.md) | | Logger | |
| [project](./cautious-journey.syncoptions.project.md) | | ProjectConfig | |
| [random](./cautious-journey.syncoptions.random.md) | | RandomGenerator | |
| [remote](./cautious-journey.syncoptions.remote.md) | | [Remote](./cautious-journey.remote.md) | |

View File

@ -23,13 +23,6 @@
"@microsoft/api-extractor": "7.33.6",
"@octokit/auth-app": "4.0.7",
"@octokit/rest": "19.0.5",
"@rollup/plugin-alias": "3.1.9",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-multi-entry": "4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-replace": "4.0.0",
"@rollup/plugin-yaml": "3.1.0",
"@types/bunyan": "1.8.8",
"@types/chai": "4.3.4",
"@types/chai-as-promised": "7.1.5",
@ -46,6 +39,7 @@
"c8": "7.12.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"esbuild": "^0.16.12",
"eslint": "8.29.0",
"eslint-plugin-chai": "0.0.1",
"eslint-plugin-chai-expect": "3.0.0",
@ -59,26 +53,12 @@
"memfs": "3.4.12",
"mocha": "10.1.0",
"noicejs": "4.0.0",
"rollup": "2.79.1",
"rollup-plugin-alias": "2.2.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-eslint": "7.0.0",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-multi-entry": "2.1.0",
"rollup-plugin-node-externals": "4.1.1",
"rollup-plugin-node-polyfills": "0.2.1",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-serve": "1.1.0",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.34.1",
"rollup-plugin-uglify": "6.0.4",
"rollup-plugin-yaml": "2.0.0",
"seedrandom": "3.0.5",
"sinon": "15.0.0",
"sinon-chai": "3.7.0",
"source-map-support": "0.5.21",
"standard-version": "9.5.0",
"tslib": "2.4.1",
"typescript": "4.9.4",
"yargs": "17.6.2"
},

View File

@ -1,13 +0,0 @@
const sourceMapSupport = require('source-map-support');
sourceMapSupport.install({
environment: 'node',
handleUncaughtExceptions: true,
hookRequire: true,
});
const chai = require('chai');
const chaiPromise = require('chai-as-promised');
const chaiSinon = require('sinon-chai');
chai.use(chaiPromise);
chai.use(chaiSinon);

View File

@ -1,6 +1,6 @@
import yargs from 'yargs';
import { VERSION_INFO } from '../version';
import { VERSION_INFO } from '../version.js';
export enum Commands {
UNKNOWN = 'unknown',

View File

@ -3,10 +3,10 @@ import Ajv from 'ajv';
import { promises } from 'fs';
import { load } from 'js-yaml';
import { LogLevel } from 'noicejs';
import { join } from 'path';
import { FlagLabel, StateLabel } from '../labels';
import { RemoteOptions } from '../remote';
import * as SCHEMA_DATA from './schema.yml';
import { FlagLabel, StateLabel } from '../labels.js';
import { RemoteOptions } from '../remote/index.js';
let { readFile } = promises;
@ -82,16 +82,22 @@ export const CONFIG_SCHEMA_KEY = 'cautious-journey#/definitions/config';
* Load the config from files.
*/
export async function initConfig(path: string): Promise<ConfigData> {
const schema = createSchema({});
const schemaPath = join(import.meta.url, '..', 'schema.yml');
// eslint-disable-next-line no-console
console.log('init config, schema path', schemaPath);
const configSchema = await readFile(schemaPath);
const validator = new Ajv(AJV_OPTIONS);
validator.addSchema(SCHEMA_DATA, 'cautious-journey');
validator.addSchema(configSchema, 'cautious-journey');
const data = await readFile(path, {
encoding: 'utf8',
});
const yamlSchema = createSchema({});
const config = load(data, {
schema,
schema: yamlSchema,
});
if (validator.validate(CONFIG_SCHEMA_KEY, config) === true) {

View File

@ -1,8 +1,8 @@
import { mustExist } from '@apextoaster/js-utils';
import { BaseLabel, FlagLabel, getValueName, StateChange, StateLabel } from './labels';
import { ChangeVerb } from './resolve';
import { defaultTo, defaultUntil } from './utils';
import { BaseLabel, FlagLabel, getValueName, StateChange, StateLabel } from './labels.js';
import { ChangeVerb } from './resolve.js';
import { defaultTo, defaultUntil } from './utils.js';
export const COLOR_CHANGE = 'aaaaaa';
export const COLOR_LABEL = 'cccccc';

View File

@ -1,11 +1,11 @@
import { main } from './main';
import { main } from './main.js';
export { ChangeSet, FlagLabel, StateLabel, StateValue } from './labels';
export { Remote, RemoteOptions } from './remote';
export { GithubRemote } from './remote/github';
export { GitlabRemote } from './remote/gitlab';
export { ResolveInput, ResolveResult, resolveProject } from './resolve';
export { syncIssueLabels, SyncOptions, syncProjectLabels } from './sync';
export { ChangeSet, FlagLabel, StateLabel, StateValue } from './labels.js';
export { Remote, RemoteOptions } from './remote/index.js';
export { GithubRemote } from './remote/github.js';
export { GitlabRemote } from './remote/gitlab.js';
export { ResolveInput, ResolveResult, resolveProject } from './resolve.js';
export { syncIssueLabels, SyncOptions, syncProjectLabels } from './sync.js';
const STATUS_ERROR = 1;

View File

@ -1,6 +1,6 @@
import { doesExist } from '@apextoaster/js-utils';
import { RandomGenerator, randomItem } from './utils';
import { RandomGenerator, randomItem } from './utils.js';
/**
* A reference to another label.

View File

@ -1,23 +1,27 @@
import { doesExist, InvalidArgumentError } from '@apextoaster/js-utils';
import { Container, Logger } from 'noicejs';
import { alea } from 'seedrandom';
import seedrandom from 'seedrandom';
import { initConfig, ProjectConfig } from './config';
import { Commands, parseArgs, ParsedArgs } from './config/args';
import { dotGraph, graphProject } from './graph';
import { BunyanLogger } from './logger/bunyan';
import { RemoteModule } from './module/RemoteModule';
import { Remote, RemoteOptions } from './remote';
import { syncIssueLabels, SyncOptions, syncProjectLabels } from './sync';
import { defaultUntil } from './utils';
import { VERSION_INFO } from './version';
import { initConfig, ProjectConfig } from './config/index.js';
import { Commands, parseArgs, ParsedArgs } from './config/args.js';
import { dotGraph, graphProject } from './graph.js';
import { BunyanLogger } from './logger/bunyan.js';
import { RemoteModule } from './module/RemoteModule.js';
import { Remote, RemoteOptions } from './remote/index.js';
import { syncIssueLabels, SyncOptions, syncProjectLabels } from './sync.js';
import { defaultUntil } from './utils.js';
import { VERSION_INFO } from './version.js';
export { FlagLabel, StateLabel } from './labels';
export { Remote, RemoteOptions } from './remote';
export { GithubRemote } from './remote/github';
export { GitlabRemote } from './remote/gitlab';
export { resolveProject } from './resolve';
export { syncIssueLabels, syncProjectLabels } from './sync';
// eslint-disable-next-line @typescript-eslint/unbound-method
const { alea } = seedrandom;
export { alea as random };
export { FlagLabel, StateLabel } from './labels.js';
export { Remote, RemoteOptions } from './remote/index.js';
export { GithubRemote } from './remote/github.js';
export { GitlabRemote } from './remote/gitlab.js';
export { resolveProject } from './resolve.js';
export { syncIssueLabels, syncProjectLabels } from './sync.js';
const ARGS_START = 2;

View File

@ -1,10 +1,10 @@
import { Gitlab } from '@gitbeaker/node';
import { Module, ModuleOptions, Provides } from 'noicejs';
import { Remote, RemoteOptions } from '../remote';
import { GithubRemote } from '../remote/github';
import { GitlabOptions, GitlabRemote, INJECT_GITLAB } from '../remote/gitlab';
import { kebabCase } from '../utils';
import { Remote, RemoteOptions } from '../remote/index.js';
import { GithubRemote } from '../remote/github.js';
import { GitlabOptions, GitlabRemote, INJECT_GITLAB } from '../remote/gitlab.js';
import { kebabCase } from '../utils.js';
export class RemoteModule extends Module {
public async configure(options: ModuleOptions) {

View File

@ -1,8 +1,8 @@
import { doesExist, InvalidArgumentError } from '@apextoaster/js-utils';
import { CommentUpdate, IssueUpdate, LabelQuery, LabelUpdate, ProjectQuery, Remote, RemoteOptions } from '.';
import { ChangeVerb } from '../resolve';
import { VERSION_INFO } from '../version';
import { ChangeVerb } from '../resolve.js';
import { VERSION_INFO } from '../version.js';
export abstract class BaseRemote<TClient, TOptions extends RemoteOptions> implements Remote {
protected client?: TClient;

View File

@ -3,7 +3,7 @@ import { createAppAuth } from '@octokit/auth-app';
import { Octokit } from '@octokit/rest';
import { CommentUpdate, IssueUpdate, LabelQuery, LabelUpdate, ProjectQuery, Remote, RemoteOptions } from '.';
import { BaseRemote } from './base';
import { BaseRemote } from './base.js';
/**
* Github/Octokit API implementation of the `Remote` contract.

View File

@ -3,7 +3,7 @@ import { Gitlab as GitlabType } from '@gitbeaker/core';
import { BaseOptions } from 'noicejs';
import { CommentUpdate, IssueUpdate, LabelUpdate, ProjectQuery, Remote, RemoteOptions } from '.';
import { BaseRemote } from './base';
import { BaseRemote } from './base.js';
export const INJECT_GITLAB = Symbol('inject-gitlab');

View File

@ -1,6 +1,6 @@
import { BaseOptions, Logger } from 'noicejs';
import { ChangeRecord, ErrorRecord } from '../resolve';
import { ChangeRecord, ErrorRecord } from '../resolve.js';
export interface ProjectQuery {
project: string;

View File

@ -1,7 +1,7 @@
import { doesExist } from '@apextoaster/js-utils';
import { BaseLabel, FlagLabel, getValueName, prioritySort, StateLabel, StateValue } from './labels';
import { defaultUntil } from './utils';
import { BaseLabel, FlagLabel, getValueName, prioritySort, StateLabel, StateValue } from './labels.js';
import { defaultUntil } from './utils.js';
/**
* How a label changed.

View File

@ -1,11 +1,11 @@
import { doesExist, InvalidArgumentError, mustExist } from '@apextoaster/js-utils';
import { Logger } from 'noicejs';
import { ProjectConfig } from './config';
import { getLabelColor, getLabelNames, getValueName } from './labels';
import { LabelUpdate, Remote } from './remote';
import { resolveProject } from './resolve';
import { compareItems, defaultTo, defaultUntil, RandomGenerator } from './utils';
import { ProjectConfig } from './config/index.js';
import { getLabelColor, getLabelNames, getValueName } from './labels.js';
import { LabelUpdate, Remote } from './remote/index.js';
import { resolveProject } from './resolve.js';
import { compareItems, defaultTo, defaultUntil, RandomGenerator } from './utils.js';
export interface SyncOptions {
logger: Logger;

View File

@ -13,8 +13,8 @@ import {
graphState,
labelEdges,
mergeEdges,
} from '../src/graph';
import { ChangeVerb } from '../src/resolve';
} from '../src/graph.js';
import { ChangeVerb } from '../src/resolve.js';
describe('graph tools', () => {
describe('label edges', () => {

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { alea } from 'seedrandom';
import { getLabelColor, getLabelNames, prioritySort, StateLabel } from '../src/labels';
import { getLabelColor, getLabelNames, prioritySort, StateLabel } from '../src/labels.js';
import { random } from '../src/main.js';
describe('label helpers', () => {
describe('label name helper', () => {
@ -108,7 +108,7 @@ describe('label helpers', () => {
describe('label color helper', () => {
it('should return the value color', () => {
expect(getLabelColor(['test'], alea(), {
expect(getLabelColor(['test'], random(), {
adds: [],
color: 'beans',
divider: '/',
@ -129,7 +129,7 @@ describe('label helpers', () => {
});
it('should return the state color when value color is unset', () => {
expect(getLabelColor(['test'], alea(), {
expect(getLabelColor(['test'], random(), {
adds: [],
color: 'beans',
divider: '/',
@ -150,7 +150,7 @@ describe('label helpers', () => {
});
it('should return the flag color', () => {
expect(getLabelColor(['test'], alea(), {
expect(getLabelColor(['test'], random(), {
adds: [],
color: 'not',
name: '',
@ -161,7 +161,7 @@ describe('label helpers', () => {
});
it('should return a random color when the flag color is unset', () => {
expect(getLabelColor(['test'], alea(), {
expect(getLabelColor(['test'], random(), {
adds: [],
name: '',
priority: 1,

View File

@ -3,10 +3,10 @@ import { expect } from 'chai';
import { Container, NullLogger } from 'noicejs';
import sinon from 'sinon';
import { Commands, ParsedArgs } from '../src/config/args';
import { GithubRemote, mainProject, Remote, RemoteOptions, STATUS_FAILURE, STATUS_SUCCESS } from '../src/main';
import { RemoteModule } from '../src/module/RemoteModule';
import { ProjectConfig } from '../src/config';
import { Commands, ParsedArgs } from '../src/config/args.js';
import { GithubRemote, mainProject, Remote, RemoteOptions, STATUS_FAILURE, STATUS_SUCCESS } from '../src/main.js';
import { RemoteModule } from '../src/module/RemoteModule.js';
import { ProjectConfig } from '../src/config/index.js';
const { createStubInstance } = sinon;

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { resolveProject } from '../src/resolve';
import { TEST_CASES } from './resolve/cases';
import { resolveProject } from '../src/resolve.js';
import { TEST_CASES } from './resolve/cases.js';
const TEST_LABELS = ['bar', 'foo'];

View File

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { compareItems, defaultTo, defaultUntil, kebabCase } from '../src/utils';
import { compareItems, defaultTo, defaultUntil, kebabCase } from '../src/utils.js';
const TEST_TRUE = 'foo';
const TEST_FALSE = 'bar';

View File

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { Commands, parseArgs } from '../../src/config/args';
import { Commands, parseArgs } from '../../src/config/args.js';
describe('args', () => {
it('should set command mode', async () => {

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { vol } from 'memfs';
import { Filesystem, initConfig, setFs } from '../../src/config';
import { Filesystem, initConfig, setFs } from '../../src/config/index.js';
describe('config', () => {
describe('init config', () => {

View File

@ -1,7 +1,7 @@
import bunyan from 'bunyan';
import { expect } from 'chai';
import { BunyanLogger } from '../../src/logger/bunyan';
import { BunyanLogger } from '../../src/logger/bunyan.js';
describe('bunyan logger', async () => {
it('should create a logger', async () => {

View File

@ -2,8 +2,8 @@ import { Gitlab } from '@gitbeaker/node';
import { expect } from 'chai';
import { Container } from 'noicejs';
import { RemoteModule } from '../../src/module/RemoteModule';
import { INJECT_GITLAB } from '../../src/remote/gitlab';
import { RemoteModule } from '../../src/module/RemoteModule.js';
import { INJECT_GITLAB } from '../../src/remote/gitlab.js';
describe('remote module', async () => {
it('should create a Gitlab client', async () => {

View File

@ -4,11 +4,11 @@ import { expect } from 'chai';
import { BaseOptions, Container, NullLogger } from 'noicejs';
import sinon from 'sinon';
import { RemoteOptions } from '../../src';
import { RemoteModule } from '../../src/module/RemoteModule';
import { GithubRemote } from '../../src/remote/github';
import { ChangeVerb } from '../../src/resolve';
import { createRemoteContainer } from './helpers';
import { RemoteModule } from '../../src/module/RemoteModule.js';
import { GithubRemote } from '../../src/remote/github.js';
import { RemoteOptions } from '../../src/remote/index.js';
import { ChangeVerb } from '../../src/resolve.js';
import { createRemoteContainer } from './helpers.js';
const { stub } = sinon;

View File

@ -3,9 +3,9 @@ import { expect } from 'chai';
import { NullLogger } from 'noicejs';
import sinon from 'sinon';
import { RemoteOptions } from '../../src';
import { GitlabRemote, INJECT_GITLAB } from '../../src/remote/gitlab';
import { createRemoteContainer } from './helpers';
import { GitlabRemote, INJECT_GITLAB } from '../../src/remote/gitlab.js';
import { RemoteOptions } from '../../src/remote/index.js';
import { createRemoteContainer } from './helpers.js';
const { stub } = sinon;

View File

@ -1,6 +1,6 @@
import { Container } from 'noicejs';
import { RemoteModule } from '../../src/module/RemoteModule';
import { RemoteModule } from '../../src/module/RemoteModule.js';
export async function createRemoteContainer() {
const module = new RemoteModule();

View File

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { resolveProject } from '../../src/resolve';
import { resolveProject } from '../../src/resolve.js';
describe('resolve labels', () => {
describe('flags with unfulfilled requires rule', () => {

View File

@ -1,5 +1,5 @@
import { ResolveInput, ResolveResult } from '../../src/resolve';
import { StateLabel, FlagLabel } from '../../src';
import { FlagLabel, StateLabel } from '../../src/labels.js';
import { ResolveInput, ResolveResult } from '../../src/resolve.js';
export interface ResolveTestCase {
input: ResolveInput;

20
test/setup.ts Normal file
View File

@ -0,0 +1,20 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
export function setupTests(): void {
/**
* This will break the whole test run if any test leaks an unhandled rejection.
*/
process.on('unhandledRejection', (reason, promise) => {
/* c8 ignore next 3 */
// eslint-disable-next-line no-console
console.error('unhandled error during tests', reason);
process.exit(1);
});
chai.use(chaiAsPromised);
chai.use(sinonChai);
}
setupTests();

View File

@ -1,11 +1,11 @@
import { NotImplementedError } from '@apextoaster/js-utils';
import { expect } from 'chai';
import { Container, NullLogger } from 'noicejs';
import { alea } from 'seedrandom';
import sinon from 'sinon';
import { random } from '../../src/main.js';
import { GithubRemote } from '../../src/remote/github';
import { syncIssueLabels } from '../../src/sync';
import { GithubRemote } from '../../src/remote/github.js';
import { syncIssueLabels } from '../../src/sync.js';
const { stub } = sinon;
@ -54,7 +54,7 @@ describe('issue sync', () => {
remote: remoteData,
states: [],
},
random: alea(),
random: random(),
remote,
});
expect(listStub).to.have.callCount(1);
@ -104,7 +104,7 @@ describe('issue sync', () => {
remote: remoteData,
states: [],
},
random: alea(),
random: random(),
remote,
});
@ -144,7 +144,7 @@ describe('issue sync', () => {
remote: remoteData,
states: [],
},
random: alea(),
random: random(),
remote,
});

View File

@ -1,13 +1,13 @@
import { InvalidArgumentError, NotImplementedError } from '@apextoaster/js-utils';
import { expect } from 'chai';
import { Container, NullLogger } from 'noicejs';
import { alea } from 'seedrandom';
import sinon from 'sinon';
import { BunyanLogger } from '../../src/logger/bunyan';
import { GithubRemote } from '../../src/remote/github';
import { syncProjectLabels, updateLabel } from '../../src/sync';
import { FlagLabel, StateLabel } from '../../src';
import { FlagLabel, StateLabel } from '../../src/labels.js';
import { BunyanLogger } from '../../src/logger/bunyan.js';
import { random } from '../../src/main.js';
import { GithubRemote } from '../../src/remote/github.js';
import { syncProjectLabels, updateLabel } from '../../src/sync.js';
const { createStubInstance, match, spy, stub } = sinon;
@ -73,7 +73,7 @@ describe('project sync', () => {
remote: remoteConfig,
states: [],
},
random: alea(),
random: random(),
remote,
}, {
color: '',
@ -120,7 +120,7 @@ describe('project sync', () => {
remote: remoteConfig,
states: [],
},
random: alea(),
random: random(),
remote,
});
@ -157,7 +157,7 @@ describe('project sync', () => {
remote: remoteConfig,
states: [TEST_STATE],
},
random: alea(),
random: random(),
remote,
});
@ -201,7 +201,7 @@ describe('project sync', () => {
remote: remoteConfig,
states: [],
},
random: alea(),
random: random(),
remote,
});
@ -237,7 +237,7 @@ describe('project sync', () => {
remote: remoteConfig,
states: [],
},
random: alea(),
random: random(),
remote,
});
@ -282,7 +282,7 @@ describe('project sync', () => {
},
states: [TEST_STATE],
},
random: alea(),
random: random(),
remote,
}, {
color: '',
@ -314,7 +314,7 @@ describe('project sync', () => {
},
states: [],
},
random: alea(),
random: random(),
remote: createStubInstance(GithubRemote),
}, {
color: '',

1185
yarn.lock

File diff suppressed because it is too large Load Diff