Refactor(json schema): Optimize import map json schema

This commit is contained in:
2024-10-26 16:59:45 +08:00
parent bb1895762e
commit bab85382d4
6 changed files with 858 additions and 822 deletions

View File

@@ -125,13 +125,13 @@ class Compiler {
}
}
let path = importMap.imports[args.path]
let path = importMap[args.path]
let tempPath = args.path
while (!path && tempPath.includes('/')) {
tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'))
if (importMap.imports[tempPath]) {
if (importMap[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}`
}
}
@@ -140,7 +140,7 @@ class Compiler {
}
const pathUrl = new URL(path)
const externals = pathUrl.searchParams.get('external')?.split(',') ?? []
Object.keys(importMap.imports).forEach((item) => {
Object.keys(importMap).forEach((item) => {
if (!(item in externals)) {
externals.push(item)
}

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff