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
27 changes: 27 additions & 0 deletions .github/workflows/unit-tests-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unit tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build_and_test:
name: Build and test package on ${{ matrix.os }}/${{ matrix.node-version }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [ 18.x, 19.x, 20.x ]
os: [ ubuntu-latest, windows-latest, macos-latest ]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
1 change: 1 addition & 0 deletions .readme-assets/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 9 additions & 155 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,169 +1,23 @@
# Copyright 2023 Liquid Labs, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file was generated by @liquid-labs/catalyst-lib-makefiles. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-lib-makefiles for further
# details

BUILD_KEY:=regex-repo
SRC:=src
CATALYST_JS_LIB_SRC_PATH:=$(SRC)
CATALYST_NODE_PROJECT_LIB_ENTRY_POINT=$(CATALYST_JS_LIB_SRC_PATH)/index.js
# The following are set by the preamble when installed
# BUILD_KEY, SRC, CATALYST_JS_LIB_SRC_PATH, CATALYST_JS_CLI_SRC_PATH, CATALYST_JS_CLI, CATALYST_NODE_PROJECT_CLI_ENTRY_POINT, CATALYST_NODE_PROJECT_LIB_ENTRY_POINT
.DELETE_ON_ERROR:
.PHONY: all build lint lint-fix qa test

SHELL:=bash

default: build
default: all

DIST:=dist
DOCS:=docs
QA:=qa
TEST_STAGING:=test-staging
PHONY_TARGETS:=all default

.PRECIOUS: $(QA)/unit-test.txt $(QA)/lint.txt
BUILD_TARGETS:=

CATALYST_JS_BABEL:=npx babel
CATALYST_JS_JEST:=npx jest
CATALYST_JS_ROLLUP:=npx rollup
CATALYST_JS_ESLINT:=npx eslint
DOC_TARGETS:=

CATALYST_NODE_PROJECT_JS_SELECTOR=\( -name "*.js" -o -name "*.cjs" -o -name "*.mjs" \)
CATALYST_NODE_PROJECT_DATA_SELECTOR=\( -path "*/test/data/*" -o -path "*/test/data-*/*" -o -path "*/test-data/*" \)
LINT_TARGETS:=

# all source files (cli and lib)
CATALYST_JS_ALL_FILES_SRC:=$(shell find $(SRC) $(CATALYST_NODE_PROJECT_JS_SELECTOR) -not $(CATALYST_NODE_PROJECT_DATA_SELECTOR))
CATALYST_JS_TEST_FILES_SRC:=$(shell find $(SRC) $(CATALYST_NODE_PROJECT_JS_SELECTOR) -not $(CATALYST_NODE_PROJECT_DATA_SELECTOR) -type f)
CATALYST_JS_TEST_FILES_BUILT:=$(patsubst %.cjs, %.js, $(patsubst %.mjs, %.js, $(patsubst $(SRC)/%, test-staging/%, $(CATALYST_JS_TEST_FILES_SRC))))
# all test data (cli and lib)
CATALYST_JS_TEST_DATA_SRC:=$(shell find $(SRC) -type f $(CATALYST_NODE_PROJECT_DATA_SELECTOR))
CATALYST_JS_TEST_DATA_BUILT:=$(patsubst $(SRC)/%, $(TEST_STAGING)/%, $(CATALYST_JS_TEST_DATA_SRC))
# lib specific files
CATALYST_JS_LIB_FILES_SRC:=$(shell find $(CATALYST_JS_LIB_SRC_PATH) $(CATALYST_NODE_PROJECT_JS_SELECTOR) -not $(CATALYST_NODE_PROJECT_DATA_SELECTOR) -not -name "*.test.js")
CATALYST_JS_LIB:=dist/$(BUILD_KEY).js
# cli speciifc files
ifdef CATALYST_JS_CLI_SRC_PATH
CATALYST_JS_CLI_FILES_SRC:=$(shell find $(CATALYST_JS_CLI_SRC_PATH) $(CATALYST_NODE_PROJECT_JS_SELECTOR) -not $(CATALYST_NODE_PROJECT_DATA_SELECTOR) -not -name "*.test.js")
endif

LINT_IGNORE_PATTERNS:=--ignore-pattern '$(DIST)/**/*' \
--ignore-pattern '$(TEST_STAGING)/**/*' \
--ignore-pattern '$(DOCS)/**/*'

# build rules
INSTALL_BASE:=$(shell npm explore @liquid-labs/catalyst-scripts-node-project -- pwd)

# We do this here so the 'rm -rf' to reset the built files will run before other targets (which may copy or create
# files).
TEST_TARGETS:=$(CATALYST_JS_TEST_FILES_BUILT)
TEST_TARGETS:=

ifneq ($(wildcard make/*.mk),)
include make/*.mk
endif

ifdef CATALYST_JS_LIB_SRC_PATH
BUILD_TARGETS+=$(CATALYST_JS_LIB)

$(CATALYST_JS_LIB): package.json $(CATALYST_JS_LIB_FILES_SRC)
JS_BUILD_TARGET=$(CATALYST_NODE_PROJECT_LIB_ENTRY_POINT) \
JS_OUT=$@ \
$(CATALYST_JS_ROLLUP) --config $(INSTALL_BASE)/dist/rollup/rollup.config.mjs
endif

ifdef CATALYST_JS_CLI_SRC_PATH
BUILD_TARGETS+=$(CATALYST_JS_CLI)

# see DEVELOPER_NOTES.md 'CLI build'
$(CATALYST_JS_CLI): package.json $(CATALYST_JS_ALL_FILES_SRC)
JS_BUILD_TARGET=$(CATALYST_NODE_PROJECT_CLI_ENTRY_POINT) \
JS_OUT=$@ \
JS_OUT_PREAMBLE='#!/usr/bin/env -S node --enable-source-maps' \
$(CATALYST_JS_ROLLUP) --config $(INSTALL_BASE)/dist/rollup/rollup.config.mjs
chmod a+x $@
endif


# test
UNIT_TEST_REPORT:=$(QA)/unit-test.txt
UNIT_TEST_PASS_MARKER:=$(QA)/.unit-test.passed

$(CATALYST_JS_TEST_DATA_BUILT): test-staging/%: $(SRC)/%
@echo "Copying test data..."
@mkdir -p $(dir $@)
@cp $< $@

# Jest is not picking up the external maps, so we inline them for the test. (As of?)
$(CATALYST_JS_TEST_FILES_BUILT) &: $(CATALYST_JS_ALL_FILES_SRC)
rm -rf $(TEST_STAGING)
mkdir -p $(TEST_STAGING)
NODE_ENV=test $(CATALYST_JS_BABEL) \
--config-file=$(INSTALL_BASE)/dist/babel/babel.config.cjs \
--out-dir=./$(TEST_STAGING) \
--source-maps=inline \
$(SRC)

# Tried to use '--testPathPattern=$(TEST_STAGING)' awithout the 'cd $(TEST_STAGING)', but it seemed to have no effect'
# '--runInBand' because some suites require serial execution (yes, it's "best practice" to have unit tests totally
# independent, but in practice there are sometimes good reasons why it's useful or necessary to run sequentially);
# also, it may be faster this way; see:
# https://stackoverflow.com/questions/43864793/why-does-jest-runinband-speed-up-tests
$(UNIT_TEST_PASS_MARKER) $(UNIT_TEST_REPORT): package.json $(CATALYST_JS_TEST_FILES_BUILT) $(CATALYST_JS_TEST_DATA_BUILT)
@rm -f $@
@mkdir -p $(dir $@)
@echo -n 'Test git rev: ' > $(UNIT_TEST_REPORT)
@git rev-parse HEAD >> $(UNIT_TEST_REPORT)
@( set -e; set -o pipefail; \
( cd $(TEST_STAGING) && $(CATALYST_JS_JEST) \
--config=$(INSTALL_BASE)/dist/jest/jest.config.js \
--runInBand \
$(TEST) 2>&1 ) \
| tee -a $(UNIT_TEST_REPORT); \
touch $@ )

TEST_TARGETS+=$(UNIT_TEST_PASS_MARKER) $(UNIT_TEST_REPORT)

# lint rules
LINT_REPORT:=$(QA)/lint.txt
LINT_PASS_MARKER:=$(QA)/.lint.passed
$(LINT_PASS_MARKER) $(LINT_REPORT): $(CATALYST_JS_ALL_FILES_SRC)
@mkdir -p $(dir $@)
@echo -n 'Test git rev: ' > $(LINT_REPORT)
@git rev-parse HEAD >> $(LINT_REPORT)
@( set -e; set -o pipefail; \
$(CATALYST_JS_ESLINT) \
--config $(INSTALL_BASE)/dist/eslint/eslint.config.js \
--ext .cjs,.js,.mjs,.cjs,.xjs \
$(LINT_IGNORE_PATTERNS) \
. \
| tee -a $(LINT_REPORT); \
touch $@ )

LINT_TARGETS+=$(LINT_PASS_MARKER) $(LINT_REPORT)

lint-fix:
@( set -e; set -o pipefail; \
$(CATALYST_JS_ESLINT) \
--config $(INSTALL_BASE)/dist/eslint/eslint.config.js \
--ext .js,.mjs,.cjs,.xjs \
$(LINT_IGNORE_PATTERNS) \
--fix . )


build: $(BUILD_TARGETS)

test: $(TEST_TARGETS)

lint: $(LINT_TARGETS)

qa: test lint

all: build
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
[![pipeline status](https://gitlab.com/liquid-labs/regex-repo/badges/master/pipeline.svg)](https://gitlab.com/liquid-labs/regex-repo/commits/master)
[![coverage report](https://gitlab.com/liquid-labs/regex-repo/badges/master/coverage.svg)](https://gitlab.com/liquid-labs/regex-repo/commits/master)

# regex-repo
[![coverage: 91%](./.readme-assets/coverage.svg)](https://google.com) [![Unit tests](https://github.com/undefined/undefined/actions/workflows/unit-tests-node.yaml/badge.svg)](https://github.com/undefined/undefined/actions/workflows/unit-tests-node.yaml)

Collection of JS regular expressions.

# Notes

This project is [cross-hosted on Gitlab](https://gitlab.com/liquid-labs/regex-repo)
which does an excellent job of integrated CI. We use Github for issue management
and generally treat it as the primary home because it is the larger network.
8 changes: 8 additions & 0 deletions make/10-locations.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by @liquid-labs/catalyst-lib-makefiles. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-lib-makefiles for further
# details

SRC:=src
DIST:=dist
TEST_STAGING:=test-staging
QA:=qa
14 changes: 14 additions & 0 deletions make/10-resources.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

CATALYST_BABEL:=npx babel
CATALYST_BABEL_CONFIG:=$(shell npm explore @liquid-labs/catalyst-resource-babel-and-rollup -- pwd)/dist/babel/babel.config.cjs

CATALYST_ROLLUP:=npx rollup
CATALYST_ROLLUP_CONFIG:=$(shell npm explore @liquid-labs/catalyst-resource-babel-and-rollup -- pwd)/dist/rollup/rollup.config.mjs

CATALYST_JEST:=npx jest
CATALYST_JEST_CONFIG:=$(shell npm explore @liquid-labs/catalyst-resource-jest -- pwd)/dist/jest.config.js

CATALYST_ESLINT:=npx eslint
CATALYST_ESLINT_CONFIG:=$(shell npm explore @liquid-labs/catalyst-resource-eslint -- pwd)/dist/eslint.config.js
8 changes: 8 additions & 0 deletions make/15-data-finder.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

CATALYST_DATA_SELECTOR=\( -path "*/test/data/*" -o -path "*/test/data-*/*" -o -path "*/test-data/*" \)

# all test data (cli and lib)
CATALYST_TEST_DATA_SRC:=$(shell find $(SRC) -type f $(CATALYST_DATA_SELECTOR))
CATALYST_TEST_DATA_BUILT:=$(patsubst $(SRC)/%, $(TEST_STAGING)/%, $(CATALYST_TEST_DATA_SRC))
10 changes: 10 additions & 0 deletions make/20-js-src-finder.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

CATALYST_JS_SELECTOR=\( -name "*.js" -o -name "*.cjs" -o -name "*.mjs" \)
CATALYST_TEST_SELECTOR=\( -name "*.test.*js" -o -path "*/test/*" \)

# all source, non-test files (cli and lib)
CATALYST_ALL_JS_FILES_SRC:=$(shell find $(SRC) $(CATALYST_JS_SELECTOR) -not $(CATALYST_DATA_SELECTOR) -type f)
CATALYST_ALL_NON_TEST_JS_FILES_SRC:=$(shell find $(SRC) $(CATALYST_JS_SELECTOR) -not $(CATALYST_DATA_SELECTOR) -not $(CATALYST_TEST_SELECTOR) -type f)
CATALYST_JS_TEST_FILES_BUILT:=$(patsubst %.cjs, %.js, $(patsubst %.mjs, %.js, $(patsubst $(SRC)/%, test-staging/%, $(CATALYST_ALL_JS_FILES_SRC))))
19 changes: 19 additions & 0 deletions make/50-regex-repo-js.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

#####
# build dist/regex-repo.js
#####

CATALYST_REGEX_REPO_JS:=$(DIST)/regex-repo.js
CATALYST_REGEX_REPO_JS_ENTRY=$(SRC)/index.js
BUILD_TARGETS+=$(CATALYST_REGEX_REPO_JS)

$(CATALYST_REGEX_REPO_JS): package.json $(CATALYST_ALL_NON_TEST_JS_FILES_SRC)
JS_BUILD_TARGET=$(CATALYST_REGEX_REPO_JS_ENTRY) \
JS_OUT=$@ \
$(CATALYST_ROLLUP) --config $(CATALYST_ROLLUP_CONFIG)

#####
# end dist/regex-repo.js
#####
39 changes: 39 additions & 0 deletions make/55-lint.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

#####
# lint rules
#####

CATALYST_LINT_REPORT:=$(QA)/lint.txt
CATALYST_LINT_PASS_MARKER:=$(QA)/.lint.passed
LINT_TARGETS+=$(CATALYST_LINT_REPORT) $(CATALYST_LINT_PASS_MARKER)
PRECIOUS_TARGETS+=$(CATALYST_LINT_REPORT)

LINT_IGNORE_PATTERNS:=--ignore-pattern '$(DIST)/**/*'\
--ignore-pattern '$(TEST_STAGING)/**/*'

$(CATALYST_LINT_REPORT) $(CATALYST_LINT_PASS_MARKER): $(CATALYST_ALL_JS_FILES_SRC)
mkdir -p $(dir $@)
echo -n 'Test git rev: ' > $(CATALYST_LINT_REPORT)
git rev-parse HEAD >> $(CATALYST_LINT_REPORT)
( set -e; set -o pipefail; \
$(CATALYST_ESLINT) \
--config $(CATALYST_ESLINT_CONFIG) \
--ext .cjs,.js,.mjs,.cjs,.xjs \
$(LINT_IGNORE_PATTERNS) \
. \
| tee -a $(CATALYST_LINT_REPORT); \
touch $(CATALYST_LINT_PASS_MARKER) )

lint-fix:
@( set -e; set -o pipefail; \
$(CATALYST_ESLINT) \
--config $(CATALYST_ESLINT_CONFIG) \
--ext .js,.mjs,.cjs,.xjs \
$(LINT_IGNORE_PATTERNS) \
--fix . )

#####
# end lint
#####
51 changes: 51 additions & 0 deletions make/55-test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This file was generated by @liquid-labs/catalyst-builder-node. Refer to
# https://npmjs.com/package/@liquid-labs/catalyst-builder-node for further details

#####
# test rules
#####

CATALYST_TEST_REPORT:=$(QA)/unit-test.txt
CATALYST_TEST_PASS_MARKER:=$(QA)/.unit-test.passed
CATALYST_COVERAGE_REPORTS:=$(QA)/coverage
TEST_TARGETS+=$(CATALYST_TEST_REPORT) $(CATALYST_TEST_PASS_MARKER) $(CATALYST_COVERAGE_REPORTS)
PRECIOUS_TARGETS+=$(CATALYST_TEST_REPORT)

CATALYST_TEST_FILES_BUILT:=$(patsubst $(SRC)/%, $(TEST_STAGING)/%, $(CATALYST_ALL_JS_FILES_SRC))

$(CATALYST_TEST_DATA_BUILT): $(TEST_STAGING)/%: $(SRC)/%
@echo "Copying test data..."
@mkdir -p $(dir $@)
@cp $< $@

# Jest is not picking up the external maps, so we inline them for the test. (As of?)
$(CATALYST_TEST_FILES_BUILT) &: $(CATALYST_ALL_JS_FILES_SRC)
rm -rf $(TEST_STAGING)
mkdir -p $(TEST_STAGING)
NODE_ENV=test $(CATALYST_BABEL) \
--config-file=$(CATALYST_BABEL_CONFIG) \
--out-dir=./$(TEST_STAGING) \
--source-maps=inline \
$(SRC)

$(CATALYST_TEST_PASS_MARKER) $(CATALYST_TEST_REPORT) $(TEST_STAGING)/coverage &: package.json $(CATALYST_TEST_FILES_BUILT) $(CATALYST_TEST_DATA_BUILT)
rm -rf $@
mkdir -p $(dir $@)
echo -n 'Test git rev: ' > $(CATALYST_TEST_REPORT)
git rev-parse HEAD >> $(CATALYST_TEST_REPORT)
( set -e; set -o pipefail; \
( cd $(TEST_STAGING) && $(CATALYST_JEST) \
--config=$(CATALYST_JEST_CONFIG) \
--runInBand \
$(TEST) 2>&1 ) \
| tee -a $(CATALYST_TEST_REPORT); \
touch $(CATALYST_TEST_PASS_MARKER) )

$(CATALYST_COVERAGE_REPORTS): $(CATALYST_TEST_PASS_MARKER) $(TEST_STAGING)/coverage
rm -rf $(CATALYST_COVERAGE_REPORTS)
mkdir -p $(CATALYST_COVERAGE_REPORTS)
cp -r $(TEST_STAGING)/coverage/* $(CATALYST_COVERAGE_REPORTS)

#####
# end test
#####
Loading