@webority/canvas-kit 0.164.0 → 0.165.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/build.d.ts +5 -1
- package/dist/build.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/metaCheck.d.ts +1 -0
- package/dist/metaCheck.js +5 -4
- package/dist/metaCheckRunner.mjs +59 -0
- package/dist/metaRules.d.ts +3 -3
- package/dist/packageSizes.d.ts +10 -0
- package/dist/packageSizes.js +1 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Copyright (c) Webority Technologies. All rights reserved.
|
|
2
2
|
|
|
3
|
-
This software and its
|
|
3
|
+
This software and its Webority packages are the proprietary and confidential property
|
|
4
4
|
of Webority Technologies. They are published publicly only for the convenience of
|
|
5
5
|
Webority's own projects and internal consumption.
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ canvas-kit build --config canvas-kit.json --out dist/canvas-kit
|
|
|
12
12
|
canvas-kit build --config canvas-kit.json --out canvas-kit-release --style-keys <file>
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`--out` must not exist. A release folder is never overwritten, so build into a new folder. Any folder name works.
|
|
15
|
+
`--out` must not exist. A release folder is never overwritten, so build into a new folder. Any folder name works. The build prints the five largest packages in kit.js and fails when kit.js is over 20 MB, the Canvas publish limit, naming those packages.
|
|
16
16
|
|
|
17
17
|
The flags are:
|
|
18
18
|
|
package/dist/build.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readManifest } from "./manifest.ts";
|
|
2
|
+
import { type PackageSize } from "./packageSizes.ts";
|
|
2
3
|
import { digest } from "./release.ts";
|
|
3
4
|
type ManifestResult = Awaited<ReturnType<typeof readManifest>>;
|
|
4
5
|
type KitManifest = ManifestResult["manifest"];
|
|
@@ -18,6 +19,7 @@ export interface BuildKitReleaseOptions {
|
|
|
18
19
|
outDir: string;
|
|
19
20
|
styleKeysFile?: string | undefined;
|
|
20
21
|
phoneRendererSupportFile?: string | undefined;
|
|
22
|
+
maxKitBytes?: number | undefined;
|
|
21
23
|
}
|
|
22
24
|
export interface BuildKitReleaseResult {
|
|
23
25
|
outDir: string;
|
|
@@ -36,7 +38,9 @@ export interface BuildKitReleaseResult {
|
|
|
36
38
|
};
|
|
37
39
|
manifest: KitManifest;
|
|
38
40
|
warnings: ManifestResult["warnings"];
|
|
41
|
+
largestPackages: PackageSize[];
|
|
39
42
|
}
|
|
43
|
+
export declare const KIT_MAX_BYTES: number;
|
|
40
44
|
export declare function readConfig(configFile: string): KitConfig;
|
|
41
|
-
export declare function buildKitRelease({ configFile, outDir, styleKeysFile, phoneRendererSupportFile, }: BuildKitReleaseOptions): Promise<BuildKitReleaseResult>;
|
|
45
|
+
export declare function buildKitRelease({ configFile, outDir, styleKeysFile, phoneRendererSupportFile, maxKitBytes, }: BuildKitReleaseOptions): Promise<BuildKitReleaseResult>;
|
|
42
46
|
export {};
|
package/dist/build.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import{KIT_MODULE_EXTERNALS as r}from"./kitModule.js";import{libraryFiles as i,readManifest as a}from"./manifest.js";import{
|
|
2
|
-
`)}function
|
|
3
|
-
`);return{script:
|
|
1
|
+
import{findPackageDir as e,readJson as t,toPosix as n}from"./files.js";import{KIT_MODULE_EXTERNALS as r}from"./kitModule.js";import{libraryFiles as i,readManifest as a}from"./manifest.js";import{formatBytes as o,packageSizes as s}from"./packageSizes.js";import{digest as c,writeReleaseFolder as l}from"./release.js";import{existsSync as u,realpathSync as d}from"node:fs";import{dirname as f,join as p,resolve as m}from"node:path";import{fileURLToPath as h}from"node:url";import{build as g}from"vite";var _=19,v=[`react-redux`,`react-router-dom`,`axios`],y=[`kit`,`platform`,`libraryPackage`,`components`,`tokens`,`rolesFile`,`styles`,`rendererProtocolVersion`,`renames`],b=[`kit`,`platform`,`libraryPackage`,`components`,`tokens`,`rendererProtocolVersion`],x=20971520,S=`canvas-kit:entry`,C=`\0${S}`,w=p(f(h(import.meta.url)),`kitModule.js`),T={"process.env.NODE_ENV":JSON.stringify(`production`),"process.env":`{}`,__DEV__:`false`},E=/(?<![\w$."'`])(process\.env|__DEV__)(?![\w$])/;function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e,t,n){let r=t[n];if(typeof r!=`string`)throw Error(`${e}: ${n} must be a string.`);return r}function k(e,t,n){let r=t[n];if(r!==void 0&&typeof r!=`string`)throw Error(`${e}: ${n} must be a string path.`);return r}function A(e,t){if(t===void 0)return;if(!Array.isArray(t))throw Error(`${e}: styles must be a list of style file paths.`);let n=t,r=[];for(let t of n){if(typeof t!=`string`||t===``)throw Error(`${e}: styles must be a list of style file paths.`);r.push(t)}for(let t of r){if(!/\.(css|scss)$/.test(t))throw Error(`${e}: styles names ${t}, which is not a .css or .scss file.`);if(!u(m(f(e),t)))throw Error(`${e}: styles names ${t}, which does not exist.`)}return r}function j(e){let n=t(e);if(!D(n))throw Error(`${e} must be a JSON object.`);if(n.entry!==void 0)throw Error(`${e}: A kit lists its components with components, a glob of .meta.js files; entry is retired.`);for(let t of Object.keys(n))if(!y.includes(t))throw Error(`${e} has the unknown key ${t}. The keys are ${y.join(`, `)}.`);for(let t of b)if(n[t]===void 0)throw Error(`${e} needs the key ${t}.`);let r=O(e,n,`platform`);if(r!==`Web`&&r!==`Phone`)throw Error(`${e}: platform must be Web or Phone.`);let i=n.rendererProtocolVersion;if(typeof i!=`number`)throw Error(`${e}: rendererProtocolVersion must be a number.`);return{kit:O(e,n,`kit`),platform:r,libraryPackage:O(e,n,`libraryPackage`),components:O(e,n,`components`),tokens:O(e,n,`tokens`),rolesFile:k(e,n,`rolesFile`),styles:A(e,n.styles),rendererProtocolVersion:i,renames:k(e,n,`renames`)}}function M(e){let n=t(e);if(!D(n))throw Error(`${e} must be a JSON object.`);let r=n.version;if(r!==void 0&&typeof r!=`string`)throw Error(`${e}: version must be a string.`);return r}function N(t){let n=e(t,`react`);if(!n)throw Error(`react is not installed for ${t}. Run pnpm install there.`);let r=M(p(n,`package.json`));if(Number(String(r).split(`.`)[0])!==_)throw Error(`The product uses React ${r}; the Canvas renderer runs React ${_}. Pin react to ${_}.x and rebuild.`)}function P(e){let t=p(e,`package.json`),n=M(t);if(!n)throw Error(`${t} needs a version; the release is stamped with it.`);return n}function F({styleFiles:e,libraryFile:t,libraryPackage:r,chromeFile:i,manifest:a,libraryNames:o,chromeNames:s,productModules:c}){let l=[...c],u=[...o.map(({fixedProps:e})=>e),...l.map(([,{fixedProps:e}])=>e)].some(e=>e!==void 0),d=e.map(e=>`import ${JSON.stringify(n(e))};`);u&&d.push(`import { createElement } from "react";`),d.push(`import { ${u?`defineKit, withFixedProps`:`defineKit`} } from ${JSON.stringify(n(w))};`),l.forEach(([,{module:e,exportName:t}],r)=>{d.push(`import { ${t} as product${r} } from ${JSON.stringify(n(e))};`)});let f=a.platform===`Phone`,p=f&&r===`@webority/mobile-ui`,m=[...new Set(o.map(({exportName:e})=>e))];if(p&&!m.includes(`KitThemeBridge`)&&m.push(`KitThemeBridge`),m.length>0&&d.push(`import { ${m.join(`, `)} } from ${JSON.stringify(n(t))};`),s.length>0){if(i===null)throw Error(`canvas-kit: the kit names phone chrome entries but no chrome file.`);d.push(`import { ${s.join(`, `)} } from ${JSON.stringify(n(i))};`)}f&&!p&&d.push(`import { KitThemeBridge } from "@webority/mobile-ui";`);let h=(e,t,n)=>n===void 0?e===t?e:`${e}: ${t}`:`${e}: withFixedProps(createElement, ${t}, ${JSON.stringify(n)}, ${JSON.stringify(e)})`,g=[...o.map(({name:e,exportName:t,fixedProps:n})=>h(e,t,n)),...s,...l.map(([e,{fixedProps:t}],n)=>h(e,`product${n}`,t))],_=Object.fromEntries(a.components.filter(({marker:e})=>e!==null).map(({name:e,marker:t})=>[e,t])),v=f?`, themeBridge: KitThemeBridge`:``;return d.push(`export default defineKit({ components: { ${g.join(`, `)} }, markers: ${JSON.stringify(_)}, tokenValues: ${JSON.stringify(a.tokenValues)}, manifest: ${JSON.stringify(a)}${v} });`,``),d.join(`
|
|
2
|
+
`)}function I(e){return{name:`canvas-kit-entry`,resolveId(e){return e===S?C:null},load(t){return t===C?e:null}}}function L(e){let t=`${n(p(e,`src`,`services`))}/`;return{name:`canvas-kit-banned-imports`,transform(e,r){let i=n(r.split(`?`)[0]??``),a=v.find(e=>i.includes(`/node_modules/${e}/`));if(a)throw Error(`The kit imports ${a} (${i}). A kit draws from its props only; the container that renders it holds the state and the calls.`);if(i.startsWith(t))throw Error(`The kit imports ${i}, which is in src/services. A kit draws from its props only; move the call into the container.`);return null}}}async function R({root:e,kit:t,platform:n,styleFiles:i,libraryFile:a,libraryPackage:o,chromeFile:c,libraryNames:l,chromeNames:u,productModules:d,manifest:f}){let p=r[n],m=await g({configFile:!1,root:e,logLevel:`warn`,publicDir:!1,envDir:!1,define:T,plugins:[I(F({styleFiles:i,libraryFile:a,libraryPackage:o,chromeFile:c,manifest:f,libraryNames:l,chromeNames:u,productModules:d})),L(e)],esbuild:{jsx:`automatic`,jsxImportSource:`react`,include:/\.[cm]?[jt]sx?$/},build:{write:!1,minify:!0,target:`es2022`,cssCodeSplit:!1,lib:{entry:S,formats:[`es`],fileName:()=>`kit.js`},rollupOptions:{input:S,external:e=>p.some(t=>e===t||e.startsWith(`${t}/`)),output:{codeSplitting:!1,minify:!0,comments:{annotation:!1}}}}}),h=(Array.isArray(m)?m:[m]).flatMap(e=>{if(!(`output`in e))throw Error(`canvas-kit: vite build returned a watcher instead of its output.`);return e.output}),_=h.find(e=>e.type===`chunk`&&e.isEntry);if(_?.type!==`chunk`)throw Error(`The bundle of ${t} has no entry module.`);let v=s(_.modules).slice(0,5),y=E.exec(_.code);if(y)throw Error(`The bundle of ${t} still reads ${y[1]}, which the renderer does not define.`);let b=h.filter(e=>e.type===`chunk`&&!e.isEntry);if(b.length>0)throw Error(`The bundle of ${t} split ${b.map(e=>e.fileName).join(`, `)} out of kit.js; a kit must be one file.`);let x=h.flatMap(e=>e.type!==`asset`||!e.fileName.endsWith(`.css`)?[]:[typeof e.source==`string`?e.source:Buffer.from(e.source).toString(`utf8`)]).join(`
|
|
3
|
+
`);return{script:_.code,styles:x,largestPackages:v}}async function z({configFile:e,outDir:t,styleKeysFile:n,phoneRendererSupportFile:r,maxKitBytes:s=x}){let p=m(e),h=m(t);if(u(h))throw Error(`${h} already exists. A release folder is never overwritten; choose a new folder.`);let g=j(p),_=d(f(p));if(g.platform!==`Phone`&&r!==void 0)throw Error(`Only a Phone kit reads --phone-renderer-support; a Web kit takes no phone support file.`);N(_);let v=g.rolesFile===void 0?void 0:m(_,g.rolesFile),{manifest:y,warnings:b,phoneChromeNames:S,productModules:C}=await a({projectRoot:_,kit:g.kit,platform:g.platform,components:g.components,tokens:g.tokens,libraryPackage:g.libraryPackage,rolesFile:v,rendererProtocolVersion:g.rendererProtocolVersion,phoneRendererSupportFile:r===void 0?void 0:m(r),styleKeysFile:n===void 0?void 0:m(n),renamesDir:g.renames===void 0?void 0:m(_,g.renames)}),w=i(_,g.libraryPackage),T=P(_),E=y.components.filter(({source:e,name:t})=>e===g.libraryPackage&&!S.includes(t)).map(({name:e,component:t,fixedProps:n})=>({name:e,exportName:t??e,...n===void 0?{}:{fixedProps:n}})),{script:D,styles:O,largestPackages:k}=await R({root:_,kit:g.kit,platform:g.platform,styleFiles:(g.styles??[]).map(e=>m(_,e)),libraryFile:w.entryFile,libraryPackage:g.libraryPackage,chromeFile:w.canvasKitFile,libraryNames:E,chromeNames:S,productModules:C,manifest:y}),A=Buffer.byteLength(D);if(A>s)throw Error(`kit.js of ${g.kit} is ${o(A)}, over the ${o(s)} Canvas publish limit. Largest packages: ${k.map(e=>`${e.name} ${o(e.bytes)}`).join(`, `)}.`);let M={"manifest.json":`${JSON.stringify(y,null,2)}\n`,"kit.js":D,"kit.css":O},F={name:g.kit,version:T,platform:g.platform,kitModuleVersion:2,rendererProtocolVersion:g.rendererProtocolVersion,library:y.library,files:{"manifest.json":c(M[`manifest.json`]),"kit.js":c(M[`kit.js`]),"kit.css":c(M[`kit.css`])}};return l(h,M,F),{outDir:h,release:F,manifest:y,warnings:b,largestPackages:k}}export{x as KIT_MAX_BYTES,z as buildKitRelease,j as readConfig};
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{buildKitRelease as e}from"./build.js";import{writeGuidance as t}from"./guidance.js";import{proposeCanvasKeys as n}from"./ids.js";import{
|
|
2
|
+
import{buildKitRelease as e}from"./build.js";import{writeGuidance as t}from"./guidance.js";import{proposeCanvasKeys as n}from"./ids.js";import{formatBytes as r}from"./packageSizes.js";import{resolve as i}from"node:path";var a=`Usage: canvas-kit build --config <file> --out <dir> [--style-keys <file>] [--phone-renderer-support <file>]
|
|
3
3
|
canvas-kit guidance --config <file> --out <file>
|
|
4
4
|
canvas-kit ids <folder> [--write] proposes Canvas keys for list items, named blocks and conditional siblings; --write writes them.
|
|
5
5
|
|
|
@@ -8,4 +8,4 @@ build: builds a kit release into <dir>: kit.js, kit.css, manifest.json and relea
|
|
|
8
8
|
--style-keys: the style key table the renderer draws from. Optional.
|
|
9
9
|
--phone-renderer-support: the phone renderer's support file. A Phone product kit needs it; a phone library's own kit release builds without it.
|
|
10
10
|
guidance: writes the usage guidance of every component the config's components glob lists to <file> (webority-guidance/1), replacing it.
|
|
11
|
-
Flag paths are relative to the working directory; the paths in the config are relative to the config file.`,
|
|
11
|
+
Flag paths are relative to the working directory; the paths in the config are relative to the config file.`,o=new Set([`--config`,`--out`,`--style-keys`,`--phone-renderer-support`]);function s(e){return e.command===`ids`}function c(e){if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return{help:!0};let[t,...n]=e;if(t===`ids`){let e,r=!1;for(let t of n)if(t===`--write`)r=!0;else if(e===void 0&&!t.startsWith(`--`))e=t;else throw Error(`Unknown argument ${t}.`);return{command:t,options:{folder:e,write:r}}}let r={};for(let e=0;e<n.length;e+=1){let t=n[e];if(t===void 0||!o.has(t))throw Error(`Unknown argument ${t}.`);let i=n[e+1];if(i===void 0||i.startsWith(`--`))throw Error(`${t} needs a value.`);r[t.slice(2)]=i,e+=1}return{command:t,options:r}}async function l(o){let l=c(o);if(l.help){process.stdout.write(`${a}\n`);return}if(l.command!==`build`&&l.command!==`guidance`&&l.command!==`ids`)throw Error(`Unknown command ${l.command}. The commands are build, guidance and ids.`);if(s(l)){if(l.options.folder===void 0)throw Error(`ids needs a folder.`);let e=await n(i(l.options.folder),{write:l.options.write});for(let t of e.proposals)process.stdout.write(`${t.file}:${t.line} ${t.element} ${t.key}\n`);for(let t of e.noKey)process.stdout.write(`${t.file}:${t.line} ${t.element} no record key\n`);process.stdout.write(`${e.proposals.length} keys proposed, ${e.written} written, ${e.noKey.length} list items have no record key.\n`);return}if(l.command===`guidance`){if(!l.options.config||!l.options.out)throw Error(`guidance needs --config and --out.`);if(l.options[`style-keys`]!==void 0||l.options[`phone-renderer-support`]!==void 0)throw Error(`guidance takes only --config and --out.`);let e=await t({configFile:i(l.options.config),outFile:i(l.options.out)});process.stdout.write(`Guidance for ${e.components.length} components written to ${i(l.options.out)}.\n`);return}if(!l.options.config||!l.options.out)throw Error(`build needs --config and --out.`);let u=l.options[`style-keys`],d=l.options[`phone-renderer-support`],f=await e({configFile:i(l.options.config),outDir:i(l.options.out),styleKeysFile:u===void 0?void 0:i(u),phoneRendererSupportFile:d===void 0?void 0:i(d)});for(let e of f.warnings)process.stderr.write(`warning: ${e}\n`);process.stdout.write(`Largest packages in kit.js: ${f.largestPackages.map(e=>`${e.name} ${r(e.bytes)}`).join(`, `)}.\n`),process.stdout.write(`Built ${f.release.name} (${f.release.platform}): ${f.manifest.components.length} components. Release written to ${f.outDir}.\n`)}l(process.argv.slice(2)).catch(e=>{process.stderr.write(`canvas-kit: ${e.message}\n`),process.exitCode=1});export{};
|
package/dist/metaCheck.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MetaEntry } from "./metas.ts";
|
|
2
2
|
export declare const TSC: string;
|
|
3
3
|
export declare function specifierOf(file: string): string;
|
|
4
|
+
export declare function removeDeadCheckFolders(modulesDir: string): string[];
|
|
4
5
|
export declare function checkMetaTypes({ root, metas, componentOf, }: {
|
|
5
6
|
root: string;
|
|
6
7
|
metas: MetaEntry[];
|
package/dist/metaCheck.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import{toPosix as e}from"./files.js";import{createRequire as t}from"node:module";import{mkdirSync as n,
|
|
2
|
-
`)}\n`)
|
|
3
|
-
`)
|
|
4
|
-
`))
|
|
1
|
+
import{toPosix as e}from"./files.js";import{createRequire as t}from"node:module";import{mkdirSync as n,readdirSync as r,realpathSync as i,rmSync as a,writeFileSync as o}from"node:fs";import{dirname as s,join as c}from"node:path";import{fileURLToPath as l}from"node:url";import{execFileSync as u}from"node:child_process";import{availableParallelism as d}from"node:os";var f=c(s(t(import.meta.url).resolve(`typescript/package.json`)),`bin`,`tsc`),p=c(s(l(import.meta.url)),`metaRules`),m=c(s(l(import.meta.url)),`metaCheckRunner.mjs`),h=20,g=Math.max(1,Math.min(4,d())),_=/^check\.ts\((\d+),\d+\): error TS\d+: (.*)$/,v=/^(.+?)\(\d+,\d+\): error TS\d+: (.*)$/,y=[`propsNotInMeta`,`metaPropsNotOnComponent`,`propsThatDiffer`,`children`,`fixedProps`],b={propsNotInMeta:`props the component takes that the meta does not list`,metaPropsNotOnComponent:`props the meta lists that the component does not take`,propsThatDiffer:`props whose type, required or nullable flag, or nested fields differ from the component`,fixedProps:`fixed props whose value does not fit the component's prop`};function x(e){return Object.hasOwn(b,e)}function S(e){return E(e)&&typeof e.status==`number`&&typeof e.output==`string`}function C(t){let n=e(t);return/\.d\.ts$/.test(n)?n.replace(/\.d\.ts$/,``):n.replace(/\.(jsx|tsx|js|ts|mjs)$/,``)}function w(e){let t=[];for(let n of e.split(/\r?\n/)){let e=_.exec(n);if(e){t.push({line:Number(e[1]),file:null,message:e[2]??``});continue}let r=v.exec(n);r&&t.push({line:null,file:r[1]??null,message:r[2]??``})}return t}function T(e){let t=/Type '(\{[^']*\})'/.exec(e);return t?[...(t[1]??``).matchAll(/: "([^"]+)"/g)].map(e=>e[1]??``):[]}function E(e){return typeof e==`object`&&!!e}function D(e){let t=new Map,n=(e,n,r,i)=>{let a=`${e} ${n}`;t.has(a)||t.set(a,{component:e,handler:n,path:r,owner:i})},r=(e,t,i)=>{if(!E(e))return;let a=e.handlers??[];if(!Array.isArray(a))throw Error(`handlerPairs: the handlers at ${t} are not a list`);for(let r of a)n(String(e.component),String(r),t,i);Array.isArray(e.children)&&e.children.forEach((e,n)=>{r(e,`${t}.children[${n}]`,i)})};return e.forEach(({meta:e},t)=>{(e.examples??[]).forEach((i,a)=>{let o=`examples[${a}]`;for(let r of i.handlers??[])n(e.name,r,o,t);r({children:i.children},o,t),r(i.wrap,`${o}.wrap`,t)});for(let r of Object.keys(e.actions??{}))n(e.name,r,`actions.${r}`,t);for(let n of[`do`,`dont`])(e.usage?.[n]??[]).forEach((e,i)=>{(e.example??[]).forEach((e,a)=>{r(e,`usage.${n}[${i}].example[${a}]`,t)})})}),t}function O(e){let t=``;return typeof e==`object`&&e&&`stdout`in e&&(t+=String(e.stdout??``)),typeof e==`object`&&e&&`stderr`in e&&(t+=String(e.stderr??``)),t}var k=/^\.canvas-kit-check-(\d+)$/;function A(e){return typeof e==`object`&&e&&`code`in e?e.code:void 0}function j(e){try{return process.kill(e,0),!0}catch(e){if(A(e)===`EPERM`)return!0;if(A(e)===`ESRCH`)return!1;throw e}}function M(e){let t;try{t=r(e)}catch(e){if(A(e)===`ENOENT`)return[];throw e}let n=[];for(let r of t){let t=Number(k.exec(r)?.[1]);t&&t!==process.pid&&!j(t)&&(a(c(e,r),{recursive:!0,force:!0}),n.push(r))}return n}function N(){return{lines:[`import type { ExtraProps, MissingProps, MismatchedProps, ChildrenOk, HandlerKeys, Flatten } from "${e(p)}";`,`type N = import("react").ReactNode;`,`type D = { "html attributes": import("react").AllHTMLAttributes<HTMLElement>; "svg attributes": import("react").SVGAttributes<SVGElement> } & import("react").JSX.IntrinsicElements;`,`type Empty = { [key: string]: never };`],owners:new Map,kinds:new Map,handlerLines:new Map}}function P(e,t,n=-1,r=null){e.lines.push(t);let i=e.lines.length;n>=0&&e.owners.set(i,n),r&&e.kinds.set(i,r)}function F({root:t,metas:r,componentOf:s}){let l=c(i(t),`node_modules`);M(l);let d=c(l,`.canvas-kit-check-${process.pid}`);try{n(d,{recursive:!0});let t=r.map(({meta:e,file:t})=>({component:C(s(t,e.component??e.name)),meta:C(t)})),i=new Map;for(let e=0;e<Math.ceil(r.length/h);e+=1)i.set(e,N());let a=e=>{let t=i.get(Math.floor(e/h));if(!t)throw Error(`checkMetaTypes: no chunk holds meta ${e}`);return t};r.forEach((e,n)=>{let r=a(n);P(r,`import type * as C${n} from "${t[n]?.component}";`,n),P(r,`import type { meta as M${n} } from "${t[n]?.meta}";`,n)});let l=e=>`{ [K in ${e}]: K }`;r.forEach(({meta:e},t)=>{let n=a(t),r=(e,r=null)=>P(n,e,t,r),i=e.name;r(`type P${t} = Flatten<import("react").ComponentProps<typeof C${t}.${e.component??e.name}>>;`),r(`export const ${i}__propsNotInMeta: Empty = null as unknown as ${l(`ExtraProps<P${t}, typeof M${t}, D>`)};`,`propsNotInMeta`),r(`export const ${i}__metaPropsNotOnComponent: Empty = null as unknown as ${l(`MissingProps<P${t}, typeof M${t}>`)};`,`metaPropsNotOnComponent`),r(`export const ${i}__propsThatDiffer: Empty = null as unknown as ${l(`MismatchedProps<P${t}, typeof M${t}, N>`)};`,`propsThatDiffer`),r(`export const ${i}__children: true = null as unknown as ChildrenOk<P${t}, typeof M${t}, D>;`,`children`),e.fixedProps!==void 0&&r(`export const ${i}__fixedProps: Partial<P${t}> = null as unknown as NonNullable<(typeof M${t})["fixedProps"]>;`,`fixedProps`)});let p=new Map(r.map(({meta:e},t)=>[e.name,t])),_=0;for(let{component:t,handler:n,path:i,owner:o}of D(r).values()){let s=p.get(t);if(s===void 0)continue;_+=1;let c=a(s);P(c,`export const ${t.replace(/[^A-Za-z0-9_]/g,`_`)}__handler_${n}_${_}: Empty = null as unknown as { [K in Exclude<"${n}", HandlerKeys<P${s}>>]: K };`),c.handlerLines.set(c.lines.length,{owner:o,where:`${e(r[o]?.file??``)}: ${i}`,component:t,handler:n})}let v=[];for(let[e,t]of i){let r=c(d,`chunk-${e}`);n(r),o(c(r,`check.ts`),`${t.lines.join(`
|
|
2
|
+
`)}\n`);let i=c(r,`tsconfig.json`);o(i,JSON.stringify({compilerOptions:{strict:!0,noEmit:!0,allowJs:!0,checkJs:!1,jsx:`react-jsx`,module:`esnext`,moduleResolution:`bundler`,allowImportingTsExtensions:!0,target:`es2022`,skipLibCheck:!0,noErrorTruncation:!0,types:[]},files:[`check.ts`]},null,2)),v.push(i)}let E;try{E=u(process.execPath,[m,f,String(g),...v],{encoding:`utf8`,stdio:`pipe`,maxBuffer:268435456,windowsHide:!0})}catch(e){throw Error(`checkMetaTypes: the type check runner failed: ${O(e)}`)}let k=JSON.parse(E);if(!Array.isArray(k)||!k.every(S)||k.length!==i.size)throw Error(`checkMetaTypes: the type check runner did not answer with one result per chunk: ${E}`);let A=k;if(A.every(e=>e.status===0))return;let j=new Map,M=[],F=[],I=(n,i)=>{for(let a of w(n)){let n=a.line===null?void 0:i.handlerLines.get(a.line);if(n){M.push({owner:n.owner,rank:y.length,text:`${n.where}: "${n.handler}" is not a function prop of ${n.component}`});continue}let o=a.line===null?void 0:i.owners.get(a.line),s=a.line===null?void 0:i.kinds.get(a.line);if(s&&o!==void 0){let e=`${o}:${s}`;if(j.has(e)||j.set(e,{owner:o,kind:s,names:new Set}),s!==`children`)for(let t of T(a.message))j.get(e)?.names.add(t);continue}let c=o??t.findIndex(e=>[a.file,a.message].some(t=>t&&(t.includes(e.component)||t.includes(e.meta)))),l=a.line===null?`${e(a.file??``)}: `:``;M.push({owner:c,rank:-1,text:`${c>=0?r[c]?.meta.name:`metaCheck`}: tsc could not read the check file: ${l}${a.message}`})}};for(let[e,t]of i){let n=A[e];if(!n)throw Error(`checkMetaTypes: the type check runner gave no result for chunk ${e}`);n.status!==0&&(F.push(n.output),I(n.output,t))}for(let{owner:e,kind:t,names:n}of j.values()){let i=r[e];if(!i)throw Error(`checkMetaTypes: no meta at index ${e} to report on`);let{meta:a}=i,o;if(t===`children`)o=`${a.name}: acceptsChildren is ${a.acceptsChildren} but the component ${a.acceptsChildren?`does not take`:`takes`} children`;else{if(!x(t))throw Error(`metaCheck: no sentence for finding kind ${t}`);o=n.size>0?`${a.name}: ${b[t]}: ${[...n].sort().join(`, `)}`:`${a.name}: ${b[t]}: see the meta against the component's props`}M.push({owner:e,rank:y.indexOf(t),text:o})}throw M.length===0?Error(`metaCheck: tsc failed: ${F.join(`
|
|
3
|
+
`).split(/\r?\n/).slice(0,20).join(`
|
|
4
|
+
`)}`):(M.sort((e,t)=>e.owner-t.owner||e.rank-t.rank),Error(M.map(e=>e.text).join(`
|
|
5
|
+
`)))}finally{a(d,{recursive:!0,force:!0})}}export{f as TSC,F as checkMetaTypes,M as removeDeadCheckFolders,C as specifierOf};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Runs tsc on each meta check chunk, a few at a time, and prints one { status, output } per chunk as JSON on stdout.
|
|
2
|
+
// A tsc that exits non-zero is a finding, not a failure of the runner; a tsc that cannot start is.
|
|
3
|
+
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
|
|
7
|
+
const MAX_BUFFER = 64 * 1024 * 1024;
|
|
8
|
+
const [tsc, concurrencyText, ...tsconfigs] = process.argv.slice(2);
|
|
9
|
+
const concurrency = Number(concurrencyText);
|
|
10
|
+
let failure = null;
|
|
11
|
+
|
|
12
|
+
function runTsc(tsconfig) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
execFile(
|
|
15
|
+
process.execPath,
|
|
16
|
+
[tsc, "-p", tsconfig, "--pretty", "false"],
|
|
17
|
+
{ cwd: dirname(tsconfig), encoding: "utf8", maxBuffer: MAX_BUFFER, windowsHide: true },
|
|
18
|
+
(error, stdout, stderr) => {
|
|
19
|
+
const output = `${stdout}${stderr}`;
|
|
20
|
+
if (error === null) {
|
|
21
|
+
resolve({ status: 0, output });
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (typeof error.code === "number") {
|
|
25
|
+
resolve({ status: error.code, output });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
failure = failure ?? `metaCheckRunner: could not run tsc on ${tsconfig}: ${error.code ?? error.message}`;
|
|
29
|
+
resolve(null);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function main() {
|
|
36
|
+
if (!tsc || !Number.isInteger(concurrency) || concurrency < 1) {
|
|
37
|
+
process.stderr.write("metaCheckRunner: usage: metaCheckRunner.mjs <tsc> <concurrency> <tsconfig>...\n");
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const results = new Array(tsconfigs.length).fill(null);
|
|
42
|
+
let next = 0;
|
|
43
|
+
const worker = async () => {
|
|
44
|
+
while (next < tsconfigs.length) {
|
|
45
|
+
const index = next;
|
|
46
|
+
next += 1;
|
|
47
|
+
results[index] = await runTsc(tsconfigs[index]);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, tsconfigs.length) }, worker));
|
|
51
|
+
if (failure !== null) {
|
|
52
|
+
process.stderr.write(`${failure}\n`);
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
process.stdout.write(`${JSON.stringify(results)}\n`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await main();
|
package/dist/metaRules.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ type Handler = (...args: never[]) => unknown;
|
|
|
5
5
|
type Constructor = abstract new (...args: never[]) => unknown;
|
|
6
6
|
type Defined<T> = Exclude<T, null | undefined>;
|
|
7
7
|
type Shape = Readonly<Record<string, MetaProp>>;
|
|
8
|
-
/** Every field a design sets at any depth: all but event handlers and component-typed fields. */
|
|
8
|
+
/** Every field a design sets at any depth: all but data-* attributes, event handlers and component-typed fields. */
|
|
9
9
|
type FieldKeys<P> = {
|
|
10
|
-
[K in keyof P]-?: IsAny<P[K]> extends true ? K : [Defined<P[K]>] extends [Handler] ? never : [Extract<Defined<P[K]>, Constructor>] extends [never] ? K : never;
|
|
10
|
+
[K in keyof P]-?: K extends `data-${string}` ? never : IsAny<P[K]> extends true ? K : [Defined<P[K]>] extends [Handler] ? never : [Extract<Defined<P[K]>, Constructor>] extends [never] ? K : never;
|
|
11
11
|
}[keyof P] & string;
|
|
12
12
|
/** Every prop a design sets: the field keys, less React's children, ref and key (a nested data field may be named key). */
|
|
13
13
|
export type DesignKeys<P> = Exclude<FieldKeys<P>, "children" | "ref" | "key">;
|
|
@@ -18,7 +18,7 @@ export type HandlerKeys<P> = {
|
|
|
18
18
|
type RequiredKeys<P> = {
|
|
19
19
|
[K in keyof P]-?: Partial<Pick<P, K>> extends Pick<P, K> ? never : K;
|
|
20
20
|
}[keyof P];
|
|
21
|
-
type ItemOf<T> = Defined<T> extends readonly (infer I)[] ? I : Defined<T> extends ReadonlySet<infer I> ? I : never
|
|
21
|
+
type ItemOf<T> = Exclude<Defined<T> extends readonly (infer I)[] ? I : Defined<T> extends ReadonlySet<infer I> ? I : never, false | null | undefined>;
|
|
22
22
|
type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
23
23
|
type ValueIn<T, K extends PropertyKey> = T extends unknown ? (K extends keyof T ? T[K] : undefined) : never;
|
|
24
24
|
type RequiredInEvery<T, K extends PropertyKey> = [T extends unknown ? (K extends RequiredKeys<T> ? never : 1) : never] extends [never] ? K : never;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface PackageSize {
|
|
2
|
+
name: string;
|
|
3
|
+
bytes: number;
|
|
4
|
+
}
|
|
5
|
+
/** The rendered length of every module of a chunk, summed by package and sorted largest first. */
|
|
6
|
+
export declare function packageSizes(modules: Readonly<Record<string, {
|
|
7
|
+
renderedLength: number;
|
|
8
|
+
}>>): PackageSize[];
|
|
9
|
+
/** "11.2 MB", "840.0 kB" or "12 B". */
|
|
10
|
+
export declare function formatBytes(bytes: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isRecord as e,toPosix as t}from"./files.js";import{existsSync as n,readFileSync as r}from"node:fs";import{dirname as i,join as a}from"node:path";var o=`/node_modules/`,s=`(kit entry)`,c=`(unnamed)`;function l(l,u){let d=t(l.split(`?`)[0]??``);if(d.startsWith(`\0`)||!d.startsWith(`/`)&&!/^[A-Za-z]:\//.test(d))return s;let f=d.lastIndexOf(o);if(f!==-1){let e=d.slice(f+14).split(`/`);return e[0]?.startsWith(`@`)?e.slice(0,2).join(`/`):e[0]??c}let p=i(d);for(;;){let t=u.get(p);if(t!==void 0)return t;let o=a(p,`package.json`);if(n(o)){let t=JSON.parse(r(o,`utf8`)),n=e(t)&&typeof t.name==`string`?t.name:c;return u.set(p,n),n}let s=i(p);if(s===p)return c;p=s}}function u(e){let t=new Map,n=new Map;for(let[r,{renderedLength:i}]of Object.entries(e)){let e=l(r,t);n.set(e,(n.get(e)??0)+i)}return[...n].map(([e,t])=>({name:e,bytes:t})).sort((e,t)=>t.bytes-e.bytes||(e.name<t.name?-1:1))}function d(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} kB`:`${e} B`}export{d as formatBytes,u as packageSizes};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/canvas-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.165.0",
|
|
4
4
|
"description": "Builds product kits for Webority Canvas: a kit bundle, its manifest, and the spec shape the renderers answer.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"private": false,
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@babel/types": "7.29.8",
|
|
49
49
|
"@types/babel__core": "7.20.5",
|
|
50
50
|
"@types/node": "25.6.0",
|
|
51
|
-
"@webority/biome-config": "0.
|
|
51
|
+
"@webority/biome-config": "0.165.0",
|
|
52
52
|
"react": "^19.3.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|