@nitpicker/core 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +191 -0
- package/README.md +13 -0
- package/lib/discover-analyze-plugins.d.ts +14 -0
- package/lib/discover-analyze-plugins.js +34 -0
- package/lib/find-nitpicker-modules-dir.d.ts +12 -0
- package/lib/find-nitpicker-modules-dir.js +23 -0
- package/lib/hooks/actions.d.ts +9 -0
- package/lib/hooks/actions.js +9 -0
- package/lib/hooks/child-process.d.ts +1 -0
- package/lib/hooks/child-process.js +34 -0
- package/lib/hooks/define-plugin.d.ts +68 -0
- package/lib/hooks/define-plugin.js +69 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/runner.d.ts +10 -0
- package/lib/hooks/runner.js +32 -0
- package/lib/import-modules.d.ts +24 -0
- package/lib/import-modules.js +38 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/load-plugin-settings.d.ts +40 -0
- package/lib/load-plugin-settings.js +85 -0
- package/lib/nitpicker.d.ts +127 -0
- package/lib/nitpicker.js +338 -0
- package/lib/page-analysis-worker.d.ts +48 -0
- package/lib/page-analysis-worker.js +98 -0
- package/lib/read-plugin-labels.d.ts +15 -0
- package/lib/read-plugin-labels.js +30 -0
- package/lib/table.d.ts +75 -0
- package/lib/table.js +132 -0
- package/lib/types.d.ts +264 -0
- package/lib/types.js +1 -0
- package/lib/url-event-bus.d.ts +32 -0
- package/lib/url-event-bus.js +20 -0
- package/lib/utils.d.ts +36 -0
- package/lib/utils.js +43 -0
- package/lib/worker/run-in-worker.d.ts +51 -0
- package/lib/worker/run-in-worker.js +120 -0
- package/lib/worker/runner.d.ts +25 -0
- package/lib/worker/runner.js +31 -0
- package/lib/worker/types.d.ts +23 -0
- package/lib/worker/types.js +1 -0
- package/lib/worker/worker.d.ts +27 -0
- package/lib/worker/worker.js +53 -0
- package/package.json +36 -0
- package/src/discover-analyze-plugins.spec.ts +21 -0
- package/src/discover-analyze-plugins.ts +37 -0
- package/src/hooks/define-plugin.spec.ts +38 -0
- package/src/hooks/define-plugin.ts +73 -0
- package/src/hooks/index.ts +1 -0
- package/src/import-modules.spec.ts +150 -0
- package/src/import-modules.ts +45 -0
- package/src/index.ts +5 -0
- package/src/load-plugin-settings.spec.ts +192 -0
- package/src/load-plugin-settings.ts +99 -0
- package/src/nitpicker.ts +418 -0
- package/src/page-analysis-worker.spec.ts +287 -0
- package/src/page-analysis-worker.ts +131 -0
- package/src/read-plugin-labels.spec.ts +151 -0
- package/src/read-plugin-labels.ts +37 -0
- package/src/table.spec.ts +83 -0
- package/src/table.ts +149 -0
- package/src/types.ts +289 -0
- package/src/url-event-bus.spec.ts +28 -0
- package/src/url-event-bus.ts +33 -0
- package/src/worker/run-in-worker.ts +155 -0
- package/src/worker/runner.ts +38 -0
- package/src/worker/types.ts +25 -0
- package/src/worker/worker.ts +64 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.4.1](https://github.com/d-zero-dev/nitpicker/compare/v0.4.0...v0.4.1) (2026-02-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nitpicker/core
|
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 D-ZERO Co., Ltd.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @nitpicker/core
|
|
2
|
+
|
|
3
|
+
プラグインベースのページ分析エンジン。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
`.nitpicker` アーカイブ内の各ページに対して、analyze プラグインを並列実行するためのエンジンです。プラグインの検出・読み込み・Worker スレッドでの実行を担当します。
|
|
8
|
+
|
|
9
|
+
このパッケージは [Nitpicker](../../README.md) モノレポの内部パッケージです。単体での利用は想定していません。
|
|
10
|
+
|
|
11
|
+
## ライセンス
|
|
12
|
+
|
|
13
|
+
Apache-2.0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the standard set of `@nitpicker/analyze-*` plugins
|
|
4
|
+
* as {@link Plugin} entries with default (empty) settings.
|
|
5
|
+
*
|
|
6
|
+
* This is used as a fallback when no configuration file is found,
|
|
7
|
+
* allowing `nitpicker analyze` to work out of the box without
|
|
8
|
+
* requiring a `.nitpickerrc` file.
|
|
9
|
+
*
|
|
10
|
+
* All analyze plugins are treated as standard packages bundled
|
|
11
|
+
* with the CLI, so no filesystem scanning is necessary.
|
|
12
|
+
* @returns Array of standard analyze plugins with empty settings.
|
|
13
|
+
*/
|
|
14
|
+
export declare function discoverAnalyzePlugins(): Plugin[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard analyze plugin module names bundled with the Nitpicker CLI.
|
|
3
|
+
*
|
|
4
|
+
* These are treated as built-in plugins and always available without
|
|
5
|
+
* explicit configuration.
|
|
6
|
+
*/
|
|
7
|
+
const STANDARD_ANALYZE_PLUGINS = [
|
|
8
|
+
'@nitpicker/analyze-axe',
|
|
9
|
+
'@nitpicker/analyze-lighthouse',
|
|
10
|
+
'@nitpicker/analyze-main-contents',
|
|
11
|
+
'@nitpicker/analyze-markuplint',
|
|
12
|
+
'@nitpicker/analyze-search',
|
|
13
|
+
'@nitpicker/analyze-textlint',
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Returns the standard set of `@nitpicker/analyze-*` plugins
|
|
17
|
+
* as {@link Plugin} entries with default (empty) settings.
|
|
18
|
+
*
|
|
19
|
+
* This is used as a fallback when no configuration file is found,
|
|
20
|
+
* allowing `nitpicker analyze` to work out of the box without
|
|
21
|
+
* requiring a `.nitpickerrc` file.
|
|
22
|
+
*
|
|
23
|
+
* All analyze plugins are treated as standard packages bundled
|
|
24
|
+
* with the CLI, so no filesystem scanning is necessary.
|
|
25
|
+
* @returns Array of standard analyze plugins with empty settings.
|
|
26
|
+
*/
|
|
27
|
+
export function discoverAnalyzePlugins() {
|
|
28
|
+
return STANDARD_ANALYZE_PLUGINS.map((moduleName) => ({
|
|
29
|
+
name: moduleName,
|
|
30
|
+
module: moduleName,
|
|
31
|
+
configFilePath: '',
|
|
32
|
+
settings: {},
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walks up from the current module's directory to locate the parent
|
|
3
|
+
* `@nitpicker` directory in the file system.
|
|
4
|
+
*
|
|
5
|
+
* This is used by plugin discovery and label resolution to find
|
|
6
|
+
* where `@nitpicker/*` packages are installed on disk. The traversal
|
|
7
|
+
* starts from `import.meta.url` of the calling module (i.e. this file,
|
|
8
|
+
* which lives inside `@nitpicker/core`) and walks up until it finds
|
|
9
|
+
* a directory named `@nitpicker`.
|
|
10
|
+
* @returns Absolute path to the `@nitpicker` directory, or `null` if not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function findNitpickerModulesDir(): string | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Walks up from the current module's directory to locate the parent
|
|
4
|
+
* `@nitpicker` directory in the file system.
|
|
5
|
+
*
|
|
6
|
+
* This is used by plugin discovery and label resolution to find
|
|
7
|
+
* where `@nitpicker/*` packages are installed on disk. The traversal
|
|
8
|
+
* starts from `import.meta.url` of the calling module (i.e. this file,
|
|
9
|
+
* which lives inside `@nitpicker/core`) and walks up until it finds
|
|
10
|
+
* a directory named `@nitpicker`.
|
|
11
|
+
* @returns Absolute path to the `@nitpicker` directory, or `null` if not found.
|
|
12
|
+
*/
|
|
13
|
+
export function findNitpickerModulesDir() {
|
|
14
|
+
const __filename = new URL(import.meta.url).pathname;
|
|
15
|
+
let dir = path.dirname(__filename);
|
|
16
|
+
while (dir !== path.dirname(dir)) {
|
|
17
|
+
if (path.basename(dir) === '@nitpicker') {
|
|
18
|
+
return dir;
|
|
19
|
+
}
|
|
20
|
+
dir = path.dirname(dir);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StartAction } from '../types.js';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
audit: {
|
|
4
|
+
start: import("typescript-fsa").ActionCreator<StartAction>;
|
|
5
|
+
log: import("typescript-fsa").ActionCreator<string>;
|
|
6
|
+
finish: import("typescript-fsa").ActionCreator<void>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { actionCreatorFactory } from 'typescript-fsa';
|
|
2
|
+
const auditActionCreator = actionCreatorFactory('@@hook/audit');
|
|
3
|
+
export default {
|
|
4
|
+
audit: {
|
|
5
|
+
start: auditActionCreator('START'),
|
|
6
|
+
log: auditActionCreator('LOG'),
|
|
7
|
+
finish: auditActionCreator('FINISH'),
|
|
8
|
+
},
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Run on child_process
|
|
2
|
+
import { Archive } from '@nitpicker/crawler';
|
|
3
|
+
import { isType } from 'typescript-fsa';
|
|
4
|
+
import actions from './actions.js';
|
|
5
|
+
const crateTable = (headers, data, options) => ({
|
|
6
|
+
headers,
|
|
7
|
+
data,
|
|
8
|
+
options,
|
|
9
|
+
});
|
|
10
|
+
process.on('message', async (action) => {
|
|
11
|
+
if (isType(action, actions.audit.start)) {
|
|
12
|
+
const mod = await import(action.payload.hookModulePath);
|
|
13
|
+
const pluginHook = mod.default;
|
|
14
|
+
const hook = await pluginHook(action.payload.settings || {}, action.payload.configFilePath);
|
|
15
|
+
if (hook.audit) {
|
|
16
|
+
const archive = await Archive.connect(action.payload.archiveTempDir, action.payload.hookModuleName);
|
|
17
|
+
const pluginReport = await hook.audit(archive, (log) => {
|
|
18
|
+
if (process.send) {
|
|
19
|
+
process.send(actions.audit.log(log));
|
|
20
|
+
}
|
|
21
|
+
}, action.payload.configFilePath, crateTable);
|
|
22
|
+
if (pluginReport) {
|
|
23
|
+
const data = {
|
|
24
|
+
name: action.payload.hookModuleName,
|
|
25
|
+
...pluginReport,
|
|
26
|
+
};
|
|
27
|
+
await archive.setData('reports', data);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (process.send) {
|
|
31
|
+
process.send(actions.audit.finish());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PluginFactory } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Identity function that provides full type inference for analyze plugin definitions.
|
|
4
|
+
*
|
|
5
|
+
* This function does **nothing at runtime** - it returns its argument unchanged.
|
|
6
|
+
* Its sole purpose is to give TypeScript enough context to infer the generic
|
|
7
|
+
* parameters `O` (options type) and `T` (column key union) from the plugin
|
|
8
|
+
* implementation, without requiring explicit type annotations at the call site.
|
|
9
|
+
*
|
|
10
|
+
* ## Why an identity function?
|
|
11
|
+
*
|
|
12
|
+
* Without this wrapper, plugin authors would need to manually annotate the
|
|
13
|
+
* `PluginFactory` type with both generic parameters:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Without definePlugin - verbose and error-prone
|
|
17
|
+
* const factory: PluginFactory<{ lang: string }, 'score' | 'details'> = (options) => { ... };
|
|
18
|
+
* export default factory;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* With `definePlugin`, TypeScript infers everything from the function body:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* // With definePlugin - concise and type-safe
|
|
25
|
+
* export default definePlugin(async (options: { lang: string }) => {
|
|
26
|
+
* return {
|
|
27
|
+
* label: 'Custom Analysis',
|
|
28
|
+
* headers: { score: 'Score', details: 'Details' },
|
|
29
|
+
* async eachPage({ window }) {
|
|
30
|
+
* return { page: { score: { value: 100 }, details: { value: 'OK' } } };
|
|
31
|
+
* },
|
|
32
|
+
* };
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This pattern is sometimes called a "satisfies helper" or "builder pattern"
|
|
37
|
+
* and is common in TypeScript libraries that need generic inference from
|
|
38
|
+
* function arguments (cf. Zod's `z.object()`, tRPC's `router()`).
|
|
39
|
+
* @template O - Shape of the plugin's settings/options from the config file.
|
|
40
|
+
* @template T - String literal union of column keys contributed by this plugin.
|
|
41
|
+
* @param factory - The plugin factory function to pass through.
|
|
42
|
+
* @returns The same function, unchanged.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { definePlugin } from '@nitpicker/core';
|
|
46
|
+
*
|
|
47
|
+
* type Options = { keywords: string[] };
|
|
48
|
+
*
|
|
49
|
+
* export default definePlugin(async (options: Options) => {
|
|
50
|
+
* return {
|
|
51
|
+
* label: 'キーワード検索',
|
|
52
|
+
* headers: { found: 'Keywords Found', count: 'Match Count' },
|
|
53
|
+
* async eachPage({ html }) {
|
|
54
|
+
* const matches = options.keywords.filter(k => html.includes(k));
|
|
55
|
+
* return {
|
|
56
|
+
* page: {
|
|
57
|
+
* found: { value: matches.join(', ') },
|
|
58
|
+
* count: { value: matches.length },
|
|
59
|
+
* },
|
|
60
|
+
* };
|
|
61
|
+
* },
|
|
62
|
+
* };
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
* @see {@link ../types.ts!PluginFactory} for the function signature being wrapped
|
|
66
|
+
* @see {@link ../types.ts!AnalyzePlugin} for the returned plugin interface
|
|
67
|
+
*/
|
|
68
|
+
export declare function definePlugin<O, T extends string = string>(factory: PluginFactory<O, T>): PluginFactory<O, T>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity function that provides full type inference for analyze plugin definitions.
|
|
3
|
+
*
|
|
4
|
+
* This function does **nothing at runtime** - it returns its argument unchanged.
|
|
5
|
+
* Its sole purpose is to give TypeScript enough context to infer the generic
|
|
6
|
+
* parameters `O` (options type) and `T` (column key union) from the plugin
|
|
7
|
+
* implementation, without requiring explicit type annotations at the call site.
|
|
8
|
+
*
|
|
9
|
+
* ## Why an identity function?
|
|
10
|
+
*
|
|
11
|
+
* Without this wrapper, plugin authors would need to manually annotate the
|
|
12
|
+
* `PluginFactory` type with both generic parameters:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Without definePlugin - verbose and error-prone
|
|
16
|
+
* const factory: PluginFactory<{ lang: string }, 'score' | 'details'> = (options) => { ... };
|
|
17
|
+
* export default factory;
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* With `definePlugin`, TypeScript infers everything from the function body:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // With definePlugin - concise and type-safe
|
|
24
|
+
* export default definePlugin(async (options: { lang: string }) => {
|
|
25
|
+
* return {
|
|
26
|
+
* label: 'Custom Analysis',
|
|
27
|
+
* headers: { score: 'Score', details: 'Details' },
|
|
28
|
+
* async eachPage({ window }) {
|
|
29
|
+
* return { page: { score: { value: 100 }, details: { value: 'OK' } } };
|
|
30
|
+
* },
|
|
31
|
+
* };
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* This pattern is sometimes called a "satisfies helper" or "builder pattern"
|
|
36
|
+
* and is common in TypeScript libraries that need generic inference from
|
|
37
|
+
* function arguments (cf. Zod's `z.object()`, tRPC's `router()`).
|
|
38
|
+
* @template O - Shape of the plugin's settings/options from the config file.
|
|
39
|
+
* @template T - String literal union of column keys contributed by this plugin.
|
|
40
|
+
* @param factory - The plugin factory function to pass through.
|
|
41
|
+
* @returns The same function, unchanged.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { definePlugin } from '@nitpicker/core';
|
|
45
|
+
*
|
|
46
|
+
* type Options = { keywords: string[] };
|
|
47
|
+
*
|
|
48
|
+
* export default definePlugin(async (options: Options) => {
|
|
49
|
+
* return {
|
|
50
|
+
* label: 'キーワード検索',
|
|
51
|
+
* headers: { found: 'Keywords Found', count: 'Match Count' },
|
|
52
|
+
* async eachPage({ html }) {
|
|
53
|
+
* const matches = options.keywords.filter(k => html.includes(k));
|
|
54
|
+
* return {
|
|
55
|
+
* page: {
|
|
56
|
+
* found: { value: matches.join(', ') },
|
|
57
|
+
* count: { value: matches.length },
|
|
58
|
+
* },
|
|
59
|
+
* };
|
|
60
|
+
* },
|
|
61
|
+
* };
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
* @see {@link ../types.ts!PluginFactory} for the function signature being wrapped
|
|
65
|
+
* @see {@link ../types.ts!AnalyzePlugin} for the returned plugin interface
|
|
66
|
+
*/
|
|
67
|
+
export function definePlugin(factory) {
|
|
68
|
+
return factory;
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { definePlugin } from './define-plugin.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { definePlugin } from './define-plugin.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StartAction } from '../types.js';
|
|
2
|
+
import type { ProcessLogger } from '@nitpicker/types';
|
|
3
|
+
import actions from './actions.js';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param phase
|
|
7
|
+
* @param startActionParam
|
|
8
|
+
* @param log
|
|
9
|
+
*/
|
|
10
|
+
export declare function runner(phase: keyof typeof actions, startActionParam: StartAction, log: ProcessLogger): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import childProcess from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isType } from 'typescript-fsa';
|
|
4
|
+
import actions from './actions.js';
|
|
5
|
+
const __filename = new URL(import.meta.url).pathname;
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param phase
|
|
10
|
+
* @param startActionParam
|
|
11
|
+
* @param log
|
|
12
|
+
*/
|
|
13
|
+
export function runner(phase, startActionParam, log) {
|
|
14
|
+
log('Fork process');
|
|
15
|
+
const child = childProcess.fork(path.join(__dirname, 'child-process'));
|
|
16
|
+
const actionOnPhase = actions[phase];
|
|
17
|
+
const session = new Promise((resolve) => {
|
|
18
|
+
child.on('message', (action) => {
|
|
19
|
+
if (isType(action, actionOnPhase.log)) {
|
|
20
|
+
log(action.payload);
|
|
21
|
+
}
|
|
22
|
+
if (isType(action, actionOnPhase.finish)) {
|
|
23
|
+
child.disconnect();
|
|
24
|
+
log('Finished');
|
|
25
|
+
resolve();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
child.send(actionOnPhase.start(startActionParam));
|
|
30
|
+
log('Started');
|
|
31
|
+
return session;
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnalyzePlugin, Plugin } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Dynamically imports and initializes all analyze plugin modules.
|
|
4
|
+
*
|
|
5
|
+
* For each plugin in the list:
|
|
6
|
+
* 1. Validates that `plugin.module` starts with `@nitpicker/analyze-`
|
|
7
|
+
* 2. Calls `import(plugin.module)` to load the npm package
|
|
8
|
+
* 3. Invokes the module's default export (a `PluginFactory` factory)
|
|
9
|
+
* with the plugin's `settings`
|
|
10
|
+
* 4. Returns the resulting `AnalyzePlugin` instance
|
|
11
|
+
*
|
|
12
|
+
* All plugins are loaded in parallel via `Promise.all` for performance.
|
|
13
|
+
*
|
|
14
|
+
* This function is called both in the main thread (for `headers` and `eachUrl`)
|
|
15
|
+
* and inside each Worker thread (for `eachPage`). The Worker-side call is
|
|
16
|
+
* necessary because plugin modules may not be transferable across threads.
|
|
17
|
+
* @param plugins - Array of plugin definitions from the resolved config.
|
|
18
|
+
* @returns Array of initialized `AnalyzePlugin` instances, in the same order.
|
|
19
|
+
* @throws {Error} If any plugin module name does not start with `@nitpicker/analyze-`.
|
|
20
|
+
* @see {@link ./types.ts} for the `PluginFactory` factory function signature
|
|
21
|
+
* @see {@link ./page-analysis-worker.ts} for Worker-side usage
|
|
22
|
+
* @see {@link ./nitpicker.ts!Nitpicker.analyze} for main-thread usage
|
|
23
|
+
*/
|
|
24
|
+
export declare function importModules(plugins: Plugin[]): Promise<AnalyzePlugin<string>[]>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowed prefix for analyze plugin module names.
|
|
3
|
+
* Only modules starting with this prefix are permitted to be dynamically imported.
|
|
4
|
+
*/
|
|
5
|
+
const ALLOWED_PREFIX = '@nitpicker/analyze-';
|
|
6
|
+
/**
|
|
7
|
+
* Dynamically imports and initializes all analyze plugin modules.
|
|
8
|
+
*
|
|
9
|
+
* For each plugin in the list:
|
|
10
|
+
* 1. Validates that `plugin.module` starts with `@nitpicker/analyze-`
|
|
11
|
+
* 2. Calls `import(plugin.module)` to load the npm package
|
|
12
|
+
* 3. Invokes the module's default export (a `PluginFactory` factory)
|
|
13
|
+
* with the plugin's `settings`
|
|
14
|
+
* 4. Returns the resulting `AnalyzePlugin` instance
|
|
15
|
+
*
|
|
16
|
+
* All plugins are loaded in parallel via `Promise.all` for performance.
|
|
17
|
+
*
|
|
18
|
+
* This function is called both in the main thread (for `headers` and `eachUrl`)
|
|
19
|
+
* and inside each Worker thread (for `eachPage`). The Worker-side call is
|
|
20
|
+
* necessary because plugin modules may not be transferable across threads.
|
|
21
|
+
* @param plugins - Array of plugin definitions from the resolved config.
|
|
22
|
+
* @returns Array of initialized `AnalyzePlugin` instances, in the same order.
|
|
23
|
+
* @throws {Error} If any plugin module name does not start with `@nitpicker/analyze-`.
|
|
24
|
+
* @see {@link ./types.ts} for the `PluginFactory` factory function signature
|
|
25
|
+
* @see {@link ./page-analysis-worker.ts} for Worker-side usage
|
|
26
|
+
* @see {@link ./nitpicker.ts!Nitpicker.analyze} for main-thread usage
|
|
27
|
+
*/
|
|
28
|
+
export async function importModules(plugins) {
|
|
29
|
+
const analyzeMods = await Promise.all(plugins.map(async (plugin) => {
|
|
30
|
+
if (!plugin.module.startsWith(ALLOWED_PREFIX)) {
|
|
31
|
+
throw new Error(`Unauthorized plugin module: "${plugin.module}". Plugin modules must start with "${ALLOWED_PREFIX}".`);
|
|
32
|
+
}
|
|
33
|
+
const mod = await import(plugin.module);
|
|
34
|
+
const factory = mod.default;
|
|
35
|
+
return factory(plugin.settings);
|
|
36
|
+
}));
|
|
37
|
+
return analyzeMods;
|
|
38
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED