Skip to content

Commit de643de

Browse files
authored
chore: switch to 'npm workspaces' (#156)
Let's try npm workspaces for handling multiple packages. The primary win is developing local changes to the helpers package and having the others automatically linked. Note that npm workspaces requires npm@7 or later, which typically means node@16 or later. For earler Node.js versions there are utils/run-* scripts to support install/test/lint.
1 parent 394566a commit de643de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+119
-147
lines changed

.ci/run-install.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.ci/run-lint.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.ci/run-test.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- uses: actions/setup-node@v3
2222
with:
2323
node-version: 18
24-
- run: .ci/run-install.sh
25-
- run: .ci/run-lint.sh
24+
- run: utils/run-install.sh
25+
- run: utils/run-lint.sh
2626

2727
test:
2828
runs-on: ubuntu-latest
@@ -36,6 +36,6 @@ jobs:
3636
with:
3737
node-version: ${{ matrix.node-version }}
3838
- name: Install dependencies
39-
run: .ci/run-install.sh
39+
run: utils/run-install.sh
4040
- name: Test Node.js v${{ matrix.node-version }}
41-
run: .ci/run-test.sh
41+
run: utils/run-test.sh

helpers/.npmrc renamed to .npmrc

File renamed without changes.

CONTRIBUTING.md

Lines changed: 20 additions & 33 deletions

Makefile

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,28 @@
1-
# All development tasks are typically available via npm scripts, i.e.
2-
# `npm run <script> ...` or via CI scripts (".ci/*.sh"). This Makefile
3-
# exists as a convenience for some common tasks.
1+
# Common development tasks are typically available via npm scripts, e.g.:
2+
# npm --workspaces install
3+
# npm --workspaces test
4+
# npm --workspaces lint
5+
# npm --workspaces lint:fix
6+
#
7+
# This Makefile exists as a convenience, to support older Node.js versions
8+
# (which npm <=7 when workspaces support was added), and to support some less
9+
# common tasks.
410

511
.PHONY: all
612
all:
7-
./.ci/run-install.sh
8-
(cd utils && npm install)
13+
./utils/run-install.sh
914

10-
.PHONY: clean
11-
clean:
12-
(cd helpers && rm -rf node_modules)
13-
(cd loggers/winston && rm -rf node_modules)
14-
(cd loggers/morgan && rm -rf node_modules)
15-
(cd loggers/pino && rm -rf node_modules)
16-
(cd utils && rm -rf node_modules)
15+
.PHONY: test
16+
test:
17+
./utils/run-test.sh
1718

1819
.PHONY: lint
1920
lint: check-license-headers
20-
./.ci/run-lint.sh
21+
./utils/run-lint.sh
2122

2223
.PHONY: fmt
2324
fmt:
24-
(cd helpers && npm run lint:fix)
25-
(cd loggers/winston && npm run lint:fix)
26-
(cd loggers/morgan && npm run lint:fix)
27-
(cd loggers/pino && npm run lint:fix)
28-
(cd utils && npm run lint:fix)
29-
30-
.PHONY: test
31-
test:
32-
./.ci/run-test.sh
33-
34-
# For local dev, setup each logger to use the local helpers, rather than
35-
# a version published to npm. Need to be careful to not *push* with that
36-
# tweak to each package.json.
37-
.PHONY: install-local-helpers undo-install-local-helpers
38-
install-local-helpers:
39-
(cd loggers/winston && npm install ../../helpers)
40-
(cd loggers/morgan && npm install ../../helpers)
41-
(cd loggers/pino && npm install ../../helpers)
42-
undo-install-local-helpers:
43-
export HELPERS_VER=$(shell cd helpers && npm info . version) && \
44-
(cd loggers/winston && npm install @elastic/ecs-helpers@v$$HELPERS_VER) && \
45-
(cd loggers/morgan && npm install @elastic/ecs-helpers@v$$HELPERS_VER) && \
46-
(cd loggers/pino && npm install @elastic/ecs-helpers@v$$HELPERS_VER)
25+
npm --workspaces lint:fix # requires npm>=7 (aka node>=16)
4726

4827
# Build and open the rendered docs for testing.
4928
#
@@ -61,7 +40,7 @@ docs-and-open:
6140
# List licenses of prod deps.
6241
.PHONY: list-licenses
6342
list-licenses:
64-
@for dir in helpers $(shell ls -d loggers/*); do \
43+
@for dir in helpers $(shell ls -d packages/*); do \
6544
(cd $$dir && npm ls --prod --parseable | while read subdir; do node -e "console.log(require('$$subdir/package.json').license)"; done) \
6645
done | sort | uniq -c | sort -n
6746

README.md

Lines changed: 3 additions & 3 deletions

docs/morgan.asciidoc

Lines changed: 3 additions & 3 deletions

docs/pino.asciidoc

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)