@norskvideo/ctl-sdk 0.1.0 → 0.1.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/frontend-spec.d.ts +17 -0
- package/frontend-spec.js +53 -0
- package/package.json +5 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ways a frontend's `index.css` drifts from deferring to the shared base. Empty
|
|
3
|
+
* means compliant. Each string is human-readable for a test failure message.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stylingViolations(indexCss: string): string[];
|
|
6
|
+
/** The sdk's vendored fonts directory, located relative to this module so it
|
|
7
|
+
* resolves whether the sdk is a workspace sibling or an installed dependency —
|
|
8
|
+
* the product no longer has to guess a `packages/sdk` monorepo path. */
|
|
9
|
+
export declare function sharedFontsDir(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a Vite dev server's `server.fs.allow` reaches the shared fonts. base.css
|
|
12
|
+
* lives outside a product's own Vite root, so without an allow entry covering it
|
|
13
|
+
* the dev server 403s the sibling font and the browser silently falls back to a
|
|
14
|
+
* system font (the guide-screenshot mismatch). True iff some allow base is an
|
|
15
|
+
* ancestor of the fonts dir. Allow bases that don't resolve are ignored.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fsAllowCoversFonts(allow: readonly string[]): boolean;
|
package/frontend-spec.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The shared styling-deference contract for product frontends: an app states no
|
|
2
|
+
// styling opinion of its own beyond embed-specific rules — font, theme tokens and
|
|
3
|
+
// resets all come from @norskvideo/ctl-sdk/base.css, whose @font-face url()s
|
|
4
|
+
// resolve to the fonts vendored here. Three products carried a byte-identical
|
|
5
|
+
// theme.test.ts asserting this; the judgment (what counts as drift, where the
|
|
6
|
+
// shared fonts live) is centralised here so a fourth product can't fork it. The
|
|
7
|
+
// vitest wrapper stays in each product's own theme.test.ts — it reads that
|
|
8
|
+
// product's index.css and resolves that product's vite config — but delegates
|
|
9
|
+
// every assertion to these pure helpers.
|
|
10
|
+
import { realpathSync } from "node:fs";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
const BASE_IMPORT = /@import\s+["']@norskvideo\/ctl-sdk\/base\.css["']/;
|
|
14
|
+
/**
|
|
15
|
+
* Ways a frontend's `index.css` drifts from deferring to the shared base. Empty
|
|
16
|
+
* means compliant. Each string is human-readable for a test failure message.
|
|
17
|
+
*/
|
|
18
|
+
export function stylingViolations(indexCss) {
|
|
19
|
+
const out = [];
|
|
20
|
+
if (!BASE_IMPORT.test(indexCss))
|
|
21
|
+
out.push("does not @import @norskvideo/ctl-sdk/base.css");
|
|
22
|
+
if (/@font-face/.test(indexCss))
|
|
23
|
+
out.push("declares a local @font-face (fonts belong to the shared base)");
|
|
24
|
+
if (/--font-sans/.test(indexCss))
|
|
25
|
+
out.push("declares a local --font-sans (font tokens belong to the shared base)");
|
|
26
|
+
if (/fonts\.(googleapis|gstatic)\.com/.test(indexCss))
|
|
27
|
+
out.push("pulls a font from a CDN instead of the shared base");
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/** The sdk's vendored fonts directory, located relative to this module so it
|
|
31
|
+
* resolves whether the sdk is a workspace sibling or an installed dependency —
|
|
32
|
+
* the product no longer has to guess a `packages/sdk` monorepo path. */
|
|
33
|
+
export function sharedFontsDir() {
|
|
34
|
+
return realpathSync(join(dirname(fileURLToPath(import.meta.url)), "fonts"));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a Vite dev server's `server.fs.allow` reaches the shared fonts. base.css
|
|
38
|
+
* lives outside a product's own Vite root, so without an allow entry covering it
|
|
39
|
+
* the dev server 403s the sibling font and the browser silently falls back to a
|
|
40
|
+
* system font (the guide-screenshot mismatch). True iff some allow base is an
|
|
41
|
+
* ancestor of the fonts dir. Allow bases that don't resolve are ignored.
|
|
42
|
+
*/
|
|
43
|
+
export function fsAllowCoversFonts(allow) {
|
|
44
|
+
const fonts = sharedFontsDir();
|
|
45
|
+
return allow.some((base) => {
|
|
46
|
+
try {
|
|
47
|
+
return fonts.startsWith(realpathSync(base));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@norskvideo/ctl-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"types": "./components/index.d.ts",
|
|
16
16
|
"default": "./components/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./frontend-spec": {
|
|
19
|
+
"types": "./frontend-spec.d.ts",
|
|
20
|
+
"default": "./frontend-spec.js"
|
|
21
|
+
},
|
|
18
22
|
"./manifest-seed": {
|
|
19
23
|
"types": "./manifest-seed.d.ts",
|
|
20
24
|
"default": "./manifest-seed.js"
|