Skip to content

Commit c5f37b9

Browse files
authored
Rewrite internals for v2 release (#83)
Addresses #15, #35, #36, #47, #51, and #59
1 parent b992c2e commit c5f37b9

Some content is hidden

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

73 files changed

+9628
-12545
lines changed

.eslintrc.yml

+14-39
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extends:
77
- "plugin:@typescript-eslint/strict"
88
- "plugin:import/recommended"
99
- "plugin:import/typescript"
10-
- "plugin:jsdoc/recommended-typescript"
10+
- "plugin:jsdoc/recommended-typescript-error"
1111
- "plugin:n/recommended"
1212
- "plugin:promise/recommended"
1313
- "plugin:sonarjs/recommended"
@@ -27,49 +27,24 @@ env:
2727
es2021: true
2828
node: true
2929

30+
rules:
31+
unicorn/prefer-top-level-await: "off"
32+
jsdoc/tag-lines: "off"
33+
3034
overrides:
3135
- files: ["**/*.js"]
3236
rules:
3337
"@typescript-eslint/no-var-requires": "off"
34-
"unicorn/prefer-module": "off"
38+
unicorn/prefer-module: "off"
3539

36-
- files: ["test/**/*"]
37-
env:
38-
mocha: true
40+
- files: ["**/__tests__/**/*"]
3941
rules:
42+
"@typescript-eslint/no-non-null-assertion": "off"
43+
"@typescript-eslint/no-unsafe-argument": "off"
44+
"@typescript-eslint/no-unsafe-assignment": "off"
4045
sonarjs/no-duplicate-string: "off"
46+
unicorn/no-useless-undefined: "off"
4147

42-
rules:
43-
n/no-unpublished-import: ["error", { "allowModules": ["@actions/core"] }]
44-
45-
# temporary rule overrides
46-
# TODO(mc, 2023-04-12): fix problems, remove overrides, and remove --quiet
47-
prefer-const: "warn"
48-
no-regex-spaces: "warn"
49-
"@typescript-eslint/no-floating-promises": "warn"
50-
"@typescript-eslint/no-unsafe-argument": "warn"
51-
"@typescript-eslint/no-unsafe-assignment": "warn"
52-
"@typescript-eslint/no-unsafe-call": "warn"
53-
"@typescript-eslint/no-unsafe-member-access": "warn"
54-
"@typescript-eslint/no-unsafe-return": "warn"
55-
"@typescript-eslint/require-await": "warn"
56-
"@typescript-eslint/restrict-plus-operands": "warn"
57-
"@typescript-eslint/restrict-template-expressions": "warn"
58-
"@typescript-eslint/unbound-method": "warn"
59-
n/no-missing-import: "warn"
60-
n/no-missing-require: "warn"
61-
n/no-process-exit: "warn"
62-
unicorn/better-regex: "warn"
63-
unicorn/catch-error-name: "warn"
64-
unicorn/import-style: "warn"
65-
unicorn/no-array-push-push: "warn"
66-
unicorn/no-process-exit: "warn"
67-
unicorn/no-useless-undefined: "warn"
68-
unicorn/prefer-export-from: "warn"
69-
unicorn/prefer-module: "warn"
70-
unicorn/prefer-node-protocol: "warn"
71-
unicorn/prefer-optional-catch-binding: "warn"
72-
unicorn/prefer-spread: "warn"
73-
unicorn/prefer-top-level-await: "warn"
74-
unicorn/prevent-abbreviations: "warn"
75-
unicorn/text-encoding-identifier-case: "warn"
48+
- files: ["src/action/**/*"]
49+
rules:
50+
n/no-unpublished-import: "off"

.github/workflows/ci-cd.yml

+33-37
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,8 @@ on:
1313
- cron: "25 12 * * 1"
1414

1515
jobs:
16-
lint:
17-
name: Lint
18-
runs-on: ubuntu-latest
19-
timeout-minutes: 10
20-
21-
steps:
22-
- name: Checkout source
23-
uses: actions/checkout@v3
24-
25-
- name: Install Node.js and dependencies
26-
uses: ./.github/actions/setup
27-
28-
- name: Run linters
29-
run: npm run lint
30-
3116
test:
32-
name: Run tests using Node ${{ matrix.node }} on ${{ matrix.os }}
17+
name: Unit tests / Node.js ${{ matrix.node-version }} / ${{ matrix.os }}
3318
runs-on: ${{ matrix.os }}
3419
timeout-minutes: 10
3520
strategy:
@@ -38,9 +23,8 @@ jobs:
3823
os:
3924
- ubuntu-latest
4025
- macos-latest
41-
# TODO(mc, 2023-04-07): investigate and fix coverage-related failures on Windows
42-
# - windows-latest
43-
node:
26+
- windows-latest
27+
node-version:
4428
- 16
4529
- 18
4630

@@ -51,10 +35,7 @@ jobs:
5135
- name: Install Node.js ${{ matrix.node }} and dependencies
5236
uses: ./.github/actions/setup
5337
with:
54-
node-version: ${{ matrix.node }}
55-
56-
- name: Build the code
57-
run: npm run build
38+
node-version: ${{ matrix.node-version }}
5839

5940
- name: Run tests
6041
run: npm run coverage
@@ -78,7 +59,7 @@ jobs:
7859
parallel-finished: true
7960

8061
build:
81-
name: Build
62+
name: Build and lint
8263
runs-on: ubuntu-latest
8364
timeout-minutes: 10
8465

@@ -92,18 +73,33 @@ jobs:
9273
- name: Build
9374
run: npm run build
9475

76+
- name: Verify no un-staged changes
77+
run: |
78+
git status --porcelain
79+
git diff-files --quiet
80+
81+
- name: Run lints
82+
run: npm run lint
83+
9584
- name: Upload publish artifact
9685
uses: actions/upload-artifact@v3
9786
with:
9887
name: publish-artifact
9988
path: lib
10089

10190
e2e:
102-
name: Run end-to-end tests
91+
name: E2E tests / Node.js ${{ matrix.node-version }}
10392
runs-on: ubuntu-latest
10493
timeout-minutes: 10
10594
needs: build
10695

96+
strategy:
97+
fail-fast: false
98+
matrix:
99+
node-version:
100+
- 16
101+
- 18
102+
107103
services:
108104
verdaccio:
109105
image: verdaccio/verdaccio:5
@@ -117,6 +113,7 @@ jobs:
117113
- name: Install Node.js and dependencies
118114
uses: ./.github/actions/setup
119115
with:
116+
node-version: ${{ matrix.node-version }}
120117
install-command: npm install --production
121118

122119
- name: Download publish artifact
@@ -130,20 +127,20 @@ jobs:
130127
shell: bash
131128
run: |
132129
echo "token=$(./e2e/00-login.sh)" >> "$GITHUB_OUTPUT"
133-
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture 0.0.1)" >> "$GITHUB_OUTPUT"
130+
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture/cool\ package 0.0.1)" >> "$GITHUB_OUTPUT"
134131
135132
- name: Run CLI end-to-end test
136133
shell: bash
137134
env:
138135
TOKEN: ${{ steps.setup.outputs.token }}
139136
PACKAGE: ${{ steps.setup.outputs.package }}
140137
run: |
141-
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
142-
./e2e/03-verify.sh ${PACKAGE}
143-
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
144-
./e2e/01-setup-package.sh ${PACKAGE} 0.0.2
145-
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
146-
./e2e/03-verify.sh ${PACKAGE}
138+
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
139+
./e2e/03-verify.sh "${PACKAGE}"
140+
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
141+
./e2e/01-setup-package.sh "${PACKAGE}" 0.0.2
142+
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
143+
./e2e/03-verify.sh "${PACKAGE}"
147144
148145
- id: action-no-publish
149146
name: Publish with already published version
@@ -154,14 +151,14 @@ jobs:
154151
token: ${{ steps.setup.outputs.token }}
155152

156153
- name: Check action output
157-
if: ${{ steps.action-no-publish.outputs.type != 'none' }}
154+
if: ${{ steps.action-no-publish.outputs.type }}
158155
run: |
159-
echo "::error::Expected release type to be 'none', got '${{ steps.action-no-publish.outputs.type }}'"
156+
echo "::error::Expected release type to be '', got '${{ steps.action-no-publish.outputs.type }}'"
160157
exit 1
161158
162159
- name: Create new version for Action end-to-end test
163160
shell: bash
164-
run: ./e2e/01-setup-package.sh ${{ steps.setup.outputs.package }} 0.0.3
161+
run: ./e2e/01-setup-package.sh "${{ steps.setup.outputs.package }}" 0.0.3
165162

166163
- id: action-publish
167164
name: Publish a new version
@@ -179,11 +176,10 @@ jobs:
179176
180177
deploy:
181178
if: ${{ github.ref == 'refs/heads/main' }}
182-
name: Publish to NPM
179+
name: Publish
183180
runs-on: ubuntu-latest
184181
timeout-minutes: 10
185182
needs:
186-
- lint
187183
- test
188184
- build
189185
- e2e

.mocharc.yml

-13
This file was deleted.

.nycrc.yml

-13
This file was deleted.

.prettierrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins:
2+
- prettier-plugin-jsdoc
3+
tsdoc: true

CONTRIBUTING.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ git clone https://github.com/JS-DevTools/npm-publish.git
1313
# Install dependencies*
1414
npm install
1515

16-
# Build the code
17-
npm run build
18-
19-
# Run the tests
20-
npm test
16+
# Run all checks, builds, and unit tests
17+
npm run all
2118
```
2219

2320
There are also various code quality checks and tests you can run:
2421

2522
```shell
23+
# Run builds and typechecking
24+
npm run build
25+
26+
# Run the unit tests in watch mode
27+
npm run test
28+
2629
# Autoformat the code
2730
npm run format
2831

action.yml

+46-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# GitHub Action
2-
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/metadata-syntax-for-github-actions
3-
41
name: NPM Publish
52
description: Fast, easy publishing to NPM
63

@@ -17,49 +14,73 @@ inputs:
1714
registry:
1815
description: The NPM registry URL to use
1916
required: false
20-
default: https://registry.npmjs.org/
2117

2218
package:
23-
description: The path of your package.json file
19+
description: The path to your package or its package.json file
2420
required: false
25-
default: package.json
2621

2722
tag:
28-
description: The tag to publish to. This allows people to install the package using "npm install <package-name>@<tag>".
23+
description: The distribution tag to publish
2924
required: false
30-
default: "latest"
3125

3226
access:
33-
description:
34-
Determines whether the published package should be publicly visible, or restricted to members of your NPM organization.
35-
This only applies to scoped packages.
27+
description: >
28+
Determines whether the published package should be publicly visible,
29+
or restricted to members of your NPM organization.
3630
required: false
3731

38-
dry-run:
39-
description: If true, run with the --dry-run flag
40-
required: false
41-
default: "false"
32+
strategy:
33+
description: >
34+
Version check and release strategy.
35+
If "all" (default), package will be published if its version is simply not yet published.
36+
If "upgrade", package will be published if its version is higher than the existing tag,
37+
according to semantic versioning.
4238
43-
check-version:
44-
description: Only publish if the version in package.json differs from the latest on NPM
4539
required: false
46-
default: "true"
4740

48-
greater-version-only:
49-
description: Only publish to NPM if the version number in package.json is greater than the latest on NPM
41+
dry-run:
42+
description: Run npm with the --dry-run flag to avoid actually publishing anything.
5043
required: false
51-
default: "false"
5244

5345
outputs:
46+
id:
47+
description: >
48+
The identifier of the published package.
49+
If a release was published, format is `${name}@${version}.
50+
If no release occurred, will be an empty string.
51+
5452
type:
55-
description: The type of version change that occurred ("none", "major", "minor", "patch", etc.)
53+
description: >
54+
The type of version change that occurred on the published tag.
55+
If release was an upgrade, will be a semver release type ("major", "minor", ...).
56+
If the published tag had no previous version, will be "initial".
57+
If version was change was not an upgrade, will be "different".
58+
If no release occurred, will be an empty string.
59+
60+
name:
61+
description: Name of the package.
5662

5763
version:
58-
description: The version that was published
64+
description: Version of the package.
5965

6066
old-version:
61-
description: The version number that was previously published to NPM
67+
description: >
68+
The previous version on the distribution tag.
69+
If there was no previous version on the tag, will be an empty string.
70+
71+
registry:
72+
description: The registry used for version checking and publishing.
73+
74+
tag:
75+
description: The distribution tag used for version checking and publishing.
76+
77+
access:
78+
description: >
79+
The package access setting used.
80+
If configured by the action or package.json, will be "public" or "protected".
81+
If not configured for a non-scoped package, will be "public".
82+
If not configured for a scoped package, will be "default".
6283
6384
runs:
6485
using: node16
65-
main: dist/index.js
86+
main: dist/main.js

0 commit comments

Comments
 (0)