dsh-plugin-toolkit 0.7.1 → 0.7.2
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 +13 -0
- package/lib/testkit/env.mjs +26 -7
- package/lib/testkit/mount.mjs +16 -11
- package/lib/verify.mjs +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 0.7.2
|
|
2
|
+
|
|
3
|
+
`verify` runs from npx's cache, so it has to find jsdom and React where the
|
|
4
|
+
plugin is, not where the tool is.
|
|
5
|
+
|
|
6
|
+
- `testkit` resolves `jsdom`, `react` and `react-dom` from the plugin folder
|
|
7
|
+
first, then the working directory, then the tool's own dependencies.
|
|
8
|
+
- `verify` passes the plugin folder through, so
|
|
9
|
+
`uses: WJDdidi-1/dsh-plugin-toolkit@v1` works in a workflow that ran `npm ci`
|
|
10
|
+
in the plugin: before this, the action failed with
|
|
11
|
+
`testkit needs a DOM: npm install --save-dev jsdom react react-dom` even
|
|
12
|
+
though the plugin declared them.
|
|
13
|
+
|
|
1
14
|
## 0.7.1
|
|
2
15
|
|
|
3
16
|
The action now checks the tarball, which is the only thing a user installs.
|
package/lib/testkit/env.mjs
CHANGED
|
@@ -6,15 +6,34 @@
|
|
|
6
6
|
* jsdom plus the real React gives us the same arrangement in Node, which is what
|
|
7
7
|
* makes panel behaviour assertable in CI instead of by hand.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolve a dependency the way the *plugin under test* would.
|
|
15
|
+
*
|
|
16
|
+
* `npx dsh-plugin-toolkit verify` installs the tool in npx's own cache, so a
|
|
17
|
+
* bare `import('jsdom')` looks there and not in the project that declared it.
|
|
18
|
+
* The plugin folder is the authority on what is installed.
|
|
19
|
+
*/
|
|
20
|
+
export function requireFrom(name, resolveFrom) {
|
|
21
|
+
const anchors = [resolveFrom, process.cwd(), path.dirname(fileURLToPath(import.meta.url))]
|
|
22
|
+
.filter((anchor) => typeof anchor === 'string' && anchor !== '');
|
|
23
|
+
for (const anchor of anchors) {
|
|
24
|
+
try {
|
|
25
|
+
return createRequire(path.join(anchor, 'noop.js'))(name);
|
|
26
|
+
} catch {
|
|
27
|
+
// Try the next place a dependency could legitimately live.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error(
|
|
31
|
+
`testkit needs ${name} where the plugin is installed: cd ${anchors[0]} && npm install --save-dev jsdom react react-dom`,
|
|
32
|
+
);
|
|
15
33
|
}
|
|
16
34
|
|
|
17
|
-
export function createDom({ html = '<!doctype html><html><body><div id="root"></div></body></html>' } = {}) {
|
|
35
|
+
export function createDom({ html = '<!doctype html><html><body><div id="root"></div></body></html>', resolveFrom } = {}) {
|
|
36
|
+
const { JSDOM, VirtualConsole } = requireFrom('jsdom', resolveFrom);
|
|
18
37
|
// jsdom's CSS parser predates nesting and `:has()`, so it complains about
|
|
19
38
|
// stylesheets it cannot parse. That is a jsdom limit, not a panel bug.
|
|
20
39
|
const virtualConsole = new VirtualConsole();
|
package/lib/testkit/mount.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The helpers are deliberately blunt — click, type, press — because that is the
|
|
5
5
|
* vocabulary a bug report uses. Anything cleverer hides which selector was hit.
|
|
6
6
|
*/
|
|
7
|
-
import { createDom, installGlobals } from './env.mjs';
|
|
7
|
+
import { createDom, installGlobals, requireFrom } from './env.mjs';
|
|
8
8
|
import { createHost } from './host.mjs';
|
|
9
9
|
import { loadBundle } from './load.mjs';
|
|
10
10
|
import { compare, write } from './snapshot.mjs';
|
|
@@ -37,24 +37,29 @@ export async function mountClient(options) {
|
|
|
37
37
|
container = 'root',
|
|
38
38
|
} = options;
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// React is resolved from the plugin's folder too: when the tool runs from
|
|
41
|
+
// npx's cache, its own dependencies are not the ones the panel was written
|
|
42
|
+
// against.
|
|
43
|
+
const resolveFrom = options.resolveFrom ?? process.cwd();
|
|
44
|
+
const need = (name) => requireFrom(name, resolveFrom);
|
|
45
|
+
|
|
46
|
+
const { dom, window, document } = createDom({ resolveFrom });
|
|
41
47
|
const restoreGlobals = installGlobals(window, document);
|
|
42
48
|
|
|
43
|
-
const
|
|
49
|
+
const React = need('react');
|
|
50
|
+
const reactDom = need('react-dom/client');
|
|
51
|
+
const jsxRuntime = need('react/jsx-runtime');
|
|
52
|
+
const jsxDevRuntime = (() => {
|
|
44
53
|
try {
|
|
45
|
-
return
|
|
54
|
+
return need('react/jsx-dev-runtime');
|
|
46
55
|
} catch {
|
|
47
|
-
|
|
56
|
+
return jsxRuntime;
|
|
48
57
|
}
|
|
49
|
-
};
|
|
50
|
-
const React = await need('react');
|
|
51
|
-
const reactDom = await need('react-dom/client');
|
|
52
|
-
const jsxRuntime = await need('react/jsx-runtime');
|
|
53
|
-
const jsxDevRuntime = await import('react/jsx-dev-runtime').catch(() => jsxRuntime);
|
|
58
|
+
})();
|
|
54
59
|
|
|
55
60
|
const modules = {
|
|
56
61
|
react: React.default ?? React,
|
|
57
|
-
'react-dom':
|
|
62
|
+
'react-dom': need('react-dom'),
|
|
58
63
|
'react-dom/client': reactDom.default ?? reactDom,
|
|
59
64
|
'react/jsx-runtime': jsxRuntime,
|
|
60
65
|
'react/jsx-dev-runtime': jsxDevRuntime,
|
package/lib/verify.mjs
CHANGED
|
@@ -121,7 +121,9 @@ export async function verify({ dir, mount = true }) {
|
|
|
121
121
|
}
|
|
122
122
|
try {
|
|
123
123
|
const { mountClient } = await import('./testkit/index.mjs');
|
|
124
|
-
|
|
124
|
+
// Resolve jsdom/React from the plugin's own folder: `verify` may be
|
|
125
|
+
// running out of npx's cache, whose dependencies are not the panel's.
|
|
126
|
+
const panel = await mountClient({ file: entryFile, resolveFrom: dir });
|
|
125
127
|
const text = panel.text();
|
|
126
128
|
await panel.unmount();
|
|
127
129
|
return { ok: true, stage: 'mount', failures: [], files: packed.files, size: packed.size, installed, text };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Preflight, release and test DeepSeek Harness plugins: checks what the host needs, waits for npm to actually serve the version, and keeps the market index honest.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|