Skip to content

Commit

Permalink
refactor(typedef): init
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Nov 7, 2024
1 parent 288627a commit 986ff3d
Show file tree
Hide file tree
Showing 151 changed files with 5,246 additions and 8,838 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions nodedevpkg/vue-vite-presets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@innoai-tech/vue-vite-presets",
"version": "0.9.6",
"version": "0.10.0",
"monobundle": {
"pipeline": {
"test": false
Expand All @@ -15,13 +15,13 @@
"@innoai-tech/vuecomponentcompleter": "^0.1.3",
"@mapbox/rehype-prism": "^0.9.0",
"@mdx-js/rollup": "^3.1.0",
"@swc/core": "^1.7.39",
"@swc/core": "^1.8.0",
"@vitejs/plugin-vue": "^5.1.4",
"hastscript": "^9.0.0",
"unist-util-visit": "^5.0.0",
"vite": "^5.4.10",
"vite-plugin-pages": "^0.32.3",
"vite-tsconfig-paths": "^5.0.1"
"vite-tsconfig-paths": "^5.1.0"
},
"peerDependencies": {},
"exports": {
Expand Down
27 changes: 13 additions & 14 deletions nodedevpkg/vue-vite-presets/src/viteChunkSplit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { get, last, sum } from "@innoai-tech/lodash";
import {
type ManualChunkMeta,
type OutputOptions,
type PreRenderedChunk
type PreRenderedChunk,
} from "rollup";
import {
type FilterPattern,
type PluginOption,
createFilter,
searchForWorkspaceRoot
searchForWorkspaceRoot,
} from "vite";

export interface ChunkSplitOptions {
lib?: FilterPattern;
handleModuleFederations?: (
pkgRelations: Record<string, ModuleFederation>
pkgRelations: Record<string, ModuleFederation>,
) => void;
}

export const viteChunkSplit = (
options: ChunkSplitOptions = {}
options: ChunkSplitOptions = {},
): PluginOption => {
const viteRoot = searchForWorkspaceRoot(".");
const cs = new ChunkSplit(resolve(viteRoot), options);
Expand All @@ -42,7 +42,7 @@ export const viteChunkSplit = (
const chunkFileNames = get(
c.build.rollupOptions.output,
["chunkFileNames"],
`${assetsDir}/[name].[hash].chunk.js`
`${assetsDir}/[name].[hash].chunk.js`,
);

(c.build.rollupOptions.output as any) = {
Expand All @@ -58,14 +58,14 @@ export const viteChunkSplit = (

const name = cs.extractName(chunkInfo.moduleIds[0]!);
return `${assetsDir}/${name}.[hash].chunk.js`;
}
},
};
},
outputOptions(o) {
o.manualChunks = (id: string, meta: ManualChunkMeta) => {
return cs.chunkName(id, meta);
};
}
},
};
};

Expand All @@ -75,7 +75,7 @@ class ChunkSplit {

constructor(
private root: string,
private options: ChunkSplitOptions
private options: ChunkSplitOptions,
) {
this.isLib = createFilter(options.lib ?? []);

Expand Down Expand Up @@ -254,8 +254,7 @@ export class ModuleFederation {

#imported = new Map<string, ModuleFederation>();

constructor(public name: string) {
}
constructor(public name: string) {}

get federation() {
return this.#federation ?? this.name;
Expand Down Expand Up @@ -293,7 +292,7 @@ export class ModuleFederation {

sortedImported() {
return [...this.#imported.entries()].toSorted(([_a, a], [_b, b]) =>
a.rank > b.rank ? -1 : 1
a.rank > b.rank ? -1 : 1,
);
}

Expand All @@ -308,13 +307,13 @@ export class ModuleFederation {

const markPkgRelegation = (
moduleFederations: Record<string, ModuleFederation>,
directs: Record<string, boolean>
directs: Record<string, boolean>,
) => {
const federations: Record<string, boolean> = {};

const walkToNearestDirectFederationFrom = (
pkg: string,
visited: Map<string, boolean>
visited: Map<string, boolean>,
): string => {
// cycle avoid
if (visited.has(pkg)) {
Expand Down Expand Up @@ -352,7 +351,7 @@ const markPkgRelegation = (
};

export const d2Graph = (
moduleFederations: Record<string, ModuleFederation>
moduleFederations: Record<string, ModuleFederation>,
) => {
let g = "";

Expand Down
15 changes: 9 additions & 6 deletions nodedevpkg/vue-vite-presets/src/viteVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import vue from "@vitejs/plugin-vue";
import type { PluginOption } from "vite";
import vitePages, {
type PageResolver,
type PageOptions
type PageOptions,
} from "vite-plugin-pages";
import { mdx } from "./mdx";
import {
createPageMetaResolver,
viteVueComponentCompleter,
viteVueComponentHMR
viteVueComponentHMR,
} from "./vue";

export interface ViteReactOptions {
Expand Down Expand Up @@ -39,7 +39,10 @@ export const viteVue = (options: ViteReactOptions = {}): PluginOption[] => {

if (r.children) {
r.children = (r.children as any[]).toSorted((a, b) => {
if (a.component.endsWith("/index.tsx") || b.component.endsWith("/index.tsx")) {
if (
a.component.endsWith("/index.tsx") ||
b.component.endsWith("/index.tsx")
) {
if (a.component.endsWith("index.tsx")) {
return -1;
}
Expand All @@ -56,8 +59,8 @@ export const viteVue = (options: ViteReactOptions = {}): PluginOption[] => {
},
resolver: {
...r.pagesResolver,
...options.pagesResolver
}
}) as PluginOption
...options.pagesResolver,
},
}) as PluginOption,
];
};
3 changes: 2 additions & 1 deletion nodedevpkg/vue-vite-presets/src/vue/componentCompleter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Plugin, createFilter } from "vite";
import { createFilter, type Plugin } from "vite";
import { usePlugin } from "@innoai-tech/vuecomponentcompleter";
import { transform } from "@swc/core";

Expand Down Expand Up @@ -34,6 +34,7 @@ export const viteVueComponentCompleter = (
parser: {
syntax: "typescript",
tsx: true,
decorators: true,
},
experimental: {
disableBuiltinTransformsForInternalTesting: true,
Expand Down
14 changes: 7 additions & 7 deletions nodedevpkg/vue-vite-presets/src/vue/componentHMR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Module {
export const viteVueComponentHMR = (options: VueJsxHmrOptions = {}): Plugin => {
const filter = createFilter(
options.include || [/\.tsx$/, /\.mdx?$/],
options.exclude
options.exclude,
);

let hmrEnabled = false;
Expand All @@ -48,7 +48,7 @@ export const viteVueComponentHMR = (options: VueJsxHmrOptions = {}): Plugin => {
}

return null;
}
},
};
};

Expand Down Expand Up @@ -86,7 +86,7 @@ export const exportScanner = (id: string, filename = id) => {
scan(code: string): Module {
const ret = {
code: "",
exports: new Map<string, ModuleExport>()
exports: new Map<string, ModuleExport>(),
};
let src = code;
let m: RegExpMatchArray | null = null;
Expand All @@ -106,12 +106,12 @@ export const exportScanner = (id: string, filename = id) => {
exported !== "default"
? exported
: `c${upperFirst(
camelCase(`${basename(filename, extname(filename))}Default`)
)}`;
camelCase(`${basename(filename, extname(filename))}Default`),
)}`;

const range = {
start: m.index ?? 0,
length: m[0].length
length: m[0].length,
};

ret.exports.set(local, { exported, id: getHash(`${id}#${exported}`) });
Expand Down Expand Up @@ -142,6 +142,6 @@ export { ${nonDefaultExports.join(", ")} }
}

return ret;
}
},
};
};
42 changes: 21 additions & 21 deletions nodedevpkg/vue-vite-presets/src/vue/pageMetaResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ type RouteMetadata = {

export const extractRouteMeta = (
id: string,
jsdoc: string
jsdoc: string,
): RouteMetadata | undefined => {
let r:
| {
imports: Record<string, Record<string, boolean>>;
meta: Record<string, any>;
id: string;
}
imports: Record<string, Record<string, boolean>>;
meta: Record<string, any>;
id: string;
}
| undefined;

for (const m of jsdoc.matchAll(reProp)) {
Expand All @@ -30,14 +30,14 @@ export const extractRouteMeta = (

// Support import("@innoai-tech/vuematerial").mdiPlus
const importType = type.match(
/(typeof +)?import\(['"](?<importPath>[^)]+)['"]\)\.(?<name>.+)/
/(typeof +)?import\(['"](?<importPath>[^)]+)['"]\)\.(?<name>.+)/,
);

if (isUndefined(r)) {
r = {
imports: {} as Record<string, Record<string, boolean>>,
meta: {} as Record<string, any>,
id
id,
};
}

Expand All @@ -47,9 +47,9 @@ export const extractRouteMeta = (
[
"imports",
importType.groups?.["importPath"] ?? "",
importType.groups?.["name"] ?? ""
importType.groups?.["name"] ?? "",
],
true
true,
);
set(r, keyPath, importType.groups?.["name"] ?? "");
} else {
Expand Down Expand Up @@ -112,22 +112,22 @@ export const createPageMetaResolver = () => {
export default {
meta: {
${Object.keys(m.meta)
.map((k) => {
const name = m.meta[k];
if (nameOfImports[name]) {
return `${k}: () => import("${nameOfImports[name]}?exportAsDefault=${name}&id=~page-meta.ts")`;
}
return `${k}: ${name}`;
})
.join(",\n")}
.map((k) => {
const name = m.meta[k];
if (nameOfImports[name]) {
return `${k}: () => import("${nameOfImports[name]}?exportAsDefault=${name}&id=~page-meta.ts")`;
}
return `${k}: ${name}`;
})
.join(",\n")}
}
}`;
}

return "export default {}";
}
return null;
}
},
} as Plugin,
onRoutesGenerated: async (routes: VueRoute[]) => {
const imports = new Map<string, string>();
Expand Down Expand Up @@ -184,8 +184,8 @@ ${code}
return `Object.assign(${importName}, ${importName}${pageMetaLocalIdSuffix})`;
}
return importName;
}
}
}
},
},
},
};
};
3 changes: 2 additions & 1 deletion nodedevpkg/vuedevconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": false,
"experimentalDecorators": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -32,6 +31,8 @@
"checkJs": false,
"declaration": true,
"emitDeclarationOnly": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": false,
"jsx": "react-jsx",
"jsxImportSource": "@innoai-tech/vuekit"
}
Expand Down
6 changes: 0 additions & 6 deletions nodepkg/codemirror/.gitignore

This file was deleted.

Loading

0 comments on commit 986ff3d

Please sign in to comment.