Refactor(json schema): Optimize import map json schema

This commit is contained in:
2024-09-15 14:54:10 +08:00
parent fd4c3750fb
commit c557311dbc
6 changed files with 858 additions and 822 deletions

View File

@@ -124,13 +124,13 @@ class Compiler {
} }
} }
let path = importMap.imports[args.path] let path = importMap[args.path]
let tempPath = args.path let tempPath = args.path
while (!path && tempPath.includes('/')) { while (!path && tempPath.includes('/')) {
tempPath = tempPath.substring(0, tempPath.lastIndexOf('/')) tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'))
if (importMap.imports[tempPath]) { if (importMap[tempPath]) {
const suffix = args.path.replace(tempPath, '') const suffix = args.path.replace(tempPath, '')
const importUrl = new URL(importMap.imports[tempPath]) const importUrl = new URL(importMap[tempPath])
path = `${importUrl.origin}${importUrl.pathname}${suffix}${importUrl.search}` path = `${importUrl.origin}${importUrl.pathname}${suffix}${importUrl.search}`
} }
} }
@@ -139,7 +139,7 @@ class Compiler {
} }
const pathUrl = new URL(path) const pathUrl = new URL(path)
const externals = pathUrl.searchParams.get('external')?.split(',') ?? [] const externals = pathUrl.searchParams.get('external')?.split(',') ?? []
Object.keys(importMap.imports).forEach((item) => { Object.keys(importMap).forEach((item) => {
if (!(item in externals)) { if (!(item in externals)) {
externals.push(item) externals.push(item)
} }

View File

@@ -126,18 +126,12 @@ export const tsconfigJsonDiagnosticsOptions: DiagnosticsOptions = {
{ {
uri: 'tsconfig.json', uri: 'tsconfig.json',
fileMatch: ['tsconfig.json'], fileMatch: ['tsconfig.json'],
schema: { schema: tsconfigSchema
type: 'object',
properties: tsconfigSchema
}
}, },
{ {
uri: 'import-map.json', uri: 'import-map.json',
fileMatch: ['import-map.json'], fileMatch: ['import-map.json'],
schema: { schema: importMapSchema
type: 'object',
properties: importMapSchema
}
} }
] ]
} }

View File

@@ -1,6 +1,4 @@
{ {
"imports": {
"type": "object", "type": "object",
"description": "Import map" "additionalProperties": {"type": "string"}
}
} }

View File

@@ -34,7 +34,7 @@ const Playground = ({
try { try {
setImportMap(JSON.parse(importMapRaw) as IImportMap) setImportMap(JSON.parse(importMapRaw) as IImportMap)
} catch (e) { } catch (e) {
setImportMap({ imports: {} }) setImportMap({})
} }
} }
if (!tsconfig) { if (!tsconfig) {

View File

@@ -14,9 +14,7 @@ export interface IFiles {
[key: string]: IFile [key: string]: IFile
} }
export interface IImportMap { export type IImportMap = Record<string, string>
imports: Record<string, string>
}
export interface ITsconfig { export interface ITsconfig {
compilerOptions: CompilerOptions compilerOptions: CompilerOptions

File diff suppressed because it is too large Load Diff